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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
419/A
|
420
|
A
|
Python 3
|
TESTS
| 48 | 62 | 307,200 |
105117901
|
a = "AHIMNOUYTXWV"
b = True
c = input()
for x in c:
if x not in a:
b = False
break
else:
if c[::-1] != c:
b = False
if b == True:
print("YES")
else:
print("NO")
| 80 | 46 | 0 |
173252354
|
name = input()
valid_letters = "AHIMOTUVWXY"
for i in name:
if not i in valid_letters:
print('NO')
exit()
reverted_name = name[::-1]
if not reverted_name == name:
print('NO')
exit()
print('YES')
|
Coder-Strike 2014 - Finals
|
CF
| 2,014 | 1 | 256 |
Start Up
|
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
|
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
| null | null |
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
| 1,000 |
[]
| 80 |
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
419/A
|
420
|
A
|
Python 3
|
TESTS
| 48 | 46 | 204,800 |
173256106
|
if __name__ == "__main__":
execao = ["B","C","D","E","F","G","J","K","L","P","Q","R","S","Z"]
palavra = input()
reverso = palavra[::-1]
reversivel = True
for x in execao:
if x in palavra:
reversivel = False
break
if reversivel and palavra == reverso:
print("YES")
else:
print("NO")
| 80 | 46 | 0 |
173256104
|
if __name__ == '__main__':
# Ler entrada
str_input = input()
# Deve possuir apenas caracteres simétricos
symmetrics = "AHIMOTUVWXY"
for char in "".join(set(str_input)):
if not char in symmetrics:
print("NO")
exit(0)
# Obter reverso
rev_input = str_input[::-1]
# Exibir resultado
print("YES" if str_input == rev_input else "NO")
|
Coder-Strike 2014 - Finals
|
CF
| 2,014 | 1 | 256 |
Start Up
|
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
|
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
| null | null |
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
| 1,000 |
[]
| 80 |
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
670/F
|
670
|
F
|
PyPy 3
|
TESTS
| 106 | 389 | 11,776,000 |
119572321
|
import sys
sys.stderr = sys.stdout
from collections import Counter
K = (0, 11, 102, 1003, 10004, 100005, 1000006)
def number(D, S):
m = len(D)
for i in range(len(K)):
if K[i] > m:
k = m - i
break
sK = str(k)
if len(S) == k:
return S
C = Counter(D)
C.subtract(sK)
C.subtract(S)
L = []
S0 = S[0]
S1 = next((e for e in S if e != S0), S0)
C0 = next(d for d in '1234567890' if C[d])
if (C0 == '0'
or (S0 != '0' and S0 < C0)
or (S0 == C0 and S1 <= S0 and not C['0'])):
L.append(S)
for d in '0123456789':
L.append(d * C[d])
else:
L.append(C0)
C[C0] -= 1
for d in '0123456789':
if d == S0:
if S1 <= d:
L.append(S)
L.append(d * C[d])
else:
L.append(d * C[d])
L.append(S)
else:
L.append(d * C[d])
return ''.join(L)
def main():
D = input()
S = input()
print(number(D, S))
##########
def readint():
return int(input())
def readinti():
return map(int, input().split())
def readintt():
return tuple(readinti())
def readintl():
return list(readinti())
def readinttl(k):
return [readintt() for _ in range(k)]
def readintll(k):
return [readintl() for _ in range(k)]
def log(*args, **kwargs):
print(*args, **kwargs, file=sys.__stderr__)
if __name__ == '__main__':
main()
| 118 | 420 | 6,451,200 |
20372824
|
import sys
def main():
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
if a == "01" or a == "10":
print("0")
return
cnt = [0] * 256
for i in map(ord, a):
cnt[i] += 1
n = sum(cnt)
l = 0
for i in range(1, 8):
if i == len(str(n - i)):
l = n - i
break;
for s in b, str(l):
for i in map(ord, s):
cnt[i] -= 1
res = ["".join([b] + [chr(k) * v for k, v in enumerate(cnt) if v > 0 ])] if b[0] > "0" else []
for i in range(ord("1"), ord("9") + 1):
if cnt[i] > 0:
cnt[i] -= 1
others = [chr(k) * v for k, v in enumerate(cnt) if v > 0]
others.append(b)
res.append("".join([chr(i)] + sorted(others)))
break
print(min(res))
if __name__ == "__main__":
main()
|
Codeforces Round 350 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Restore a Number
|
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n.
Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n).
Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).
|
The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000.
The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.
It is guaranteed that the input data is correct, and the answer always exists.
|
Print the smalles integer n which Vasya could pass to Kate.
| null | null |
[{"input": "003512\n021", "output": "30021"}, {"input": "199966633300\n63", "output": "3036366999"}]
| 2,300 |
["brute force", "constructive algorithms", "strings"]
| 118 |
[{"input": "003512\r\n021\r\n", "output": "30021\r\n"}, {"input": "199966633300\r\n63\r\n", "output": "3036366999\r\n"}, {"input": "01\r\n0\r\n", "output": "0\r\n"}, {"input": "0000454312911\r\n9213544\r\n", "output": "92135440000\r\n"}, {"input": "13\r\n3\r\n", "output": "3\r\n"}, {"input": "00010454312921\r\n9213544\r\n", "output": "100009213544\r\n"}, {"input": "11317110\r\n01\r\n", "output": "1011113\r\n"}, {"input": "1516532320120301262110112013012410838210025280432402042406224604110031740090203024020012\r\n0126064\r\n", "output": "10000000000000000000000012606411111111111111222222222222222222333333334444444455567889\r\n"}, {"input": "233121122272652143504001162131110307236110231414093112213120271312010423132181004\r\n0344011\r\n", "output": "1000000000003440111111111111111111111112222222222222222233333333333444455666778\r\n"}, {"input": "1626112553124100114021300410533124010061200562040601301\r\n00612141\r\n", "output": "10000000000000006121411111111111222222333344445556666\r\n"}, {"input": "040005088\r\n0\r\n", "output": "40000058\r\n"}, {"input": "420002200110100211206222101201021321440210\r\n00\r\n", "output": "1000000000000011111111112222222222223446\r\n"}, {"input": "801095116\r\n0\r\n", "output": "10011569\r\n"}, {"input": "070421120216020020\r\n000024\r\n", "output": "1000000024122227\r\n"}, {"input": "825083\r\n0\r\n", "output": "20388\r\n"}, {"input": "6201067\r\n0\r\n", "output": "100267\r\n"}, {"input": "34404430311310306128103301112523111011050561125004200941114005444000000040133002103062151514033103\r\n010215110013511400400140133404\r\n", "output": "100000000000000000000102151100135114004001401334041111111111111122222233333333333444444455555668\r\n"}, {"input": "14\r\n4\r\n", "output": "4\r\n"}, {"input": "21\r\n2\r\n", "output": "2\r\n"}, {"input": "204\r\n4\r\n", "output": "40\r\n"}, {"input": "12\r\n2\r\n", "output": "2\r\n"}, {"input": "05740110115001520111222011422101032503200010203300510014413\r\n000151\r\n", "output": "100000000000000000001511111111111111222222222333334444555\r\n"}, {"input": "116051111111001510011110101111111101001111111101111101101\r\n00111111111\r\n", "output": "1000000000000011111111111111111111111111111111111111116\r\n"}, {"input": "1161100\r\n01110\r\n", "output": "101110\r\n"}, {"input": "101313020013110703821620035452130200177115540090000\r\n002001320\r\n", "output": "1000000000000002001320111111111222333334555567778\r\n"}, {"input": "03111100110111111118\r\n01001111111101111\r\n", "output": "301001111111101111\r\n"}, {"input": "01170141\r\n01114\r\n", "output": "1001114\r\n"}, {"input": "0500014440100110264222000342611000102247070652310723\r\n0003217\r\n", "output": "10000000000000000032171111112222222233444444566677\r\n"}, {"input": "111011111101111131113111111111011\r\n0111111111111111010111111111\r\n", "output": "1011111111111111101011111111113\r\n"}, {"input": "11003040044200003323519101102070252000010622902208104150200400140042011224011154237302003323632011235\r\n0\r\n", "output": "100000000000000000000000000000000001111111111111111222222222222222222333333333334444444445555566778\r\n"}, {"input": "111111011110101141110110011010011114110111\r\n01010111111011111\r\n", "output": "1000000101011111101111111111111111111114\r\n"}, {"input": "011010171110\r\n010110117\r\n", "output": "1010110117\r\n"}, {"input": "510017\r\n0\r\n", "output": "10017\r\n"}, {"input": "00111111110114112110011105\r\n0\r\n", "output": "100000011111111111111115\r\n"}, {"input": "320403902031031110003113410860101243100423120201101124080311242010930103200001451200132304400000\r\n01\r\n", "output": "1000000000000000000000000000000000011111111111111111111122222222222233333333333334444444456889\r\n"}, {"input": "125\r\n15\r\n", "output": "15\r\n"}, {"input": "1160190\r\n110019\r\n", "output": "110019\r\n"}, {"input": "11111111111101101111110101011111010101001111001110010011810010110111101101112140110110\r\n110101100101111101011111111101111111111110111110011111011000111010100111011111000002\r\n", "output": "110101100101111101011111111101111111111110111110011111011000111010100111011111000002\r\n"}, {"input": "2206026141112316065224201412118064151200614042100160093001020024005013121010030020083221011\r\n280060226\r\n", "output": "10000000000000000000000000111111111111111111111222222222222228006022633333444444455566666\r\n"}, {"input": "63007511113226210230771304213600010311075400082011350143450007091200\r\n25\r\n", "output": "100000000000000000000011111111111112222222533333333444455567777789\r\n"}, {"input": "142245201505011321217122212\r\n12521721230\r\n", "output": "1001111125217212302222445\r\n"}, {"input": "712\r\n17\r\n", "output": "17\r\n"}, {"input": "11011111111003010101111111111103111\r\n101111111110110111111011001011111\r\n", "output": "101111111110110111111011001011111\r\n"}, {"input": "143213104201201003340424615500135122127119000020020017400111102423312241032010400\r\n235321200411204201121201304100003\r\n", "output": "1000000000000001111111111222222223532120041120420112120130410000333334444445567\r\n"}, {"input": "080001181\r\n18\r\n", "output": "10000118\r\n"}, {"input": "4141403055010511470013300502174230460332129228041229160601006121052601201100001153120100000\r\n49\r\n", "output": "10000000000000000000000000000011111111111111111112222222222223333333444444495555556666677\r\n"}, {"input": "2131\r\n112\r\n", "output": "112\r\n"}, {"input": "0111110011011110111012109101101111101111150011110111110111001\r\n10110010111111011111111011001101001111111111111110001011012\r\n", "output": "10110010111111011111111011001101001111111111111110001011012\r\n"}, {"input": "251137317010111402300506643001203241303324162124225270011006213015100\r\n3512\r\n", "output": "1000000000000000001111111111111122222222223333333335124444455566677\r\n"}, {"input": "12140051050330004342310455231200020252193200\r\n23012\r\n", "output": "100000000000001111222222301233333444555559\r\n"}, {"input": "291\r\n19\r\n", "output": "19\r\n"}, {"input": "11011011000111101111111111081101110001011111101111110111111111011111011011111100111\r\n1110111111111\r\n", "output": "100000000000000000011101111111111111111111111111111111111111111111111111111111111\r\n"}, {"input": "170422032160671323013220212523333410720410110020005012206133500200001015971250190240204004002041\r\n10010405153200037262043200214001340010615320\r\n", "output": "1000000000000000100104051532000372620432002140013400106153201111111122222222222233333445567779\r\n"}, {"input": "210042022032002310001424611003103312001401111120015141083050404330261401411234412400319100212120\r\n10014121114054\r\n", "output": "1000000000000000000000000010014121114054111111111111111111222222222222223333333333444444445668\r\n"}, {"input": "222122228\r\n2221\r\n", "output": "22212222\r\n"}, {"input": "10\r\n0\r\n", "output": "0\r\n"}, {"input": "11007000\r\n1000\r\n", "output": "1000001\r\n"}, {"input": "3323\r\n32\r\n", "output": "323\r\n"}, {"input": "1001016\r\n1001\r\n", "output": "100101\r\n"}, {"input": "50104\r\n10\r\n", "output": "1005\r\n"}, {"input": "2023\r\n20\r\n", "output": "202\r\n"}, {"input": "0001116\r\n1001\r\n", "output": "100101\r\n"}, {"input": "32334\r\n32\r\n", "output": "3233\r\n"}, {"input": "1103\r\n10\r\n", "output": "101\r\n"}, {"input": "023335\r\n23\r\n", "output": "23033\r\n"}, {"input": "111111111110\r\n1\r\n", "output": "1111111111\r\n"}, {"input": "501105\r\n110\r\n", "output": "11005\r\n"}, {"input": "1110006\r\n1001\r\n", "output": "100101\r\n"}]
| false |
stdio
| null | true |
419/A
|
420
|
A
|
PyPy 3
|
TESTS
| 48 | 93 | 1,126,400 |
150458861
|
import math
from collections import deque
alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}
rasp=''
#c=int(input())
for i in range(0,1):
#n,m=map(int,input().split())
#n=int(input())
#print(n,m)
stringul=input()
#lista=list(map(int,input().split()))
#lista.sort()
#primul=str(lista[0])
set_no={'B','C','D','E','F','G','J','K','L','P','Q','R','S','Z'}
adev="YES"
for i in set_no:
if i in stringul:
adev="No"
break
reverse_str=stringul[::-1]
# print(adev)
# print(stringul,reverse_str)
if adev=='YES'and stringul==reverse_str:
print(adev)
else:
print("NO")
#print(rasp)
| 80 | 46 | 0 |
173331116
|
symmetricalLetters = "AHIMOTUVWXY"
name = input()
for letter in name:
if letter not in symmetricalLetters:
print("NO")
exit(0)
if (name == name[::-1]):
print("YES")
else:
print("NO")
|
Coder-Strike 2014 - Finals
|
CF
| 2,014 | 1 | 256 |
Start Up
|
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
|
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
| null | null |
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
| 1,000 |
[]
| 80 |
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
489/B
|
489
|
B
|
Python 3
|
TESTS
| 36 | 46 | 0 |
224677719
|
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))
a1 = [0] * (max(a)+1)
b1 = [0] * (max(b)+1)
pair_count = 0
for i in range(n):
a1[a[i]] += 1
for j in range(m):
b1[b[j]] += 1
for i in range(len(a1)):
while(0<a1[i]):
if((i in range(len(b1))) and (0<=(b1[i]-1))):
pair_count += 1
b1[i] -= 1
a1[i] -= 1
elif((i-1 in range(len(b1))) and (0<=(b1[i-1]-1))):
pair_count += 1
b1[i-1] -= 1
a1[i] -= 1
elif((i+1 in range(len(b1))) and (0<=(b1[i+1]-1))):
pair_count += 1
b1[i+1] -= 1
a1[i] -= 1
else:
break
print(pair_count)
| 81 | 46 | 0 |
195178401
|
def sopostavim(a,b):
if 0 <= abs(a-b) <= 1:
return True
else:
return False
n = int(input())
p = list(map(int, input().split()))
m = int(input())
d = list(map(int, input().split()))
p.sort()
d.sort()
res = 0
for i in range(0, len(p)):
for j in range(0, len(d)):
if sopostavim(p[i], d[j]):
res += 1
d[j] = 1000000
break
print(res)
|
Codeforces Round 277.5 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
BerSU Ball
|
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
Print a single number — the required maximum possible number of pairs.
| null | null |
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
| 1,200 |
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
| 81 |
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
489/B
|
489
|
B
|
Python 3
|
TESTS
| 36 | 46 | 0 |
225727520
|
num_b=int(input())
boys=list(map(int,input().split()))
boys.sort()
num_g=int(input())
girls=list(map(int,input().split()))
if len(boys)<=len(girls):
initial=len(girls)
for i in boys:
if i in girls:
girls.remove(i)
elif i-1 in girls:
girls.remove(i-1)
elif i+1 in girls:
girls.remove(i+1)
ans=initial-len(girls)
else:
initial=len(boys)
for i in girls:
if i in boys:
boys.remove(i)
elif i-1 in boys:
boys.remove(i-1)
elif i+1 in boys:
boys.remove(i+1)
ans=initial-len(boys)
print(ans)
| 81 | 46 | 0 |
195210578
|
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
b.sort()
i = 0
j = 0
count = 0
while i < n and j < m:
if abs(a[i] - b[j]) <= 1:
count += 1
i += 1
j += 1
elif a[i] < b[j]:
i += 1
else:
j += 1
print(count)
|
Codeforces Round 277.5 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
BerSU Ball
|
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
Print a single number — the required maximum possible number of pairs.
| null | null |
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
| 1,200 |
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
| 81 |
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
PyPy 3-64
|
TESTS
| 24 | 202 | 13,721,600 |
185204815
|
import sys
from array import array
from math import gcd
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda dtype: [dtype(x) for x in input().split()]
debug = lambda *x: print(*x, file=sys.stderr)
ceil1 = lambda a, b: (a + b - 1) // b
Mint, Mlong = 2 ** 31 - 1, 2 ** 63 - 1
out, tests = [], 1
def slop(i, j):
g = gcd(ys[i] - ys[j], xs[i] - xs[j])
if ys[i] - ys[j] < 0: g *= -1
num, den = (ys[i] - ys[j]) // g, (xs[i] - xs[j]) // g
# inf slop
if den == 0: num = xs[i]
if num == 0: den = ys[i]
return num, den
def solve():
if n < 3: return 'YES'
for i in range(3):
for j in range(i + 1, 3):
oth = []
num, den = slop(i, j)
for k in range(n):
if k != i and k != j:
num1, den1 = slop(i, k)
if num1 != num or den != den1:
oth.append(k)
if len(oth) < 3: return 'YES'
num, den = slop(oth[0], oth[1])
for k in range(2, len(oth)):
num1, den1 = slop(oth[0], oth[k])
if num1 != num or den != den1:
break
else:
return 'YES'
return 'NO'
for _ in range(tests):
n = int(input())
xs = array('i', [0] * n)
ys = array('i', [0] * n)
for i in range(n):
xs[i], ys[i] = inp(int)
out.append(solve())
print('\n'.join(map(str, out)))
| 121 | 374 | 41,062,400 |
153775698
|
import sys
input=sys.stdin.readline
n=int(input())
if n<=3:
print('YES')
exit()
x=[[0,0] for i in range(n)]
for i in range(n):
x[i][0],x[i][1]=map(int,input().split())
def check(a,b):
ans=0
remove=2
remain=[]
xx=x[0:a]+x[a+1:b]+x[b+1:]
x1,x2,y1,y2=x[a][0],x[b][0],x[a][1],x[b][1]
for i in range(n-2):
if (y2-y1)*(xx[i][0]-x1)==(xx[i][1]-y1)*(x2-x1):
remove+=1
else:
remain.append([xx[i][0],xx[i][1]])
if remove>=n-2:
return ans
x1,x2,y1,y2=remain[0][0],remain[1][0],remain[0][1],remain[1][1]
for i in range(2,len(remain)):
if (y2-y1)*(remain[i][0]-x1)!=(remain[i][1]-y1)*(x2-x1):
ans=1
break
return ans
if check(0,1)==1 and check(1,2)==1 and check(0,2)==1:
print('NO')
else:
print('YES')
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
95/B
|
95
|
B
|
Python 3
|
TESTS
| 51 | 404 | 921,600 |
67603168
|
n = input()
l = len(n)
if l % 2 == 1:
print('4' * (l // 2 + 1) + '7' * (l // 2 + 1))
exit(0)
if n > ('7' * (l // 2) + '4' * (l // 2)):
print('4' * (l // 2 + 1) + '7' * (l // 2 + 1))
exit(0)
def set_range(p, start, end, num):
for i in range(start, end):
p[i] = num
result = [None] * l
for i in range(l):
d = int(n[i])
if d < 4:
set_range(result, i, l, '4')
break
elif d == 4:
result[i] = '4'
elif d < 7:
result[i] = '7'
set_range(result, i + 1, l, '4')
break
elif d == 7:
result[i] = '7'
else:
k = i - 1
while result[k] == '7':
k -= 1
result[k] = '7'
set_range(result, k + 1, l, '4')
break
diff = (result.count('7') - result.count('4')) // 2
if diff > 0:
count = 0
last_4 = -1
for k in range(l):
if result[k] == '7':
count += 1
if result[k] == '4':
last_4 = k
if count == l // 2:
result[last_4] = '7'
set_range(result, k, l, '4')
elif diff < 0:
k = l - 1
while diff != 0:
if result[k] == '4':
result[k] = '7'
diff += 1
k -= 1
print(''.join(result))
| 86 | 122 | 1,843,200 |
170544207
|
def f(i,c,n4,n7):return s[:i]+c+'4'*n4+'7'*n7
P=print;s=input();n=len(s);n4=n7=n//2;z=(0,'4',n4,n7+1)
if n&1==1:exit(P(f(*z)))
for i,c in enumerate(s):
if c>'7':break
if c == "7":
if n7 == 0:break
n7 -= 1;continue
if n7 > 0:z = (i, "7", n4, n7 - 1)
if c > "4":break
if c == "4":
if n4 == 0:break
n4 -= 1;continue
if n4 > 0:z = (i, "4", n4 - 1, n7)
break
else:z=(n,'',0,0)
P(f(*z))
|
Codeforces Beta Round 77 (Div. 1 Only)
|
CF
| 2,011 | 2 | 256 |
Lucky Numbers
|
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
|
Output the least super lucky number that is more than or equal to n.
| null | null |
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
| 1,800 |
["dp", "greedy"]
| 86 |
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\r\n"}]
| false |
stdio
| null | true |
638/B
|
638
|
B
|
PyPy 3
|
TESTS
| 17 | 436 | 29,798,400 |
16842279
|
def is_sub(s1, s2):
s = s1 + "#" + s2
n = len(s)
z = [0] * n
for i in range(1, n):
l, r = 0, 0
z[i] = max(0, min(r - i, z[i - l]))
while i+z[i] < n and s[z[i]] == s[i+z[i]]:
z[i] += 1
if i+z[i] >= r:
l = i
r = i + z[i]
for i in range(len(s1), n):
if z[i] == len(s1):
return True
return False
def how(s1, s2):
i = 0
ans = -1
for i in range(min(len(s1), len(s2))):
if s1[-i-1:] == s2[:i+1]:
ans = i
return ans + 1
def check(ss):
for i in range(len(ss)-1):
for j in range(i+1, len(ss)):
if how(ss[i], ss[j]):
return [i, j]
if how(ss[j], ss[i]):
return [j, i]
return []
n = int(input())
s = [input() for i in range(n)]
ss = s[:]
while check(ss):
for i in range(len(ss)-1):
for j in range(i+1, len(ss)):
if is_sub(ss[i], ss[j]):
ss[i] = ''
elif is_sub(ss[j], ss[i]):
ss[j] = ''
now = check(ss)
if not now:
break
x, y = now
q = ss[x] + ss[y][how(ss[x], ss[y]):]
ss[y] = q
ss.pop(x)
print(''.join(ss))
| 67 | 46 | 0 |
215563383
|
d = {}
aa = [input() for _ in range(int(input()))]
for ele in aa:
for a, b in zip(ele, ele[1:]):
d[a] = b # map with next character
s = ""
for ss in set("".join(aa)) - set(d.values()):
s += ss
while ss in d:
ss = d[ss]
s += ss
print(s)
|
VK Cup 2016 - Qualification Round 2
|
CF
| 2,016 | 1 | 256 |
Making Genome in Berland
|
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.
Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.
You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.
|
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.
It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.
|
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
| null | null |
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
| 1,500 |
["*special", "dfs and similar", "strings"]
| 67 |
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijklmnopqrstuvwxyz\r\n"}, {"input": "1\r\nf\r\n", "output": "f\r\n"}, {"input": "1\r\nqwertyuiopzxcvbnmasdfghjkl\r\n", "output": "qwertyuiopzxcvbnmasdfghjkl\r\n"}, {"input": "3\r\ndfghj\r\nghjkl\r\nasdfg\r\n", "output": "asdfghjkl\r\n"}, {"input": "4\r\nab\r\nab\r\nab\r\nabc\r\n", "output": "abc\r\n"}, {"input": "3\r\nf\r\nn\r\nux\r\n", "output": "uxfn\r\n"}, {"input": "2\r\nfgs\r\nfgs\r\n", "output": "fgs\r\n"}, {"input": "96\r\nc\r\ndhf\r\no\r\nq\r\nry\r\nh\r\nr\r\nf\r\nji\r\nek\r\ndhf\r\np\r\nk\r\no\r\nf\r\nw\r\nc\r\nc\r\nfgw\r\nbps\r\nhfg\r\np\r\ni\r\nji\r\nto\r\nc\r\nou\r\ny\r\nfg\r\na\r\ne\r\nu\r\nc\r\ny\r\nhf\r\nqn\r\nu\r\nj\r\np\r\ns\r\no\r\nmr\r\na\r\nqn\r\nb\r\nlb\r\nn\r\nji\r\nji\r\na\r\no\r\nat\r\ns\r\nf\r\nb\r\ndh\r\nk\r\nl\r\nl\r\nvq\r\nt\r\nb\r\nc\r\nv\r\nc\r\nh\r\nh\r\ny\r\nh\r\nq\r\ne\r\nx\r\nd\r\no\r\nq\r\nm\r\num\r\nmr\r\nfg\r\ni\r\nl\r\na\r\nh\r\nt\r\num\r\nr\r\no\r\nn\r\nk\r\ne\r\nji\r\na\r\nc\r\nh\r\ne\r\nm\r\n", "output": "atoumrydhfgwekjilbpsvqncx\r\n"}, {"input": "3\r\npbi\r\nopbi\r\ngh\r\n", "output": "ghopbi\r\n"}, {"input": "4\r\ng\r\np\r\no\r\nop\r\n", "output": "opg\r\n"}, {"input": "5\r\np\r\nf\r\nu\r\nf\r\np\r\n", "output": "pfu\r\n"}, {"input": "4\r\nr\r\nko\r\nuz\r\nko\r\n", "output": "kouzr\r\n"}, {"input": "5\r\nzt\r\nted\r\nlzt\r\nted\r\ndyv\r\n", "output": "lztedyv\r\n"}, {"input": "6\r\ngul\r\ng\r\njrb\r\nul\r\nd\r\njr\r\n", "output": "guljrbd\r\n"}, {"input": "5\r\nlkyh\r\naim\r\nkyh\r\nm\r\nkyhai\r\n", "output": "lkyhaim\r\n"}, {"input": "4\r\nzrncsywd\r\nsywdx\r\ngqzrn\r\nqzrncsy\r\n", "output": "gqzrncsywdx\r\n"}, {"input": "5\r\ntbxzc\r\njrdtb\r\njrdtb\r\nflnj\r\nrdtbx\r\n", "output": "flnjrdtbxzc\r\n"}, {"input": "10\r\ng\r\nkagijn\r\nzxt\r\nhmkag\r\nhm\r\njnc\r\nxtqupw\r\npwhmk\r\ng\r\nagi\r\n", "output": "zxtqupwhmkagijnc\r\n"}, {"input": "20\r\nf\r\nf\r\nv\r\nbn\r\ne\r\nmr\r\ne\r\ne\r\nn\r\nj\r\nqfv\r\ne\r\ndpb\r\nj\r\nlc\r\nr\r\ndp\r\nf\r\na\r\nrt\r\n", "output": "dpbnlcmrtqfveja\r\n"}, {"input": "30\r\nxlo\r\nwx\r\ne\r\nf\r\nyt\r\nw\r\ne\r\nl\r\nxl\r\nojg\r\njg\r\niy\r\ngkz\r\ne\r\nw\r\nloj\r\ng\r\nfw\r\nl\r\nlo\r\nbe\r\ne\r\ngk\r\niyt\r\no\r\nb\r\nqv\r\nz\r\nb\r\nzq\r\n", "output": "befwxlojgkzqviyt\r\n"}, {"input": "50\r\nmd\r\nei\r\nhy\r\naz\r\nzr\r\nmd\r\nv\r\nz\r\nke\r\ny\r\nuk\r\nf\r\nhy\r\njm\r\nke\r\njm\r\ncn\r\nwf\r\nzr\r\nqj\r\ng\r\nzr\r\ndv\r\ni\r\ndv\r\nuk\r\nj\r\nwf\r\njm\r\nn\r\na\r\nqj\r\nei\r\nf\r\nzr\r\naz\r\naz\r\nke\r\na\r\nr\r\ndv\r\nei\r\nzr\r\ndv\r\nq\r\ncn\r\nyg\r\nqj\r\nnh\r\nhy\r\n", "output": "azrcnhygqjmdvukeiwf\r\n"}, {"input": "80\r\ni\r\nioh\r\nquc\r\nexioh\r\niohb\r\nex\r\nrwky\r\nz\r\nquc\r\nrw\r\nplnt\r\nq\r\nhbrwk\r\nexioh\r\ntv\r\nxioh\r\nlnt\r\nxi\r\nn\r\npln\r\niohbr\r\nwky\r\nhbr\r\nw\r\nyq\r\nrwky\r\nbrw\r\nplnt\r\nv\r\nkyq\r\nrwkyq\r\nt\r\nhb\r\ngplnt\r\np\r\nkyqu\r\nhbr\r\nrwkyq\r\nhbr\r\nve\r\nhbrwk\r\nkyq\r\nkyquc\r\ngpln\r\ni\r\nbr\r\ntvex\r\nwkyqu\r\nz\r\nlnt\r\ngp\r\nky\r\ngplnt\r\ne\r\nhbrwk\r\nbrw\r\nve\r\no\r\nplnt\r\nn\r\nntve\r\ny\r\nln\r\npln\r\ntvexi\r\nr\r\nzgp\r\nxiohb\r\nl\r\nn\r\nt\r\nplnt\r\nlntv\r\nexi\r\nexi\r\ngpl\r\nioh\r\nk\r\nwk\r\ni\r\n", "output": "zgplntvexiohbrwkyquc\r\n"}, {"input": "70\r\njp\r\nz\r\nz\r\nd\r\ndy\r\nk\r\nsn\r\nrg\r\nz\r\nsn\r\nh\r\nj\r\ns\r\nkx\r\npu\r\nkx\r\nm\r\njp\r\nbo\r\nm\r\ntk\r\ndy\r\no\r\nm\r\nsn\r\nv\r\nrg\r\nv\r\nn\r\no\r\ngh\r\np\r\no\r\nx\r\nq\r\nzv\r\nr\r\nbo\r\ng\r\noz\r\nu\r\nub\r\nnd\r\nh\r\ny\r\njp\r\no\r\nq\r\nbo\r\nhq\r\nhq\r\nkx\r\nx\r\ndy\r\nn\r\nb\r\nub\r\nsn\r\np\r\nub\r\ntk\r\nu\r\nnd\r\nvw\r\nt\r\nub\r\nbo\r\nyr\r\nyr\r\nub\r\n", "output": "jpubozvwsndyrghqtkxm\r\n"}, {"input": "100\r\nm\r\nj\r\nj\r\nf\r\nk\r\nq\r\ni\r\nu\r\ni\r\nl\r\nt\r\nt\r\no\r\nv\r\nk\r\nw\r\nr\r\nj\r\nh\r\nx\r\nc\r\nv\r\nu\r\nf\r\nh\r\nj\r\nb\r\ne\r\ni\r\nr\r\ng\r\nb\r\nl\r\nb\r\ng\r\nb\r\nf\r\nq\r\nv\r\na\r\nu\r\nn\r\ni\r\nl\r\nk\r\nc\r\nx\r\nu\r\nr\r\ne\r\ni\r\na\r\nc\r\no\r\nc\r\na\r\nx\r\nd\r\nf\r\nx\r\no\r\nx\r\nm\r\nl\r\nr\r\nc\r\nr\r\nc\r\nv\r\nj\r\ng\r\nu\r\nn\r\nn\r\nd\r\nl\r\nl\r\nc\r\ng\r\nu\r\nr\r\nu\r\nh\r\nl\r\na\r\nl\r\nr\r\nt\r\nm\r\nf\r\nm\r\nc\r\nh\r\nl\r\nd\r\na\r\nr\r\nh\r\nn\r\nc\r\n", "output": "mjfkqiultovwrhxcbegand\r\n"}, {"input": "99\r\nia\r\nz\r\nsb\r\ne\r\nnm\r\nd\r\nknm\r\nt\r\nm\r\np\r\nqvu\r\ne\r\nq\r\nq\r\ns\r\nmd\r\nz\r\nfh\r\ne\r\nwi\r\nn\r\nsb\r\nq\r\nw\r\ni\r\ng\r\nr\r\ndf\r\nwi\r\nl\r\np\r\nm\r\nb\r\ni\r\natj\r\nb\r\nwia\r\nx\r\nnm\r\nlk\r\nx\r\nfh\r\nh\r\np\r\nf\r\nzr\r\nz\r\nr\r\nsbz\r\nlkn\r\nsbz\r\nz\r\na\r\nwia\r\ntjx\r\nk\r\nj\r\nx\r\nl\r\nqvu\r\nzr\r\nfh\r\nbzrg\r\nz\r\nplk\r\nfhe\r\nn\r\njxqv\r\nrgp\r\ne\r\ndf\r\nz\r\ns\r\natj\r\ndf\r\nat\r\ngp\r\nw\r\new\r\nt\r\np\r\np\r\nfhe\r\nq\r\nxq\r\nt\r\nzr\r\nat\r\ndfh\r\nj\r\ns\r\nu\r\npl\r\np\r\nrg\r\nlk\r\nq\r\nwia\r\ng\r\n", "output": "sbzrgplknmdfhewiatjxqvu\r\n"}, {"input": "95\r\np\r\nk\r\nd\r\nr\r\nn\r\nz\r\nn\r\nb\r\np\r\nw\r\ni\r\nn\r\ny\r\ni\r\nn\r\nn\r\ne\r\nr\r\nu\r\nr\r\nb\r\ni\r\ne\r\np\r\nk\r\nc\r\nc\r\nh\r\np\r\nk\r\nh\r\ns\r\ne\r\ny\r\nq\r\nq\r\nx\r\nw\r\nh\r\ng\r\nt\r\nt\r\na\r\nt\r\nh\r\ni\r\nb\r\ne\r\np\r\nr\r\nu\r\nn\r\nn\r\nr\r\nq\r\nn\r\nu\r\ng\r\nw\r\nt\r\np\r\nt\r\nk\r\nd\r\nz\r\nh\r\nf\r\nd\r\ni\r\na\r\na\r\nf\r\ne\r\na\r\np\r\ns\r\nk\r\nt\r\ng\r\nf\r\ni\r\ng\r\ng\r\nt\r\nn\r\nn\r\nt\r\nt\r\nr\r\nx\r\na\r\nz\r\nc\r\nn\r\nk\r\n", "output": "pkdrnzbwiyeuchsqxgtaf\r\n"}, {"input": "3\r\nh\r\nx\r\np\r\n", "output": "hxp\r\n"}, {"input": "4\r\nrz\r\nvu\r\nxy\r\npg\r\n", "output": "pgrzvuxy\r\n"}, {"input": "5\r\ndrw\r\nu\r\nzq\r\npd\r\naip\r\n", "output": "aipdrwzqu\r\n"}, {"input": "70\r\ne\r\no\r\ng\r\ns\r\nsz\r\nyl\r\ns\r\nn\r\no\r\nq\r\np\r\nl\r\noa\r\ndq\r\ny\r\np\r\nn\r\nio\r\ng\r\nb\r\nk\r\nv\r\ny\r\nje\r\nc\r\ncb\r\nfx\r\ncbv\r\nfxp\r\nkt\r\nhm\r\nz\r\nrcb\r\np\r\nt\r\nu\r\nzh\r\ne\r\nb\r\na\r\nyl\r\nd\r\nv\r\nl\r\nrc\r\nq\r\nt\r\nt\r\nj\r\nl\r\nr\r\ny\r\nlg\r\np\r\nt\r\nd\r\nq\r\nje\r\nqwu\r\ng\r\nz\r\ngi\r\ndqw\r\nz\r\nvyl\r\nk\r\nt\r\nc\r\nb\r\nrc\r\n", "output": "dqwufxpjektrcbvylgioaszhmn\r\n"}, {"input": "3\r\ne\r\nw\r\nox\r\n", "output": "oxew\r\n"}, {"input": "100\r\npr\r\nfz\r\nru\r\ntk\r\nld\r\nvq\r\nef\r\ngj\r\ncp\r\nbm\r\nsn\r\nld\r\nua\r\nzl\r\ndw\r\nef\r\nua\r\nbm\r\nxb\r\nvq\r\nav\r\ncp\r\nko\r\nwc\r\nru\r\ni\r\ne\r\nav\r\nbm\r\nav\r\nxb\r\nog\r\ng\r\nme\r\ntk\r\nog\r\nxb\r\nef\r\ntk\r\nhx\r\nqt\r\nvq\r\ndw\r\nv\r\nxb\r\ndw\r\nko\r\nd\r\nbm\r\nua\r\nvq\r\nis\r\nwc\r\ntk\r\ntk\r\ngj\r\ng\r\ngj\r\nef\r\nqt\r\nvq\r\nbm\r\nog\r\nvq\r\ngj\r\nvq\r\nzl\r\ngj\r\nji\r\nvq\r\nhx\r\ng\r\nbm\r\nji\r\nqt\r\nef\r\nav\r\ntk\r\nxb\r\nru\r\nko\r\nny\r\nis\r\ncp\r\nxb\r\nog\r\nru\r\nhx\r\nwc\r\nko\r\nu\r\nfz\r\ndw\r\nji\r\nzl\r\nvq\r\nqt\r\nko\r\ngj\r\nis\r\n", "output": "hxbmefzldwcpruavqtkogjisny\r\n"}, {"input": "23\r\nw\r\nz\r\nk\r\nc\r\ne\r\np\r\nt\r\na\r\nx\r\nc\r\nq\r\nx\r\na\r\nf\r\np\r\nw\r\nh\r\nx\r\nf\r\nw\r\np\r\nw\r\nq\r\n", "output": "wzkceptaxqfh\r\n"}, {"input": "12\r\nu\r\na\r\nhw\r\na\r\ngh\r\nog\r\nr\r\nd\r\nw\r\nk\r\nl\r\ny\r\n", "output": "oghwuardkly\r\n"}, {"input": "2\r\ny\r\nd\r\n", "output": "yd\r\n"}, {"input": "1\r\nd\r\n", "output": "d\r\n"}, {"input": "100\r\nwm\r\nq\r\nhf\r\nwm\r\niz\r\ndl\r\nmiz\r\np\r\nzoa\r\nbk\r\nw\r\nxv\r\nfj\r\nd\r\nxvsg\r\nr\r\nx\r\nt\r\nyd\r\nbke\r\ny\r\neq\r\nx\r\nn\r\nry\r\nt\r\nc\r\nuh\r\nn\r\npw\r\nuhf\r\neq\r\nr\r\nw\r\nk\r\nt\r\nsg\r\njb\r\nd\r\nke\r\ne\r\nx\r\nh\r\ntuh\r\nan\r\nn\r\noa\r\nw\r\nq\r\nz\r\nk\r\noan\r\nbk\r\nj\r\nzoan\r\nyd\r\npwmi\r\nyd\r\nc\r\nry\r\nfj\r\nlx\r\nqr\r\nke\r\nizo\r\nm\r\nz\r\noan\r\nwmi\r\nl\r\nyd\r\nz\r\ns\r\nke\r\nw\r\nfjbk\r\nqry\r\nlxv\r\nhf\r\ns\r\nnc\r\nq\r\nlxv\r\nzoa\r\nn\r\nfj\r\np\r\nhf\r\nmiz\r\npwm\r\ntu\r\noan\r\ng\r\nd\r\nqr\r\na\r\nan\r\nxvs\r\ny\r\ntuhf\r\n", "output": "pwmizoanctuhfjbkeqrydlxvsg\r\n"}, {"input": "94\r\ncw\r\nm\r\nuhbk\r\ntfy\r\nsd\r\nu\r\ntf\r\ntfym\r\nfy\r\nbk\r\nx\r\nx\r\nxl\r\npu\r\noq\r\nkt\r\ny\r\nb\r\nj\r\nqxl\r\no\r\noqx\r\nr\r\nr\r\njr\r\nk\r\ne\r\nw\r\nsd\r\na\r\nljre\r\nhbk\r\nym\r\nxl\r\np\r\nreg\r\nktf\r\nre\r\nw\r\nhbk\r\nxlj\r\nzn\r\ne\r\nm\r\nms\r\nsdv\r\nr\r\nr\r\no\r\naoq\r\nzna\r\nymsd\r\nqx\r\nr\r\no\r\nlj\r\nm\r\nk\r\nu\r\nkt\r\nms\r\ne\r\nx\r\nh\r\ni\r\nz\r\nm\r\nc\r\nb\r\no\r\nm\r\nvcw\r\ndvc\r\nq\r\na\r\nb\r\nfyms\r\nv\r\nxl\r\nxl\r\ntfym\r\nx\r\nfy\r\np\r\nyms\r\nms\r\nb\r\nt\r\nu\r\nn\r\nq\r\nnaoqx\r\no\r\ne\r\n", "output": "puhbktfymsdvcwznaoqxljregi\r\n"}, {"input": "13\r\ngku\r\nzw\r\nstvqc\r\najy\r\njystvq\r\nfilden\r\nstvq\r\nfild\r\nqcporh\r\najys\r\nqcpor\r\nqcpor\r\ncporhm\r\n", "output": "ajystvqcporhmfildengkuzw\r\n"}, {"input": "2\r\not\r\nqu\r\n", "output": "otqu\r\n"}, {"input": "100\r\nv\r\nh\r\nj\r\nf\r\nr\r\ni\r\ns\r\nw\r\nv\r\nd\r\nv\r\np\r\nd\r\nu\r\ny\r\nd\r\nu\r\nx\r\nr\r\nu\r\ng\r\nm\r\ns\r\nf\r\nv\r\nx\r\na\r\ng\r\ng\r\ni\r\ny\r\ny\r\nv\r\nd\r\ni\r\nq\r\nq\r\nu\r\nx\r\nj\r\nv\r\nj\r\ne\r\no\r\nr\r\nh\r\nu\r\ne\r\nd\r\nv\r\nb\r\nv\r\nq\r\nk\r\ni\r\nr\r\ne\r\nm\r\na\r\nj\r\na\r\nu\r\nq\r\nx\r\nq\r\ny\r\ns\r\nw\r\nk\r\ni\r\ns\r\nr\r\np\r\ni\r\np\r\ns\r\nd\r\nj\r\nw\r\no\r\nm\r\ns\r\nr\r\nd\r\nf\r\ns\r\nw\r\nv\r\ne\r\ny\r\no\r\nx\r\na\r\np\r\nk\r\nr\r\ng\r\ng\r\nb\r\nq\r\n", "output": "vhjfriswdpuyxgmaqeobk\r\n"}, {"input": "99\r\ntnq\r\nep\r\nuk\r\nk\r\nx\r\nvhy\r\nepj\r\nx\r\nj\r\nhy\r\nukg\r\nsep\r\nquk\r\nr\r\nw\r\no\r\nxrwm\r\ndl\r\nh\r\no\r\nad\r\ng\r\ng\r\nhy\r\nxr\r\nad\r\nhyx\r\nkg\r\nvh\r\nb\r\nlovh\r\nuk\r\nl\r\ntn\r\nkg\r\ny\r\nu\r\nxr\r\nse\r\nyx\r\nmt\r\nlo\r\nm\r\nu\r\nukg\r\ngse\r\na\r\nuk\r\nn\r\nr\r\nlov\r\nep\r\nh\r\nadl\r\nyx\r\nt\r\nukg\r\nz\r\nepj\r\nz\r\nm\r\nx\r\nov\r\nyx\r\nxr\r\nep\r\nw\r\ny\r\nmtn\r\nsep\r\nep\r\nmt\r\nrwmt\r\nuk\r\nlo\r\nz\r\nnq\r\nj\r\ntn\r\nj\r\nkgs\r\ny\r\nb\r\nmtn\r\nsep\r\nr\r\ns\r\no\r\nr\r\nepjb\r\nadl\r\nrwmt\r\nyxrw\r\npj\r\nvhy\r\nk\r\ns\r\nx\r\nt\r\n", "output": "adlovhyxrwmtnqukgsepjbz\r\n"}, {"input": "95\r\nx\r\np\r\nk\r\nu\r\ny\r\nz\r\nt\r\na\r\ni\r\nj\r\nc\r\nh\r\nk\r\nn\r\nk\r\ns\r\nr\r\ny\r\nn\r\nv\r\nf\r\nb\r\nr\r\no\r\no\r\nu\r\nb\r\nj\r\no\r\nd\r\np\r\ns\r\nb\r\nt\r\nd\r\nq\r\nq\r\na\r\nm\r\ny\r\nq\r\nj\r\nz\r\nk\r\ne\r\nt\r\nv\r\nj\r\np\r\np\r\ns\r\nz\r\no\r\nk\r\nt\r\na\r\na\r\nc\r\np\r\nb\r\np\r\nx\r\nc\r\ny\r\nv\r\nj\r\na\r\np\r\nc\r\nd\r\nj\r\nt\r\nj\r\nt\r\nf\r\no\r\no\r\nn\r\nx\r\nq\r\nc\r\nk\r\np\r\nk\r\nq\r\na\r\ns\r\nl\r\na\r\nq\r\na\r\nb\r\ne\r\nj\r\nl\r\n", "output": "xpkuyztaijchnsrvfbodqmel\r\n"}, {"input": "96\r\not\r\njo\r\nvpr\r\nwi\r\ngx\r\nay\r\nzqf\r\nzq\r\npr\r\nigx\r\ntsb\r\nv\r\nr\r\ngxc\r\nigx\r\ngx\r\nvpr\r\nxc\r\nylk\r\nigx\r\nlkh\r\nvp\r\nuvp\r\nz\r\nbuv\r\njo\r\nvpr\r\npr\r\nprn\r\nwi\r\nqfw\r\nbuv\r\nd\r\npr\r\ndmj\r\nvpr\r\ng\r\nylk\r\nsbu\r\nhz\r\nk\r\nzqf\r\nylk\r\nxc\r\nwi\r\nvpr\r\nbuv\r\nzq\r\nmjo\r\nkh\r\nuv\r\nuvp\r\nts\r\nt\r\nylk\r\nnay\r\nbuv\r\nhzq\r\nts\r\njo\r\nsbu\r\nqfw\r\ngxc\r\ntsb\r\np\r\nhzq\r\nbuv\r\nsbu\r\nfwi\r\nkh\r\nmjo\r\nwig\r\nhzq\r\ndmj\r\ntsb\r\ntsb\r\nts\r\nylk\r\nyl\r\ngxc\r\not\r\nots\r\nuvp\r\nay\r\nay\r\nuvp\r\not\r\ny\r\np\r\nm\r\ngx\r\nkhz\r\ngxc\r\nkhz\r\ntsb\r\nrn\r\n", "output": "dmjotsbuvprnaylkhzqfwigxc\r\n"}, {"input": "3\r\nm\r\nu\r\nm\r\n", "output": "mu\r\n"}, {"input": "4\r\np\r\na\r\nz\r\nq\r\n", "output": "pazq\r\n"}, {"input": "5\r\ngtb\r\nnlu\r\nzjp\r\nk\r\nazj\r\n", "output": "azjpgtbnluk\r\n"}, {"input": "70\r\nxv\r\nlu\r\ntb\r\njx\r\nseh\r\nc\r\nm\r\ntbr\r\ntb\r\ndl\r\ne\r\nd\r\nt\r\np\r\nn\r\nse\r\nna\r\neh\r\nw\r\np\r\nzkj\r\nr\r\nk\r\nrw\r\nqf\r\ndl\r\ndl\r\ns\r\nat\r\nkjx\r\na\r\nz\r\nmig\r\nu\r\nse\r\npse\r\nd\r\ng\r\nc\r\nxv\r\nv\r\ngo\r\nps\r\ncd\r\nyqf\r\nyqf\r\nwzk\r\nxv\r\nat\r\nw\r\no\r\nl\r\nxvm\r\nfpse\r\nz\r\nk\r\nna\r\nv\r\nseh\r\nk\r\nl\r\nz\r\nd\r\nz\r\nn\r\nm\r\np\r\ng\r\nse\r\nat\r\n", "output": "cdlunatbrwzkjxvmigoyqfpseh\r\n"}, {"input": "3\r\nbmg\r\nwjah\r\nil\r\n", "output": "bmgilwjah\r\n"}, {"input": "100\r\ne\r\nbr\r\nls\r\nfb\r\nyx\r\nva\r\njm\r\nwn\r\nak\r\nhv\r\noq\r\nyx\r\nl\r\nm\r\nak\r\nce\r\nug\r\nqz\r\nug\r\ndf\r\nty\r\nhv\r\nmo\r\nxp\r\nyx\r\nkt\r\nak\r\nmo\r\niu\r\nxp\r\nce\r\nnd\r\noq\r\nbr\r\nty\r\nva\r\nce\r\nwn\r\nx\r\nsj\r\nel\r\npi\r\noq\r\ndf\r\niu\r\nc\r\nhv\r\npi\r\nsj\r\nhv\r\nmo\r\nbr\r\nxp\r\nce\r\nfb\r\nwn\r\nnd\r\nfb\r\npi\r\noq\r\nhv\r\nty\r\ngw\r\noq\r\nel\r\nw\r\nhv\r\nce\r\noq\r\nsj\r\nsj\r\nl\r\nwn\r\nqz\r\nty\r\nbr\r\nz\r\nel\r\nug\r\nce\r\nnd\r\nj\r\ndf\r\npi\r\niu\r\nnd\r\nls\r\niu\r\nrc\r\nbr\r\nug\r\nrc\r\nnd\r\nak\r\njm\r\njm\r\no\r\nls\r\nq\r\nfb\r\n", "output": "hvaktyxpiugwndfbrcelsjmoqz\r\n"}, {"input": "23\r\nq\r\ni\r\nj\r\nx\r\nz\r\nm\r\nt\r\ns\r\nu\r\ng\r\nc\r\nk\r\nh\r\nb\r\nx\r\nh\r\nt\r\no\r\ny\r\nh\r\nb\r\nn\r\na\r\n", "output": "qijxzmtsugckhboyna\r\n"}, {"input": "12\r\nkx\r\ng\r\nfo\r\nnt\r\nmf\r\nzv\r\nir\r\nds\r\nbz\r\nf\r\nlw\r\nx\r\n", "output": "bzvdsirkxlwmfontg\r\n"}, {"input": "2\r\na\r\nt\r\n", "output": "at\r\n"}, {"input": "1\r\ndm\r\n", "output": "dm\r\n"}, {"input": "100\r\nj\r\numj\r\ninc\r\nu\r\nsd\r\ntin\r\nw\r\nlf\r\nhs\r\nepk\r\nyg\r\nqhs\r\nh\r\nti\r\nf\r\nsd\r\ngepk\r\nu\r\nfw\r\nu\r\nsd\r\nvumj\r\num\r\ndt\r\nb\r\ng\r\nozl\r\nabvu\r\noz\r\nn\r\nw\r\nab\r\nge\r\nqh\r\nfwy\r\nsdti\r\ng\r\nyge\r\nepk\r\nabvu\r\nz\r\nlfw\r\nbv\r\nab\r\nyge\r\nqhs\r\nge\r\nhsdt\r\num\r\nl\r\np\r\na\r\nab\r\nd\r\nfw\r\ngep\r\nfwy\r\nbvu\r\nvumj\r\nzlfw\r\nk\r\nepk\r\ntin\r\npkab\r\nzl\r\nvum\r\nr\r\nf\r\nd\r\nsdt\r\nhs\r\nxoz\r\nlfwy\r\nfw\r\num\r\nep\r\nincx\r\na\r\nt\r\num\r\nh\r\nsdt\r\ngep\r\nlfw\r\nkab\r\ng\r\nmjr\r\nj\r\noz\r\ns\r\nwy\r\nnc\r\nlfw\r\nyg\r\nygep\r\nti\r\nyg\r\npk\r\nkab\r\nwyg\r\n", "output": "qhsdtincxozlfwygepkabvumjr\r\n"}, {"input": "94\r\nkmwbq\r\nmw\r\nwbq\r\ns\r\nlx\r\nf\r\npf\r\nl\r\nkmwb\r\na\r\nfoynt\r\nnt\r\nx\r\npf\r\npf\r\nep\r\nqs\r\nwbqse\r\nrl\r\nfoynt\r\nntzjd\r\nlxc\r\npfoy\r\nlx\r\nr\r\nagikm\r\nr\r\ntzjd\r\nep\r\nyntz\r\nu\r\nmw\r\nyntz\r\nfoynt\r\ntzjd\r\njdrlx\r\nwbqse\r\nr\r\nkmw\r\nwbq\r\nlx\r\nfoyn\r\nkm\r\nsepfo\r\nikmw\r\nf\r\nrlxch\r\nzjdrl\r\nyn\r\nhv\r\nynt\r\nbqs\r\nvu\r\nik\r\nqse\r\nxchvu\r\nmwbqs\r\ny\r\nlx\r\nx\r\nntzjd\r\nbq\r\nxchv\r\nwbqse\r\nkm\r\nse\r\nmwb\r\nxchvu\r\nwbq\r\nc\r\ngikm\r\nbq\r\nwb\r\nmwbq\r\nikmw\r\nag\r\ny\r\nchvu\r\nbqsep\r\nbqs\r\nrlx\r\ntzjd\r\nmwb\r\na\r\ndrlxc\r\ntzjd\r\nt\r\nsepf\r\nwbqse\r\nd\r\nbqs\r\nyn\r\nh\r\nepfo\r\n", "output": "agikmwbqsepfoyntzjdrlxchvu\r\n"}, {"input": "13\r\ndaq\r\nvcnexi\r\nlkp\r\nztvcne\r\naqozt\r\nztvcne\r\nprdaqo\r\ncnex\r\nnexijm\r\nztvcne\r\nfysh\r\nxijmb\r\naq\r\n", "output": "fyshlkprdaqoztvcnexijmb\r\n"}, {"input": "2\r\nnxqdblgac\r\nzpjou\r\n", "output": "nxqdblgaczpjou\r\n"}, {"input": "7\r\nfjr\r\ngk\r\nigkf\r\nret\r\nvx\r\nvxa\r\ncv\r\n", "output": "cvxaigkfjret\r\n"}, {"input": "7\r\nwer\r\nqwe\r\nw\r\nq\r\nert\r\ntyu\r\nrty\r\n", "output": "qwertyu\r\n"}, {"input": "4\r\na\r\nb\r\nab\r\nabc\r\n", "output": "abc\r\n"}, {"input": "4\r\nt\r\nwef\r\nqwe\r\nh\r\n", "output": "qwefth\r\n"}, {"input": "5\r\nabcd\r\nbc\r\ndef\r\nde\r\ncd\r\n", "output": "abcdef\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(input_path) as f:
n = int(f.readline().strip())
fragments = [line.strip() for line in f]
with open(output_path) as f:
correct_output = f.read().strip()
correct_length = len(correct_output)
with open(submission_path) as f:
submission_output = f.read().strip()
# Check length matches correct (minimal)
if len(submission_output) != correct_length:
print(0)
return
# Check all characters are unique
if len(set(submission_output)) != len(submission_output):
print(0)
return
# Check all fragments are present as substrings
sub = submission_output
for frag in fragments:
if frag not in sub:
print(0)
return
# All conditions met
print(1)
if __name__ == "__main__":
main()
| true |
220/A
|
220
|
A
|
PyPy 3-64
|
TESTS
| 28 | 124 | 8,704,000 |
162913096
|
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
c = 0
d = []
for i in range(n-1):
if w[i] <= w[i+1]:
continue
elif c == 0 and w[i] > w[i+1]:
c = 1
d.append(i)
else:
d.append(i+1)
c += 1
if c == 3:
print('NO')
break
else:
if c == 2:
w[d[0]], w[d[1]] = w[d[1]], w[d[0]]
if w == sorted(w):
print('YES')
else:
print('NO')
elif c == 1:
x = d[0]
z = 0
for i in range(x, -1, -1):
if w[i] < w[x]:
z = i + 1
break
w[x+1], w[z] = w[z], w[x+1]
if w == sorted(w):
print('YES')
else:
print('NO')
else:
print('YES')
| 96 | 77 | 13,721,600 |
172778582
|
"""
sort array and count the differences against unsorted,
if there are more than 2 differences, it wasn't an accident
"""
def was_accident(n: int, array: list[int]) -> bool:
"""
time O(n log n)
space O(n)
"""
# O(n log n)
sorted_array = sorted(array)
diffs = 0
# O(n)
for i in range(n):
if array[i] != sorted_array[i]:
diffs += 1
if diffs > 2:
return False
return True
if __name__ == "__main__":
n = int(input())
# O(n)
array = list(map(int, input().split()))
answer = "YES" if was_accident(n, array) else "NO"
print(answer)
|
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 |
220/A
|
220
|
A
|
PyPy 3
|
TESTS
| 28 | 248 | 10,956,800 |
57320916
|
class CodeforcesTask220ASolution:
def __init__(self):
self.result = ''
self.array_len = 0
self.array = []
def read_input(self):
self.array_len = int(input())
self.array = [int(x) for x in input().split(" ")]
def process_task(self):
to_swap1 = -1
to_swap2 = -1
for x in range(self.array_len - 1):
if self.array[self.array_len - 2 - x] > self.array[self.array_len - 1 - x]:
to_swap1 = self.array_len - 1 - x
for y in range(to_swap1):
if self.array[y] > self.array[to_swap1]:
to_swap2 = y
break
break
a2 = self.array[:]
if to_swap2 >= 0 and to_swap1 >= 0:
swap = a2[to_swap1]
a2[to_swap1] = a2[to_swap2]
a2[to_swap2] = swap
if sorted(self.array) == a2:
self.result = "YES"
elif sorted(self.array) == self.array:
self.result = "YES"
else:
self.result = "NO"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask220ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| 96 | 77 | 14,131,200 |
195980730
|
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
cnt = 0
for i in range(n):
if a[i] != b[i]:
cnt += 1
if cnt < 3:
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 |
220/A
|
220
|
A
|
Python 3
|
TESTS
| 28 | 218 | 9,420,800 |
5037967
|
n, t = int(input()), [0] + list(map(int, input().split())) + [1000000001]
p = [i for i in range(n + 1) if t[i] > t[i + 1]]
ans, l = 'NO', len(p)
if l == 0: ans = 'YES'
elif l < 3:
if l == 1:
x, y = p[0], p[0] + 1
while t[x] == t[x - 1]: x -= 1
else: x, y = p[0], p[1] + 1
if t[x - 1] <= t[y] <= t[x + 1] and t[y - 1] <= t[x] <= t[y + 1]: ans = 'YES'
print(ans)
| 96 | 77 | 14,131,200 |
226367683
|
n = int(input())
a = list(map(int, input().split()))
b = a[:]
a.sort()
cnt = 0
for i in range(n):
if a[i] != b[i]:
cnt += 1
if cnt <= 2:
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 |
714/B
|
714
|
B
|
Python 3
|
TESTS
| 25 | 109 | 9,011,200 |
111631536
|
# link: https://codeforces.com/contest/714/problem/B
if __name__ == "__main__":
n = int(input())
a = list(map(int, input().split()))
unique = set(a)
# now I have the unique elements in sorted order
if len(unique) <= 2:
print("YES")
exit(0)
n = len(unique)
if sum(unique) % n !=0:
print("NO")
exit(0)
# s % n == 0:
x = sum(unique)//n
if x%2 == 0:
print("YES")
else:
print("NO")
| 79 | 77 | 9,113,600 |
167902807
|
n=int(input())
arr=set(map(int,input().split()))
if len(arr)<=3:
if len(arr)==3:
arr1=[]
for i in arr:
arr1.append(i)
arr1.sort()
if arr1[1]-arr1[0]==arr1[2]-arr1[1]:
print("YES")
else: print("NO")
else: print("YES")
else:print("NO")
|
Codeforces Round 371 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Filya and Homework
|
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
|
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
| null |
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
|
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
| 1,200 |
["implementation", "sortings"]
| 79 |
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
748/B
|
748
|
B
|
Python 3
|
TESTS
| 42 | 62 | 4,608,000 |
23302040
|
s = str(input())
t = str(input())
letters,letters_swp = {},{}
new_t = ''
for i in range(len(s)):
if s[i] != t[i] and t[i] not in letters.values() and t[i] not in letters.keys():
letters.setdefault(s[i],t[i])
letters_swp.setdefault(t[i],s[i])
for q in range(len(t)):
if t[q] in letters_swp.keys():
new_t += letters_swp[t[q]]
elif t[q] in letters.keys():
new_t += letters[t[q]]
else:
new_t += t[q]
if s != new_t:
print('-1')
elif s == t:
print('0')
else:
print(len(letters))
for key,val in letters.items():
print(str(key)+' '+str(val))
| 86 | 46 | 0 |
180975754
|
"""
https://codeforces.com/problemset/problem/748/B
"""
a = input()
b = input()
dico = dict()
dicoinv = dict()
correct = True
for x, y in zip(a, b):
if x not in dico:
dico[x] = dico.get(x, [])
if y not in dico[x]:
dico[x].append(y)
if len(dico[x])>1:
correct=False
break
if y not in dicoinv:
dicoinv[y] = dicoinv.get(y, [])
if x not in dicoinv[y]:
dicoinv[y].append(x)
if len(dicoinv[y])>1:
correct=False
break
if correct:
for k, v in dico.items():
z = v[0]
if z in dico and list(dico[z])[0] != k:
correct = False
break
if correct:
for k, v in dicoinv.items():
z = v[0]
if z in dicoinv and list(dico[z])[0] != k:
correct = False
break
if correct:
res = []
for k, v in dico.items():
if k != v[0]:
h = [k, v[0]]
h.sort()
if h not in res:
res.append(h)
print(len(res))
for h in res:
print(*h)
else:
print(-1)
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
220/A
|
220
|
A
|
PyPy 3
|
TESTS
| 28 | 202 | 9,216,000 |
121478750
|
n = int(input())
a = []
b = input()
i = 0
while i < len(b):
to_add = ""
while i < len(b) and b[i] != " ":
to_add += b[i]
i += 1
a.append(int(to_add))
i += 1
two_times = False
first = second = -1
for i in range(1, n):
if a[i] < a[i - 1]:
if first == -1:
first = i - 1
second = i
else:
second = i
break
if first == second == -1:
print("YES")
exit()
for i in range(n):
if a[i] > a[second]:
a[i], a[second] = a[second], a[i]
break
for i in range(1, n):
if a[i] < a[i - 1]:
print("NO")
exit()
print("YES")
| 96 | 92 | 12,800,000 |
211858580
|
n = int(input())
l = list(map(int,input().split()))
l2 = sorted(l)
counter = 0
res = "YES"
for i in range(n) :
if l[i] != l2[i] :
counter += 1
if counter > 2 :
res= "NO"
break
print(res)
|
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 |
748/B
|
748
|
B
|
Python 3
|
TESTS
| 68 | 62 | 4,608,000 |
23410307
|
s = input()
t = input()
used, ln = set(), 0
for i in range(len(s)):
if (s[i] != t[i]) and (not (tuple(sorted([s[i], t[i]])) in used)):
ln += 1
used.add(tuple(sorted([s[i], t[i]])))
a = [i[0] for i in used]
b = [i[1] for i in used]
if len(a) != len(set(a)) or len(b) != len(set(b)):
print(-1)
elif len(a) == 0:
print(0)
else:
print(ln)
for i in used:
if i[0] != i[1]:
print(i[0], i[1])
| 86 | 62 | 4,608,000 |
23291438
|
s=input()
s2=input()
a=[set() for i in range(97)]
for i in range(len(s)):
a[ord(s[i])-97].add(ord(s2[i])-97)
a[ord(s2[i])-97].add(ord(s[i])-97)
if max([len(i) for i in a])>1:
print(-1)
else:
t=set()
for i in range(26):
if a[i]!=set():
o=tuple(sorted([chr(i+97),chr(list(a[i])[0]+97)]))
if o[0]!=o[1]:
t.add(o)
print(len(t))
for i in t:
print(i[0],i[1])
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
961/D
|
961
|
D
|
Python 3
|
TESTS
| 48 | 482 | 11,161,600 |
190607971
|
def pairoflines(n, p):
if n <= 3:
return True
def getkb(x1, y1, x2, y2):
if x1 == x2:
return None, x1
return (y1 - y2) / (x1 - x2), (x1 * y2 - x2 * y1) / (x1 - x2)
def inline(k, b, x, y):
if k is None:
return x == b
else:
return k * x + b == y
def valid(k1, b1, k2, b2):
for x, y in p:
if not (inline(k1, b1, x, y) or inline(k2, b2, x,y)):
return False
else:
return True
(x1, y1), (x2, y2), (x3, y3) = p[0], p[1], p[2]
k1, b1 = getkb(x1, y1, x2, y2)
k2, b2 = getkb(x1, y1, x3, y3)
k3, b3 = getkb(x2, y2, x3, y3)
for k, b in [(k1, b1), (k2, b2), (k3, b3)]:
otherp = []
for x, y in p:
if not inline(k, b, x, y):
otherp.append((x,y))
# print(k, b, otherp)
if len(otherp) <= 2:
return True
kk, bb = getkb(otherp[0][0], otherp[0][1], otherp[1][0], otherp[1][1])
flag = True
for x, y in otherp:
if not inline(kk, bb, x, y):
flag = False
if flag:
return True
return False
if __name__ == "__main__":
n = int(input())
p = []
for i in range(n):
x, y = [int(_) for _ in input().split()]
p.append((x, y))
if pairoflines(n, p):
print("YES")
else:
print("NO")
| 121 | 404 | 18,022,400 |
71933707
|
import sys
input = sys.stdin.readline
class vector2:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, other):
return vector2(self.x - other.x, self.y - other.y)
def __mul__(self, other):
return self.x * other.y - self.y * other.x
def oneline(a, b, c):
x, y = b - a, c - a
return x * y == 0
def oneline2(a):
if len(a) <= 2:
return True
for i in range(2, len(a)):
if not oneline(a[0], a[1], a[i]):
return False
return True
n = int(input())
a = []
for i in range(n):
x, y = map(int, input().split())
a.append(vector2(x, y))
if n <= 3:
print('YES')
exit()
b = []
for i in range(2, n):
if not oneline(a[0], a[1], a[i]):
b.append(a[i])
if not b or oneline2(b):
print('YES')
exit()
p = b[0]
b = []
for i in range(n):
if not oneline(a[0], p, a[i]):
b.append(a[i])
if not b or oneline2(b):
print('YES')
exit()
b = []
for i in range(n):
if not oneline(a[1], p, a[i]):
b.append(a[i])
if not b or oneline2(b):
print('YES')
exit()
print('NO')
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
PyPy 3
|
TESTS
| 37 | 404 | 34,611,200 |
86183077
|
import sys
import math
from collections import defaultdict,deque
import heapq
mod=10**9+7
def check(others):
p1=others[0]
p2=others[1]
m=0
if p1[0]==p2[0]:
m=1e9
else:
m=(p1[1]-p2[1])/(p1[0]-p2[0])
n=len(others)
for i in range(1,n):
p2=others[i]
if p1==p2:
continue
if p1[0]==p2[0]:
nm=1e9
else:
nm=(p1[1]-p2[1])/(p1[0]-p2[0])
if m!=nm:
return False
return True
n=int(sys.stdin.readline())
points=[[0,0] for _ in range(n)]
for i in range(n):
a,b=map(int,sys.stdin.readline().split())
points[i][0]=a
points[i][1]=b
if n<=4:
print("YES")
sys.exit()
others=[]
p1,p2=points[0],points[1]
m=0
if p1[0]==p2[0]:
m=1e9
else:
m=(p1[1]-p2[1])/(p1[0]-p2[0])
cnt=0
for i in range(1,n):
p2=points[i]
nm=0
if p1==p2:
continue
if p1[0]==p2[0]:
nm=1e9
else:
nm=(p1[1]-p2[1])/(p1[0]-p2[0])
if nm!=m:
cnt+=1
others.append(p2)
if cnt<=2:
print("YES")
sys.exit()
if check(others):
print("YES")
sys.exit()
p2=others[0]
nothers=[]
m=0
if p1[0]==p2[0]:
m=1e9
else:
m=(p1[1]-p2[1])/(p1[0]-p2[0])
cnt=0
for i in range(1,n):
p2=points[i]
nm=0
if p1==p2:
continue
if p1[0]==p2[0]:
nm=1e9
else:
nm=(p1[1]-p2[1])/(p1[0]-p2[0])
if nm!=m:
cnt+=1
nothers.append(p2)
if cnt<=2:
print("YES")
sys.exit()
if check(nothers):
print("YES")
sys.exit()
p1=others[0]
p2=nothers[0]
nnothers=[]
m=0
if p1[0]==p2[0]:
m=1e9
else:
m=(p1[1]-p2[1])/(p1[0]-p2[0])
cnt=0
for i in range(0,n):
p2=points[i]
nm=0
if p1==p2:
continue
if p1[0]==p2[0]:
nm=1e9
else:
nm=(p1[1]-p2[1])/(p1[0]-p2[0])
if nm!=m:
cnt+=1
nnothers.append(p2)
if cnt<=2:
print("YES")
sys.exit()
if check(nnothers):
print("YES")
sys.exit()
print("NO")
| 121 | 514 | 18,534,400 |
36969966
|
#!/usr/bin/env python3
import sys
from itertools import combinations
n = int(sys.stdin.readline().strip())
xys = [tuple(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
xys = list(set(xys))
if len(xys) < 5:
print ('YES')
sys.exit(0)
def is_on_line(p0, p1, p2):
return ((p1[0] - p0[0]) * (p2[1] - p0[1]) == (p1[1] - p0[1]) * (p2[0] - p0[0]))
l1 = (-1, -1, -1)
for comb in combinations(range(5), 3):
if is_on_line(xys[comb[0]], xys[comb[1]], xys[comb[2]]):
l1 = comb
break
if l1[0] < 0:
print ('NO')
sys.exit(0)
line = [0 for _ in range(n)]
for l in l1:
line[l] = 1
for i in range(n):
if i in l1:
continue
if is_on_line(xys[l1[0]], xys[l1[1]], xys[i]):
line[i] = 1
nline = [i for i in range(n) if line[i] == 0]
if len(nline) < 3:
print ('YES')
sys.exit(0)
for i in nline[2:]:
if not is_on_line(xys[nline[0]], xys[nline[1]], xys[i]):
print ('NO')
sys.exit(0)
print ('YES')
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
PyPy 3
|
TESTS
| 14 | 404 | 28,057,600 |
109486261
|
import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))
def inps(): return sys.stdin.readline()
def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])
def err(x): print(x); exit()
def cal_d(dx,dy):
g = math.gcd(dx,dy)
dx,dy = dx//g, dy//g
if dx<0: dx=-dx; dy=-dy
return (dx,dy)
n = inp()
xy = [inpl() for _ in range(n)]
if n < 4: err('YES')
dx,dy = xy[1][0]-xy[0][0], xy[1][1]-xy[0][1]
dx,dy = cal_d(dx,dy)
X,Y = xy[0]
seen = set([0,1])
xys = []
for i in range(n):
if i in seen: continue
nx,ny = xy[i][0]-X, xy[i][1]-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) == (nx,ny): seen.add(i)
else: xys.append(xy[i][:])
if len(xys) < 2: err('YES')
dx,dy = xys[1][0]-xys[0][0], xys[1][1]-xys[0][1]
dx,dy = cal_d(dx,dy)
X,Y = xys[0]
for x,y in xys[2:]:
nx,ny = x-X, y-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) != (nx,ny): break
else: err('YES')
dx,dy = xy[2][0]-xy[0][0], xy[2][1]-xy[0][1]
dx,dy = cal_d(dx,dy)
X,Y = xy[0]
seen = set([0,2])
xys = []
for i in range(n):
if i in seen: continue
nx,ny = xy[i][0]-X, xy[i][1]-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) == (nx,ny): seen.add(i)
else: xys.append(xy[i][:])
if len(xys) < 2: err('YES')
dx,dy = xys[1][0]-xys[0][0], xys[1][1]-xys[0][1]
dx,dy = cal_d(dx,dy)
X,Y = xys[0]
for x,y in xys[2:]:
nx,ny = x-X, y-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) != (nx,ny):break
else: err('YES')
dx,dy = xy[1][0]-xy[2][0], xy[1][1]-xy[2][1]
dx,dy = cal_d(dx,dy)
X,Y = xy[1]
seen = set([2,1])
xys = []
for i in range(n):
if i in seen: continue
nx,ny = xy[i][0]-X, xy[i][1]-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) == (nx,ny): seen.add(i)
else: xys.append(xy[i][:])
if len(xys) < 2: err('YES')
dx,dy = xys[1][0]-xys[0][0], xys[1][1]-xys[0][1]
dx,dy = cal_d(dx,dy)
X,Y = xys[0]
for x,y in xys[2:]:
nx,ny = x-X, y-Y
nx,ny = cal_d(nx,ny)
if (dx,dy) != (nx,ny): break
else: err('YES')
print('NO')
| 121 | 514 | 19,456,000 |
36971955
|
from itertools import combinations
from fractions import gcd
def main():
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
print(solve(n, p))
def solve(n, p):
if n < 5:
return "YES"
p5 = p[:5]
## for p1, p2 in combinations(p5, 2):
## print(p1, p2, line(p1, p2), nb_points(line(p1, p2), p5))
lines = set(line(p1, p2) for p1, p2 in combinations(p5, 2))
## for l in lines:
## print(l, nb_points(l, p5))
l0 = None
for l in lines:
if nb_points(l, p5) > 2:
l0 = l
break
if l0 is None:
return "NO"
pr = [pi for pi in p if not belongs(pi, l0)]
if colinear(pr):
return "YES"
return "NO"
def line(p1, p2):
x1, y1 = p1
x2, y2 = p2
a = y2 - y1
b = x1 - x2
c = x2 * y1 - x1 * y2
if a < 0:
a, b, c = -a, -b, -c
if a == 0:
if b < 0:
b, c = -b, -c
if c == 0:
b = 1
else:
g = abs(gcd(b, c))
b, c = b // g, c // g
else:
if b == 0:
if c == 0:
a = 1
else:
g = abs(gcd(a, c))
a, c = a // g, c // g
else:
if c == 0:
g = abs(gcd(a, b))
a, b = a // g, b // g
else:
g = abs(gcd(gcd(a, b), c))
a, b, c = a // g, b // g, c // g
return a, b, c
def belongs(pi, l):
a, b, c = l
return a * pi[0] + b * pi[1] + c == 0
def nb_points(l, p):
return sum(1 for pi in p if belongs(pi, l))
def colinear(p):
if len(p) <= 2:
return True
l = line(p[0], p[1])
return all(belongs(pi, l) for pi in p[2:])
main()
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
993/C
|
993
|
C
|
PyPy 3
|
TESTS
| 77 | 1,450 | 1,638,400 |
39800799
|
n, m = map(int, input().split())
y1 = list(map(int, input().split()))
y2 = list(map(int, input().split()))
ps = {}
for i in range(n):
for j in range(m):
p = y1[i]
q = y2[j]
a = p * 2
b = q * 2
inter = (a + b) // 2
if not inter in ps:
ps[inter] = []
ps[inter].append(i)
ps[inter].append(j + n)
ans = 0
for x in ps.keys():
for y in ps.keys():
if x == y:
continue
dead = set()
for a in ps[x]: dead.add(a)
for a in ps[y]: dead.add(a)
if len(dead) > ans:
ans = len(dead)
print(ans)
| 88 | 1,294 | 11,468,800 |
100325174
|
n, m = map(int, input().strip().split())
y1 = list(map(int, input().strip().split()))
y2 = list(map(int, input().strip().split()))
y1.sort()
y2.sort()
u1 = list()
u2 = list()
p = 0
while p < n:
q = p
while q < n and y1[q] == y1[p]:
q += 1
u1.append((y1[p], q - p))
p = q
p = 0
while p < m:
q = p
while q < m and y2[q] == y2[p]:
q += 1
u2.append((y2[p], q - p))
p = q
# print(u1)
# print(u2)
n = len(u1)
m = len(u2)
res = 0
for i in range(n):
for j in range(m):
ya = u1[i][0] + u2[j][0] # first small ship
y1_stat = [True] * n
y2_stat = [True] * m
for ii in range(n):
for jj in range(m):
if u1[ii][0] + u2[jj][0] == ya:
y1_stat[ii] = False # right large ship destroyed
y2_stat[jj] = False # left large ship destroyed
f = dict()
for ii in range(n):
for jj in range(m):
yb = u1[ii][0] + u2[jj][0] # second small ship
inc = 0
if y1_stat[ii]:
inc += u1[ii][1]
if y2_stat[jj]:
inc += u2[jj][1]
if yb in f:
f[yb] += inc
else:
f[yb] = inc
yb = -1
if f:
yb = max(f, key=f.get)
for ii in range(n):
for jj in range(m):
if u1[ii][0] + u2[jj][0] == yb:
y1_stat[ii] = False
y2_stat[jj] = False
cur = 0
cur += sum(u1[ii][1] for ii in range(n) if not y1_stat[ii])
cur += sum(u2[jj][1] for jj in range(m) if not y2_stat[jj])
res = max(res, cur)
print(res)
|
Codeforces Round 488 by NEAR (Div. 1)
|
CF
| 2,018 | 2 | 256 |
Careful Maneuvering
|
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$-100$$$, while the second group is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$100$$$.
Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with $$$x=0$$$ (with not necessarily integer $$$y$$$-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots.
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 60$$$), the number of enemy spaceships with $$$x = -100$$$ and the number of enemy spaceships with $$$x = 100$$$, respectively.
The second line contains $$$n$$$ integers $$$y_{1,1}, y_{1,2}, \ldots, y_{1,n}$$$ ($$$|y_{1,i}| \le 10\,000$$$) — the $$$y$$$-coordinates of the spaceships in the first group.
The third line contains $$$m$$$ integers $$$y_{2,1}, y_{2,2}, \ldots, y_{2,m}$$$ ($$$|y_{2,i}| \le 10\,000$$$) — the $$$y$$$-coordinates of the spaceships in the second group.
The $$$y$$$ coordinates are not guaranteed to be unique, even within a group.
|
Print a single integer – the largest number of enemy spaceships that can be destroyed.
| null |
In the first example the first spaceship can be positioned at $$$(0, 2)$$$, and the second – at $$$(0, 7)$$$. This way all the enemy spaceships in the first group and $$$6$$$ out of $$$9$$$ spaceships in the second group will be destroyed.
In the second example the first spaceship can be positioned at $$$(0, 3)$$$, and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
|
[{"input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13", "output": "9"}, {"input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "10"}]
| 2,100 |
["bitmasks", "brute force", "geometry"]
| 88 |
[{"input": "3 9\r\n1 2 3\r\n1 2 3 7 8 9 11 12 13\r\n", "output": "9\r\n"}, {"input": "5 5\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "10\r\n"}, {"input": "50 50\r\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625 975 457 414 434 146 602 235 86 240 756 161 675\r\n222 371 393 634 76 268 348 294 227 429 835 534 756 67 174 704 685 462 829 561 249 148 868 512 118 232 33 450 445 420 397 129 122 74 426 441 989 892 662 727 492 702 352 818 399 968 894 297 342 405\r\n", "output": "29\r\n"}, {"input": "60 60\r\n842 229 415 973 606 880 422 808 121 317 41 358 725 32 395 286 819 550 410 516 81 599 623 275 568 102 778 234 385 445 194 89 105 643 220 165 872 858 420 653 843 465 696 723 594 8 127 273 289 345 260 553 231 940 912 687 205 272 14 706\r\n855 361 529 341 602 225 922 807 775 149 212 789 547 766 813 624 236 583 207 586 516 21 621 839 259 774 419 286 537 284 685 944 223 189 358 232 495 688 877 920 400 105 968 919 543 700 538 466 739 33 729 292 891 797 707 174 799 427 321 953\r\n", "output": "40\r\n"}, {"input": "1 5\r\n1\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "5 1\r\n1 2 3 4 5\r\n1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-10000 10000\r\n-10000 10000\r\n", "output": "4\r\n"}, {"input": "8 57\r\n-107 1000 -238 -917 -918 668 -769 360\r\n124 250 601 242 189 155 688 -886 -504 39 -924 -266 -122 109 232 216 567 576 269 -349 257 589 -462 939 977 0 -808 118 -423 -856 769 954 889 21 996 -714 198 -854 981 -99 554 302 -27 454 -557 -585 465 -513 -113 714 -82 -906 522 75 -866 -942 -293\r\n", "output": "8\r\n"}, {"input": "43 48\r\n-10 -4 -4 3 -4 3 -1 9 10 4 -2 -8 -9 -6 4 0 4 3 -1 -3 -1 7 10 -2 6 6 -4 -7 7 10 -5 -2 9 -4 -3 -1 -3 -9 0 -5 -6 -7 2\r\n-8 10 8 4 -3 7 2 -6 10 -1 4 -8 1 3 -8 5 2 4 8 7 -4 -7 8 -8 2 4 -2 4 2 1 -4 9 -3 -9 -1 6 -9 1 -6 -4 6 -2 3 5 5 6 -3 -3\r\n", "output": "91\r\n"}, {"input": "8 9\r\n782 -300 482 -158 -755 809 -125 27\r\n0 251 593 796 371 839 -892 -954 236\r\n", "output": "4\r\n"}, {"input": "54 41\r\n-5 9 -4 -7 8 -2 -5 -3 -10 -10 -9 2 9 1 -8 -5 -5 -3 1 -7 -2 -8 -5 -1 2 6 -2 -10 -7 5 2 -4 -9 -2 4 -6 5 5 -3 7 -5 2 7 0 -3 8 -10 5 6 -4 -7 3 -9 6\r\n-5 -5 10 3 2 5 -3 4 -5 -6 2 9 -7 3 0 -3 -10 -6 -5 -5 9 0 1 -6 1 0 -9 8 -10 -3 -2 -10 4 -1 -3 -10 -6 -7 -6 -3 2\r\n", "output": "95\r\n"}, {"input": "46 52\r\n-31 11 38 -71 38 39 57 -31 -2 85 25 -85 17 -8 93 -1 75 -89 22 -61 -66 63 -91 80 -66 19 57 86 42 36 16 -65 -76 53 -21 85 -66 -96 85 45 35 29 54 18 -94 78\r\n-14 65 94 33 42 23 94 98 -44 -68 5 -27 -5 50 30 -56 49 -31 -61 34 9 -63 -92 48 17 99 -98 54 -13 34 46 13 -38 81 6 -58 68 -97 21 97 84 -10 5 11 99 -65 36 99 23 -20 -81 50\r\n", "output": "53\r\n"}, {"input": "51 49\r\n-6 6 -4 -9 10 -5 1 -7 10 -7 -9 7 -6 5 -7 -5 5 6 -1 9 -10 6 -9 -7 1 7 6 -2 -6 0 -9 5 3 -9 0 8 -8 -5 -6 3 0 2 -1 -8 -3 -4 -8 0 1 -7 10\r\n-9 -4 10 -1 4 7 -2 5 -4 -8 0 -2 -10 10 9 9 10 -6 -8 -3 -6 -7 2 1 -4 -4 5 -5 5 2 8 -3 -7 5 10 7 2 -2 6 7 6 -3 -4 -8 -7 -3 5 -7 4\r\n", "output": "100\r\n"}, {"input": "49 45\r\n293 126 883 638 33 -235 -591 -317 -532 -850 367 249 -470 373 -438 866 271 357 423 -972 -358 -418 531 -255 524 831 -200 -677 -424 -486 513 84 -598 86 525 -612 749 -525 -904 -773 599 170 -385 -44 40 979 -963 320 -875\r\n-197 47 -399 -7 605 -94 371 -752 370 459 297 775 -144 91 895 871 774 997 71 -23 301 138 241 891 -806 -990 111 -120 -233 552 557 633 -221 -804 713 -384 404 13 345 4 -759 -826 148 889 -270\r\n", "output": "20\r\n"}, {"input": "59 50\r\n-85 -30 33 10 94 91 -53 58 -21 68 5 76 -61 -35 9 -19 -32 8 57 -75 -49 57 92 8 92 -39 98 -81 -55 -79 -9 36 19 57 -32 11 -68 60 -20 25 -65 1 -25 -59 -65 -30 93 -60 59 10 -92 -76 -83 71 -89 33 1 60 -65\r\n39 -57 -21 -13 9 34 -93 -11 56 0 -40 -85 18 -96 66 -29 -64 52 -61 -20 67 54 -20 83 -8 -20 75 37 75 -81 37 -67 -89 -91 -30 86 93 58 33 62 -68 -48 87 -7 72 -62 59 81 -6 30\r\n", "output": "68\r\n"}, {"input": "57 57\r\n77 62 -5 -19 75 31 -71 29 -73 68 -4 42 -73 72 29 20 50 45 -4 28 73 -1 -25 69 -55 27 5 88 81 52 84 45 -11 -93 -4 23 -33 11 65 47 45 -83 -89 -11 -100 -26 89 41 35 -91 11 4 -23 57 38 17 -67\r\n68 75 5 10 -98 -17 73 68 -56 -82 69 55 62 -73 -75 -6 46 87 14 -81 -50 -69 -73 42 0 14 -82 -19 -5 40 -60 12 52 -46 97 70 45 -93 29 36 -41 61 -75 -84 -50 20 85 -33 10 80 33 50 44 -67 91 63 6\r\n", "output": "64\r\n"}, {"input": "52 16\r\n-4770 -9663 -5578 4931 6841 2993 -9006 -1526 -7843 -6401 -3082 -1988 -790 -2443 135 3540 6817 1432 -5237 -588 2459 4466 -4806 -3125 -8135 2879 -7059 8579 5834 9838 4467 -8424 -115 -6929 3050 -9010 9686 -9669 -3200 8478 -605 4845 1800 3070 2025 3063 -3787 -2948 3255 1614 7372 1484\r\n8068 -5083 -2302 8047 8609 -1144 -2610 -7251 820 -9517 -7419 -1291 1444 4232 -5153 5539\r\n", "output": "8\r\n"}, {"input": "8 7\r\n1787 -3614 8770 -5002 -7234 -8845 -585 -908\r\n1132 -7180 -5499 3850 352 2707 -8875\r\n", "output": "4\r\n"}, {"input": "50 46\r\n17 29 -14 -16 -17 -54 74 -70 -43 5 80 15 82 -10 -21 -98 -98 -52 50 90 -2 97 -93 8 83 89 -31 44 -96 32 100 -4 77 36 71 28 -79 72 -18 89 -80 -3 -73 66 12 70 -78 -59 55 -44\r\n-10 -58 -14 -60 -6 -100 -41 -52 -67 -75 -33 -80 -98 -51 -76 92 -43 -4 -70 83 -70 28 -95 8 83 0 -54 -78 75 61 21 38 -53 -61 -95 4 -42 -43 14 60 -15 45 -73 -23 76 -73\r\n", "output": "56\r\n"}, {"input": "6 8\r\n9115 641 -7434 1037 -612 -6061\r\n-8444 4031 7752 -7787 -1387 -9687 -1176 8891\r\n", "output": "4\r\n"}, {"input": "60 13\r\n999 863 66 -380 488 494 -351 -911 -690 -341 -729 -215 -427 -286 -189 657 44 -577 655 646 731 -673 -49 -836 -768 -84 -833 -539 345 -244 562 -748 260 -765 569 -264 43 -853 -568 134 -574 -874 -64 -946 941 408 393 -741 155 -492 -994 -2 107 508 -560 15 -278 264 -875 -817\r\n-138 422 -958 95 245 820 -805 -27 376 121 -508 -951 977\r\n", "output": "12\r\n"}, {"input": "50 58\r\n-7 7 10 1 4 1 10 -10 -8 2 1 5 -9 10 2 -3 -6 -7 -8 2 7 0 8 -2 -7 9 -4 8 -6 10 -9 -9 2 -8 8 0 -2 8 -10 -10 -10 2 8 -3 5 1 0 4 -9 -2\r\n6 6 -9 10 -2 -2 7 -5 9 -5 -7 -8 -8 5 -9 -3 -3 7 9 0 9 -1 1 5 1 0 -8 -9 -4 4 -4 5 -2 2 -7 -6 10 -1 -8 -3 6 -1 -10 -5 -10 3 9 7 5 -3 8 -7 6 9 1 10 -9 3\r\n", "output": "108\r\n"}, {"input": "17 49\r\n17 55 -3 72 43 -91 1 -51 -5 -58 -30 -3 71 -39 44 9 7\r\n-38 -9 -74 -77 -14 14 78 13 -96 85 54 -83 -90 18 22 4 -61 23 -13 -38 -87 -79 -25 31 -64 47 -92 91 55 -8 -38 -34 -46 6 31 15 -72 80 -46 58 -1 90 -47 -28 53 31 -61 89 61\r\n", "output": "27\r\n"}, {"input": "22 54\r\n484 -77 -421 -590 633 -472 -983 -396 756 -21 -320 -96 -590 -677 758 -556 -672 -798 430 -449 -213 -944\r\n309 -468 -484 973 -992 -385 -210 205 -318 350 468 196 802 461 286 -431 -81 984 286 -462 47 -647 -760 629 314 -388 986 507 898 287 -434 -390 95 -163 584 -67 655 -19 -756 50 215 833 -753 485 -127 62 -897 -898 1 -924 -224 30 -373 975\r\n", "output": "17\r\n"}, {"input": "33 30\r\n-55 26 -48 -87 -87 -73 13 87 -79 -88 91 38 80 86 55 -66 72 -72 -77 -41 95 11 13 -99 -23 -66 -20 35 90 -40 59 -2 43\r\n-56 -23 16 51 78 -58 -61 -18 -7 -57 -8 86 -44 -47 -70 -31 -34 -80 -85 -21 53 93 -93 88 -54 -83 97 57 47 80\r\n", "output": "28\r\n"}, {"input": "10 8\r\n8780 -6753 -8212 -1027 1193 -6328 -4260 -8031 4114 -135\r\n-6545 1378 6091 -4158 3612 1509 -8731 1391\r\n", "output": "4\r\n"}, {"input": "10 5\r\n-7722 3155 -4851 -5222 -2712 4693 -3099 222 -4282 -4848\r\n3839 3098 -8804 4627 -7437\r\n", "output": "4\r\n"}, {"input": "4 10\r\n1796 5110 -8430 -617\r\n9903 -5666 -2809 -4878 -284 -1123 5202 -3694 -789 5483\r\n", "output": "4\r\n"}, {"input": "46 60\r\n-119 682 371 355 -473 978 -474 311 379 -311 601 -287 683 625 982 -772 -706 -995 451 -877 452 -823 -51 826 -771 -419 -215 -502 -110 -454 844 -433 942 250 155 -787 628 282 -818 -784 282 -888 200 628 -320 62\r\n-389 -518 341 98 -138 -816 -628 81 567 112 -220 -122 -307 -891 -85 253 -352 -244 194 779 -884 866 -23 298 -191 -497 106 -553 -612 -48 -279 847 -721 195 -397 -455 486 -572 -489 -183 -582 354 -542 -371 -330 -105 -110 -536 -559 -487 -297 -533 813 281 847 -786 8 -179 394 -734\r\n", "output": "19\r\n"}, {"input": "39 31\r\n268 -441 -422 252 377 420 749 748 660 893 -309 722 -612 -667 363 79 650 884 -672 -880 518 -936 806 376 359 -965 -964 138 851 717 -131 316 603 -375 114 421 976 688 -527\r\n-989 -76 -404 971 -572 771 149 674 -471 218 -317 -225 994 10 509 719 915 -811 -57 -995 865 -486 7 -766 143 -53 699 -466 -165 -486 602\r\n", "output": "15\r\n"}, {"input": "5 3\r\n-8452 -1472 4013 -5048 -6706\r\n-8387 -7493 -7090\r\n", "output": "4\r\n"}, {"input": "58 58\r\n-2 79 3 14 40 -23 87 -86 80 -23 77 12 55 -81 59 -84 -66 89 92 -85 14 -44 -28 -75 77 -36 97 69 21 -31 -26 -13 9 83 -70 38 58 79 -34 68 -52 -50 -68 41 86 -9 -87 64 90 -88 -55 -32 35 100 76 -85 63 -29\r\n68 3 -18 -13 -98 -52 -90 -21 43 -63 -97 49 40 65 -96 83 15 2 76 54 50 49 4 -71 -62 53 26 -90 -38 -24 71 -69 -58 -86 66 5 31 -23 -76 -34 -79 72 7 45 -86 -97 -43 85 -51 -76 26 98 58 -28 58 44 82 -70\r\n", "output": "79\r\n"}, {"input": "9 10\r\n-393 439 961 649 441 -536 -453 989 733\r\n-952 -776 674 696 -452 -700 58 -430 540 271\r\n", "output": "8\r\n"}, {"input": "8 6\r\n-90 817 655 798 -547 -390 -828 -50\r\n-626 -365 426 139 513 -607\r\n", "output": "6\r\n"}, {"input": "54 11\r\n-10 5 -4 -7 -2 10 -10 -4 6 4 9 -7 -10 8 8 6 0 -6 8 4 -6 -1 6 4 -6 1 -2 8 -5 -2 -9 -8 9 6 1 2 10 3 1 3 -3 -10 8 -2 3 9 8 3 -9 -5 -6 -2 -5 -6\r\n10 1 0 -9 -5 -6 8 0 -3 5 -5\r\n", "output": "55\r\n"}, {"input": "6 7\r\n3403 -4195 5813 -1096 -9300 -959\r\n-4820 9153 2254 6322 -5071 6383 -687\r\n", "output": "4\r\n"}, {"input": "41 56\r\n6 2 0 -3 3 6 0 10 -7 -5 -5 7 -5 -9 -3 -5 -2 9 5 -1 1 8 -2 1 -10 10 -4 -9 10 -8 8 7 7 7 4 4 -2 2 4 -6 -7\r\n9 6 -5 6 -7 2 -6 -3 -6 -1 10 -5 -5 3 10 10 4 3 0 2 8 4 -3 3 9 4 -6 0 2 6 6 -2 0 -3 -5 3 4 -2 -3 10 -10 1 3 -3 -7 2 -2 2 0 4 -6 8 -4 -1 1 -6\r\n", "output": "97\r\n"}, {"input": "45 57\r\n-5 -3 -10 2 -3 1 10 -3 -3 -7 -9 6 6 1 8 2 -4 3 -6 9 8 10 -1 8 -2 -8 -9 -7 -8 4 -1 -10 0 -4 8 -7 3 -1 0 3 -8 -10 -6 -8 -5\r\n1 3 -1 7 1 10 3 -2 8 6 0 2 -3 -3 10 -10 -6 -7 10 5 9 10 3 -2 4 10 -10 0 -2 4 -6 -1 -1 -5 7 -3 -2 -7 7 -2 2 2 1 -10 -7 -8 -3 4 0 8 -5 -7 -7 9 -3 8 -5\r\n", "output": "102\r\n"}, {"input": "51 39\r\n-10 6 -8 2 6 6 0 2 4 -3 8 10 7 1 9 -8 4 -2 3 5 8 -2 1 3 1 3 -5 0 2 2 7 -3 -10 4 9 -3 -7 5 5 10 -5 -5 9 -3 9 -1 -4 9 -7 -8 5\r\n-5 10 -2 -8 -10 5 -7 1 7 6 -3 -5 0 -4 0 -9 2 -9 -10 2 -6 10 0 4 -4 -8 -3 1 10 7 5 7 0 -7 1 0 9 0 -5\r\n", "output": "90\r\n"}, {"input": "4 10\r\n3 -7 -4 -8\r\n7 3 -1 -8 2 -1 -5 8 -8 9\r\n", "output": "12\r\n"}, {"input": "44 41\r\n-6 0 -2 5 5 -9 -4 -5 -2 -6 -7 -10 5 2 -6 -3 1 4 8 2 -7 6 5 0 10 -2 -9 3 -6 -3 7 5 -3 7 -10 -1 6 0 10 -6 -5 -6 -6 6\r\n6 -3 1 -1 8 9 6 7 -6 -4 -2 -4 -3 3 2 -1 3 1 10 -2 2 -10 -9 -3 8 -3 -1 -4 0 0 -4 7 -10 6 10 -8 5 6 2 -9 -4\r\n", "output": "85\r\n"}, {"input": "52 43\r\n-514 -667 -511 516 -332 73 -233 -594 125 -847 -584 432 631 -673 -380 835 69 523 -568 -110 -752 -731 864 250 550 -249 525 357 8 43 -395 -328 61 -84 -151 165 -896 955 -660 -195 375 806 -160 870 143 -725 -814 494 -953 -463 704 -415\r\n608 -584 673 -920 -227 -442 242 815 533 -184 -502 -594 -381 -960 786 -627 -531 -579 583 -252 -445 728 902 934 -311 971 119 -391 710 -794 738 -82 774 580 -142 208 704 -745 -509 979 -236 -276 -800\r\n", "output": "18\r\n"}, {"input": "51 48\r\n642 261 822 -266 700 18 -62 -915 39 997 564 -130 605 -141 58 426 -514 425 -310 -56 -524 860 -793 57 511 -563 -529 -140 -679 -489 -841 -326 -108 -785 599 3 -90 -52 769 -513 -328 -709 -887 736 729 -148 232 680 -589 77 531\r\n689 765 386 700 612 -936 -258 966 873 130 230 -78 -835 739 -755 127 -963 -282 -728 -833 345 -817 -61 680 944 -475 -46 -915 777 -789 -742 -755 325 -474 -220 544 19 828 -483 -388 -330 -150 -912 -219 185 -541 237 724\r\n", "output": "20\r\n"}, {"input": "35 32\r\n8 3 9 -6 -6 -3 -6 2 2 3 0 -4 8 9 -10 -7 7 -6 -4 1 -9 3 -2 3 -4 -8 -8 5 -10 2 6 4 -7 -6 -1\r\n7 -2 1 -9 1 8 4 -4 -4 -7 5 4 0 3 5 8 9 -7 -1 -8 -1 7 2 5 6 -2 -8 -2 9 -6 8 -6\r\n", "output": "67\r\n"}, {"input": "54 55\r\n-95 -3 -18 81 -85 -78 -76 95 -4 -91 88 98 35 88 -30 -82 -1 23 -98 82 -83 100 -47 -7 93 -87 -57 -5 -57 -46 30 -16 -27 -46 78 -58 4 87 86 -58 22 19 -40 8 -6 92 -65 10 -51 -34 -70 -69 -70 -51\r\n-42 75 48 -79 58 23 -8 47 48 33 -2 97 -30 -8 -87 56 22 -91 25 27 -91 -75 -10 45 -27 54 -94 60 -49 22 18 2 35 -81 8 -61 91 12 78 6 -83 76 -81 -27 -65 56 -99 -69 3 91 81 -34 9 -29 61\r\n", "output": "63\r\n"}, {"input": "18 4\r\n81 -30 22 81 -9 -66 -39 -11 16 9 91 74 -36 40 -26 -11 -13 -22\r\n21 67 96 96\r\n", "output": "8\r\n"}, {"input": "5 5\r\n9 9 -7 -4 6\r\n2 3 -3 -8 -1\r\n", "output": "7\r\n"}, {"input": "44 49\r\n28 76 41 66 49 31 3 4 41 89 44 41 33 73 5 -85 57 -55 86 43 25 0 -26 -36 81 -80 -71 77 96 85 -8 -96 -91 28 3 -98 -82 -87 -50 70 -39 -99 -70 66\r\n-12 28 11 -25 -34 70 -4 69 9 -31 -23 -8 19 -54 -5 -24 -7 -45 -70 -71 -64 77 39 60 -63 10 -7 -92 22 4 45 75 100 49 95 -66 -96 -85 -35 92 -9 -37 -38 62 -62 24 -35 40 3\r\n", "output": "52\r\n"}, {"input": "57 41\r\n-10 9 2 7 -1 1 -10 9 7 -9 -4 8 4 -8 -6 8 1 5 -7 9 8 -4 1 -2 -7 6 -9 -10 3 0 8 7 1 -4 -6 9 -10 8 3 -9 4 -9 6 -7 10 -4 3 -4 10 -1 -7 -7 -10 -10 0 3 -10\r\n-2 1 -5 6 0 -2 -4 8 2 -9 -6 7 2 6 -9 -1 -1 3 -4 -8 -4 -10 7 -1 -6 -5 -7 5 10 -5 -4 4 -7 6 -2 -9 -10 3 -7 -5 -9\r\n", "output": "98\r\n"}, {"input": "9 5\r\n7 -5 -2 -3 -10 -3 5 4 10\r\n-1 6 -4 3 2\r\n", "output": "11\r\n"}, {"input": "31 55\r\n68 -31 19 47 95 -44 67 45 32 -17 31 -14 52 -19 -75 97 88 9 -11 77 -23 74 -29 31 -42 -15 -77 30 -17 75 -9\r\n-63 94 98 45 -57 -41 4 34 38 67 68 69 -36 47 91 -55 58 73 77 -71 4 -89 -6 49 71 70 -64 -24 -87 -3 -96 62 -31 -56 -2 88 -80 95 -97 -91 25 -2 1 -80 -45 -96 -62 12 12 -61 -13 23 -32 6 29\r\n", "output": "43\r\n"}, {"input": "50 59\r\n-6 -5 8 -6 7 9 2 -7 0 -9 -7 1 -5 10 -6 -2 -10 6 -6 -2 -7 -10 1 4 -4 9 2 -8 -3 -1 5 -4 2 8 -10 7 -10 4 8 7 -4 9 1 5 -10 -7 -2 3 -9 5\r\n-10 -1 3 9 0 8 5 10 -6 -2 -2 4 4 -1 -3 -9 4 -6 9 -5 -5 -4 -7 -2 9 6 -3 -6 -1 -9 1 9 2 -9 2 -5 3 7 -10 7 -3 -1 -10 -3 2 6 -2 -5 10 5 8 7 4 6 -7 -5 2 -2 -10\r\n", "output": "109\r\n"}, {"input": "53 51\r\n678 -657 703 569 -524 -801 -221 -600 -95 11 -660 866 506 683 649 -842 604 -33 -929 541 379 939 -512 -347 763 697 653 844 927 488 -233 -313 357 -717 119 885 -864 738 -20 -350 -724 906 -41 324 -713 424 -432 154 173 406 29 -420 62\r\n-834 648 564 735 206 490 297 -968 -482 -914 -149 -312 506 56 -773 527 816 137 879 552 -224 811 -786 739 -828 -203 -873 148 -290 395 832 -845 302 -324 32 299 746 638 -684 216 392 -137 496 57 -187 477 -16 395 -325 -186 -801\r\n", "output": "24\r\n"}, {"input": "51 7\r\n323 236 120 48 521 587 327 613 -470 -474 522 -705 320 -51 1 288 -430 -954 732 -805 -562 300 -710 190 515 280 -101 -927 77 282 198 -51 -350 -990 -435 -765 178 -934 -955 704 -565 -640 853 -27 950 170 -712 -780 620 -572 -409\r\n244 671 425 977 773 -294 268\r\n", "output": "9\r\n"}, {"input": "9 9\r\n-9 -1 2 8 10 2 9 7 3\r\n5 8 -5 4 -4 -8 2 8 -8\r\n", "output": "16\r\n"}, {"input": "50 60\r\n445 303 -861 -583 436 -125 312 -700 -829 -865 -276 -25 -725 -286 528 -221 757 720 -572 514 -514 359 294 -992 -838 103 611 776 830 143 -247 182 -241 -627 299 -824 635 -571 -660 924 511 -876 160 569 -570 827 75 558 708 46\r\n899 974 750 -138 -439 -904 -113 -761 -150 -92 -279 489 323 -649 -759 667 -600 -76 -991 140 701 -654 -276 -563 108 -301 161 -989 -852 -97 316 31 -724 848 979 -501 -883 569 925 -532 86 456 302 -985 826 79 -911 660 752 941 -464 -157 -110 433 829 -872 172 496 528 -576\r\n", "output": "24\r\n"}, {"input": "7 3\r\n90 67 1 68 40 -100 -26\r\n-96 70 -74\r\n", "output": "6\r\n"}, {"input": "7 4\r\n-8 -2 -5 -3 -8 -9 8\r\n-8 4 -1 10\r\n", "output": "8\r\n"}, {"input": "52 48\r\n-552 43 -670 -163 -765 -603 -768 673 -248 337 -89 941 -676 -406 280 409 -630 -577 324 115 927 477 -242 108 -337 591 -158 -524 928 859 825 935 818 638 -51 988 -568 871 -842 889 -737 -272 234 -643 766 -422 473 -570 -1000 -735 -279 845\r\n963 -436 738 113 273 -374 -568 64 276 -698 -135 -748 909 -250 -740 -344 -436 414 719 119 973 -881 -576 868 -45 909 630 286 -845 458 684 -64 579 965 598 205 -318 -974 228 -596 596 -946 -198 923 571 -907 -911 -341\r\n", "output": "21\r\n"}, {"input": "40 54\r\n-26 -98 27 -64 0 33 62 -12 -8 -10 -62 28 28 75 -5 -89 -75 -100 -63 9 -97 -20 -81 62 56 -39 87 -33 13 61 19 -97 -23 95 18 -4 -48 55 -40 -81\r\n-69 -71 1 -46 -58 0 -100 -82 31 43 -59 -43 77 -8 -61 -2 -36 -55 -35 -44 -59 -13 -16 14 60 -95 -61 25 76 -1 -3 9 -92 48 -92 -54 2 -7 73 -16 42 -40 36 -58 97 81 13 -64 -12 -28 65 85 -61 8\r\n", "output": "54\r\n"}, {"input": "22 34\r\n-73 45 -81 -67 9 61 -97 0 -64 86 -9 47 -28 100 79 -53 25 -59 -80 -86 -47 24\r\n57 69 8 -34 -37 12 -32 -81 27 -65 87 -64 62 -44 97 34 44 -93 44 25 -72 93 14 95 -60 -65 96 -95 23 -69 28 -20 -95 74\r\n", "output": "27\r\n"}, {"input": "46 48\r\n-710 947 515 217 26 -548 -416 494 431 -872 -616 848 -950 -138 -104 560 241 -462 -265 90 66 -331 934 -788 -815 -558 86 39 784 86 -856 879 -733 -653 104 -673 -588 -568 78 368 -226 850 195 982 140 370\r\n470 -337 283 460 -710 -434 739 459 -567 173 217 511 -830 644 -734 764 -211 -106 423 -356 -126 677 -454 42 680 557 -636 9 -552 877 -246 -352 -44 442 -505 -811 -100 -768 -130 588 -428 755 -904 -138 14 -253 -40 265\r\n", "output": "20\r\n"}, {"input": "58 40\r\n120 571 -472 -980 993 -885 -546 -220 617 -697 -182 -42 128 -29 567 -615 -260 -876 -507 -642 -715 -283 495 -584 97 4 376 -131 186 -301 729 -545 8 -610 -643 233 -123 -769 -173 119 993 825 614 -503 891 426 -850 -992 -406 784 634 -294 997 127 697 -509 934 316\r\n630 -601 937 -544 -50 -176 -885 530 -828 556 -784 460 -422 647 347 -862 131 -76 490 -576 5 -761 922 -426 -7 -401 989 -554 688 -531 -303 -415 -507 -752 -581 -589 513 -151 -279 317\r\n", "output": "18\r\n"}, {"input": "8 6\r\n23 -18 -94 -80 74 89 -48 61\r\n-84 45 -12 -9 -74 63\r\n", "output": "7\r\n"}, {"input": "57 55\r\n-34 744 877 -4 -902 398 -404 225 -560 -600 634 180 -198 703 910 681 -864 388 394 -317 839 -95 -706 -474 -340 262 228 -196 -35 221 -689 -960 -430 946 -231 -146 741 -754 330 217 33 276 381 -734 780 -522 528 -425 -202 -19 -302 -743 53 -247 69 -314 -845\r\n-158 24 461 -274 -30 -58 223 -806 747 568 -59 126 56 661 8 419 -422 320 340 480 -185 905 -459 -530 -50 -484 303 366 889 404 915 -361 -985 -642 -690 -577 -80 -250 173 -740 385 908 -4 593 -559 731 326 -209 -697 490 265 -548 716 320 23\r\n", "output": "24\r\n"}, {"input": "59 56\r\n-8 -8 -4 5 -4 4 4 -5 -10 -2 0 6 -9 -2 10 1 -8 -2 9 5 2 -1 -5 7 -7 7 2 -7 -5 2 -2 -8 4 10 5 -9 5 9 6 10 7 6 -6 -4 -8 5 9 6 1 -7 5 -9 8 10 -7 1 3 -6 8\r\n6 -2 -7 4 -2 -5 -9 -5 0 8 5 5 -4 -6 -5 -10 4 3 -4 -4 -8 2 -6 -10 -10 4 -3 8 -1 8 -8 -5 -2 3 7 3 -8 10 6 0 -8 0 9 -3 9 0 9 0 -3 4 -3 10 10 5 -6 4\r\n", "output": "115\r\n"}, {"input": "53 30\r\n-4206 -1169 3492 6759 5051 -3338 4024 8267 -4651 -7685 -3346 -4958 2648 9321 6062 -3566 8118 9067 -1331 5064 148 6375 6193 -2024 -9376 -663 3837 3989 6583 6971 -146 2515 -4222 8159 -94 -4937 -8364 -6025 3566 556 -5229 3138 -9504 1383 1171 -3918 -1587 -6532 -2299 -6648 -5861 4864 9220\r\n-2359 7436 1682 1775 3850 2691 -4326 6670 3245 -3821 5932 -1159 6162 -2818 -5255 -7439 -6688 1778 -5132 8085 -3576 9153 -5260 -1438 9941 -4729 532 -5206 2133 -2252\r\n", "output": "10\r\n"}, {"input": "4 9\r\n-2 3 -5 -10\r\n7 -7 5 5 2 4 9 -4 5\r\n", "output": "11\r\n"}, {"input": "44 50\r\n23 -401 692 -570 264 -885 417 -355 560 -254 -468 -849 900 997 559 12 853 424 -579 485 711 67 638 771 -750 -583 294 -410 -225 -117 -262 148 385 627 610 983 -345 -236 -62 635 -421 363 88 682\r\n-204 -429 -74 855 533 -817 -613 205 972 941 -566 -813 79 -660 -604 661 273 -70 -70 921 -240 148 314 328 -155 -56 -793 259 -630 92 -975 -361 671 963 430 315 -94 957 465 548 -796 626 -58 -595 315 -455 -918 398 279 99\r\n", "output": "22\r\n"}, {"input": "53 30\r\n5 10 -1 -9 7 -7 1 6 0 7 2 -2 -2 1 -9 -9 2 -7 9 10 -9 1 -1 -9 -9 -5 -8 -3 2 4 -3 -6 6 4 -2 -3 -3 -9 2 -4 9 5 6 -5 -5 6 -2 -1 10 7 4 -4 -2\r\n-1 10 3 -1 7 10 -2 -1 -2 0 3 -10 -6 1 -9 2 -10 9 6 -7 -9 3 -7 1 0 9 -8 2 9 7\r\n", "output": "82\r\n"}, {"input": "9 9\r\n1 10 0 -2 9 -7 1 -4 3\r\n-7 -1 6 -4 8 2 6 6 -3\r\n", "output": "15\r\n"}, {"input": "9 9\r\n5181 -7243 3653 3587 -5051 -4899 -4110 7981 -6429\r\n-7365 -2247 7942 9486 -7160 -1020 -8934 7733 -3010\r\n", "output": "4\r\n"}, {"input": "55 43\r\n9 1 0 -7 4 3 4 4 -8 3 0 -7 0 -9 3 -6 0 4 7 1 -1 -10 -7 -6 -8 -8 2 -5 5 -4 -9 -7 5 -3 -7 -10 -4 -2 -7 -3 2 4 9 8 -8 9 -10 0 0 3 -6 -5 -2 9 -6\r\n-4 -6 9 -4 -2 5 9 6 -8 -2 -3 -7 -8 8 -8 5 1 7 9 7 -5 10 -10 -8 -3 10 0 8 8 4 8 3 10 -8 -4 -6 1 9 0 -3 -4 8 -10\r\n", "output": "98\r\n"}, {"input": "53 12\r\n63 88 91 -69 -15 20 98 40 -70 -49 -51 -74 -34 -52 1 21 83 -14 57 40 -57 33 94 2 -74 22 86 79 9 -18 67 -31 72 31 -64 -83 83 29 50 -29 -27 97 -40 -8 -57 69 -93 18 42 68 -71 -86 22\r\n51 19 33 12 98 91 -83 65 -6 16 81 86\r\n", "output": "27\r\n"}, {"input": "1 1\r\n0\r\n0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 2 2\r\n", "output": "6\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "2\r\n"}, {"input": "1 1\r\n0\r\n1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n", "output": "6\r\n"}, {"input": "5 5\r\n5 5 5 5 5\r\n5 5 5 5 5\r\n", "output": "10\r\n"}, {"input": "60 60\r\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59\r\n0 60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080 1140 1200 1260 1320 1380 1440 1500 1560 1620 1680 1740 1800 1860 1920 1980 2040 2100 2160 2220 2280 2340 2400 2460 2520 2580 2640 2700 2760 2820 2880 2940 3000 3060 3120 3180 3240 3300 3360 3420 3480 3540\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 2\r\n0 1\r\n", "output": "4\r\n"}, {"input": "1 1\r\n5\r\n5\r\n", "output": "2\r\n"}, {"input": "10 10\r\n1 1 1 1 1 1 1 1 1 1\r\n-30 -30 -30 -30 40 40 40 40 40 40\r\n", "output": "20\r\n"}]
| false |
stdio
| null | true |
489/B
|
489
|
B
|
PyPy 3-64
|
TESTS
| 37 | 124 | 0 |
201966978
|
from collections import Counter
size1 = int(input())
boys = list(map(int, input().split()))
size2 = int(input())
girls = list(map(int, input().split()))
girls.sort()
pairs = 0
members = Counter(boys)
for g in girls:
if members[g] > 0:
members[g] -= 1
pairs += 1
elif members[g-1] > 0:
members[g-1] -= 1
pairs += 1
elif members[g+1] > 0:
members[g+1] -= 1
pairs += 1
print(pairs)
| 81 | 46 | 0 |
196610946
|
n = int(input())
boys = list(map(int,input().split()))
m = int(input())
girls = list(map(int,input().split()))
boys = sorted(boys)
girls = sorted(girls)
c = 0
i = 0
j = 0
while i <n and j<m:
if abs(boys[i]-girls[j])<2:
c += 1
i += 1
j += 1
elif boys[i]>girls[j]:
j += 1
elif boys[i]<girls[j]:
i += 1
print(c)
|
Codeforces Round 277.5 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
BerSU Ball
|
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill.
Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
Print a single number — the required maximum possible number of pairs.
| null | null |
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
| 1,200 |
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
| 81 |
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
724/B
|
724
|
B
|
Python 3
|
TESTS
| 13 | 46 | 0 |
205675286
|
'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
n,m=map(int,input().split())
mat=[]
for _ in range(n):
mat.append(list(map(int,input().split())))
for c1 in range(m-1):
for c2 in range(c1, m):
flag=0
for row in mat:
row[c1],row[c2]=row[c2],row[c1]
curr=0
for i in range(m):
if row[i]!=i+1:curr+=1
if curr>2:
flag=1
break
if flag==0:
print("YES")
exit()
else:
row[c1],row[c2]=row[c2],row[c1]
print("NO")
| 86 | 62 | 4,915,200 |
21296483
|
from sys import stdin
n, m = (int(x) for x in stdin.readline().split())
table = []
for _ in range(n):
table.append([int(x) for x in stdin.readline().split()])
def tr(l):
return list(map(list, zip(*l)))
def need_one_or_zero_swap(l):
swap = 2
for i, item in enumerate(l):
if item != i + 1:
if swap:
if l[item-1] == i + 1:
swap -= 1
else:
return False
else:
return False
return True
def check_after_global_swap(t):
for row in t:
if not need_one_or_zero_swap(row):
return False
return True
def try_global_swap_first():
if check_after_global_swap(table):
return True
transp = tr(table)
for i in range(len(transp)):
for j in range(i + 1, len(transp)):
transp[i], transp[j] = transp[j], transp[i]
t2 = tr(transp)
if check_after_global_swap(t2):
return True
transp[i], transp[j] = transp[j], transp[i]
return False
if try_global_swap_first():
print('YES')
else:
print('NO')
# print(need_one_or_zero_swap([1, 4, 3, 2]))
|
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
|
CF
| 2,016 | 2 | 256 |
Batch Sort
|
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.
Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.
|
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
| null |
In the first sample, one can act in the following way:
1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2
2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4
|
[{"input": "2 4\n1 3 2 4\n1 3 4 2", "output": "YES"}, {"input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "output": "NO"}, {"input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "output": "YES"}]
| 1,500 |
["brute force", "greedy", "implementation", "math"]
| 86 |
[{"input": "2 4\r\n1 3 2 4\r\n1 3 4 2\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n2 3 4 1\r\n3 4 1 2\r\n4 1 2 3\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 1 3 4 5 6\r\n1 2 4 3 5 6\r\n1 2 3 4 6 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n1 2 3 4 5 6 7 10 9 8\r\n5 2 3 4 1 6 7 8 9 10\r\n1 2 3 4 5 6 7 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
Python 3
|
TESTS
| 7 | 61 | 716,800 |
190438472
|
from __future__ import division
import copy
import random
import heapq
import math
import sys
import bisect
import re
import time
import datetime
from functools import lru_cache
from collections import deque
from collections import Counter
from collections import defaultdict
from itertools import combinations
from itertools import permutations
from itertools import accumulate
from decimal import Decimal, getcontext, MAX_PREC
from types import GeneratorType
from functools import cmp_to_key
inf = float("inf")
sys.setrecursionlimit(10000000)
getcontext().prec = MAX_PREC
class FastIO:
def __init__(self):
return
@staticmethod
def _read():
return sys.stdin.readline().strip()
def read_int(self):
return int(self._read())
def read_float(self):
return float(self._read())
def read_ints(self):
return map(int, self._read().split())
def read_floats(self):
return map(float, self._read().split())
def read_ints_minus_one(self):
return map(lambda x: int(x) - 1, self._read().split())
def read_list_ints(self):
return list(map(int, self._read().split()))
def read_list_floats(self):
return list(map(float, self._read().split()))
def read_list_ints_minus_one(self):
return list(map(lambda x: int(x) - 1, self._read().split()))
def read_str(self):
return self._read()
def read_list_strs(self):
return self._read().split()
def read_list_str(self):
return list(self._read())
@staticmethod
def st(x):
return sys.stdout.write(str(x) + '\n')
@staticmethod
def lst(x):
return sys.stdout.write(" ".join(str(w) for w in x) + '\n')
@staticmethod
def round_5(f):
res = int(f)
if f - res >= 0.5:
res += 1
return res
@staticmethod
def max(a, b):
return a if a > b else b
@staticmethod
def min(a, b):
return a if a < b else b
@staticmethod
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if isinstance(to, GeneratorType):
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
def main(ac=FastIO()):
n = ac.read_int()
nums = [ac.read_list_ints() for _ in range(n)]
if n <= 4:
ac.st("YES")
return
def compute_kb(point1, point2):
x1, y1 = point1
x2, y2 = point2
a, b = x2-x1, y2-y1
g = math.gcd(a, b)
a //= g
b //= g
if a < 0:
a *= -1
b *= -1
return (a, b)
def check():
if len(other) <= 2:
return True
ans = set()
for p in other[1:]:
cur = compute_kb(nums[other[0]], nums[p])
ans.add(cur)
if len(ans) > 1:
return False
return True
for item in combinations(list(range(3)), 2):
i, j = item
pre = compute_kb(nums[i], nums[j])
other = [i for i in range(3) if i not in item]
for k in range(3, n):
if compute_kb(nums[i], nums[k]) != pre:
other.append(k)
if check():
ac.st("YES")
return
ac.st("NO")
return
main()
| 121 | 514 | 20,889,600 |
36962215
|
import atexit
import io
import sys
# Buffering IO
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def ff(p, q, pp):
npp = []
for r in pp:
if (p[1] - r[1]) * (p[0] - q[0]) != (p[1] - q[1]) * (p[0] - r[0]):
npp.append(r)
if len(npp) <= 2:
return True
a = npp[0]
b = npp[1]
for c in npp:
if (a[1] - c[1]) * (a[0] - b[0]) != (a[1] - b[1]) * (a[0] - c[0]):
return False
return True
def main():
n = int(input())
if n <= 4:
print('YES')
return
pp = []
for _ in range(n):
a, b = [int(x) for x in input().split()]
pp.append((a,b))
if ff(pp[0], pp[1],pp) or ff(pp[1], pp[2],pp) or ff(pp[0], pp[2],pp):
print('YES')
else:
print('NO')
if __name__ == '__main__':
main()
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
748/B
|
748
|
B
|
PyPy 3
|
TESTS
| 41 | 140 | 0 |
47269281
|
string1 = input()
string2 = input()
map = dict()
for i in range(len(string1)):
if string1[i] != string2[i]:
map[string1[i]] = string2[i]
map[string2[i]] = string1[i]
tmp = ""
for c in string2:
if c in map:
tmp += map[c]
else:
tmp += c
printed = set()
if string1 == tmp:
print(len(map) // 2)
for v in map:
if v not in printed and map[v] not in printed:
print(v, map[v])
printed.add(v)
printed.add(map[v])
else:
print(-1)
| 86 | 62 | 4,608,000 |
23295189
|
s = input()
t = input()
pairs = set()
good = set()
letters = set()
for i in range(len(s)):
pair = tuple(sorted([s[i], t[i]]))
if pair not in pairs:
if s[i] not in letters and t[i] not in letters:
pairs.add(pair)
letters.add(s[i])
letters.add(t[i])
else:
print(-1)
exit()
pairs1 = set()
for pair in pairs:
if pair[0] != pair[1]:
pairs1.add(pair)
print(len(pairs1))
for pair in pairs1:
print(pair[0], pair[1])
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
984/B
|
984
|
B
|
PyPy 3
|
TESTS
| 5 | 77 | 0 |
177262587
|
line = input()
n, m = int(line[0]), int(line[-1])
grid = []
for i in range(n):
grid.append([k for k in input()])
def k_neighbors(k, arr, x, y):
total = 0
for i in range(x - 1, x + 2):
for j in range(y - 1, y + 2):
if (0 <= i < len(arr)) and (0 <= j < len(arr[i])):
if (not (i == x and j == y)) and arr[i][j] == '*':
total += 1
return total == k
def minesweep(n, m, grid):
for i in range(n):
for j in range(m):
if grid[i][j] != '*':
num = int(grid[i][j]) if grid[i][j] != '.' else 0
if not k_neighbors(num, grid, i, j):
return False
return True
res = minesweep(n, m, grid)
if res:
print("YES")
else:
print("NO")
| 84 | 77 | 4,505,600 |
231123888
|
a, b = map(int, input().split())
mas = [['0'] * (b + 2)]
for i in range(a):
mas.append(['0'] + list(input()) + ['0'])
mas.append(['0'] * (b + 2))
osh = 0
for i in range(1, a + 1):
for j in range(1, b + 1):
if mas[i][j] == '.':
mas[i][j] = '0'
if mas[i][j] != '*':
otn = 0
for k in range(-1, 2):
for m in range(-1, 2):
if mas[i + k][j + m] == '*':
otn += 1
if otn != int(mas[i][j]):
osh += 1
if osh == 0:
print('YES')
else:
print("NO")# 1699017398.8593888
|
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
|
CF
| 2,018 | 1 | 256 |
Minesweeper
|
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field.
The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to $$$8$$$, inclusive.
|
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
| null |
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
|
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
| 1,100 |
["implementation"]
| 84 |
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| false |
stdio
| null | true |
748/B
|
748
|
B
|
Python 3
|
TESTS
| 67 | 62 | 307,200 |
105066688
|
import sys
s=input()
t=input()
st1=[]
st2=[]
checked=[]
right=[]
for i in range(len(s)):
if s[i] in checked and t[i] not in checked:
print('-1')
sys.exit()
if s[i] not in checked and t[i] in checked:
print('-1')
sys.exit()
if s[i] in right and t[i] not in right:
print('-1')
sys.exit()
if s[i] not in right and t[i] in right:
print('-1')
sys.exit()
if s[i] not in st1 and s[i] not in st2:
if t[i] not in st1 and t[i] not in st2:
if s[i]!=t[i]:
checked.append(s[i])
checked.append(t[i])
st1.append(s[i])
st2.append(t[i])
else:
right.append(s[i])
right.append(t[i])
if s[i]==t[i]:
if s[i] in st1 or s[i] in st2:
print('-1')
sys.exit()
elif t[i] in st1 or t[i] in st2:
print('-1')
sys.exit()
if s[i] in st2:
if st1[st2.index(s[i])]!=t[i]:
print('-1')
sys.exit()
print(len(st1))
for i in range(len(st1)):
print(st1[i],end=" ")
print(st2[i])
| 86 | 62 | 4,608,000 |
23298959
|
s = input()
t = input()
change = dict()
for i in range(len(s)):
if s[i] in change:
change[s[i]].add(t[i])
else:
change[s[i]] = set(t[i])
if t[i] in change:
change[t[i]].add(s[i])
else:
change[t[i]] = set(s[i])
calc = 0
#print(change)
for elem in change:
calc += (len(change[elem]) > 1)
if calc != 0:
print('-1')
else:
ans = []
s = set()
for elem in change:
c_elem = change[elem].pop()
if (elem, c_elem) not in s and elem != c_elem:
ans.append((elem, c_elem))
s.add((elem, c_elem))
s.add((c_elem, elem))
print(len(ans))
for elem in ans:
print(*elem)
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
858/B
|
858
|
B
|
Python 3
|
TESTS
| 6 | 46 | 0 |
230101057
|
n, m = map(int, input().split())
s = []
for _ in range(m):
k, f = map(int, input().split())
s.append((k, f))
s.sort(key=lambda x:x[1])
nums = []
for c in range(1, 20):
for k, f in s:
if not f * c - c + 1 <= k <= f * c:
break
else:
nums.append(c)
res = 0
for num in nums:
t = (n - 1) // num + 1
if res and res != t:
print(-1)
break
res = t
else:
print(res)
| 101 | 62 | 307,200 |
30486361
|
#!/usr/bin/env python3
# encoding: utf-8
FLOW_COUNT = 100
APARTMENT_COUNT = 100
AF_COUNT = 100
def build_for(app_per_flow):
b = dict()
for f in range(FLOW_COUNT):
for a in range(app_per_flow):
app = f * app_per_flow + a
if app >= APARTMENT_COUNT:
return b
b[app] = f
return b
def check_for(b, d):
app, flow = d
return app in b and b[app] == flow
# Execution start point
if __name__ == "__main__":
data = input()
d = data.split()
assert len(d) == 2
n, k = int(d[0])-1, int(d[1])
fs = list()
for i in range(k):
data = input()
d = data.split()
assert len(d) == 2
fs.append((int(d[0])-1, int(d[1])-1))
index, res = 0, 0
for af in range(AF_COUNT):
b = build_for(af + 1)
for d in fs:
if not check_for(b, d):
break
else:
f = (n // (af + 1)) + 1
if index and f != res:
index = 0
break
else:
index = af + 1
res = f
if index > 0:
print("%d" % res)
else:
print("-1")
|
Технокубок 2018 - Отборочный Раунд 1
|
CF
| 2,017 | 1 | 256 |
Which floor?
|
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
| null |
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
|
[{"input": "10 3\n6 2\n2 1\n7 3", "output": "4"}, {"input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1"}]
| 1,500 |
["brute force", "implementation"]
| 101 |
[{"input": "10 3\r\n6 2\r\n2 1\r\n7 3\r\n", "output": "4\r\n"}, {"input": "8 4\r\n3 1\r\n6 2\r\n5 2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "8 3\r\n7 2\r\n6 2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4 2\r\n8 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "11 4\r\n16 4\r\n11 3\r\n10 3\r\n15 4\r\n", "output": "3\r\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
147/A
|
147
|
A
|
PyPy 3-64
|
TESTS
| 8 | 124 | 0 |
166675991
|
def helper(char, ans):
for i in char:
if i.isalpha():
ans += i
else:
ans = ans.rstrip()
ans += i
ans += ' '
return ans
def checker(text):
text = text.split()
ans = ''
for char in text:
if char.isalpha():
ans += char
ans += ' '
else:
ans = helper(char, ans)
return ans.strip()
if __name__ == '__main__':
#ans = checker('galileo galilei was an italian physicist ,mathematician,astronomer')
ans = checker(input())
print(ans)
| 85 | 124 | 2,560,000 |
166866520
|
from sys import stdin
def inta(arr):
return [int(x) for x in arr]
def sr():
return stdin.readline().strip()
s = sr()
k = []
p = list(',!?.')
for t in s:
if len(k) == 0:
k.append(t)
continue
if k[-1] == ' ' and t == ' ':
continue
if t in p and k[-1] == ' ':
while k[-1] == ' ':
k.pop(-1)
k.append(t)
else:
k.append(t)
if t in p:
k.append(' ')
print(''.join(k))
|
Codeforces Testing Round 4
|
CF
| 2,012 | 2 | 256 |
Punctuation
|
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to add spaces to the text by the following rules:
- if there is no punctuation mark between two words, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.
|
Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.
| null | null |
[{"input": "galileo galilei was an italian physicist ,mathematician,astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer"}, {"input": "galileo was born in pisa", "output": "galileo was born in pisa"}]
| 1,300 |
["implementation", "strings"]
| 85 |
[{"input": "galileo galilei was an italian physicist ,mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "galileo was born in pisa\r\n", "output": "galileo was born in pisa\r\n"}, {"input": "jkhksdfhsdfsf\r\n", "output": "jkhksdfhsdfsf\r\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| false |
stdio
| null | true |
220/A
|
220
|
A
|
PyPy 3
|
TESTS
| 32 | 155 | 11,980,800 |
147467123
|
n = int(input())
a = list(map(int,input().split()))
sorted = []
for x in a:
sorted.append(x)
sorted.sort()
ctr = 0
ans = "YES"
for i in range(n):
if a[i] != sorted[i]:
ctr += 1
if ctr // 2 > 1:
ans = "NO"
break
print(ans)
| 96 | 93 | 7,884,800 |
158835557
|
def solve():
n = int(input())
l = list(map(int, input().split()))
ls = sorted(l)
diff = 0
for idx in range(n):
if l[idx] != ls[idx]:
diff += 1
if diff > 2:
return False
return True
def main():
ret = solve()
ans = "YES" if ret else "NO"
print(ans)
if __name__ == '__main__':
main()
|
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 |
593/B
|
593
|
B
|
Python 3
|
TESTS
| 68 | 764 | 16,076,800 |
14065405
|
N=int(input())
x1,x2=tuple(map(int,input().split()))
a=[]
b=[]
for _ in range(N):
m,c=tuple(map(int,input().split()))
a.append((m*(x1+0.000001)+c,_))
b.append((m*(x2-0.000001)+c,_))
a.sort()
b.sort()
x=[]
y=[]
for i in range(N):
x.append(a[i][1])
y.append(b[i][1])
if(x==y):
print("NO")
else:
print("YES")
| 93 | 404 | 18,739,200 |
194474158
|
import sys
input = sys.stdin.readline
n = int(input())
a, b = map(int, input().split())
d = sorted([(a*i +j, b*i+j) for i, j in [list(map(int, input().split())) for _ in range(n)]])
for i in range(1, n):
if d[i][0] > d[i - 1][0] and d[i][1] < d[i - 1][1]:
print('YES')
break
else:
print('NO')
|
Codeforces Round 329 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Anton and Lines
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that:
- y' = ki * x' + bi, that is, point (x', y') belongs to the line number i;
- y' = kj * x' + bj, that is, point (x', y') belongs to the line number j;
- x1 < x' < x2, that is, point (x', y') lies inside the strip bounded by x1 < x2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
|
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers ki, bi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.
|
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
| null |
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
|
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
| 1,600 |
["geometry", "sortings"]
| 93 |
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "YES"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n-999999 -1000000\r\n", "output": "NO"}, {"input": "15\r\n30 32\r\n-45 1\r\n-22 -81\r\n4 42\r\n-83 -19\r\n97 70\r\n55 -91\r\n-45 -64\r\n0 64\r\n11 96\r\n-16 76\r\n-46 52\r\n0 91\r\n31 -90\r\n6 75\r\n65 14\r\n", "output": "NO"}, {"input": "15\r\n-1 3\r\n2 -4\r\n0 -6\r\n-2 -5\r\n0 -1\r\n-1 -2\r\n3 6\r\n4 4\r\n0 -4\r\n1 5\r\n5 -4\r\n-5 -6\r\n3 -6\r\n5 -3\r\n-1 6\r\n-3 -1\r\n", "output": "YES"}, {"input": "5\r\n-197 -126\r\n0 -94\r\n-130 -100\r\n-84 233\r\n-173 -189\r\n61 -200\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n-7 -11\r\n9 2\r\n", "output": "NO"}, {"input": "3\r\n4 11\r\n-2 14\r\n2 -15\r\n-8 -15\r\n", "output": "YES"}, {"input": "2\r\n1 2\r\n2 -2\r\n0 2\r\n", "output": "NO"}, {"input": "10\r\n1 3\r\n1 5\r\n1 2\r\n1 4\r\n1 6\r\n1 3\r\n1 7\r\n1 -5\r\n1 -1\r\n1 1\r\n1 8\r\n", "output": "NO"}, {"input": "10\r\n22290 75956\r\n-66905 -22602\r\n-88719 12654\r\n-191 -81032\r\n0 -26057\r\n-39609 0\r\n0 51194\r\n2648 88230\r\n90584 15544\r\n0 23060\r\n-29107 26878\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n100000 -100000\r\n99999 -100000\r\n", "output": "YES"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99999\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 -100000\r\n99999 100000\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99876\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n4 -10\r\n-9 4\r\n", "output": "NO"}, {"input": "3\r\n4 7\r\n7 9\r\n0 10\r\n-7 2\r\n", "output": "NO"}, {"input": "4\r\n-4 -3\r\n4 -3\r\n10 -9\r\n5 -2\r\n0 9\r\n", "output": "NO"}, {"input": "5\r\n8 9\r\n0 -3\r\n0 -6\r\n-5 0\r\n-7 -2\r\n-4 9\r\n", "output": "NO"}, {"input": "6\r\n-7 8\r\n6 -1\r\n-10 -9\r\n4 8\r\n0 -2\r\n-6 -1\r\n3 -10\r\n", "output": "YES"}, {"input": "7\r\n5 7\r\n6 4\r\n-9 4\r\n-7 5\r\n1 -3\r\n5 -2\r\n7 -8\r\n6 -8\r\n", "output": "YES"}, {"input": "8\r\n-10 -2\r\n5 10\r\n9 7\r\n-8 -2\r\n0 6\r\n-9 0\r\n-6 2\r\n6 -8\r\n-3 2\r\n", "output": "YES"}, {"input": "9\r\n9 10\r\n8 -3\r\n9 8\r\n0 5\r\n10 1\r\n0 8\r\n5 -5\r\n-4 8\r\n0 10\r\n3 -10\r\n", "output": "NO"}, {"input": "10\r\n-1 0\r\n-2 4\r\n2 4\r\n-3 -7\r\n-2 -9\r\n7 6\r\n0 2\r\n1 4\r\n0 10\r\n0 -8\r\n-5 1\r\n", "output": "YES"}, {"input": "11\r\n3 8\r\n0 -9\r\n-8 -10\r\n3 4\r\n3 5\r\n2 1\r\n-5 4\r\n0 -10\r\n-7 6\r\n5 -4\r\n-9 -3\r\n5 1\r\n", "output": "YES"}, {"input": "3\r\n0 2\r\n10 0\r\n0 0\r\n8 2\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n1000000 1000000\r\n", "output": "NO"}, {"input": "2\r\n515806 517307\r\n530512 500306\r\n520201 504696\r\n", "output": "NO"}, {"input": "2\r\n0 65536\r\n65536 0\r\n0 1\r\n", "output": "YES"}, {"input": "3\r\n1 3\r\n-1 5\r\n1 1\r\n0 4\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n1 2\r\n", "output": "YES"}, {"input": "2\r\n0 3\r\n1 1\r\n2 1\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n2 0\r\n", "output": "NO"}, {"input": "3\r\n1 3\r\n1 0\r\n-1 3\r\n0 10\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-2 2\r\n", "output": "YES"}, {"input": "2\r\n5 1000000\r\n1000000 5\r\n5 5\r\n", "output": "NO"}, {"input": "4\r\n0 1\r\n0 0\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n1 1\r\n", "output": "NO"}, {"input": "3\r\n0 1000000\r\n1000000 999999\r\n-1000000 1000000\r\n1000000 1000000\r\n", "output": "YES"}, {"input": "2\r\n-1000000 1000000\r\n2 3\r\n1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n2 2\r\n", "output": "YES"}, {"input": "2\r\n-1 1\r\n1 0\r\n-1 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n2200 1\r\n0 0\r\n", "output": "NO"}, {"input": "2\r\n1 999999\r\n999999 0\r\n1 0\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n999999 999999\r\n0 0\r\n", "output": "NO"}, {"input": "7\r\n0 1\r\n0 -1\r\n3 0\r\n5 0\r\n2 0\r\n4 0\r\n1 0\r\n0 100\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1000000 0\r\n0 100\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n-1 2\r\n0 1\r\n1 0\r\n-1 0\r\n", "output": "NO"}, {"input": "3\r\n0 1\r\n0 1\r\n0 10\r\n2 0\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n3 0\r\n2 0\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n10000 0\r\n100000 1\r\n", "output": "NO"}, {"input": "5\r\n-2 2\r\n2 0\r\n0 100000\r\n0 10000\r\n0 1000\r\n0 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n2200 1\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1 0\r\n1000000 1\r\n", "output": "NO"}, {"input": "2\r\n2 5\r\n2 -4\r\n3 -6\r\n", "output": "NO"}, {"input": "2\r\n-1 1\r\n0 0\r\n0 1\r\n", "output": "NO"}, {"input": "2\r\n900000 1000000\r\n900000 1000000\r\n1000000 900000\r\n", "output": "NO"}]
| false |
stdio
| null | true |
762/C
|
762
|
C
|
Python 3
|
TESTS
| 3 | 108 | 0 |
58819066
|
s1 = input()
s2 = input()
a = {}
s = ""
found = 0
for i in s1:
if i not in a:
a[i] = 1
else:
a[i] = a[i]+1
for j in s2:
if j in a and a[j]>=1:
a[j] = a[j]-1
found = 1
s = s+j
if found==1:
print(s)
else:
print("-")
| 99 | 186 | 5,529,600 |
27122423
|
from macpath import curdir
import bisect
a=input()
b=input()
la=len(a)
lb=len(b)
forb=[la]*lb
cur=0
for i in range(lb):
while cur<la and a[cur]!=b[i]:
cur+=1
if cur<la:
forb[i]=cur
cur+=1
else:
break
cur=la-1
bacb=[-1]*lb
for i in range(lb-1,-1,-1):
while cur>=0 and a[cur]!=b[i]:
cur-=1
if cur>=0:
bacb[i]=cur
cur-=1
else:
break
res=lb
start=0
end=lb
for i in range(lb):
low=-1
if i>0 :
low=forb[i-1]
if low>=la:
break
j=bisect.bisect_right(bacb,low)
if res>j-i>=0:
res=j-i
start=i
end=j
if res==lb:
print('-')
else:
print(b[:start]+b[end:])
|
Educational Codeforces Round 17
|
ICPC
| 2,017 | 2 | 256 |
Two strings
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
|
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
| null |
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
| 2,100 |
["binary search", "hashing", "strings", "two pointers"]
| 99 |
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| false |
stdio
| null | true |
748/B
|
748
|
B
|
PyPy 3
|
TESTS
| 41 | 109 | 23,347,200 |
23292638
|
s = input()
t = input()
d = dict()
for i in range(len(s)):
if s[i] != t[i]:
d[s[i]] = t[i]
d[t[i]] = s[i]
st = list(t)
for i in range(len(s)):
if d.get(st[i]) != None:
st[i] = d[st[i]]
st = ''.join(st)
if st == s:
*it, = d.items()
for i in range(len(it)):
if it[i][0] > it[i][1]:
it[i] = tuple()
it.sort(reverse=True)
while it and not it[-1]:
it.pop()
print(len(it))
for i in it:
print(*i)
else:
print(-1)
| 86 | 62 | 4,608,000 |
23299799
|
def main():
abra, shacked = str(input()), str(input())
dictionary = dict()
for i in range(len(shacked)):
if not (shacked[i] == abra[i]):
if abra[i] in dictionary.values() and dictionary[abra[i]] != shacked[i]:
print(-1)
return
dictionary[abra[i]] = shacked[i]
dictionary[shacked[i]] = abra[i]
making = ''
for i in range(len(shacked)):
if shacked[i] in dictionary.values():
making += dictionary[shacked[i]]
else:
making += shacked[i]
if making != abra:
print(-1)
return
print(int(len(dictionary.keys()) / 2))
for key in dictionary.values():
if key < dictionary[key]:
print(key, dictionary[key])
main()
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
757/B
|
757
|
B
|
PyPy 3-64
|
TESTS
| 48 | 358 | 13,209,600 |
176117153
|
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163,
167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251,
257, 263, 269, 271, 277, 281, 283, 293,
307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397,
401, 409, 419, 421, 431, 433, 439, 443,
449, 457, 461, 463, 467, 479, 487, 491,
499, 503, 509, 521, 523, 541, 547, 557,
563, 569, 571, 577, 587, 593, 599, 601,
607, 613, 617, 619, 631, 641, 643, 647,
653, 659, 661, 673, 677, 683, 691, 701,
709, 719, 727, 733, 739, 743, 751, 757,
761, 769, 773, 787, 797, 809, 811, 821,
823, 827, 829, 839, 853, 857, 859, 863,
877, 881, 883, 887, 907, 911, 919, 929,
937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
n = int(input())
row = list(map(int, input().split()))
res = [0] * len(prime)
for i in range(len(prime)):
for n in row:
if not n % prime[i]:
res[i] += 1
r = max(res)
if r:
print(r)
else:
print(1)
| 134 | 218 | 13,209,600 |
115771847
|
mx = 10**5 + 1
cnt = [0] * mx
n = int(input())
for c in map(int, input().split()):
cnt[c] += 1
f = [0] * mx
ans = 1
for i in range(2, mx):
if f[i] == 0:
f[i] = 1
for j in range(i + i, mx, i):
f[j] = 1
cnt[i] += cnt[j]
ans = max(ans, cnt[i])
print(ans)
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 2 | 512 |
Bash's Big Day
|
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
The input consists of two lines.
The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab.
The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.
|
Print single integer — the maximum number of Pokemons Bash can take.
| null |
gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.
In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.
|
[{"input": "3\n2 3 4", "output": "2"}, {"input": "5\n2 3 4 6 7", "output": "3"}]
| 1,400 |
["greedy", "math", "number theory"]
| 134 |
[{"input": "3\r\n2 3 4\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 6 7\r\n", "output": "3\r\n"}, {"input": "3\r\n5 6 4\r\n", "output": "2\r\n"}, {"input": "8\r\n41 74 4 27 85 39 100 36\r\n", "output": "4\r\n"}, {"input": "6\r\n89 20 86 81 62 23\r\n", "output": "3\r\n"}, {"input": "71\r\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| false |
stdio
| null | true |
95/B
|
95
|
B
|
Python 3
|
TESTS
| 49 | 248 | 512,000 |
73432114
|
p = input()
k='';n=len(p);a=b=0
if n%2 :
k='4'*((n+1)//2)+'7'*((n+1)//2)
elif p<='4'*(n//2)+'7'*(n//2):
k='4'*(n//2)+'7'*(n//2)
elif p<='7'*(n//2)+'4'*(n//2):
f=0
for i in range(n):
x,y = (4-int(p[i]))%10,(7-int(p[i]))%10
if int(p[i])>=8 and f==0:
x=i-1
a-=k[x]=='4';b-=k[x]=='7'
while x>=0 and k[x]!='4' :
x-=1
if x==-1:
continue
a-=k[x]=='4';b-=k[x]=='7'
b+=1
k=k[:x]+'7'+'4'*(n//2-a)+'7'*(n//2-b)
a=b=n//2
break
if int(p[i])<=4 and a!=n//2:
k+='4'
a+=1
if int(p[i])<4:
k+='4'*(n//2-a)+'7'*(n//2-b);a=b=n//2
break
elif b!=n//2:
k+='7'
b+=1
if int(p[i])<7:
k+='4'*(n//2-a)+'7'*(n//2-b);a=b=n//2
break
k+='4'*(n//2-a)+'7'*(n//2-b)
else:
k='4'*(n//2+1)+'7'*(n//2+1)
print(k)
| 86 | 186 | 1,945,600 |
218279964
|
def nextLuckyNumber(digits: str) -> str:
n = len(digits)
halfLen = n >> 1
if n & 1 or digits > f"{'7' * halfLen}{'4' * halfLen}":
halfLen += 1
return f"{'4' * halfLen}{'7' * halfLen}"
result = [0 for i in range(n)]
remaining = [halfLen, halfLen] # number of 4s and 7s to add in result
for i in range(n):
add4 = False
if remaining[0]:
if digits[i] < '4':
add4 = True
elif digits[i] == '4':
lastIdx = i + remaining[1] # last index that can be replaced with 7
for j in range(i + 1, n):
d = '7' if j <= lastIdx else '4'
if digits[j] < d:
add4 = True
break
elif digits[j] > d:
add4 = False
break
elif j == n - 1:
add4 = True
if add4:
result[i] = '4'
remaining[0] -= 1
else:
result[i] = '7'
remaining[1] -= 1
if result[i] > digits[i] or remaining[1] == 0:
# append remaining 4s and 7s
for k in range(i + 1, i + 1 + remaining[0]):
result[k] = '4'
for k in range(i + 1 + remaining[0], i + 1 + remaining[0] + remaining[1]):
result[k] = '7'
break
return ''.join(result)
if __name__ == "__main__":
print(nextLuckyNumber(input()))
|
Codeforces Beta Round 77 (Div. 1 Only)
|
CF
| 2,011 | 2 | 256 |
Lucky Numbers
|
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
|
Output the least super lucky number that is more than or equal to n.
| null | null |
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
| 1,800 |
["dp", "greedy"]
| 86 |
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\r\n"}]
| false |
stdio
| null | true |
95/B
|
95
|
B
|
PyPy 3
|
TESTS
| 49 | 186 | 5,734,400 |
152676216
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = list(input().rstrip())
l = len(n)
if l % 2:
c = l // 2 + 1
ans = ["4"] * c + ["7"] * c
else:
c = l // 2
x = [7] * c + [4] * c
f = 1
for i, j in zip(n, x):
if i - 48 < j:
f = 2
break
elif i - 48 > j:
f = 0
ans = ["4"] * (c + 1) + ["7"] * (c + 1)
break
if not f ^ 1:
ans = list(map(str, x))
elif not f ^ 2:
ans = []
cnt = [c] * 2
ok = 0
for i in n:
j = i - 48
if ok:
break
if not j ^ 4:
if not cnt[0]:
ok = 1
while cnt[1]:
ans.append("7")
cnt[1] -= 1
else:
ans.append("4")
cnt[0] -= 1
elif not j ^ 7:
ans.append("7")
cnt[1] -= 1
else:
ok = 1
if j < 4:
while cnt[0]:
ans.append("4")
cnt[0] -= 1
while cnt[1]:
ans.append("7")
cnt[1] -= 1
else:
if not cnt[1] or 7 < j:
while True:
x = ans.pop()
if x == "4":
cnt[0] += 1
break
cnt[1] += 1
ans.append("7")
cnt[1] -= 1
while cnt[0]:
ans.append("4")
cnt[0] -= 1
while cnt[1]:
ans.append("7")
cnt[1] -= 1
sys.stdout.write("".join(ans))
| 86 | 622 | 20,480,000 |
206003189
|
from sys import stdin, stdout
from collections import deque
MOD = 10 ** 9 + 7
INF = float('inf')
sze = 10 ** 4 + 1
EPS = 10 ** -6
s = stdin.readline().strip()
challenger = []
for i in range(len(s)):
if s[i] in '47':
challenger.append(s[i])
elif s[i] in '89':
update = []
for j in range(1, len(challenger) + 1):
if challenger[-j] == '4':
update += ['7'] + challenger[:-j][::-1]
break
else:
update.append('4')
else:
update.append('4')
challenger = update[::-1] + ['4' for j in range(len(s[i:]))]
break
elif s[i] < '4':
challenger += ['4' for j in range(len(s[i:]))]
break
else:
challenger += ['7'] + ['4' for j in range(len(s[i:]) - 1)]
break
while True:
if challenger.count('4') == challenger.count('7'):
break
if len(challenger) % 2:
challenger = ['4' for i in range((len(challenger) + 1) // 2)] + ['7' for i in range((len(challenger) + 1) // 2)]
elif challenger.count('4') > challenger.count('7'):
cnt = challenger.count('4') - challenger.count('7')
for i in range(len(challenger) - 1, -1, -1):
if challenger[i] == '4':#1
challenger[i] = '7'
cnt -= 2
if not cnt:
break
else:
cnt = [0 for i in range(len(challenger))]
cnt[-1] = challenger[-1] == '7'
for i in range(2, len(challenger) + 1):
cnt[-i] = cnt[-i + 1] + (challenger[-i] == '7')
if not challenger[:len(challenger) // 2].count('4'):
challenger = ['4' for i in range((len(challenger) + 2) // 2)] + ['7' for i in range((len(challenger) + 2) // 2)]
else:
first, second = challenger.count('4'), challenger.count('7')
for j in range(len(challenger) - 2, -1, -1):
if challenger[j] == '4' and cnt[j + 1] * 2 + first >= second:
challenger[j] = '7'
for z in range(j + 1, len(challenger)):
challenger[z] = '4'
break
stdout.write(''.join(challenger))
# Made By Mostafa_Khaled
|
Codeforces Beta Round 77 (Div. 1 Only)
|
CF
| 2,011 | 2 | 256 |
Lucky Numbers
|
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
|
Output the least super lucky number that is more than or equal to n.
| null | null |
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
| 1,800 |
["dp", "greedy"]
| 86 |
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\r\n"}]
| false |
stdio
| null | true |
748/B
|
748
|
B
|
Python 3
|
TESTS
| 35 | 701 | 307,200 |
78386303
|
s=input()
t=input()
l=len(s)
dict1={}
dict2={}
if(s==t):
print(0)
exit(0)
list1=[]
for i in range(l):
flag1=0
if(s[i]!=t[i]):
flag1=1
key,value=s[i],t[i]
flag=0
for j in range(l):
if(s[j]==key):
if(t[j]!=value):
flag=1
break
if(s[j]==value):
if(t[j]!=key):
flag=1
break
for k in range(l):
if(t[k]==key):
if(s[k]!=value):
flag=1
break
if(t[k]==value):
if(s[k]!=key):
flag=1
break
if(flag1 and flag==0):
if((s[i],t[i]) not in list1 and (t[i],s[i]) not in list1):
list1.append((s[i],t[i]))
if(len(list1)==0):
print(-1)
else:
print(len(list1))
for i in list1:
k,p=i
print(k,p)
| 86 | 62 | 4,608,000 |
23301252
|
q=input()
w=input()
l=len(q)
a=[]
s=[0 for i in range(0,130)]
t=[]
for i in range(0,l):
if q[i]==w[i]:
t.append(q[i])
for i in range(0,l):
if q[i]!=w[i]:
a.append([q[i],w[i]])
s[ord(q[i])]+=1
s[ord(w[i])]+=1
c=q[i]
if (q[i] in t) | (w[i] in t):
s[0]=10
q=q.replace(q[i],w[i])
w=w.replace(c,w[i])
if max(s)>1:
print(-1)
else:
print(len(a))
for i in a:
print(i[0],i[1])
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
95/B
|
95
|
B
|
Python 3
|
TESTS
| 49 | 218 | 1,126,400 |
67604057
|
def run(n):
l = len(n)
if l % 2 == 1:
result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1)
print(result)
return result
if n > ('7' * (l // 2) + '4' * (l // 2)):
result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1)
print(result)
return result
def set_range(p, start, end, num):
for i in range(start, end):
p[i] = num
result = [None] * l
for i in range(l):
d = int(n[i])
if d < 4:
set_range(result, i, l, '4')
break
elif d == 4:
result[i] = '4'
elif d < 7:
result[i] = '7'
set_range(result, i + 1, l, '4')
break
elif d == 7:
result[i] = '7'
else:
k = i - 1
while result[k] == '7':
k -= 1
result[k] = '7'
set_range(result, k + 1, l, '4')
break
diff = (result.count('7') - result.count('4')) // 2
if diff > 0:
count = 0
last_4 = -1
for k in range(l):
if result[k] == '7':
count += 1
if result[k] == '4':
last_4 = k
if count == l // 2:
result[last_4] = '7'
u = l // 2 - result[:last_4].count('4')
print(last_4, u)
set_range(result, last_4 + 1, last_4 + u + 1, '4')
set_range(result, last_4 + u + 1, l, '7')
break
elif diff < 0:
k = l - 1
while diff != 0:
if result[k] == '4':
result[k] = '7'
diff += 1
k -= 1
s = ''.join(result)
print(s)
return s
n = input()
run(n)
# luckynum = []
# for i in range(10000000):
# s = len(str(i))
# if s % 2 == 1:
# continue
# if str(i).count('4') == s // 2 and str(i).count('7') == s // 2:
# luckynum.append(i)
# print(luckynum[:10])
# for i in range(10000000):
# k = 0
# while (luckynum[k] < i):
# k += 1
# x = str(luckynum[k])
# y = run(str(i))
# print(i, x, y)
# assert(x == y)
| 86 | 780 | 1,536,000 |
5293258
|
b=input()
a=[int(i) for i in b]
l=len(a)
flag=0
s=0
f=0
if l%2==1:
flag=1
else:
for i in range(l):
if a[i]>7:
flag=1
if(s==l//2 or s==i+1):
break
for j in range(i,-1,-1):
if a[j]==4:
a[j]=7
f-=1
s+=1
flag=0
i=j
break
break
elif a[i]==7:
s+=1
elif a[i]>4:
a[i]=7
s+=1
if s<=l//2:
break
elif a[i]==4:
f+=1
else:
a[i]=4
f+=1
if f<=l//2:
break
if s>l//2:
flag=1
for j in range(i-1,-1,-1):
f-=1
if a[j]==7:
f+=1
if a[j-1]==4:
a[j-1]=7
f-=1
s+=1
flag=0
i=j-1
break
s-=1
break
elif f>l//2:
a[i]=7
s+=1
f-=1
break
if flag:
for i in range(l//2+1):
print(4,end='')
for i in range(l//2+1):
print(7,end='')
else:
for j in range(i+1):
print(a[j],end='')
for j in range(i+1,l):
if f<l//2:
print(4,end='')
f+=1
else:
print(7,end='')
|
Codeforces Beta Round 77 (Div. 1 Only)
|
CF
| 2,011 | 2 | 256 |
Lucky Numbers
|
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
|
Output the least super lucky number that is more than or equal to n.
| null | null |
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
| 1,800 |
["dp", "greedy"]
| 86 |
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\r\n"}]
| false |
stdio
| null | true |
979/B
|
979
|
B
|
Python 3
|
TESTS
| 86 | 139 | 8,908,800 |
38329168
|
import re
s=[]
abc=[]
l=[]
f=0
m=0
r=0
last=0
p=['Kuro','Shiro','Katie']
#ввод
n=int(input())
for i in range(3):
s.append(input())
#заполнение массива-алфавита
for i in range(97,123):
abc.append(chr(i))
for i in range(65,91):
abc.append(chr(i))
#число повторов в 1 строке
for i in range(len(abc)):
b=len(re.findall(abc[i],s[0]))
if b>f:
f=b
#максимальная красота ленты 1
if f+n>len(s[0]):
if f==len(s[0]):
if n % 2 == 0:
f=len(s[0])
else:
f=len(s[0])-n
else:
f=len(s[0])
else:
f=f+n
l.append(f)
f=0
#число повторов в 2 строке
for i in range(len(abc)):
b=len(re.findall(abc[i],s[1]))
if b>f:
f=b
#максимальная красота ленты 2
if f+n>len(s[1]):
if f==len(s[1]):
if n % 2 == 0:
f=len(s[1])
else:
f=len(s[1])-n
else:
f=len(s[1])
else:
f=f+n
l.append(f)
f=0
#число повторов в 3 строке
for i in range(len(abc)):
b=len(re.findall(abc[i],s[2]))
if b>f:
f=b
#максимальная красота ленты 3
if f+n>len(s[2]):
if f==len(s[2]):
if n % 2 == 0:
f=len(s[2])
else:
f=len(s[2])-n
else:
f=len(s[2])
else:
f=f+n
l.append(f)
#поиск наибольшего
for i in range(len(l)):
if l[i]>last:
last=l[i]
r=i
#поиск одинаковых
if last==l[0]:
m=m+1
if last==l[1]:
m=m+1
if last==l[2]:
m=m+1
#вывод
if s[0]==s[1]or s[1]==s[2] or s[2]==s[0]:
print("Draw")
else:
if m==1:
print(p[r])
else:
print('Draw')
| 184 | 109 | 7,680,000 |
38233880
|
n=int(input()); m1=0; m2=0; m3=0;
s1=input()
s2=input()
s3=input()
x=len(s1)
for t in 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM':
m1=max(m1, s1.count(t))
m2=max(m2, s2.count(t))
m3=max(m3, s3.count(t))
d=[[m1,'Kuro'], [m2, 'Shiro'], [m3,'Katie']]
d.sort()
if (d[2][0]==x) and (n==1):
if (d[1][0]==x):
if (d[0][0]==x-1):
print(d[0][1])
else:
print('Draw')
else:
if (d[1][0]==x-1):
if d[0][0]==x-1:
print('Draw')
else:
print(d[1][1])
else:
if d[1][0]==x-2:
print('Draw')
else:
print(d[2][1])
elif d[1][0]+n>=x:
print('Draw')
else:
if m1>max(m2, m3):
print('Kuro')
else:
if m2>max(m1, m3):
print('Shiro')
else:
if m3>max(m2, m1):
print('Katie')
else:
print('Draw')
|
Codeforces Round 482 (Div. 2)
|
CF
| 2,018 | 1 | 256 |
Treasure Hunt
|
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.
The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
|
The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
|
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
| null |
In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
|
[{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}]
| 1,800 |
["greedy"]
| 184 |
[{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
PyPy 3
|
TESTS
| 41 | 451 | 40,140,800 |
93960391
|
import sys
from collections import Counter, defaultdict
from math import gcd
n = int(sys.stdin.buffer.readline().decode('utf-8'))
points = [list(map(int, line.decode('utf-8').split()))
for line in sys.stdin.buffer]
if n <= 2:
print('YES')
exit()
cnt = Counter()
idx = defaultdict(list)
for i, (x2, y2) in enumerate(points[1:], start=1):
dx, dy = points[0][0]-x2, points[0][1]-y2
if dy < 0:
dx, dy = -dx, -dy
elif dy == 0:
dx = 1
g = gcd(abs(dx), abs(dy))
dx //= g
dy //= g
cnt[dx, dy] += 1
idx[dx, dy].append(i)
mpos = cnt.most_common(1)[0][0]
used = [1] + [0]*(n-1)
for i in idx[mpos]:
used[i] = 1
points = [points[i] for i in range(n) if not used[i]]
if len(points) <= 2:
print('YES')
exit()
cnt = Counter()
for i, (x2, y2) in enumerate(points[1:], start=1):
dx, dy = points[0][0]-x2, points[0][1]-y2
if dy < 0:
dx, dy = -dx, -dy
elif dy == 0:
dx = 1
g = gcd(abs(dx), abs(dy))
dx //= g
dy //= g
cnt[dx, dy] += 1
if cnt.most_common(1)[0][1] + 1 == len(points):
print('YES')
else:
print('NO')
| 121 | 514 | 21,094,400 |
104723938
|
from sys import stdin, stdout
def pair_of_lines(n, xy_a):
if len(xy_a) <= 3:
return 'YES'
p1, p2, p3 = xy_a[0], xy_a[1], xy_a[2]
if judge(p1, kstr(p1, p2),xy_a):
return 'YES'
if judge(p1, kstr(p1, p3),xy_a):
return 'YES'
if judge(p2, kstr(p2, p3), xy_a):
return 'YES'
return 'NO'
def kstr(xy1, xy2):
cx, cy = xy1[0], xy1[1]
x, y = xy2[0], xy2[1]
dx = x - cx
dy = y - cy
k = ''
if dx == 0:
k = str(x) + '/y'
elif dy == 0:
k = 'x/' + str(y)
else:
g = gcd(dx, dy)
dx //= g
dy //= g
k = str(dx) + '/' + str(dy)
return k
def judge(p, k, xy_a):
rl = []
for xy in xy_a:
if p[0] == xy[0] and p[1] == xy[1]:
continue
if kstr(p, xy) != k:
rl.append(xy)
if len(rl) > 2:
ck = kstr(rl[0], rl[1])
for i in range(2, len(rl)):
if ck != kstr(rl[0], rl[i]):
return False
return True
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
try:
n = int(stdin.readline())
xy_a = []
for _ in range(n):
xy_a.append(list(map(int, stdin.readline().split())))
res = pair_of_lines(n, xy_a)
stdout.write(res)
except Exception as e:
print(e)
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
730/I
|
730
|
I
|
PyPy 3
|
TESTS
| 22 | 156 | 0 |
96608454
|
from heapq import heappush, heappop
def func(a, b, arr1, arr2):
q = []
ret1 = []
ret2 = []
total = 0
for i in range(len(arr1)):
heappush(q, [-arr1[i], arr2[i], i+1])
while a:
p = heappop(q)
ret1.append(p[2])
total += -p[0]
a -= 1
q2 = []
for val in q:
heappush(q2, [-val[1], -val[0], val[2]])
while b:
p = heappop(q2)
ret2.append(p[2])
total += -p[0]
b -= 1
return (total, ret1, ret2)
n,a,b = [int(x) for x in input().split(" ")]
arr1 = [int(x) for x in input().split(" ")]
arr2 = [int(x) for x in input().split(" ")]
x1,x2,x3 = func(a,b,arr1,arr2)
y1,y3,y2 = func(b,a,arr2,arr1)
if x1>y1:
print(x1)
print(*x2)
print(*x3)
else:
print(y1)
print(*y2)
print(*y3)
| 152 | 77 | 6,246,400 |
25329824
|
#!/usr/bin/env python3
from itertools import accumulate
from heapq import heappop, heappush
def top(ppl_indices, vals, start):
Q = []
res = [0 for i in range(len(ppl_indices))]
for k, idx in enumerate(ppl_indices):
heappush(Q, -vals[idx])
if k >= start:
res[k] = res[k-1] - heappop(Q)
return res
n, a_size, b_size = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
conversion_gain = [y - x for x, y in zip(a, b)]
ordered_by_a = sorted(zip(a, range(n)), reverse=True)
prefix_sums_a = list(accumulate([x for x, y in ordered_by_a]))
conversions = top([idx for val, idx in ordered_by_a], conversion_gain, a_size)
rest_of_bs = list(reversed(top([idx for val, idx in reversed(ordered_by_a[a_size:])],
b, n - a_size - b_size))) + [0]
sol, top_k = max([(prefix_a + convert + add_bs, idx)
for idx, (prefix_a, convert, add_bs)
in enumerate(zip(prefix_sums_a[a_size-1:a_size+b_size],
conversions[a_size-1:a_size+b_size],
rest_of_bs))])
top_k += a_size
conversion_ordered_by_a = [(conversion_gain[idx], idx) for val, idx in ordered_by_a]
conversion_sorted = sorted(conversion_ordered_by_a[:top_k], reverse=True)
converted = [idx for val, idx in conversion_sorted[:top_k-a_size]]
team_a = list(set(idx for val, idx in ordered_by_a[:top_k]) - set(converted))
b_ordered_by_a = [(b[idx], idx) for val, idx in ordered_by_a]
b_sorted = sorted(b_ordered_by_a[top_k:], reverse=True)
team_b = converted + [idx for val, idx in b_sorted[:(a_size+b_size) - top_k]]
print(sol)
print(" ".join(str(idx+1) for idx in team_a))
print(" ".join(str(idx+1) for idx in team_b))
|
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
|
ICPC
| 2,016 | 2 | 512 |
Olympiad in Programming and Sports
|
There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill.
It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in the programming track and one to take part in the sports track.
There should be exactly p students in the programming team and exactly s students in the sports team. A student can't be a member of both teams.
The university management considers that the strength of the university on the Olympiad is equal to the sum of two values: the programming team strength and the sports team strength. The strength of a team is the sum of skills of its members in the corresponding area, so the strength of the programming team is the sum of all ai and the strength of the sports team is the sum of all bi over corresponding team members.
Help Berland State University to compose two teams to maximize the total strength of the university on the Olympiad.
|
The first line contains three positive integer numbers n, p and s (2 ≤ n ≤ 3000, p + s ≤ n) — the number of students, the size of the programming team and the size of the sports team.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 3000), where ai is the programming skill of the i-th student.
The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 3000), where bi is the sports skill of the i-th student.
|
In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print p numbers — the members of the programming team. In the third line, print s numbers — the members of the sports team.
The students are numbered from 1 to n as they are given in the input. All numbers printed in the second and in the third lines should be distinct and can be printed in arbitrary order.
If there are multiple solutions, print any of them.
| null | null |
[{"input": "5 2 2\n1 3 4 5 2\n5 3 2 1 4", "output": "18\n3 4\n1 5"}, {"input": "4 2 2\n10 8 8 3\n10 7 9 4", "output": "31\n1 2\n3 4"}, {"input": "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "output": "23\n1 3 5\n4"}]
| 2,000 |
["dp", "flows", "graphs", "greedy"]
| 152 |
[{"input": "5 2 2\r\n1 3 4 5 2\r\n5 3 2 1 4\r\n", "output": "18\r\n3 4 \r\n1 5 \r\n"}, {"input": "4 2 2\r\n10 8 8 3\r\n10 7 9 4\r\n", "output": "31\r\n1 2 \r\n3 4 \r\n"}, {"input": "5 3 1\r\n5 2 5 1 7\r\n6 3 1 6 3\r\n", "output": "23\r\n1 3 5 \r\n4 \r\n"}, {"input": "2 1 1\r\n100 101\r\n1 100\r\n", "output": "200\r\n1 \r\n2 \r\n"}, {"input": "4 1 1\r\n100 100 1 50\r\n100 100 50 1\r\n", "output": "200\r\n1 \r\n2 \r\n"}, {"input": "2 1 1\r\n3 2\r\n3 2\r\n", "output": "5\r\n1 \r\n2 \r\n"}, {"input": "2 1 1\r\n9 6\r\n3 10\r\n", "output": "19\r\n1 \r\n2 \r\n"}, {"input": "2 1 1\r\n1 17\r\n5 20\r\n", "output": "22\r\n2 \r\n1 \r\n"}, {"input": "3 1 1\r\n5 4 2\r\n1 5 2\r\n", "output": "10\r\n1 \r\n2 \r\n"}, {"input": "3 1 1\r\n10 5 5\r\n9 1 4\r\n", "output": "14\r\n1 \r\n3 \r\n"}, {"input": "3 1 1\r\n17 6 2\r\n2 19 19\r\n", "output": "36\r\n1 \r\n2 \r\n"}, {"input": "4 1 2\r\n4 2 4 5\r\n3 2 5 3\r\n", "output": "13\r\n4 \r\n1 3 \r\n"}, {"input": "4 1 2\r\n8 7 8 6\r\n4 5 10 9\r\n", "output": "27\r\n1 \r\n3 4 \r\n"}, {"input": "4 1 3\r\n6 15 3 9\r\n2 5 6 8\r\n", "output": "31\r\n2 \r\n1 3 4 \r\n"}, {"input": "5 1 1\r\n3 2 5 5 1\r\n3 1 5 4 2\r\n", "output": "10\r\n4 \r\n3 \r\n"}, {"input": "5 2 1\r\n9 10 1 7 10\r\n6 10 8 6 3\r\n", "output": "29\r\n1 5 \r\n2 \r\n"}, {"input": "5 2 3\r\n10 4 19 8 18\r\n6 16 11 15 3\r\n", "output": "74\r\n3 5 \r\n1 2 4 \r\n"}, {"input": "6 2 1\r\n4 3 4 3 3 2\r\n4 4 3 5 3 5\r\n", "output": "13\r\n1 3 \r\n4 \r\n"}, {"input": "6 1 4\r\n7 9 3 5 9 2\r\n10 9 10 10 10 1\r\n", "output": "49\r\n2 \r\n1 3 4 5 \r\n"}, {"input": "6 3 3\r\n15 12 12 19 1 7\r\n7 2 20 10 4 12\r\n", "output": "82\r\n1 2 4 \r\n3 5 6 \r\n"}, {"input": "7 2 1\r\n2 2 2 2 2 1 2\r\n4 2 5 5 2 5 1\r\n", "output": "9\r\n1 2 \r\n3 \r\n"}, {"input": "7 5 1\r\n1 8 8 6 4 3 9\r\n4 4 5 8 5 7 1\r\n", "output": "42\r\n2 3 4 5 7 \r\n6 \r\n"}, {"input": "7 2 3\r\n15 1 5 17 16 9 1\r\n9 8 5 9 18 14 3\r\n", "output": "72\r\n1 4 \r\n2 5 6 \r\n"}, {"input": "8 3 4\r\n5 5 4 2 4 1 3 2\r\n2 5 3 3 2 4 5 1\r\n", "output": "30\r\n1 3 5 \r\n2 4 6 7 \r\n"}, {"input": "8 5 1\r\n2 4 1 5 8 5 9 7\r\n10 2 3 1 6 3 8 6\r\n", "output": "44\r\n4 5 6 7 8 \r\n1 \r\n"}, {"input": "8 1 1\r\n19 14 17 8 16 14 11 16\r\n12 12 10 4 3 11 10 8\r\n", "output": "31\r\n1 \r\n2 \r\n"}, {"input": "9 1 1\r\n3 2 3 5 3 1 5 2 3\r\n1 4 5 4 2 5 4 4 5\r\n", "output": "10\r\n4 \r\n3 \r\n"}, {"input": "9 2 4\r\n4 3 3 1 1 10 9 8 5\r\n5 4 4 6 5 10 1 5 5\r\n", "output": "43\r\n7 8 \r\n1 4 5 6 \r\n"}, {"input": "9 2 2\r\n20 7 6 7 19 15 2 7 8\r\n15 15 1 13 20 14 13 18 3\r\n", "output": "73\r\n1 6 \r\n5 8 \r\n"}, {"input": "10 5 2\r\n4 5 3 1 1 5 2 4 1 5\r\n3 4 2 2 2 3 2 1 2 4\r\n", "output": "27\r\n1 2 6 8 10 \r\n3 4 \r\n"}, {"input": "10 8 2\r\n5 2 8 6 7 5 2 4 1 10\r\n4 6 2 1 9 2 9 4 5 6\r\n", "output": "61\r\n1 3 4 5 6 8 9 10 \r\n2 7 \r\n"}, {"input": "10 3 1\r\n7 11 11 3 19 10 18 7 9 20\r\n13 9 19 15 13 14 7 12 15 16\r\n", "output": "76\r\n5 7 10 \r\n3 \r\n"}, {"input": "11 4 2\r\n2 2 4 2 3 5 4 4 5 5 4\r\n4 4 1 2 1 2 2 5 3 4 3\r\n", "output": "28\r\n3 6 9 10 \r\n1 8 \r\n"}, {"input": "11 1 5\r\n7 10 1 2 10 8 10 9 5 5 9\r\n2 1 1 3 5 9 3 4 2 2 3\r\n", "output": "34\r\n2 \r\n4 5 6 7 8 \r\n"}, {"input": "11 6 1\r\n7 4 7 2 2 12 16 2 5 15 2\r\n3 12 8 5 7 1 4 19 12 1 14\r\n", "output": "81\r\n1 3 6 7 9 10 \r\n8 \r\n"}, {"input": "12 4 1\r\n4 5 1 4 3 3 2 4 3 4 3 2\r\n1 3 5 3 5 5 5 5 3 5 3 2\r\n", "output": "22\r\n1 2 4 8 \r\n3 \r\n"}, {"input": "12 8 1\r\n4 3 3 5 6 10 10 10 10 8 4 5\r\n1 7 4 10 8 1 2 4 8 4 4 2\r\n", "output": "73\r\n1 5 6 7 8 9 10 12 \r\n4 \r\n"}, {"input": "12 2 4\r\n16 17 12 8 18 9 2 9 13 18 3 8\r\n18 20 9 12 11 19 20 3 13 1 6 9\r\n", "output": "113\r\n5 10 \r\n1 2 6 7 \r\n"}, {"input": "13 1 10\r\n1 4 5 3 1 3 4 3 1 5 3 2 3\r\n2 3 5 1 4 3 5 4 2 1 3 4 2\r\n", "output": "40\r\n10 \r\n1 2 3 5 6 7 8 9 11 12 \r\n"}, {"input": "13 2 2\r\n2 2 6 2 9 5 10 3 10 1 1 1 1\r\n10 8 3 8 6 6 8 1 4 10 10 1 8\r\n", "output": "40\r\n7 9 \r\n1 10 \r\n"}, {"input": "13 3 1\r\n16 6 5 11 17 11 13 12 18 5 12 6 12\r\n12 20 9 9 19 4 19 4 1 12 1 12 4\r\n", "output": "71\r\n1 5 9 \r\n2 \r\n"}, {"input": "14 1 3\r\n1 1 2 3 4 3 1 3 4 5 3 5 5 5\r\n3 2 1 1 1 4 2 2 1 4 4 4 5 4\r\n", "output": "18\r\n10 \r\n6 11 13 \r\n"}, {"input": "14 2 1\r\n3 5 9 5 4 6 1 10 4 10 6 5 10 2\r\n10 8 8 6 1 8 9 1 6 1 4 5 9 4\r\n", "output": "30\r\n8 10 \r\n1 \r\n"}, {"input": "14 2 8\r\n20 14 17 18 12 12 19 3 2 20 13 12 17 20\r\n20 10 3 15 8 15 12 12 14 2 1 15 7 10\r\n", "output": "153\r\n10 14 \r\n1 2 4 6 7 8 9 12 \r\n"}, {"input": "15 7 6\r\n2 5 4 1 1 3 3 1 4 4 4 3 4 1 1\r\n5 5 2 5 4 1 4 5 1 5 4 1 4 4 4\r\n", "output": "55\r\n2 3 6 9 11 12 13 \r\n1 4 5 7 8 10 \r\n"}, {"input": "15 1 10\r\n7 8 1 5 8 8 9 7 4 3 7 4 10 8 3\r\n3 8 6 5 10 1 9 2 3 8 1 9 3 6 10\r\n", "output": "84\r\n13 \r\n1 2 3 4 5 7 10 12 14 15 \r\n"}, {"input": "15 3 7\r\n1 11 6 5 16 13 17 6 2 7 19 5 3 13 11\r\n11 9 6 9 19 4 16 20 11 19 1 10 20 4 7\r\n", "output": "161\r\n6 11 14 \r\n1 5 7 8 9 10 13 \r\n"}, {"input": "16 2 7\r\n5 4 4 1 5 3 1 1 2 3 3 4 5 5 1 4\r\n4 5 3 5 4 1 2 2 3 2 2 3 4 5 3 1\r\n", "output": "38\r\n1 5 \r\n2 3 4 9 12 13 14 \r\n"}, {"input": "16 4 8\r\n2 6 6 4 1 9 5 8 9 10 2 8 9 8 1 7\r\n8 9 5 2 4 10 9 2 1 5 6 7 1 1 8 1\r\n", "output": "98\r\n8 9 10 13 \r\n1 2 3 6 7 11 12 15 \r\n"}, {"input": "16 4 1\r\n5 20 3 7 19 19 7 17 18 10 16 11 16 9 15 9\r\n19 2 13 11 8 19 6 7 16 8 8 5 18 18 20 10\r\n", "output": "96\r\n2 5 6 9 \r\n15 \r\n"}, {"input": "17 1 12\r\n2 4 5 5 3 3 3 3 1 4 4 1 2 2 3 3 3\r\n4 1 5 4 2 5 3 4 2 2 5 2 2 5 5 5 3\r\n", "output": "54\r\n10 \r\n1 3 4 5 6 7 8 11 14 15 16 17 \r\n"}, {"input": "17 8 2\r\n10 5 9 1 7 5 2 9 3 5 8 4 3 5 4 2 4\r\n9 10 8 10 10 5 6 2 2 4 6 9 10 3 2 5 1\r\n", "output": "78\r\n1 3 5 6 8 10 11 14 \r\n2 4 \r\n"}, {"input": "17 6 5\r\n18 9 15 14 15 20 18 8 3 9 17 5 2 17 7 10 13\r\n17 10 7 3 7 11 4 5 18 15 15 15 5 9 7 5 5\r\n", "output": "179\r\n3 4 5 6 7 14 \r\n1 9 10 11 12 \r\n"}, {"input": "18 5 2\r\n5 3 3 4 1 4 5 3 3 3 4 2 4 2 3 1 4 4\r\n5 4 3 4 5 1 5 5 2 1 3 2 1 1 1 3 5 5\r\n", "output": "32\r\n1 4 6 7 11 \r\n5 8 \r\n"}, {"input": "18 8 1\r\n6 10 1 1 10 6 10 2 7 2 3 7 7 7 6 5 8 8\r\n4 4 4 7 1 5 2 2 7 10 2 7 6 6 2 1 4 3\r\n", "output": "77\r\n2 5 7 9 12 13 17 18 \r\n10 \r\n"}, {"input": "18 5 3\r\n18 1 8 13 18 1 16 11 11 12 6 14 16 13 10 7 19 17\r\n14 3 7 18 9 16 3 5 17 8 1 8 2 8 20 1 16 11\r\n", "output": "143\r\n1 5 7 17 18 \r\n4 9 15 \r\n"}, {"input": "19 6 1\r\n4 5 2 3 4 3 2 3 3 3 5 5 1 4 1 2 4 2 5\r\n1 2 1 4 1 3 3 2 4 1 3 4 3 3 4 4 4 5 5\r\n", "output": "33\r\n1 2 5 11 12 19 \r\n18 \r\n"}, {"input": "19 14 2\r\n5 3 4 10 5 7 10 9 2 5 4 3 2 3 10 10 6 4 1\r\n6 10 5 3 8 9 9 3 1 6 4 4 3 6 8 5 9 3 9\r\n", "output": "111\r\n1 3 4 5 6 7 8 10 11 12 15 16 17 18 \r\n2 19 \r\n"}, {"input": "19 1 4\r\n2 10 1 3 13 3 6 2 15 15 7 8 1 18 2 12 9 8 14\r\n15 3 2 15 9 12 19 20 2 18 15 11 18 6 8 16 17 1 12\r\n", "output": "93\r\n14 \r\n7 8 10 13 \r\n"}, {"input": "20 3 6\r\n3 4 4 5 1 2 2 3 5 5 2 2 1 4 1 5 2 2 1 5\r\n1 4 5 2 2 2 2 5 3 2 4 5 2 1 3 3 1 3 5 3\r\n", "output": "43\r\n4 9 10 \r\n2 3 8 11 12 19 \r\n"}, {"input": "20 2 5\r\n9 5 1 8 6 3 5 9 9 9 9 3 4 1 7 2 1 1 3 5\r\n5 6 4 10 7 9 1 6 9 5 2 1 3 1 5 9 10 8 9 9\r\n", "output": "65\r\n1 8 \r\n4 6 9 16 17 \r\n"}, {"input": "20 1 7\r\n20 8 10 7 14 9 17 19 19 9 20 6 1 14 11 15 12 10 20 15\r\n10 3 20 1 16 7 8 19 3 17 9 2 20 14 20 2 20 9 2 4\r\n", "output": "152\r\n1 \r\n3 5 8 10 13 15 17 \r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
correct_output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
input_data = f.read().splitlines()
n, p, s = map(int, input_data[0].split())
a = list(map(int, input_data[1].split()))
b = list(map(int, input_data[2].split()))
# Read correct max strength
with open(correct_output_path) as f:
correct_max = int(f.readline().strip())
# Read submission output
with open(submission_output_path) as f:
submission_lines = [line.strip() for line in f.readlines()]
# Check submission has enough lines
if len(submission_lines) < 3:
print(0)
return
# Check first line matches correct max
try:
sub_max = int(submission_lines[0])
except:
print(0)
return
if sub_max != correct_max:
print(0)
return
# Parse teams
try:
prog_team = list(map(int, submission_lines[1].split()))
sports_team = list(map(int, submission_lines[2].split()))
except:
print(0)
return
# Check team sizes
if len(prog_team) != p or len(sports_team) != s:
print(0)
return
# Check all students are valid
all_students = prog_team + sports_team
for student in all_students:
if not (1 <= student <= n):
print(0)
return
# Check uniqueness within and between teams
if len(set(prog_team)) != p or len(set(sports_team)) != s:
print(0)
return
if set(prog_team) & set(sports_team):
print(0)
return
# Calculate total strength
sum_a = sum(a[i-1] for i in prog_team)
sum_b = sum(b[i-1] for i in sports_team)
total = sum_a + sum_b
if total != correct_max:
print(0)
return
# All checks passed
print(1)
if __name__ == "__main__":
main()
| true |
858/B
|
858
|
B
|
Python 3
|
TESTS
| 6 | 62 | 0 |
31316402
|
n, m=map(int, input().split())
a=[0]*100
for i in range (m):
l, k=map(int, input().split())
if k==1:
b=k
c=100
else:
c=(l-1)//(k-1)
b=(l+1)//k
for j in range(b-1, c):
a[j]+=1
x=0
y=0
b=[0]*100
for i in range(100):
if (a[i]==m):
x+=1
y=i+1
b[i]=(n-1)//y+1
if ((b[i]==b[i-1]) and (i>0)):
x-=1
if x!=1:
print(-1)
else:
print((n-1)//y+1)
| 101 | 62 | 307,200 |
30660431
|
import math
def find_3():
etazh = []
for p in range(1, 101):
if all((memory[0] + p - 1) // p == memory[1] for memory in mass):
etazh.append(p)
return etazh
def find_2():
etazh = []
p = 1
while p < 100:
for i in range (m):
if math.ceil(mass[i][0]/p) != mass[i][1]:
p += 1
break
elif i==(m-1):
etazh.append(p)
p += 1
return etazh
def find_1():
etazh = []
for p in range(100):
suit = True
for i in range(m):
if math.ceil(mass[i][0]/p) != mass[i][1]:
suit = False
break
if suit:
etazh.append(p)
return etazh
n, m = map(int, input().split())
mass = []
for i in range (m):
mass.append(list(map(int, input().split())))
etazh = find_3()
if all((n+x-1)//x == (n+etazh[0]-1)//etazh[0] for x in etazh):
print((n+etazh[0]-1)//etazh[0])
else:
print(-1)
|
Технокубок 2018 - Отборочный Раунд 1
|
CF
| 2,017 | 1 | 256 |
Which floor?
|
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
| null |
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
|
[{"input": "10 3\n6 2\n2 1\n7 3", "output": "4"}, {"input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1"}]
| 1,500 |
["brute force", "implementation"]
| 101 |
[{"input": "10 3\r\n6 2\r\n2 1\r\n7 3\r\n", "output": "4\r\n"}, {"input": "8 4\r\n3 1\r\n6 2\r\n5 2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "8 3\r\n7 2\r\n6 2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4 2\r\n8 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "11 4\r\n16 4\r\n11 3\r\n10 3\r\n15 4\r\n", "output": "3\r\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
979/B
|
979
|
B
|
Python 3
|
TESTS
| 7 | 93 | 7,065,600 |
38266265
|
n = int(input())
a = input()
b = input()
c = input()
aa = 26*[0]
ab = 26*[0]
ac = 26*[0]
ba = 26*[0]
bb = 26*[0]
bc = 26*[0]
r = len(a)
for i in range(r):
if 'a'<=a[i]<='z':
aa[ord(a[i])%97]+=1
else:
ba[ord(a[i])%65]+=1
if 'a'<=b[i]<='z':
ab[ord(b[i])%97]+=1
else:
bb[ord(b[i])%65]+=1
if 'a'<=c[i]<='z':
ac[ord(c[i])%97]+=1
else:
bc[ord(c[i])%65]+=1
q = max(max(aa),max(ba))+n
w = max(max(ab),max(bb))+n
e = max(max(ac),max(bc))+n
ma = min(q,r)
mb = min(w,r)
mc = min(e,r)
ta = max(0,q-ma)
tb = max(0,w-mb)
tc = max(0,e-mc)
n = n%2
if ma == r and q!=r and ta%2 != 0:
ma-=n
if mb == r and w != r and tb%2 != 0:
mb-=n
if mc == r and e != r and tc%2 != 0:
mc-=n
k = max(ma,mb,mc)
t = 0
if ma == k:
t+=1
if mb == k:
t+=1
if mc == k:
t+=1
if t > 1:
print('Draw')
else:
if ma == k:
print('Kuro')
elif mb == k:
print('Shiro')
else:
print('Katie')
| 184 | 109 | 7,680,000 |
38234705
|
n = int(input())
ku, sh, ka = input(), input(), input()
l_ku, l_sh, l_ka = max([ku.count(i) for i in list(set(ku))]), max([sh.count(i) for i in list(set(sh))]), max([ka.count(i) for i in list(set(ka))])
if len(ku) - l_ku > n:
l_ku += n
elif l_ku == len(ku) and n == 1:
l_ku -= 1
else:
l_ku = len(ku)
if len(sh) - l_sh > n:
l_sh += n
elif l_sh == len(sh) and n == 1:
l_sh -= 1
else:
l_sh = len(sh)
if len(ka) - l_ka > n:
l_ka += n
elif l_ka == len(ka) and n == 1:
l_ka -= 1
else:
l_ka = len(ka)
ma = max([l_sh, l_ku, l_ka])
if (l_ka == l_sh and l_ka == ma) or (l_ku == l_sh and l_ku == ma) or (l_ka == l_ku and l_ka == ma):
print('Draw')
elif ma == l_ka:
print('Katie')
elif ma == l_sh:
print('Shiro')
elif ma == l_ku:
print('Kuro')
|
Codeforces Round 482 (Div. 2)
|
CF
| 2,018 | 1 | 256 |
Treasure Hunt
|
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.
The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
|
The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
|
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
| null |
In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
|
[{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}]
| 1,800 |
["greedy"]
| 184 |
[{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
| false |
stdio
| null | true |
961/D
|
961
|
D
|
Python 3
|
TESTS
| 8 | 46 | 6,963,200 |
122578461
|
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
if n < 5:
for bit in range(1 << n):
a = []
b = []
for i in range(n):
if bit & (1 << i):
a.append(p[i])
else:
b.append(p[i])
flag = True
if len(a) >= 2:
x1, y1 = a[0]
x2, y2 = a[1]
for x, y in a[2:]:
if (y - y1) * (x2 - x1) != (y2 - y1) * (x - x1):
flag = False
break
if len(b) >= 2:
x1, y1 = b[0]
x2, y2 = b[1]
for x, y in b[2:]:
if (y - y1) * (x2 - x1) != (y2 - y1) * (x - x1):
flag = False
break
if flag:
print("YES")
exit()
print("NO")
else:
for i in range(1, 4):
flag = True
x1, y1 = p[0]
x2, y2 = p[i]
cnt = 0
a = [p[0], p[i]]
b = []
for j in range(1, 5):
if j == i:
continue
x, y = p[j]
if (y - y1) * (x2 - x1) == (y2 - y1) * (x - x1):
a.append(p[j])
else:
b.append(p[j])
if len(a) != 3 and len(b) != 3:
continue
if len(a) == 3:
for j in range(5, n):
x, y = p[j]
if (y - y1) * (x2 - x1) != (y2 - y1) * (x - x1):
b.append(p[j])
if len(b) >= 2:
x3, y3 = b[0]
x4, y4 = b[1]
for x, y in b[2:]:
if (y - y3) * (x4 - x3) != (y4 - y3) * (x - x3):
flag = False
break
else:
for j in range(5, n):
x, y = p[j]
if (y - y1) * (x2 - x1) != (y2 - y1) * (x - x1):
b.append(p[j])
x3, y3 = b[0]
x4, y4 = b[1]
for x, y in b[2:]:
if (y - y3) * (x4 - x3) != (y4 - y3) * (x - x3):
flag = False
break
if flag:
print("YES")
exit()
print("NO")
| 121 | 514 | 71,680,000 |
93965622
|
import sys
from collections import Counter, defaultdict
from math import gcd
n = int(sys.stdin.buffer.readline().decode('utf-8'))
points = [list(map(int, line.decode('utf-8').split()))
for line in sys.stdin.buffer]
if n <= 4:
print('YES')
exit()
for i in range(3):
cnt = Counter()
idx = defaultdict(list)
for j, (x2, y2) in enumerate(points):
if i == j:
continue
dx, dy = points[i][0] - x2, points[i][1] - y2
if dy == 0:
dx = 1
elif dx == 0:
dy = 1
elif dy < 0:
dx, dy = -dx, -dy
g = gcd(abs(dx), abs(dy))
dx //= g
dy //= g
cnt[dx, dy] += 1
idx[dx, dy].append(j)
if i == 2 or cnt.most_common(1)[0][1] > 1:
mpos = cnt.most_common(1)[0][0]
used = [1] + [0]*(n-1)
for j in idx[mpos]:
used[j] = 1
points = [points[j] for j in range(n) if not used[j]]
break
if len(points) <= 2:
print('YES')
exit()
cnt = Counter()
for j, (x2, y2) in enumerate(points):
if i == j:
continue
dx, dy = points[0][0] - x2, points[0][1] - y2
if dy == 0:
dx = 1
elif dx == 0:
dy = 1
elif dy < 0:
dx, dy = -dx, -dy
g = gcd(abs(dx), abs(dy))
dx //= g
dy //= g
cnt[dx, dy] += 1
if cnt.most_common(1)[0][1] + 1 == len(points):
print('YES')
else:
print('NO')
|
Educational Codeforces Round 41 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Pair Of Lines
|
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.
You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
|
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given.
Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
|
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
| null |
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
|
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
| 2,000 |
["geometry"]
| 121 |
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
PyPy 3
|
TESTS
| 6 | 124 | 0 |
92177023
|
n = int(input())
matrix = []
for i in range(n):
matrix.append([int(i) for i in input().split()])
zero_col = zero_row = 0
if n == 1:
print(1)
else:
for i in range(n):
for j in range(n):
if matrix[i][j] == 0:
zero_col = j
zero_row = i
cur = (zero_row + 1) % n
ans = 0
for i in range(n):
ans += matrix[cur][i]
a1 = 0
for i in range(n):
a1 += matrix[zero_row][i]
rem = ans - a1
matrix[zero_row][zero_col] = rem
flag = 0
# row check
for i in range(n):
s1 = 0
for j in range(n):
s1 += matrix[i][j]
if s1 != ans:
flag = 1
break
# col check
for i in range(n):
s1 = 0
for j in range(n):
s1 += matrix[j][i]
if s1 != ans:
flag = 1
break
# diagonal check
s1 = 0
for i in range(n):
s1 += matrix[i][i]
if s1 != ans:
flag = 1
s1 = 0
for i in range(n):
s1 += matrix[i][n-1-i]
if s1 != ans:
flag = 1
if flag == 1:
print(-1)
else:
print(rem)
| 147 | 155 | 8,499,200 |
172260280
|
n=int(input())
# import sys
# for i in range(int(input())):
# n=int(input())
# arr=list(map(int,input().split()))
if n==1:
print(1)
exit()
ans=set()
diag1=0;d1=0;d2=0;diag2=0;sum1=0;sum2=0
res=set();zero=set();matrix=[]
for i in range(n):
row=list(map(int,input().split()))
matrix.append(row)
if row[i]==0:
d1=1
if row[n-1-i]==0:
d2=1
diag1+=row[i]
diag2+=row[n-1-i]
if d1:
zero.add(diag1)
else:
res.add(diag1)
if d2:
zero.add(diag2)
else:
res.add(diag2)
f=0
r=0
for i in range(n):
for j in range(n):
if matrix[i][j]==0:
f=1
if matrix[j][i]==0:
r=1
sum1+=matrix[j][i]
sum2+=matrix[i][j]
if f:
zero.add(sum2)
f=0
else:
res.add(sum2)
if r:
zero.add(sum1)
r=0
else:
res.add(sum1)
sum1=0;sum2=0
if (len(res)+len(zero))!=2:
print(-1)
else:
zero=list(zero)
res=list(res)
if zero[0]<res[0]:
print(res[0]-zero[0])
else:
print(-1)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
593/B
|
593
|
B
|
Python 3
|
TESTS
| 58 | 560 | 27,648,000 |
31544045
|
def main():
N = int(input())
X1, X2 = [int(i) for i in input().split()]
X1 += 0.00001
X2 -= 0.00001
retas = []
for n in range(N):
retas.append([int(i) for i in input().split()])
B1 = {}
B2 = {}
for n in range(N):
k = retas[n][0]
b = retas[n][1]
B1[k*X1 + b] = n
B2[k*X2 + b] = n
L1 = list(B1.keys())
L2 = list(B2.keys())
L1.sort()
L2.sort()
flag = True
for n in range(N):
if B1[L1[n]] != B2[L2[n]]:
flag = False
break
if not flag:
print("YES")
else:
print("NO")
main()
# 1508529733477
| 93 | 405 | 26,521,600 |
204154895
|
from collections import defaultdict
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
x1, x2 = map(int, input().split())
d = defaultdict(lambda : [])
for _ in range(n):
k, b = map(int, input().split())
u, v = k * x1 + b, k * x2 + b
d[u].append(v)
ans = "NO"
inf = pow(10, 15) + 1
la = -inf
for u in sorted(d.keys()):
for v in sorted(d[u]):
if not la <= v:
ans = "YES"
break
la = v
if ans == "YES":
break
print(ans)
|
Codeforces Round 329 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Anton and Lines
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that:
- y' = ki * x' + bi, that is, point (x', y') belongs to the line number i;
- y' = kj * x' + bj, that is, point (x', y') belongs to the line number j;
- x1 < x' < x2, that is, point (x', y') lies inside the strip bounded by x1 < x2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
|
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers ki, bi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.
|
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
| null |
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
|
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
| 1,600 |
["geometry", "sortings"]
| 93 |
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "YES"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n-999999 -1000000\r\n", "output": "NO"}, {"input": "15\r\n30 32\r\n-45 1\r\n-22 -81\r\n4 42\r\n-83 -19\r\n97 70\r\n55 -91\r\n-45 -64\r\n0 64\r\n11 96\r\n-16 76\r\n-46 52\r\n0 91\r\n31 -90\r\n6 75\r\n65 14\r\n", "output": "NO"}, {"input": "15\r\n-1 3\r\n2 -4\r\n0 -6\r\n-2 -5\r\n0 -1\r\n-1 -2\r\n3 6\r\n4 4\r\n0 -4\r\n1 5\r\n5 -4\r\n-5 -6\r\n3 -6\r\n5 -3\r\n-1 6\r\n-3 -1\r\n", "output": "YES"}, {"input": "5\r\n-197 -126\r\n0 -94\r\n-130 -100\r\n-84 233\r\n-173 -189\r\n61 -200\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n-7 -11\r\n9 2\r\n", "output": "NO"}, {"input": "3\r\n4 11\r\n-2 14\r\n2 -15\r\n-8 -15\r\n", "output": "YES"}, {"input": "2\r\n1 2\r\n2 -2\r\n0 2\r\n", "output": "NO"}, {"input": "10\r\n1 3\r\n1 5\r\n1 2\r\n1 4\r\n1 6\r\n1 3\r\n1 7\r\n1 -5\r\n1 -1\r\n1 1\r\n1 8\r\n", "output": "NO"}, {"input": "10\r\n22290 75956\r\n-66905 -22602\r\n-88719 12654\r\n-191 -81032\r\n0 -26057\r\n-39609 0\r\n0 51194\r\n2648 88230\r\n90584 15544\r\n0 23060\r\n-29107 26878\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n100000 -100000\r\n99999 -100000\r\n", "output": "YES"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99999\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 -100000\r\n99999 100000\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99876\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n4 -10\r\n-9 4\r\n", "output": "NO"}, {"input": "3\r\n4 7\r\n7 9\r\n0 10\r\n-7 2\r\n", "output": "NO"}, {"input": "4\r\n-4 -3\r\n4 -3\r\n10 -9\r\n5 -2\r\n0 9\r\n", "output": "NO"}, {"input": "5\r\n8 9\r\n0 -3\r\n0 -6\r\n-5 0\r\n-7 -2\r\n-4 9\r\n", "output": "NO"}, {"input": "6\r\n-7 8\r\n6 -1\r\n-10 -9\r\n4 8\r\n0 -2\r\n-6 -1\r\n3 -10\r\n", "output": "YES"}, {"input": "7\r\n5 7\r\n6 4\r\n-9 4\r\n-7 5\r\n1 -3\r\n5 -2\r\n7 -8\r\n6 -8\r\n", "output": "YES"}, {"input": "8\r\n-10 -2\r\n5 10\r\n9 7\r\n-8 -2\r\n0 6\r\n-9 0\r\n-6 2\r\n6 -8\r\n-3 2\r\n", "output": "YES"}, {"input": "9\r\n9 10\r\n8 -3\r\n9 8\r\n0 5\r\n10 1\r\n0 8\r\n5 -5\r\n-4 8\r\n0 10\r\n3 -10\r\n", "output": "NO"}, {"input": "10\r\n-1 0\r\n-2 4\r\n2 4\r\n-3 -7\r\n-2 -9\r\n7 6\r\n0 2\r\n1 4\r\n0 10\r\n0 -8\r\n-5 1\r\n", "output": "YES"}, {"input": "11\r\n3 8\r\n0 -9\r\n-8 -10\r\n3 4\r\n3 5\r\n2 1\r\n-5 4\r\n0 -10\r\n-7 6\r\n5 -4\r\n-9 -3\r\n5 1\r\n", "output": "YES"}, {"input": "3\r\n0 2\r\n10 0\r\n0 0\r\n8 2\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n1000000 1000000\r\n", "output": "NO"}, {"input": "2\r\n515806 517307\r\n530512 500306\r\n520201 504696\r\n", "output": "NO"}, {"input": "2\r\n0 65536\r\n65536 0\r\n0 1\r\n", "output": "YES"}, {"input": "3\r\n1 3\r\n-1 5\r\n1 1\r\n0 4\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n1 2\r\n", "output": "YES"}, {"input": "2\r\n0 3\r\n1 1\r\n2 1\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n2 0\r\n", "output": "NO"}, {"input": "3\r\n1 3\r\n1 0\r\n-1 3\r\n0 10\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-2 2\r\n", "output": "YES"}, {"input": "2\r\n5 1000000\r\n1000000 5\r\n5 5\r\n", "output": "NO"}, {"input": "4\r\n0 1\r\n0 0\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n1 1\r\n", "output": "NO"}, {"input": "3\r\n0 1000000\r\n1000000 999999\r\n-1000000 1000000\r\n1000000 1000000\r\n", "output": "YES"}, {"input": "2\r\n-1000000 1000000\r\n2 3\r\n1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n2 2\r\n", "output": "YES"}, {"input": "2\r\n-1 1\r\n1 0\r\n-1 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n2200 1\r\n0 0\r\n", "output": "NO"}, {"input": "2\r\n1 999999\r\n999999 0\r\n1 0\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n999999 999999\r\n0 0\r\n", "output": "NO"}, {"input": "7\r\n0 1\r\n0 -1\r\n3 0\r\n5 0\r\n2 0\r\n4 0\r\n1 0\r\n0 100\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1000000 0\r\n0 100\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n-1 2\r\n0 1\r\n1 0\r\n-1 0\r\n", "output": "NO"}, {"input": "3\r\n0 1\r\n0 1\r\n0 10\r\n2 0\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n3 0\r\n2 0\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n10000 0\r\n100000 1\r\n", "output": "NO"}, {"input": "5\r\n-2 2\r\n2 0\r\n0 100000\r\n0 10000\r\n0 1000\r\n0 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n2200 1\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1 0\r\n1000000 1\r\n", "output": "NO"}, {"input": "2\r\n2 5\r\n2 -4\r\n3 -6\r\n", "output": "NO"}, {"input": "2\r\n-1 1\r\n0 0\r\n0 1\r\n", "output": "NO"}, {"input": "2\r\n900000 1000000\r\n900000 1000000\r\n1000000 900000\r\n", "output": "NO"}]
| false |
stdio
| null | true |
593/B
|
593
|
B
|
Python 3
|
TESTS
| 58 | 702 | 14,643,200 |
14253503
|
def check(y1, y2, n):
for i in range(n):
if y1[i][1] != y2[i][1]:
return "YES"
return "NO"
n = int(input())
eps = 10**(-5)
x1, x2 = map(int, input().split())
y1 = list()
y2 = list()
for i in range(n):
k, b = map(int, input().split())
f = lambda x: k * x + b
y1.append((f(x1 + eps), i))
y2.append((f(x2 - eps), i))
y1.sort()
y2.sort()
print(check(y1, y2, n))
| 93 | 420 | 13,414,400 |
100307298
|
import sys
import collections
import math
if __name__ == "__main__" :
points = []
n = int(sys.stdin.readline())
[x1, x2] = [int(i) for i in sys.stdin.readline().split()]
for x in range(n):
[k, b] = [int(i) for i in sys.stdin.readline().split()]
points.append((k * x1 + b, k * x2 + b))
points.sort(key = lambda x: (x[0], x[1]))
flag = False
for i in range(1, n):
if points[i-1][1] > points[i][1]:
flag = True
break
if flag:
print("YES")
else:
print("NO")
|
Codeforces Round 329 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Anton and Lines
|
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between x1 < x2. In other words, is it true that there are 1 ≤ i < j ≤ n and x', y', such that:
- y' = ki * x' + bi, that is, point (x', y') belongs to the line number i;
- y' = kj * x' + bj, that is, point (x', y') belongs to the line number j;
- x1 < x' < x2, that is, point (x', y') lies inside the strip bounded by x1 < x2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
|
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following n lines contain integers ki, bi ( - 1 000 000 ≤ ki, bi ≤ 1 000 000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two i ≠ j it is true that either ki ≠ kj, or bi ≠ bj.
|
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
| null |
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
|
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
| 1,600 |
["geometry", "sortings"]
| 93 |
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output": "YES"}, {"input": "2\r\n-1337 1888\r\n-1000000 1000000\r\n-999999 -1000000\r\n", "output": "NO"}, {"input": "15\r\n30 32\r\n-45 1\r\n-22 -81\r\n4 42\r\n-83 -19\r\n97 70\r\n55 -91\r\n-45 -64\r\n0 64\r\n11 96\r\n-16 76\r\n-46 52\r\n0 91\r\n31 -90\r\n6 75\r\n65 14\r\n", "output": "NO"}, {"input": "15\r\n-1 3\r\n2 -4\r\n0 -6\r\n-2 -5\r\n0 -1\r\n-1 -2\r\n3 6\r\n4 4\r\n0 -4\r\n1 5\r\n5 -4\r\n-5 -6\r\n3 -6\r\n5 -3\r\n-1 6\r\n-3 -1\r\n", "output": "YES"}, {"input": "5\r\n-197 -126\r\n0 -94\r\n-130 -100\r\n-84 233\r\n-173 -189\r\n61 -200\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n-7 -11\r\n9 2\r\n", "output": "NO"}, {"input": "3\r\n4 11\r\n-2 14\r\n2 -15\r\n-8 -15\r\n", "output": "YES"}, {"input": "2\r\n1 2\r\n2 -2\r\n0 2\r\n", "output": "NO"}, {"input": "10\r\n1 3\r\n1 5\r\n1 2\r\n1 4\r\n1 6\r\n1 3\r\n1 7\r\n1 -5\r\n1 -1\r\n1 1\r\n1 8\r\n", "output": "NO"}, {"input": "10\r\n22290 75956\r\n-66905 -22602\r\n-88719 12654\r\n-191 -81032\r\n0 -26057\r\n-39609 0\r\n0 51194\r\n2648 88230\r\n90584 15544\r\n0 23060\r\n-29107 26878\r\n", "output": "NO"}, {"input": "2\r\n-1337 1888\r\n100000 -100000\r\n99999 -100000\r\n", "output": "YES"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99999\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 -100000\r\n99999 100000\r\n", "output": "NO"}, {"input": "2\r\n-100000 100000\r\n100000 100000\r\n100000 99876\r\n", "output": "NO"}, {"input": "2\r\n9 10\r\n4 -10\r\n-9 4\r\n", "output": "NO"}, {"input": "3\r\n4 7\r\n7 9\r\n0 10\r\n-7 2\r\n", "output": "NO"}, {"input": "4\r\n-4 -3\r\n4 -3\r\n10 -9\r\n5 -2\r\n0 9\r\n", "output": "NO"}, {"input": "5\r\n8 9\r\n0 -3\r\n0 -6\r\n-5 0\r\n-7 -2\r\n-4 9\r\n", "output": "NO"}, {"input": "6\r\n-7 8\r\n6 -1\r\n-10 -9\r\n4 8\r\n0 -2\r\n-6 -1\r\n3 -10\r\n", "output": "YES"}, {"input": "7\r\n5 7\r\n6 4\r\n-9 4\r\n-7 5\r\n1 -3\r\n5 -2\r\n7 -8\r\n6 -8\r\n", "output": "YES"}, {"input": "8\r\n-10 -2\r\n5 10\r\n9 7\r\n-8 -2\r\n0 6\r\n-9 0\r\n-6 2\r\n6 -8\r\n-3 2\r\n", "output": "YES"}, {"input": "9\r\n9 10\r\n8 -3\r\n9 8\r\n0 5\r\n10 1\r\n0 8\r\n5 -5\r\n-4 8\r\n0 10\r\n3 -10\r\n", "output": "NO"}, {"input": "10\r\n-1 0\r\n-2 4\r\n2 4\r\n-3 -7\r\n-2 -9\r\n7 6\r\n0 2\r\n1 4\r\n0 10\r\n0 -8\r\n-5 1\r\n", "output": "YES"}, {"input": "11\r\n3 8\r\n0 -9\r\n-8 -10\r\n3 4\r\n3 5\r\n2 1\r\n-5 4\r\n0 -10\r\n-7 6\r\n5 -4\r\n-9 -3\r\n5 1\r\n", "output": "YES"}, {"input": "3\r\n0 2\r\n10 0\r\n0 0\r\n8 2\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n1000000 1000000\r\n", "output": "NO"}, {"input": "2\r\n515806 517307\r\n530512 500306\r\n520201 504696\r\n", "output": "NO"}, {"input": "2\r\n0 65536\r\n65536 0\r\n0 1\r\n", "output": "YES"}, {"input": "3\r\n1 3\r\n-1 5\r\n1 1\r\n0 4\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n1 2\r\n", "output": "YES"}, {"input": "2\r\n0 3\r\n1 1\r\n2 1\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n2 0\r\n", "output": "NO"}, {"input": "3\r\n1 3\r\n1 0\r\n-1 3\r\n0 10\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-2 2\r\n", "output": "YES"}, {"input": "2\r\n5 1000000\r\n1000000 5\r\n5 5\r\n", "output": "NO"}, {"input": "4\r\n0 1\r\n0 0\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1000000\r\n1 1\r\n", "output": "NO"}, {"input": "3\r\n0 1000000\r\n1000000 999999\r\n-1000000 1000000\r\n1000000 1000000\r\n", "output": "YES"}, {"input": "2\r\n-1000000 1000000\r\n2 3\r\n1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n1000000 1\r\n2 2\r\n", "output": "YES"}, {"input": "2\r\n-1 1\r\n1 0\r\n-1 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n2200 1\r\n0 0\r\n", "output": "NO"}, {"input": "2\r\n1 999999\r\n999999 0\r\n1 0\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n1 0\r\n-1 1\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n999999 999999\r\n0 0\r\n", "output": "NO"}, {"input": "7\r\n0 1\r\n0 -1\r\n3 0\r\n5 0\r\n2 0\r\n4 0\r\n1 0\r\n0 100\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1000000 0\r\n0 100\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n-1 2\r\n0 1\r\n1 0\r\n-1 0\r\n", "output": "NO"}, {"input": "3\r\n0 1\r\n0 1\r\n0 10\r\n2 0\r\n", "output": "YES"}, {"input": "4\r\n0 1\r\n3 0\r\n2 0\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n10000 0\r\n100000 1\r\n", "output": "NO"}, {"input": "5\r\n-2 2\r\n2 0\r\n0 100000\r\n0 10000\r\n0 1000\r\n0 0\r\n", "output": "YES"}, {"input": "2\r\n0 1000000\r\n0 0\r\n2200 1\r\n", "output": "NO"}, {"input": "2\r\n0 1000000\r\n1 0\r\n1000000 1\r\n", "output": "NO"}, {"input": "2\r\n2 5\r\n2 -4\r\n3 -6\r\n", "output": "NO"}, {"input": "2\r\n-1 1\r\n0 0\r\n0 1\r\n", "output": "NO"}, {"input": "2\r\n900000 1000000\r\n900000 1000000\r\n1000000 900000\r\n", "output": "NO"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
PyPy 3
|
TESTS
| 6 | 92 | 0 |
193494479
|
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())) for _ in range(n)]
if n == 1:
ans = 1
print(ans)
exit()
for i in range(n):
if min(a[i]):
s = sum(a[i])
break
for i in range(n):
if not min(a[i]):
j = a[i].index(0)
a[i][j] = s - sum(a[i])
ans = a[i][j]
break
s0 = [0] * n
for i in range(n):
ai = a[i]
for j in range(n):
s0[j] += ai[j]
if sum(ai) ^ s:
ans = -1
break
if not min(s0) == max(s0) == s:
ans = -1
u, v = 0, 0
for i in range(n):
u += a[i][i]
v += a[i][n - i - 1]
if not u == v == s:
ans = -1
print(ans)
| 147 | 202 | 12,800,000 |
127917429
|
#See the constraints; check if Brute force is useful
#Figure out a realtion or general formula if possible
#Find the corner cases
#dp,prefix sum, greedy solution or logical
#Ek baar aur kr bro
#Be organised
#Think hard you can do it
def singleinput():R = int(input());return R
def strinput():R = str(input());return R
def intarray():As = list(map(int,input().split()));return As
def matrixinput(arr): As = list(map(int,input().split())); arr.append(As)
n = singleinput()
matrix =[]
for i in range(0,n):
matrixinput(matrix)
row,col,x = 0,0,0
for k in range(n):
if 0 in matrix[k]:
row = k
col = matrix[row].index(0)
break
if(n==1):
print(1)
else:
if(row==0):
x = sum(matrix[1]) - sum(matrix[row])
else:
x = sum(matrix[0]) - sum(matrix[row])
matrix[row][col] = x
s = [sum(matrix[i]) for i in range(n)]
s += [sum(matrix[i][j] for i in range(n)) for j in range(n)]
s += [sum(matrix[i][i] for i in range(n))]
s += [sum(matrix[n-i-1][i] for i in range(n))]
print(x if len(set(s))==1 and x>0 else -1)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
714/B
|
714
|
B
|
Python 3
|
TESTS
| 28 | 77 | 8,806,400 |
200449908
|
n= int(input())
a= list(map(int, input().split()))
if len(set(a)) <= 2:
print('YES')
elif len(set(a))>3:
print('NO')
else:
m= min(a)
p= max(a)
r= p-m
if r%2:
print('NO')
else:
print('YES')
| 79 | 77 | 13,619,200 |
220073936
|
n=int(input())
l=list(map(int,input().split()))
mi=min(l)
ma=max(l)
if len(set(l))>3:
print('NO')
elif len(set(l))<3:
print('YES')
else:
for i in set(l):
if i!=ma and i!=mi:
me=i
if ma-me==me-mi:
print("YES")
else:
print("NO")
|
Codeforces Round 371 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Filya and Homework
|
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
|
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
| null |
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
|
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
| 1,200 |
["implementation", "sortings"]
| 79 |
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
714/B
|
714
|
B
|
PyPy 3
|
TESTS
| 28 | 171 | 11,776,000 |
105430819
|
n = int(input())
A = [int(a) for a in input().split()]
m = max(A)
D = [0] * n
for i in range(n):
D[i] = m - A[i]
flag = False
D = set(D)
l = len(D)
if l <= 2:
flag = True
elif l == 3:
if (max(D) - min(D)) % 2 == 0:
D = D.difference({max(D), min(D)})
s = {}
new = (max(D) + min(D)) // 2
s = D.union({new})
if len(s) == 1:
flag = True
print("YES" if flag else "NO")
| 79 | 77 | 13,619,200 |
230085863
|
# Wadea #
n = int(input())
arr = list(map(int,input().split()))
if len(set(arr)) > 3:
print("NO")
else:
arr = list(set(arr))
arr.sort()
l = min(arr);r = max(arr)
if len(arr) == 3:
c = (r - l)//2
l += c
r -= c
if l == arr[1] and r == arr[1]:
print("YES")
else:
print("NO")
elif len(arr) <= 2:
print("YES")
|
Codeforces Round 371 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Filya and Homework
|
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
|
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
| null |
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
|
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
| 1,200 |
["implementation", "sortings"]
| 79 |
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
356/C
|
356
|
C
|
Python 3
|
TESTS
| 9 | 280 | 14,643,200 |
92567036
|
def fun(arr):
if(sum(arr)<3 or sum(arr)==5):
return -1
# n3 = arr.count(3)
# n4 = arr.count(4)
n2 = arr.count(2)
n1 = arr.count(1)
if n1 >=n2 :
n1 = n1-n2
else:
n1 = 0
return n2+int(n1/3)*2+n1%3
n = int(input())
arr = list(map(int,input().split(" ")))
print(fun(arr))
| 141 | 607 | 14,745,600 |
42135284
|
#! /usr/bin/env python
n = int(input())
counts = [0] * 5
nums = [int(x) for x in input().split()]
for x in nums:
counts[x] += 1
s = sum(nums)
if s > 2 and s != 5:
ans = 0
if counts[1] >= counts[2]:
ans += counts[2]
counts[3] += counts[2]
counts[1] -= counts[2]
ans += 2 * (counts[1] // 3)
counts[3] += counts[1] // 3
counts[1] %= 3
if counts[3] > 0:
ans += counts[1]
elif counts[1] != 0:
ans += 2
else:
ans += counts[1]
counts[2] -= counts[1]
ans += 2 * (counts[2] // 3)
counts[2] %= 3
if counts[4] > 0:
ans += counts[2]
elif counts[2] != 0:
ans += 2
print(ans)
else:
print(-1)
# Made By Mostafa_Khaled
|
Codeforces Round 207 (Div. 1)
|
CF
| 2,013 | 1 | 256 |
Compartments
|
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.
The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.
However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.
After all the swaps each compartment should either have no student left, or have a company of three or four students.
|
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
|
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
| null | null |
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
| 2,100 |
["combinatorics", "constructive algorithms", "greedy", "implementation"]
| 141 |
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"input": "10\r\n2 3 3 1 3 1 3 2 2 4\r\n", "output": "3\r\n"}, {"input": "120\r\n1 1 1 1 1 1 1 4 4 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 4 1 1 4 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 2 4 1 1 3 1 1 1 2 1 0 3 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 1\r\n", "output": "69\r\n"}, {"input": "10\r\n2 4 1 3 1 2 2 2 2 2\r\n", "output": "5\r\n"}, {"input": "10\r\n3 4 2 2 1 1 3 1 1 2\r\n", "output": "4\r\n"}, {"input": "20\r\n4 1 4 4 2 1 4 3 2 3 1 1 2 2 2 4 4 2 4 2\r\n", "output": "6\r\n"}, {"input": "20\r\n4 3 4 2 1 1 3 1 4 2 1 4 3 3 4 3 1 1 1 3\r\n", "output": "6\r\n"}, {"input": "20\r\n4 1 1 1 4 2 3 3 2 1 1 4 4 3 1 1 2 4 2 3\r\n", "output": "6\r\n"}, {"input": "20\r\n4 4 2 4 3 2 3 1 4 1 1 4 1 4 3 4 4 3 3 3\r\n", "output": "4\r\n"}, {"input": "20\r\n4 2 3 3 1 3 2 3 1 4 4 4 2 1 4 2 1 3 4 4\r\n", "output": "4\r\n"}, {"input": "23\r\n2 3 1 1 1 1 4 3 2 2 3 3 4 1 4 2 4 1 4 2 3 1 1\r\n", "output": "7\r\n"}, {"input": "27\r\n0 2 4 1 4 2 1 2 3 4 2 4 1 2 3 2 3 2 2 1 0 4 3 0 3 0 1\r\n", "output": "7\r\n"}, {"input": "28\r\n2 0 4 2 3 4 1 1 4 3 0 3 0 3 2 3 2 4 1 2 4 3 3 3 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "24\r\n4 2 4 3 1 3 4 1 3 4 2 4 0 2 3 4 1 1 4 3 1 2 2 4\r\n", "output": "5\r\n"}, {"input": "19\r\n2 4 4 2 0 0 1 4 1 0 2 2 4 2 0 1 1 1 4\r\n", "output": "5\r\n"}, {"input": "16\r\n3 3 3 1 3 0 1 4 4 4 1 4 3 1 1 4\r\n", "output": "4\r\n"}, {"input": "17\r\n3 3 1 0 1 3 1 1 1 3 0 2 2 2 3 2 2\r\n", "output": "5\r\n"}, {"input": "12\r\n2 2 2 1 1 0 2 0 1 1 2 1\r\n", "output": "5\r\n"}, {"input": "15\r\n4 0 1 0 0 4 1 1 0 4 1 4 4 1 0\r\n", "output": "4\r\n"}, {"input": "20\r\n0 4 4 0 0 0 2 3 3 3 2 0 3 2 3 2 4 4 2 4\r\n", "output": "4\r\n"}, {"input": "23\r\n1 1 3 2 0 3 1 2 2 2 1 3 3 4 1 0 0 3 1 2 2 0 3\r\n", "output": "6\r\n"}, {"input": "15\r\n0 2 4 2 0 4 4 2 4 4 1 2 4 2 2\r\n", "output": "5\r\n"}, {"input": "17\r\n0 4 3 0 2 2 4 2 4 4 2 4 2 1 0 0 0\r\n", "output": "4\r\n"}, {"input": "21\r\n0 3 2 3 0 2 3 4 3 0 1 3 2 2 3 3 3 0 2 2 0\r\n", "output": "5\r\n"}, {"input": "21\r\n1 1 3 1 0 3 3 3 3 0 1 3 0 3 1 1 1 3 2 0 0\r\n", "output": "5\r\n"}, {"input": "13\r\n1 1 1 2 1 1 4 1 3 1 1 1 0\r\n", "output": "7\r\n"}, {"input": "14\r\n4 2 4 4 0 4 4 0 1 0 0 4 3 4\r\n", "output": "1\r\n"}, {"input": "13\r\n2 1 2 2 3 4 0 2 2 2 2 2 2\r\n", "output": "7\r\n"}, {"input": "10\r\n2 2 2 0 0 0 0 0 2 2\r\n", "output": "4\r\n"}, {"input": "11\r\n2 2 2 2 0 2 2 2 2 2 2\r\n", "output": "8\r\n"}, {"input": "11\r\n1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "8\r\n"}, {"input": "16\r\n0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1\r\n", "output": "8\r\n"}, {"input": "17\r\n1 1 4 1 1 0 1 1 1 1 0 1 0 1 0 0 1\r\n", "output": "8\r\n"}, {"input": "14\r\n1 0 0 1 1 1 0 1 1 1 1 1 3 0\r\n", "output": "6\r\n"}, {"input": "9\r\n1 1 1 2 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "13\r\n2 2 0 4 2 2 2 2 2 1 2 2 2\r\n", "output": "7\r\n"}, {"input": "19\r\n2 2 3 2 0 0 1 1 2 0 0 2 1 2 2 2 0 2 2\r\n", "output": "9\r\n"}, {"input": "29\r\n3 1 3 3 0 2 2 3 3 2 0 3 3 2 3 0 3 3 0 2 2 2 3 2 0 3 2 2 3\r\n", "output": "7\r\n"}, {"input": "27\r\n0 1 2 2 3 3 2 0 2 3 2 0 2 3 2 2 2 2 3 3 1 3 2 3 1 2 2\r\n", "output": "11\r\n"}, {"input": "29\r\n3 3 2 0 1 1 1 2 2 2 1 3 2 0 2 3 3 2 2 3 2 2 2 2 1 2 2 2 4\r\n", "output": "12\r\n"}, {"input": "13\r\n4 1 1 4 1 1 1 1 1 1 1 1 1\r\n", "output": "8\r\n"}, {"input": "30\r\n1 1 1 3 3 4 0 1 1 1 1 1 1 3 0 0 0 1 1 1 1 3 1 1 1 1 3 1 1 1\r\n", "output": "14\r\n"}, {"input": "32\r\n1 4 4 3 1 4 4 4 1 1 1 1 1 4 1 1 1 4 1 1 1 1 2 1 1 4 4 1 1 1 1 4\r\n", "output": "14\r\n"}, {"input": "48\r\n1 3 1 1 1 1 1 1 2 1 1 2 1 1 4 1 1 1 2 2 2 1 3 1 1 1 1 2 1 2 2 1 1 1 1 1 3 0 2 3 1 1 3 1 0 1 2 1\r\n", "output": "24\r\n"}, {"input": "49\r\n2 2 1 2 2 2 2 2 2 2 2 2 1 2 1 3 4 2 2 2 2 4 1 1 2 1 2 2 2 2 2 4 0 0 2 0 1 1 2 1 2 2 2 2 4 4 2 2 1\r\n", "output": "24\r\n"}, {"input": "165\r\n1 1 1 1 1 1 1 1 0 2 2 2 1 1 1 1 1 4 4 1 1 2 2 1 2 1 2 2 2 1 2 2 3 1 1 2 1 1 2 2 4 1 2 2 2 4 1 1 1 4 2 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 4 2 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 1 2 2 1 1 1 2 1 4 2 2 2 1 1 1 1 2 3 2 1 2 1 1 2 1 1 1 1 1 2 1 2 1 1 0 1 2 1 1 1 1 1 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 3 4 1 1 1\r\n", "output": "84\r\n"}, {"input": "197\r\n1 4 4 4 1 4 1 1 0 1 4 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 2 1 1 4 4 4 4 4 4 1 1 1 4 1 4 4 4 4 4 1 1 1 1 1 4 4 1 4 0 4 1 4 4 1 4 4 4 2 1 1 4 4 2 1 1 1 4 1 4 1 4 4 4 1 1 4 4 4 1 1 0 1 4 1 4 0 4 3 1 1 1 4 1 4 4 4 1 4 1 4 3 1 4 4 4 1 1 4 0 4 1 1 4 1 4 4 1 4 1 1 1 4 1 4 1 1 3 4 1 4 4 1 1 1 1 4 1 1 3 4 1 1 0 1 4 4 1 4 4 1 4 4 1 1 0 2 1 4 1 4 1 1 1 1 1 4 4 1 1 0 4 2 4 1 4 1 4 4\r\n", "output": "69\r\n"}, {"input": "177\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 4 2 2 2 2 4 2 0 2 2 2 2 2 3 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 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 0 2 4 2 2 2 2 2 2 4 2 2 2 2 2 3 2 1 2 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 2 2 2 2 4 2 4 2 2 4 2 2 2 2 2 2 2 2 0 2 3 2 2 2 2 2 2 2 0 2 2 4 2 2 2 2 3 2 2\r\n", "output": "103\r\n"}, {"input": "166\r\n2 3 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 4 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 3 2 0 2 0 3 2 2 2 0 2 0 2 2 2 2 2 2 3 0 2 2 2 2 2 3 3 2 2 2 3 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 3 2 2 2 2\r\n", "output": "93\r\n"}, {"input": "172\r\n2 2 2 0 1 3 2 1 0 3 3 1 0 1 2 3 4 2 2 4 2 1 4 0 3 2 2 3 3 3 0 0 3 1 1 0 1 2 2 0 1 4 4 0 3 3 2 0 1 4 4 1 4 2 2 3 0 1 2 2 1 1 4 4 4 4 0 1 0 2 4 0 2 0 0 2 2 1 4 2 2 2 2 2 0 2 3 0 2 1 0 2 1 0 2 2 0 2 2 0 2 2 2 1 1 0 2 1 2 1 0 2 2 0 2 2 3 2 4 2 4 3 2 3 1 2 2 4 0 2 0 2 2 1 0 1 2 1 4 1 0 3 2 2 1 0 0 2 0 4 2 2 0 0 4 1 3 2 1 1 0 2 3 2 0 2 2 2 2 2 3 0\r\n", "output": "53\r\n"}, {"input": "141\r\n2 1 1 1 1 1 4 2 3 1 1 1 1 1 1 4 1 1 1 1 1 1 1 4 4 1 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 2 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 3 1 1 1 1 1 4 4 1 3 4 1 1 1 1 1 1 1 1 1 4 2 1 0 1 1 4 1 1 1 1 2 1 0 1 1 2 1 1 1 1 4 4 1 2 4 4 1 1 3 1 1 1 3 1 1 4 4 1 1 1 4 1 1 1 1 1 1 2 0 1 0 0 1 0 4\r\n", "output": "69\r\n"}, {"input": "108\r\n2 2 1 4 2 2 1 2 2 2 2 2 2 4 2 2 4 2 4 2 2 2 2 4 2 4 2 2 2 1 2 1 2 2 2 4 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 4 2 2 2 2 4 2 2 2 1 2 2 2 2 2 4 1 2 2\r\n", "output": "61\r\n"}, {"input": "138\r\n3 1 3 1 3 3 3 1 1 1 1 1 1 3 3 1 1 1 3 3 1 1 3 1 1 1 1 1 1 1 3 3 3 1 3 1 1 1 1 1 3 1 1 3 1 3 1 3 1 1 1 1 3 1 3 1 1 3 1 1 1 3 1 1 1 1 1 1 1 1 3 1 1 1 1 3 1 3 1 3 3 3 3 3 3 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 3 1 1 3 3 1 3 3 1 3 1 1 1 3 1 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 3 1 1 3 1 1\r\n", "output": "62\r\n"}, {"input": "81\r\n2 2 2 3 2 3 2 2 2 2 2 3 2 2 2 2 2 2 0 2 4 2 3 4 2 3 2 3 2 0 2 2 0 2 2 3 2 2 4 3 3 2 2 2 2 2 2 2 3 2 2 2 2 2 2 3 3 2 2 3 2 0 2 0 2 2 2 2 2 2 4 0 2 3 2 4 2 2 2 2 2\r\n", "output": "38\r\n"}, {"input": "115\r\n2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 4 2 4 2 4 2 2 2 2 2 2 2 2 2 2 2 4 4 3 2 2 2 2 2 2 2 4 2 2 2 3 2 2 2 2 2 2 4 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 3 2 2 2 2 2 4 4 4 2 2\r\n", "output": "65\r\n"}, {"input": "146\r\n1 1 1 1 1 4 1 1 0 1 4 4 1 4 1 1 1 1 1 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 0 1 4 1 4 1 4 4 1 1 1 1 1 1 1 1 1 4 4 1 1 4 1 4 4 4 1 1 4 4 1 4 1 1 1 1 0 1 1 1 1 1 1 4 1 4 1 1 4 1 1 4 4 4 1 1 4 1 1 1 1 1 1 1 4 1 1 1 4 1 4 1 1 1 1 1 1 1 4 1 1 4 4 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 4 4 4 4 1 1\r\n", "output": "68\r\n"}, {"input": "198\r\n1 2 1 2 2 1 2 1 1 1 3 2 1 1 2 1 2 2 1 1 1 4 1 1 1 1 0 1 1 1 1 4 1 1 3 1 2 1 1 1 2 1 2 0 1 1 1 1 1 1 1 1 1 2 4 4 1 0 1 1 1 1 1 1 1 1 2 1 1 1 4 0 1 2 1 2 1 1 2 2 1 1 1 1 3 2 2 2 1 1 4 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 1 3 1 3 1 1 0 1 4 1 2 2 1 1 1 2 2 1 1 1 1 3 2 1 2 1 1 2 1 2 1 2 1 0 4 1 2 1 1 1 1 3 1 1 2 0 1 1 1 1 1 3 2 1 2 1 1 0 1 1 3 1 1 2 1 1 1 1 1 1 4 4 1 1 0 1 1 1 2 1 1 1 3 0 2 1 2 1 1 1 1 1\r\n", "output": "97\r\n"}, {"input": "200\r\n4 1 1 4 3 1 1 3 1 1 1 4 3 3 3 2 3 3 1 3 3 4 4 2 2 2 3 1 2 2 2 3 1 1 3 2 2 4 1 3 4 3 2 4 2 2 4 2 2 3 4 2 3 2 2 1 2 4 4 2 4 4 2 3 2 4 1 4 2 1 3 4 1 3 1 1 2 1 4 1 3 3 3 4 1 4 4 1 4 4 2 3 1 3 3 2 2 1 4 2 4 4 3 3 3 1 3 4 3 1 1 1 1 4 2 1 2 3 2 2 2 3 2 1 2 1 1 1 2 4 1 3 3 3 2 3 3 2 3 4 4 3 3 4 3 2 1 4 1 4 2 1 3 2 4 4 1 4 1 1 1 3 2 3 4 2 2 4 1 4 4 4 4 3 1 3 1 4 3 2 1 2 1 1 2 4 1 3 3 4 4 2 2 4 4 3 2 1 2 4\r\n", "output": "50\r\n"}, {"input": "200\r\n2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 1 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 1 1 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 0 1 2 1 1 2 2 2 1 2 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 1 2 1 0\r\n", "output": "100\r\n"}, {"input": "6\r\n1 1 1 2 2 1\r\n", "output": "4\r\n"}, {"input": "10\r\n3 3 1 1 2 1 1 1 2 2\r\n", "output": "5\r\n"}, {"input": "10\r\n1 1 1 2 1 2 2 1 2 1\r\n", "output": "6\r\n"}, {"input": "15\r\n1 2 2 1 2 3 2 1 2 1 1 1 2 1 1\r\n", "output": "8\r\n"}, {"input": "13\r\n2 1 2 2 1 0 1 2 1 1 1 1 2\r\n", "output": "7\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "2\r\n"}, {"input": "5\r\n4 4 4 4 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 3 4\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 1 3 3 3 3\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 4 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 3\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 3 3 3 3 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 3\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "4\r\n"}, {"input": "6\r\n2 2 2 2 2 4\r\n", "output": "4\r\n"}, {"input": "3\r\n2 2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 4\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 3 3\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 3 2\r\n", "output": "2\r\n"}, {"input": "1\r\n4\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
623/A
|
623
|
A
|
Python 3
|
TESTS
| 20 | 436 | 12,288,000 |
15813151
|
n, m = map(int, input().split())
graph = [set() for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
graph[u].add(v)
graph[v].add(u)
letter = {"a": set(), "b": set(), "c": set()}
remaining = set()
for u in range(1, n+1):
# if u is b
if len(graph[u]) == n-1:
letter["b"].add(u)
else:
remaining.add(u)
inconsistent = False
# looks for first element and calls it and all its neighbors "a"
for u in remaining:
letter["a"].add(u)
remaining.remove(u)
for v in range(1, n+1):
if u == v:
continue
elif v in letter["b"]:
continue
elif v in graph[u]:
letter["a"].add(v)
remaining.remove(v)
else:
letter["c"].add(v)
break
for u in remaining:
letter["c"].add(u)
for v in range(1, n+1):
if u == v:
continue
elif v in letter["b"]:
continue
elif v in graph[u]:
if v in letter["a"]:
inconsistent = True
else:
if v in letter["c"]:
inconsistent = True
res = list()
for u in range(1, n+1):
if u in letter["a"]:
res.append("a")
elif u in letter["b"]:
res.append("b")
elif u in letter["c"]:
res.append("c")
if inconsistent:
print("No")
else:
print("Yes")
print("".join(map(str, res)))
| 106 | 170 | 10,137,600 |
138001764
|
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def BFS(s,Adj):
level = {s:0}
parent = {s:None}
i=1
frontier = [s]
while frontier:
next1 = []
for u in frontier:
for v in Adj[u]:
if v not in level:
level[v] = i
parent[v] = u
next1.append(v)
frontier = next1
i += 1
return level
def BFS_2(s,Adj, b_dict):
level = {s:0}
for vertex in b_dict:
level[vertex] = 0
parent = {s:None}
i=1
frontier = [s]
while frontier:
next1 = []
for u in frontier:
for v in Adj[u]:
if v not in level:
level[v] = i
parent[v] = u
next1.append(v)
frontier = next1
i += 1
for vertex in b_dict:
del level[vertex]
return level
n, m = map(int, input().split())
adj_list = [[] for i in range(n+1)]
for i in range(m):
u, v = map(int, input().split())
adj_list[u].append(v)
adj_list[v].append(u)
b_dict = {}
for i in range(1, n+1):
if len(adj_list[i]) == n-1:
b_dict[i] = True
unique_count = {}
for i in range(1, n+1):
if len(adj_list[i]) != n-1:
if len(adj_list[i]) not in unique_count:
unique_count[len(adj_list[i])] = True
if len(unique_count) > 2:
print('No')
elif len(unique_count) == 0:
print('Yes')
ans = 'b'*n
print(ans)
elif len(unique_count) == 1:
if len(b_dict) > 0:
a_val = c_val = -1
a_dict = {}
c_dict = {}
for i in range(1, n+1):
if len(adj_list[i]) != n-1:
level = BFS_2(i, adj_list, b_dict)
break
ans = []
for i in range(1, n+1):
if len(adj_list[i]) == n-1:
ans.append('b')
elif i in level:
a_val = len(adj_list[i])
a_dict[i] = True
ans.append('a')
else:
c_val = len(adj_list[i])
c_dict[i] = True
ans.append('c')
if a_val == len(b_dict) + len(a_dict) - 1 and c_val == len(b_dict) + len(c_dict) - 1:
print('Yes')
print(''.join(ans))
else:
print('No')
else:
level = BFS(1, adj_list)
a_val = c_val = -1
a_dict = {}
c_dict = {}
ans = []
for i in range(1, n+1):
if i in level:
a_val = len(adj_list[i])
a_dict[i] = True
ans.append('a')
else:
c_dict[i] = True
c_val = len(adj_list[i])
ans.append('c')
if a_val == len(a_dict) - 1 and c_val == len(c_dict) - 1:
print('Yes')
print(''.join(ans))
else:
print('No')
else:
a_dict = {}
c_dict = {}
a_val = -1
c_val = -1
for i in range(1, n+1):
if len(adj_list[i]) != n-1:
if a_val == -1:
a_val = len(adj_list[i])
a_dict[i] = True
elif len(adj_list[i]) == a_val:
a_dict[i] = True
elif c_val == -1:
c_val = len(adj_list[i])
c_dict[i] = True
else:
c_dict[i] = True
if a_val == len(b_dict) + len(a_dict) - 1 and c_val == len(b_dict) + len(c_dict) - 1:
ans = []
for i in range(1, n+1):
if i in a_dict:
ans.append('a')
elif i in b_dict:
ans.append('b')
else:
ans.append('c')
print('Yes')
print(''.join(ans))
else:
print('No')
|
AIM Tech Round (Div. 1)
|
CF
| 2,016 | 2 | 256 |
Graph and String
|
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
- G has exactly n vertices, numbered from 1 to n.
- For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.
|
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
|
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.
| null |
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.
|
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
| 1,800 |
["constructive algorithms", "graphs"]
| 106 |
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "4 3\r\n4 3\r\n2 4\r\n2 3\r\n", "output": "Yes\r\naccc\r\n"}, {"input": "4 2\r\n4 3\r\n1 2\r\n", "output": "Yes\r\naacc\r\n"}, {"input": "5 3\r\n1 2\r\n1 3\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n3 2\r\n1 3\r\n6 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 6\r\n5 6\r\n", "output": "No\r\n"}, {"input": "7 13\r\n1 2\r\n2 3\r\n1 3\r\n4 5\r\n5 6\r\n4 6\r\n2 5\r\n2 7\r\n3 7\r\n7 4\r\n7 6\r\n7 1\r\n7 5\r\n", "output": "No\r\n"}, {"input": "8 18\r\n3 7\r\n2 5\r\n5 3\r\n3 8\r\n8 6\r\n6 3\r\n6 4\r\n4 8\r\n1 2\r\n6 1\r\n2 7\r\n2 4\r\n4 5\r\n4 3\r\n6 5\r\n1 4\r\n5 7\r\n3 1\r\n", "output": "No\r\n"}, {"input": "20 55\r\n20 11\r\n14 5\r\n4 9\r\n17 5\r\n16 5\r\n20 16\r\n11 17\r\n2 14\r\n14 19\r\n9 15\r\n20 19\r\n5 18\r\n15 20\r\n1 16\r\n12 20\r\n4 7\r\n16 19\r\n17 19\r\n16 12\r\n19 9\r\n11 13\r\n18 17\r\n10 8\r\n20 1\r\n16 8\r\n1 13\r\n11 12\r\n13 18\r\n4 13\r\n14 10\r\n9 13\r\n8 9\r\n6 9\r\n2 13\r\n10 16\r\n19 1\r\n7 17\r\n20 4\r\n12 8\r\n3 2\r\n18 10\r\n6 13\r\n14 9\r\n7 9\r\n19 7\r\n8 15\r\n20 6\r\n16 13\r\n14 13\r\n19 8\r\n7 14\r\n6 2\r\n9 1\r\n7 1\r\n10 6\r\n", "output": "No\r\n"}, {"input": "15 84\r\n11 9\r\n3 11\r\n13 10\r\n2 12\r\n5 9\r\n1 7\r\n14 4\r\n14 2\r\n14 1\r\n11 8\r\n1 8\r\n14 10\r\n4 15\r\n10 5\r\n5 12\r\n13 11\r\n6 14\r\n5 7\r\n12 11\r\n9 1\r\n10 15\r\n2 6\r\n7 15\r\n14 9\r\n9 7\r\n11 14\r\n8 15\r\n12 7\r\n13 6\r\n2 9\r\n9 6\r\n15 3\r\n12 15\r\n6 15\r\n4 6\r\n4 1\r\n9 12\r\n10 7\r\n6 1\r\n11 10\r\n2 3\r\n5 2\r\n13 2\r\n13 3\r\n12 6\r\n4 3\r\n5 8\r\n12 1\r\n9 15\r\n14 5\r\n12 14\r\n10 1\r\n9 4\r\n7 13\r\n3 6\r\n15 1\r\n13 9\r\n11 1\r\n10 4\r\n9 3\r\n8 12\r\n13 12\r\n6 7\r\n12 10\r\n4 12\r\n13 15\r\n2 10\r\n3 8\r\n1 5\r\n15 2\r\n4 11\r\n2 1\r\n10 8\r\n14 3\r\n14 8\r\n8 7\r\n13 1\r\n5 4\r\n11 2\r\n6 8\r\n5 15\r\n2 4\r\n9 8\r\n9 10\r\n", "output": "No\r\n"}, {"input": "15 13\r\n13 15\r\n13 3\r\n14 3\r\n10 7\r\n2 5\r\n5 12\r\n12 11\r\n9 2\r\n13 7\r\n7 4\r\n12 10\r\n15 7\r\n6 13\r\n", "output": "No\r\n"}, {"input": "6 6\r\n1 4\r\n3 4\r\n6 4\r\n2 6\r\n5 3\r\n3 2\r\n", "output": "No\r\n"}, {"input": "4 6\r\n4 2\r\n3 1\r\n3 4\r\n3 2\r\n4 1\r\n2 1\r\n", "output": "Yes\r\naaaa\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n1 2\r\n3 4\r\n", "output": "Yes\r\nabcc\r\n"}, {"input": "4 3\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacaa\r\n"}, {"input": "4 4\r\n1 2\r\n4 1\r\n3 4\r\n3 1\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "4 4\r\n4 2\r\n3 4\r\n3 1\r\n2 3\r\n", "output": "Yes\r\nacbc\r\n"}, {"input": "4 5\r\n3 1\r\n2 1\r\n3 4\r\n2 4\r\n3 2\r\n", "output": "Yes\r\nabbc\r\n"}, {"input": "4 4\r\n4 1\r\n3 1\r\n3 2\r\n3 4\r\n", "output": "Yes\r\nacba\r\n"}, {"input": "4 5\r\n3 4\r\n2 1\r\n3 1\r\n4 1\r\n2 3\r\n", "output": "Yes\r\nbabc\r\n"}, {"input": "4 4\r\n1 3\r\n3 4\r\n2 1\r\n3 2\r\n", "output": "Yes\r\naabc\r\n"}, {"input": "4 3\r\n2 1\r\n1 4\r\n2 4\r\n", "output": "Yes\r\naaca\r\n"}, {"input": "4 4\r\n2 4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "Yes\r\nbaca\r\n"}, {"input": "4 2\r\n3 1\r\n2 4\r\n", "output": "Yes\r\nacac\r\n"}, {"input": "4 4\r\n4 2\r\n2 1\r\n3 2\r\n1 4\r\n", "output": "Yes\r\nabca\r\n"}, {"input": "4 5\r\n4 1\r\n2 4\r\n2 1\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbbac\r\n"}, {"input": "4 4\r\n1 2\r\n3 1\r\n2 4\r\n2 3\r\n", "output": "Yes\r\nabac\r\n"}, {"input": "4 2\r\n2 3\r\n1 4\r\n", "output": "Yes\r\nacca\r\n"}, {"input": "4 4\r\n2 1\r\n1 4\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbaac\r\n"}, {"input": "4 3\r\n3 2\r\n1 2\r\n1 3\r\n", "output": "Yes\r\naaac\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n3 4\r\n4 1\r\n", "output": "Yes\r\naccb\r\n"}, {"input": "4 5\r\n4 2\r\n3 2\r\n4 3\r\n4 1\r\n2 1\r\n", "output": "Yes\r\nabcb\r\n"}, {"input": "4 4\r\n3 1\r\n2 4\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacab\r\n"}, {"input": "4 5\r\n3 1\r\n4 3\r\n4 1\r\n2 1\r\n2 4\r\n", "output": "Yes\r\nbacb\r\n"}, {"input": "4 4\r\n2 4\r\n3 4\r\n1 2\r\n4 1\r\n", "output": "Yes\r\naacb\r\n"}, {"input": "4 5\r\n1 4\r\n4 3\r\n4 2\r\n3 2\r\n1 3\r\n", "output": "Yes\r\nacbb\r\n"}, {"input": "2 0\r\n", "output": "Yes\r\nac\r\n"}, {"input": "3 0\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2\r\n", "output": "Yes\r\naac\r\n"}, {"input": "3 2\r\n1 2\r\n3 2\r\n", "output": "Yes\r\nabc\r\n"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "Yes\r\naaa\r\n"}, {"input": "3 1\r\n2 3\r\n", "output": "Yes\r\nacc\r\n"}, {"input": "3 1\r\n1 3\r\n", "output": "Yes\r\naca\r\n"}, {"input": "4 3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "No\r\n"}, {"input": "5 9\r\n4 3\r\n4 2\r\n3 1\r\n5 1\r\n4 1\r\n2 1\r\n5 2\r\n3 2\r\n5 4\r\n", "output": "Yes\r\nbbabc\r\n"}, {"input": "6 9\r\n1 4\r\n1 6\r\n3 6\r\n5 4\r\n2 6\r\n3 5\r\n4 6\r\n1 5\r\n5 6\r\n", "output": "No\r\n"}, {"input": "8 21\r\n4 7\r\n7 8\r\n6 4\r\n8 5\r\n8 1\r\n3 4\r\n4 8\r\n4 5\r\n6 7\r\n6 8\r\n7 1\r\n4 2\r\n1 5\r\n6 5\r\n8 2\r\n3 6\r\n5 2\r\n7 5\r\n1 2\r\n7 2\r\n4 1\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 4\r\n1 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n3 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n1 4\r\n", "output": "No\r\n"}, {"input": "5 6\r\n1 2\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 10\r\n1 5\r\n1 4\r\n3 4\r\n3 6\r\n1 2\r\n3 5\r\n2 5\r\n2 6\r\n1 6\r\n4 6\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 2\r\n3 4\r\n2 3\r\n", "output": "No\r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
edges = []
for _ in range(m):
u, v = map(int, f.readline().split())
edges.append((u, v))
# Read reference output
with open(ref_output_path) as f:
ref_lines = [line.strip() for line in f.readlines()]
# Read submission output
with open(sub_output_path) as f:
sub_lines = [line.strip() for line in f.readlines()]
# Check submission lines
if not ref_lines or not sub_lines:
print(0)
return
ref_first = ref_lines[0]
sub_first = sub_lines[0]
if ref_first != sub_first:
print(0)
return
if ref_first == 'Yes':
if len(sub_lines) != 2:
print(0)
return
s = sub_lines[1]
if len(s) != n:
print(0)
return
for c in s:
if c not in {'a', 'b', 'c'}:
print(0)
return
# Create adjacency set
adj = set()
for u, v in edges:
u_idx = u - 1
v_idx = v - 1
adj.add((u_idx, v_idx))
adj.add((v_idx, u_idx))
# Check all pairs
valid = True
for i in range(n):
for j in range(n):
if i == j:
continue
edge_exists = (i, j) in adj
c1 = s[i]
c2 = s[j]
allowed = (c1 == c2) or (abs(ord(c1) - ord(c2)) == 1)
if edge_exists != allowed:
valid = False
break
if not valid:
break
if valid:
print(1)
else:
print(0)
else:
if len(sub_lines) != 1:
print(0)
else:
print(1)
if __name__ == "__main__":
main()
| true |
623/A
|
623
|
A
|
PyPy 3-64
|
TESTS
| 50 | 311 | 146,944,000 |
140243046
|
import sys
zz=1
sys.setrecursionlimit(10**5)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def fori(n):
return [fi() for i in range(n)]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def ii():
return input().rstrip()
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def dadd(d,p,val):
if p in d:
d[p].append(val)
else:
d[p]=[val]
def gi():
return [xx for xx in input().split()]
def gtc(tc,*ans):
print("Case #"+str(tc)+":",*ans)
def cil(n,m):
return n//m+int(n%m>0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def bits(i,n):
p=bin(i)[2:]
return (n-len(p))*"0"+p
def prec(a,pre):
for i in a:
pre.append(pre[-1]+i)
pre.pop(0)
def YN(flag):
print("YES" if flag else "NO")
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j,n,m):
return 0<=i<n and 0<=j<m
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=1
INF=10**18
uu=t
mod=10**9+7
def find(i):
if i==a[i]:
return i
a[i]=find(a[i])
return a[i]
def union(x,y):
xs,ys=find(x),find(y)
if xs!=ys:
if rank[xs]<rank[ys]:
xs,ys=ys,xs
a[ys]=xs
rank[xs]+=1
return False
return True
while t>0:
t-=1
n,m=mi()
d=[1]*(n+1)
rank=[0]*(n+1)
a=[i for i in range(n+1)]
s=set()
b=[]
for i in range(m):
x,y=mi()
b.append([x,y])
d[x]+=1
d[y]+=1
for i in range(1,n+1):
s.add(d[i])
if len(s)>3:
print("No")
continue
p=max(d)
ans=['a']*n
s=list(s)
s.sort()
if p<n:
if len(s)==3:
print("No")
continue
for i,j in b:
if d[i]!=d[j]:
print("No")
exit(0)
if m==103:
print(s)
exit(0)
for i in range(1,n+1):
if p==n and d[i]==p:
ans[i-1]='b'
if len(s)==3 or (len(s)==2 and p!=n):
for i,j in b:
if max(d[i],d[j])!=p and d[i]!=d[j]:
print("No")
exit(0)
for i in range(1,n+1):
if d[i]==s[0]:
ans[i-1]='c'
elif (len(s)==1 and p!=n) or (len(s)==2 and p==n):
r=1
for i in range(1,n+1):
if d[i]!=p:
r=i
for i,j in b:
if p!=n or max(d[i],d[j])!=p:
union(i,j)
r=i
f={}
for i in range(1,n+1):
dadd(f,find(i),i)
for j in f[r]:
ans[j-1]='c'
z={'a':0,'b':0,'c':0}
for i in range(1,n+1):
inc(z,ans[i-1])
if (z['a'] and z['a']+z['b'] not in s)\
or (z['c'] and z['c']+z['b'] not in s)\
or (z['b'] and z['a']+z['b']+z['c'] not in s):
print("No")
exit(0)
print("Yes")
print("".join(ans))
| 106 | 404 | 1,228,800 |
16542882
|
def main():
n, m = map(int, input().split())
links = [[False] * n for i in range(n)]
for i in range(n):
links[i][i] = True
for _ in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
links[u][v] = links[v][u] = True
res = [0] * n
ref1 = ref3 = None
for i, link in enumerate(links):
if all(link):
res[i] = 2
if not all(res):
i = res.index(0)
res[i] = 1
ref1 = links[i]
for i, f in enumerate(ref1):
if f and not (res[i]):
res[i] = 1
if not all(res):
i = res.index(0)
res[i] = 3
ref3 = links[i]
for i, f in enumerate(ref3):
if f:
mark = res[i]
if mark == 1:
print("No")
return
if not mark:
res[i] = 3
ref = [None, ref1, None, ref3]
for i, mark in enumerate(res):
if not mark:
print("No")
return
if mark & 1:
if ref[mark] != links[i]:
print("No")
return
print("Yes")
print(''.join(" abc"[mark] for mark in res))
if __name__ == '__main__':
main()
|
AIM Tech Round (Div. 1)
|
CF
| 2,016 | 2 | 256 |
Graph and String
|
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
- G has exactly n vertices, numbered from 1 to n.
- For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.
|
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
|
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.
| null |
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.
|
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
| 1,800 |
["constructive algorithms", "graphs"]
| 106 |
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "4 3\r\n4 3\r\n2 4\r\n2 3\r\n", "output": "Yes\r\naccc\r\n"}, {"input": "4 2\r\n4 3\r\n1 2\r\n", "output": "Yes\r\naacc\r\n"}, {"input": "5 3\r\n1 2\r\n1 3\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n3 2\r\n1 3\r\n6 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 6\r\n5 6\r\n", "output": "No\r\n"}, {"input": "7 13\r\n1 2\r\n2 3\r\n1 3\r\n4 5\r\n5 6\r\n4 6\r\n2 5\r\n2 7\r\n3 7\r\n7 4\r\n7 6\r\n7 1\r\n7 5\r\n", "output": "No\r\n"}, {"input": "8 18\r\n3 7\r\n2 5\r\n5 3\r\n3 8\r\n8 6\r\n6 3\r\n6 4\r\n4 8\r\n1 2\r\n6 1\r\n2 7\r\n2 4\r\n4 5\r\n4 3\r\n6 5\r\n1 4\r\n5 7\r\n3 1\r\n", "output": "No\r\n"}, {"input": "20 55\r\n20 11\r\n14 5\r\n4 9\r\n17 5\r\n16 5\r\n20 16\r\n11 17\r\n2 14\r\n14 19\r\n9 15\r\n20 19\r\n5 18\r\n15 20\r\n1 16\r\n12 20\r\n4 7\r\n16 19\r\n17 19\r\n16 12\r\n19 9\r\n11 13\r\n18 17\r\n10 8\r\n20 1\r\n16 8\r\n1 13\r\n11 12\r\n13 18\r\n4 13\r\n14 10\r\n9 13\r\n8 9\r\n6 9\r\n2 13\r\n10 16\r\n19 1\r\n7 17\r\n20 4\r\n12 8\r\n3 2\r\n18 10\r\n6 13\r\n14 9\r\n7 9\r\n19 7\r\n8 15\r\n20 6\r\n16 13\r\n14 13\r\n19 8\r\n7 14\r\n6 2\r\n9 1\r\n7 1\r\n10 6\r\n", "output": "No\r\n"}, {"input": "15 84\r\n11 9\r\n3 11\r\n13 10\r\n2 12\r\n5 9\r\n1 7\r\n14 4\r\n14 2\r\n14 1\r\n11 8\r\n1 8\r\n14 10\r\n4 15\r\n10 5\r\n5 12\r\n13 11\r\n6 14\r\n5 7\r\n12 11\r\n9 1\r\n10 15\r\n2 6\r\n7 15\r\n14 9\r\n9 7\r\n11 14\r\n8 15\r\n12 7\r\n13 6\r\n2 9\r\n9 6\r\n15 3\r\n12 15\r\n6 15\r\n4 6\r\n4 1\r\n9 12\r\n10 7\r\n6 1\r\n11 10\r\n2 3\r\n5 2\r\n13 2\r\n13 3\r\n12 6\r\n4 3\r\n5 8\r\n12 1\r\n9 15\r\n14 5\r\n12 14\r\n10 1\r\n9 4\r\n7 13\r\n3 6\r\n15 1\r\n13 9\r\n11 1\r\n10 4\r\n9 3\r\n8 12\r\n13 12\r\n6 7\r\n12 10\r\n4 12\r\n13 15\r\n2 10\r\n3 8\r\n1 5\r\n15 2\r\n4 11\r\n2 1\r\n10 8\r\n14 3\r\n14 8\r\n8 7\r\n13 1\r\n5 4\r\n11 2\r\n6 8\r\n5 15\r\n2 4\r\n9 8\r\n9 10\r\n", "output": "No\r\n"}, {"input": "15 13\r\n13 15\r\n13 3\r\n14 3\r\n10 7\r\n2 5\r\n5 12\r\n12 11\r\n9 2\r\n13 7\r\n7 4\r\n12 10\r\n15 7\r\n6 13\r\n", "output": "No\r\n"}, {"input": "6 6\r\n1 4\r\n3 4\r\n6 4\r\n2 6\r\n5 3\r\n3 2\r\n", "output": "No\r\n"}, {"input": "4 6\r\n4 2\r\n3 1\r\n3 4\r\n3 2\r\n4 1\r\n2 1\r\n", "output": "Yes\r\naaaa\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n1 2\r\n3 4\r\n", "output": "Yes\r\nabcc\r\n"}, {"input": "4 3\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacaa\r\n"}, {"input": "4 4\r\n1 2\r\n4 1\r\n3 4\r\n3 1\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "4 4\r\n4 2\r\n3 4\r\n3 1\r\n2 3\r\n", "output": "Yes\r\nacbc\r\n"}, {"input": "4 5\r\n3 1\r\n2 1\r\n3 4\r\n2 4\r\n3 2\r\n", "output": "Yes\r\nabbc\r\n"}, {"input": "4 4\r\n4 1\r\n3 1\r\n3 2\r\n3 4\r\n", "output": "Yes\r\nacba\r\n"}, {"input": "4 5\r\n3 4\r\n2 1\r\n3 1\r\n4 1\r\n2 3\r\n", "output": "Yes\r\nbabc\r\n"}, {"input": "4 4\r\n1 3\r\n3 4\r\n2 1\r\n3 2\r\n", "output": "Yes\r\naabc\r\n"}, {"input": "4 3\r\n2 1\r\n1 4\r\n2 4\r\n", "output": "Yes\r\naaca\r\n"}, {"input": "4 4\r\n2 4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "Yes\r\nbaca\r\n"}, {"input": "4 2\r\n3 1\r\n2 4\r\n", "output": "Yes\r\nacac\r\n"}, {"input": "4 4\r\n4 2\r\n2 1\r\n3 2\r\n1 4\r\n", "output": "Yes\r\nabca\r\n"}, {"input": "4 5\r\n4 1\r\n2 4\r\n2 1\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbbac\r\n"}, {"input": "4 4\r\n1 2\r\n3 1\r\n2 4\r\n2 3\r\n", "output": "Yes\r\nabac\r\n"}, {"input": "4 2\r\n2 3\r\n1 4\r\n", "output": "Yes\r\nacca\r\n"}, {"input": "4 4\r\n2 1\r\n1 4\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbaac\r\n"}, {"input": "4 3\r\n3 2\r\n1 2\r\n1 3\r\n", "output": "Yes\r\naaac\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n3 4\r\n4 1\r\n", "output": "Yes\r\naccb\r\n"}, {"input": "4 5\r\n4 2\r\n3 2\r\n4 3\r\n4 1\r\n2 1\r\n", "output": "Yes\r\nabcb\r\n"}, {"input": "4 4\r\n3 1\r\n2 4\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacab\r\n"}, {"input": "4 5\r\n3 1\r\n4 3\r\n4 1\r\n2 1\r\n2 4\r\n", "output": "Yes\r\nbacb\r\n"}, {"input": "4 4\r\n2 4\r\n3 4\r\n1 2\r\n4 1\r\n", "output": "Yes\r\naacb\r\n"}, {"input": "4 5\r\n1 4\r\n4 3\r\n4 2\r\n3 2\r\n1 3\r\n", "output": "Yes\r\nacbb\r\n"}, {"input": "2 0\r\n", "output": "Yes\r\nac\r\n"}, {"input": "3 0\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2\r\n", "output": "Yes\r\naac\r\n"}, {"input": "3 2\r\n1 2\r\n3 2\r\n", "output": "Yes\r\nabc\r\n"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "Yes\r\naaa\r\n"}, {"input": "3 1\r\n2 3\r\n", "output": "Yes\r\nacc\r\n"}, {"input": "3 1\r\n1 3\r\n", "output": "Yes\r\naca\r\n"}, {"input": "4 3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "No\r\n"}, {"input": "5 9\r\n4 3\r\n4 2\r\n3 1\r\n5 1\r\n4 1\r\n2 1\r\n5 2\r\n3 2\r\n5 4\r\n", "output": "Yes\r\nbbabc\r\n"}, {"input": "6 9\r\n1 4\r\n1 6\r\n3 6\r\n5 4\r\n2 6\r\n3 5\r\n4 6\r\n1 5\r\n5 6\r\n", "output": "No\r\n"}, {"input": "8 21\r\n4 7\r\n7 8\r\n6 4\r\n8 5\r\n8 1\r\n3 4\r\n4 8\r\n4 5\r\n6 7\r\n6 8\r\n7 1\r\n4 2\r\n1 5\r\n6 5\r\n8 2\r\n3 6\r\n5 2\r\n7 5\r\n1 2\r\n7 2\r\n4 1\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 4\r\n1 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n3 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n1 4\r\n", "output": "No\r\n"}, {"input": "5 6\r\n1 2\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 10\r\n1 5\r\n1 4\r\n3 4\r\n3 6\r\n1 2\r\n3 5\r\n2 5\r\n2 6\r\n1 6\r\n4 6\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 2\r\n3 4\r\n2 3\r\n", "output": "No\r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
edges = []
for _ in range(m):
u, v = map(int, f.readline().split())
edges.append((u, v))
# Read reference output
with open(ref_output_path) as f:
ref_lines = [line.strip() for line in f.readlines()]
# Read submission output
with open(sub_output_path) as f:
sub_lines = [line.strip() for line in f.readlines()]
# Check submission lines
if not ref_lines or not sub_lines:
print(0)
return
ref_first = ref_lines[0]
sub_first = sub_lines[0]
if ref_first != sub_first:
print(0)
return
if ref_first == 'Yes':
if len(sub_lines) != 2:
print(0)
return
s = sub_lines[1]
if len(s) != n:
print(0)
return
for c in s:
if c not in {'a', 'b', 'c'}:
print(0)
return
# Create adjacency set
adj = set()
for u, v in edges:
u_idx = u - 1
v_idx = v - 1
adj.add((u_idx, v_idx))
adj.add((v_idx, u_idx))
# Check all pairs
valid = True
for i in range(n):
for j in range(n):
if i == j:
continue
edge_exists = (i, j) in adj
c1 = s[i]
c2 = s[j]
allowed = (c1 == c2) or (abs(ord(c1) - ord(c2)) == 1)
if edge_exists != allowed:
valid = False
break
if not valid:
break
if valid:
print(1)
else:
print(0)
else:
if len(sub_lines) != 1:
print(0)
else:
print(1)
if __name__ == "__main__":
main()
| true |
419/A
|
420
|
A
|
PyPy 3-64
|
TESTS
| 62 | 62 | 30,412,800 |
192188318
|
s = str(input())
alp = 'AHIMOTUVWXY'
count = 0
if(len(s) == 1):
if(s in alp):
print('YES')
else:
print('NO')
else:
if(len(s) % 2 == 0):
part1 = s[ : len(s) // 2]
part2 = s[len(s)//2 : ]
part2 = part2[::-1]
for el in range(len(part1)):
if(part1[el] == part2[el]):
if(part1[el] in alp and part2[el] in alp):
continue
else:
count += 1
break
else:
count += 1
break
else:
part1 = s[: len(s) // 2]
part2 = s[len(s)//2+1 : ]
part2 = part2[::-1]
if(s[len(s)//2+1] in alp):
for i in range(len(part1)):
if(part1[i] in alp and part2[i] in alp):
continue
else:
count += 1
break
else:
count += 1
if(count == 0):
print('YES')
else:
print('NO')
| 80 | 46 | 0 |
179134237
|
n=input()
if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES")
else: print("NO")
|
Coder-Strike 2014 - Finals
|
CF
| 2,014 | 1 | 256 |
Start Up
|
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
|
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
| null | null |
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
| 1,000 |
[]
| 80 |
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
757/A
|
757
|
A
|
Python 3
|
TESTS
| 55 | 77 | 307,200 |
120062236
|
input_str = input()
sample_str = str("Bulbasaur")
sample_dict = dict()
temp_dict = dict()
# Initialize
for i in sample_str:
sample_dict[i] = 0
for i in sample_str:
sample_dict[i] = sample_dict[i] + 1
for i in range(65,91):
text = chr(i)
temp_dict[text] = 0
for i in range(97,123):
text = chr(i)
temp_dict[text] = 0
for x in input_str:
temp_dict[x] = temp_dict[x] + 1
# End
# Solve
min = 9999
for x in sample_dict.keys():
sample_dict[x] = temp_dict[x] / sample_dict[x]
if(min > sample_dict[x]):
min = sample_dict[x]
print(int(min))
# End
| 107 | 46 | 0 |
151629051
|
s = input()
t = "Bulbasaur"
frq = [s.count(c)//t.count(c) for c in t]
print(min(frq))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
762/C
|
762
|
C
|
Python 3
|
TESTS
| 4 | 61 | 4,915,200 |
27939150
|
a, b = str(input()), str(input())
p, s, pp, sp = [0] * len(b), [0] * len(b), 0, len(a) - 1
p[0] = a.find(b[0])
while sp >= 0 and a[sp] != b[-1]:
sp -= 1
s[len(b) - 1] = sp
pp, sp = p[0] + 1, sp - 1
for i in range(1, len(b)):
if p[i - 1] == -1:
p[i] = -1
else:
while pp < len(a) and a[pp] != b[i]:
pp += 1
p[i] = (pp if pp < len(a) else -1)
pp += 1
for i in range(len(b) - 2, -1, -1):
if s[i + 1] == -1:
s[i] = -1
else:
while sp >= 0 and a[sp] != b[i]:
sp -= 1
s[i] = (sp if sp >= 0 else -1)
sp -= 1
anss, ans = 0, (-1, -1, -1)
for i in range(0, len(b)):
if p[i] == -1:
break
while anss < len(b) and (s[anss] <= p[i] or a[anss] == -1) or anss <= i:
anss += 1
ln = (i + 1 if p[i] != -1 else 0) + (len(b) - anss if anss < len(b) and s[anss] != -1 else 0)
if ln > ans[0]:
ans = (ln, i, anss)
if ans[0] == -1:
print("-")
else:
print(b[:ans[1] + 1] + (b[ans[2]:] if ans[2] < len(b) else ""))
| 99 | 311 | 6,144,000 |
82586553
|
# cook your dish here
a = list(input())
b = list(input())
m = len(a)
n = len(b)
s = [-1]
i = 0
j = 0
while i<m and j<n:
if(a[i]==b[j]):
s.append(i)
j+=1
i+=1
e = [1000000]
i = m-1
j= n-1
while i>=0 and j>=0:
if(a[i]==b[j]):
e.append(i)
j-=1
i-=1
i = len(s)-1
j = 0
ans = "-"
ctr = 0
while j<len(e) and i>=0:
if(s[i]<e[j]):
if(i+j > ctr and i+j<=len(b)):
ctr = i+j
if(j>0):
ans = b[:i] + b[-j:]
else:
ans = b[:i]
j+=1
else:
i -= 1
print(''.join(ans))
|
Educational Codeforces Round 17
|
ICPC
| 2,017 | 2 | 256 |
Two strings
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
|
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
| null |
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
| 2,100 |
["binary search", "hashing", "strings", "two pointers"]
| 99 |
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
PyPy 3
|
TESTS
| 92 | 233 | 11,673,600 |
109836816
|
import sys,os,io
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int,input().split()))
test, = Neo()
n = test
A = []
C = []
if test == 1:
print(1)
exit()
for i in range(test):
B = Neo()
C.append(sum(B))
A.append(B)
p,q = 0,0
f = 0
# print(A)
for i in range(n):
for j in range(n):
if i == j:
p += A[i][j]
if A[i][j] == 0:
f += 1
if i+j == n-1:
q += A[i][j]
# print(A[i][j],'r',i+j)
if A[i][j] == 0:
f += 1
A = list(zip(*A))
# print(A)
for i in A:
C.append(sum(i))
C = Counter(C)
C[p] += 1
C[q] += 1
t = tuple(sorted(C.values()))
# print(t,f)
k = sorted(C.keys())
# print(C)
if ((2,2*test) == t and len(C) == 2 and f == 0) or ((3,2*test-1) == t and len(C) == 2 and f == 1) or ((4,2*test-2) == t and len(C) == 2 and f == 2) :
print(k[1]-k[0])
else:
print(-1)
| 147 | 217 | 7,372,800 |
20402497
|
n = int(input())
a = 0
r,c = 0,-1
dl = []
for i in range(n):
tl = list(map(int, input().split()))
if c<0 and tl.count(0):
r = i
c = tl.index(0)
dl+=[tl]
s = sum(dl[(r+1)%n])
a = s-sum(dl[r])
dl[r][c] = a
if n>1 and a<1:
print(-1)
exit()
# print(dl)
for i in range(n):
if s!=sum(dl[i]):
print(-1)
exit()
dl = list(map(list,zip(*dl)))
for i in range(n):
if s!=sum(dl[i]):
print(-1)
exit()
s1 = s2 = 0
for i in range(n):
s1+=dl[i][i]
s2+=dl[i][n-i-1]
if not(s1==s2==s):
print(-1)
exit()
if n==1:
a=1
print(a)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
540/B
|
540
|
B
|
PyPy 3-64
|
TESTS
| 40 | 62 | 28,774,400 |
225517032
|
def check(x, y, arr: list, i_median):
sum_ = sum(arr)
arr1 = arr.copy()
arr1.sort()
return sum_ <= x and arr1[i_median] >= y
def main():
n, k, p, x, y = map(int, input().split())
i_median = (n + 1) // 2 - 1
high_median = 0
arr = []
x_new = x
if x < y:
return -1
if k != 0:
arr = list(map(int, input().split()))
arr.sort(reverse=True)
i = 0
while i < k and arr[i] >= y:
high_median += 1
i += 1
count_y = (n + 1) // 2 - high_median
count_one = n - k - count_y
arr = arr + [y] * count_y + [1] * count_one
if not check(x, y, arr, i_median):
return -1
for i in range(n):
arr[i] = str(arr[i])
ans = ' '.join(arr[k:n])
return ans
print(main())
| 78 | 62 | 0 |
223776009
|
n, k, p, x, y = map(int, input().split())
a = list(map(int, input().split()))
start_sum = sum(a)
major = 0
for i in range(k):
if a[i] >= y:
major += 1
count_max = (n + 1) // 2 - major
if k - major > n // 2:
print(-1)
else:
cnt_mx = (n + 1) // 2 - major # кол-во макс оценок которые осталось дописать
if cnt_mx <= 0:
cnt_mx = 0
optim = x - start_sum - cnt_mx * y - (n - k - cnt_mx)
if optim < 0:
print(-1)
else:
print(cnt_mx * (str(y) + ' ') + '1 ' * (n - k - cnt_mx))
# cur_min = 1
# count_min = n // 2 - minor
#
# if count_min < 0:
# print(-1)
# else:
# optim = count_min * cur_min + (n - k - count_min) * y
# if optim > sum_marks:
# print(-1)
# else:
# print('1 ' * count_min + (str(y) + ' ') * (n - k - count_min))
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
School Marks
|
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
|
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
|
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
| null |
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
|
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
| 1,700 |
["greedy", "implementation"]
| 78 |
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5 2 4 5\r\n", "output": "-1\r\n"}, {"input": "7 4 5 27 5\r\n5 2 4 5\r\n", "output": "5 5 1\r\n"}, {"input": "1 0 1000 999 1000\r\n\r\n", "output": "-1\r\n"}, {"input": "1 0 1000 1000 1000\r\n\r\n", "output": "1000\r\n"}, {"input": "1 0 1000 1000 999\r\n\r\n", "output": "999\r\n"}, {"input": "995 1 1000 1772 2\r\n1\r\n", "output": "2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1\n"}, {"input": "993 0 1000 63930 1\r\n\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "5 3 5 25 4\r\n3 3 3\r\n", "output": "-1\r\n"}, {"input": "7 4 5 25 5\r\n5 5 4 5\r\n", "output": "-1\r\n"}, {"input": "7 4 5 26 5\r\n5 5 4 5\r\n", "output": "5 1 1\r\n"}, {"input": "7 4 5 26 5\r\n5 5 4 5\r\n", "output": "5 1 1\r\n"}, {"input": "5 3 5 17 4\r\n3 3 4\r\n", "output": "-1\r\n"}, {"input": "5 3 5 18 4\r\n3 3 4\r\n", "output": "4 4\r\n"}, {"input": "5 3 5 5 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "5 3 5 6 1\r\n1 1 2\r\n", "output": "1 1\r\n"}, {"input": "3 0 2 3 1\r\n\r\n", "output": "1 1 1\r\n"}, {"input": "3 0 2 4 2\r\n\r\n", "output": "-1\r\n"}, {"input": "3 0 2 5 2\r\n\r\n", "output": "2 2 1\r\n"}, {"input": "9 7 3 16 2\r\n1 3 1 3 1 3 1\r\n", "output": "-1\r\n"}, {"input": "9 7 3 17 2\r\n1 3 1 3 1 3 1\r\n", "output": "2 2\r\n"}, {"input": "9 7 3 18 2\r\n1 3 1 3 1 3 1\r\n", "output": "2 2\r\n"}, {"input": "9 7 3 18 3\r\n1 3 1 3 1 3 1\r\n", "output": "-1\r\n"}, {"input": "9 7 3 19 3\r\n1 3 1 3 1 3 1\r\n", "output": "3 3\r\n"}, {"input": "9 7 3 20 3\r\n1 3 1 3 1 3 1\r\n", "output": "3 3\r\n"}, {"input": "9 6 3 27 2\r\n1 1 1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "9 6 3 13 2\r\n1 1 1 2 1 2\r\n", "output": "-1\r\n"}, {"input": "9 6 3 14 2\r\n1 1 1 2 1 2\r\n", "output": "2 2 2\r\n"}, {"input": "5 0 5 13 4\r\n\r\n", "output": "-1\r\n"}, {"input": "5 0 5 14 4\r\n\r\n", "output": "4 4 4 1 1\r\n"}, {"input": "5 0 5 5 1\r\n\r\n", "output": "1 1 1 1 1\r\n"}, {"input": "5 0 5 7 2\r\n\r\n", "output": "-1\r\n"}, {"input": "5 0 5 8 2\r\n\r\n", "output": "2 2 2 1 1\r\n"}, {"input": "9 7 2 18 2\r\n1 1 1 2 2 1 1\r\n", "output": "-1\r\n"}, {"input": "9 7 2 13 1\r\n2 2 2 1 1 2 2\r\n", "output": "-1\r\n"}, {"input": "9 7 2 14 1\r\n2 2 2 1 1 2 2\r\n", "output": "1 1\r\n"}, {"input": "993 0 3 993 2\r\n\r\n", "output": "-1\r\n"}, {"input": "995 1 3 2877 3\r\n3\r\n", "output": "1 3 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1\n"}, {"input": "997 100 3 1102 2\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 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 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 3\r\n", "output": "-1\r\n"}, {"input": "993 0 42 12022 1\r\n\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "995 1 42 28887 42\r\n13\r\n", "output": "42 42 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1\n"}, {"input": "997 100 42 3151 1\r\n27 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 22 1 1 1 32 1 1 1 1 1 1 1 16 42 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 38 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 38 1 1 1\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "11 8 10 110 5\r\n9 9 9 9 9 9 9 9\r\n", "output": "1 1 1\r\n"}, {"input": "9 8 10 90 2\r\n1 1 1 1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3 2 10 30 2\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "3 2 10 30 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5 4 100 14 4\r\n4 4 4 4\r\n", "output": "-1\r\n"}, {"input": "5 4 2 8 2\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "5 4 2 7 2\r\n1 1 1 2\r\n", "output": "-1\r\n"}, {"input": "11 10 1000 101 5\r\n10 10 10 10 10 10 10 10 10 10\r\n", "output": "1\r\n"}, {"input": "7 5 100 100 5\r\n7 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "5 4 5 25 2\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "9 8 10 89 5\r\n8 8 8 8 8 8 8 8\r\n", "output": "1\r\n"}, {"input": "5 3 5 18 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "11 10 1000 100 5\r\n10 10 10 10 10 10 10 10 10 10\r\n", "output": "-1\r\n"}, {"input": "9 7 10 30 2\r\n3 3 3 3 3 3 3\r\n", "output": "1 1\r\n"}, {"input": "5 4 2 10 2\r\n2 2 2 2\r\n", "output": "1\r\n"}, {"input": "7 6 1000 31 5\r\n5 5 5 5 5 5\r\n", "output": "1\r\n"}, {"input": "9 8 100 100 2\r\n1 1 1 1 1 1 1 1\r\n", "output": "-1\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
if submission_line == "-1":
sum_existing = sum(existing)
m = (n + 1) // 2
cnt_ge_y = sum(1 for mark in existing if mark >= y)
required = max(0, m - cnt_ge_y)
remaining = n - k
if required > remaining or (sum_existing + required * y + (remaining - required) * 1) > x:
print(100)
else:
print(0)
else:
try:
parts = list(map(int, submission_line.split()))
except:
print(0)
return
if len(parts) != n - k:
print(0)
return
for num in parts:
if not (1 <= num <= p):
print(0)
return
total_marks = existing + parts
sum_total = sum(total_marks)
if sum_total > x:
print(0)
return
sorted_marks = sorted(total_marks)
median = sorted_marks[(n - 1) // 2]
if median >= y:
print(100)
else:
print(0)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
main(input_path, output_path, submission_path)
| true |
748/B
|
748
|
B
|
Python 3
|
TESTS
| 23 | 342 | 4,608,000 |
23293128
|
s = input()
g = input()
n = len(s)
k = 0
letters = []
flag = True
for i in range(n):
t = s[i]
m = g[i]
for j in range(n):
if s[j] == m:
if g[j] != t:
flag = False
if s[j] == t:
if g[j] != m:
flag = False
if flag:
if [t, m] not in letters and [m, t] not in letters and t!=m:
letters.append([t, m])
k+=1
if not flag:
print(-1)
else:
print(k)
for i in range(len(letters)):
print(letters[i][0], letters[i][1])
| 86 | 62 | 4,608,000 |
23301916
|
s, t = input(), input()
#d = dict(zip(s, t))
d = {}
no = False
for i, j in zip(s, t):
if i in d and d[i] != j:
no = True
d[i] = j
# print(d)
d2 = {}
for key in d:
if (d[key] in d and key != d[d[key]]) or d[key] in d2.values():
no = True
break
else:
if key != d[key] and key not in d2.values():
d2[key] = d[key]
if no:
print(-1)
else:
print(len(d2))
for key in d2:
print(key, d2[key])
|
Technocup 2017 - Elimination Round 3
|
CF
| 2,016 | 2 | 256 |
Santa Claus and Keyboard Check
|
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
|
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
|
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
| null | null |
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
| 1,500 |
["implementation", "strings"]
| 86 |
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaaabaaba\r\n", "output": "1\r\nb a\r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\r\nqwertyuiopasdfghjklzx\r\n", "output": "-1\r\n"}, {"input": "accdccdcdccacddbcacc\r\naccbccbcbccacbbdcacc\r\n", "output": "1\r\nd b\r\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\r\n", "output": "0\r\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\r\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\r\n", "output": "5\r\ng f\r\nn i\r\nd h\r\ne o\r\nb k\r\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\r\n", "output": "0\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "zz\r\nzy\r\n", "output": "-1\r\n"}, {"input": "as\r\ndf\r\n", "output": "2\r\na d\r\ns f\r\n"}, {"input": "abc\r\nbca\r\n", "output": "-1\r\n"}, {"input": "rtfg\r\nrftg\r\n", "output": "1\r\nt f\r\n"}, {"input": "y\r\ny\r\n", "output": "0\r\n"}, {"input": "qwertyuiopasdfghjklzx\r\nzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "-1\r\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\r\nqwertyuiasdfghjkzxcvbnm\r\n", "output": "-1\r\n"}, {"input": "aaaaaa\r\nabcdef\r\n", "output": "-1\r\n"}, {"input": "qwerty\r\nffffff\r\n", "output": "-1\r\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\r\n", "output": "0\r\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\r\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\r\n", "output": "-1\r\n"}, {"input": "bacccbbacabbcaacbbba\r\nbacccbbacabbcaacbbba\r\n", "output": "0\r\n"}, {"input": "dbadbddddb\r\nacbacaaaac\r\n", "output": "-1\r\n"}, {"input": "dacbdbbbdd\r\nadbdadddaa\r\n", "output": "-1\r\n"}, {"input": "bbbbcbcbbc\r\ndaddbabddb\r\n", "output": "-1\r\n"}, {"input": "dddddbcdbd\r\nbcbbbdacdb\r\n", "output": "-1\r\n"}, {"input": "cbadcbcdaa\r\nabbbababbb\r\n", "output": "-1\r\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\r\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\r\n", "output": "-1\r\n"}, {"input": "acbbccabaa\r\nabbbbbabaa\r\n", "output": "-1\r\n"}, {"input": "ccccaccccc\r\naaaabaaaac\r\n", "output": "-1\r\n"}, {"input": "acbacacbbb\r\nacbacacbbb\r\n", "output": "0\r\n"}, {"input": "abbababbcc\r\nccccccccbb\r\n", "output": "-1\r\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\r\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\r\n", "output": "-1\r\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\r\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\r\n", "output": "-1\r\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\r\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\r\n", "output": "-1\r\n"}, {"input": "z\r\nz\r\n", "output": "0\r\n"}, {"input": "a\r\nz\r\n", "output": "1\r\na z\r\n"}, {"input": "z\r\na\r\n", "output": "1\r\nz a\r\n"}, {"input": "aa\r\nzz\r\n", "output": "1\r\na z\r\n"}, {"input": "az\r\nza\r\n", "output": "1\r\na z\r\n"}, {"input": "aa\r\nza\r\n", "output": "-1\r\n"}, {"input": "za\r\nzz\r\n", "output": "-1\r\n"}, {"input": "aa\r\nab\r\n", "output": "-1\r\n"}, {"input": "hehe\r\nheeh\r\n", "output": "-1\r\n"}, {"input": "bd\r\ncc\r\n", "output": "-1\r\n"}, {"input": "he\r\nhh\r\n", "output": "-1\r\n"}, {"input": "hee\r\nheh\r\n", "output": "-1\r\n"}, {"input": "aa\r\nac\r\n", "output": "-1\r\n"}, {"input": "ab\r\naa\r\n", "output": "-1\r\n"}, {"input": "hello\r\nehlol\r\n", "output": "-1\r\n"}, {"input": "ac\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaabbb\r\nbbbaab\r\n", "output": "-1\r\n"}, {"input": "aa\r\nfa\r\n", "output": "-1\r\n"}, {"input": "hg\r\nee\r\n", "output": "-1\r\n"}, {"input": "helloworld\r\nehoolwlrow\r\n", "output": "-1\r\n"}, {"input": "abb\r\nbab\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naae\r\n", "output": "-1\r\n"}, {"input": "aba\r\nbaa\r\n", "output": "-1\r\n"}, {"input": "aa\r\nba\r\n", "output": "-1\r\n"}, {"input": "da\r\naa\r\n", "output": "-1\r\n"}, {"input": "aaa\r\naab\r\n", "output": "-1\r\n"}, {"input": "xy\r\nzz\r\n", "output": "-1\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(input_path, 'r') as f:
s, t = f.read().split()
s = s.strip()
t = t.strip()
with open(submission_path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
if not lines:
print(0)
return
if lines[0] == '-1':
possible = True
mapping = {}
n = len(s)
for i in range(n):
c = s[i]
d = t[i]
if c == d:
continue
if c in mapping:
if mapping[c] != d:
possible = False
break
else:
mapping[c] = d
if d in mapping:
if mapping[d] != c:
possible = False
break
else:
mapping[d] = c
for key in mapping:
val = mapping[key]
if key == val or mapping.get(val, None) != key:
possible = False
break
for i in range(n):
c = s[i]
expected = mapping.get(c, c)
if expected != t[i]:
possible = False
break
for c in mapping:
d = mapping[c]
for i in range(n):
if s[i] == c and t[i] != d:
possible = False
break
if s[i] == d and t[i] != c:
possible = False
break
if possible:
print(0)
else:
print(1)
else:
try:
k = int(lines[0])
if k < 0:
print(0)
return
if len(lines) < k + 1:
print(0)
return
pairs = lines[1:k+1]
swap_map = {}
seen = set()
valid = True
for pair in pairs:
parts = pair.split()
if len(parts) != 2:
valid = False
break
a, b = parts
if a == b or a in seen or b in seen:
valid = False
break
seen.add(a)
seen.add(b)
swap_map[a] = b
swap_map[b] = a
if not valid:
print(0)
return
transformed = []
for c in s:
transformed.append(swap_map.get(c, c))
if ''.join(transformed) != t:
print(0)
else:
print(1)
except:
print(0)
if __name__ == "__main__":
main()
| true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,529,600 |
32714122
|
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
pe = 0
va = a[0]
for i in range(1,len(a)):
if pe<va:
pe+=a[i]
else:
va+=a[i]
print(abs(va-pe))
| 93 | 62 | 5,632,000 |
32698789
|
from itertools import cycle
n=int(input())
a=list(map(int,input().split()))
s,m=0,360
j=cycle(a)
for ai in a:
while s<180:
s+=next(j)
m=min(m,s)
s-=ai
print(2*m-360)
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,529,600 |
32743576
|
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
sumr=a[0]
suml=0
for i in range(1,n):
#print(sumr,suml)
if sumr>suml:
suml+=a[i]
else:
sumr+=a[i]
print(abs(sumr-suml))
| 93 | 62 | 5,632,000 |
32839935
|
def diff(val):
return 2 * abs(180 - val)
n = int(input())
arr = input().split(' ')
arr = [int(x) for x in arr]
sum = 0
min_diff = 360
last_idx = 0
for a in arr:
sum += a
min_diff = min(min_diff, diff(sum))
while sum > 180:
sum -= arr[last_idx]
last_idx += 1
min_diff = min(min_diff, diff(sum))
if sum == 180:
min_diff = 0
break
print(min_diff)
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
214/B
|
214
|
B
|
Python 3
|
TESTS
| 10 | 186 | 4,403,200 |
143773505
|
n = int(input())
s = input().split()
s = [int(i) for i in s]
if(n == 1 and s[0] == 0):
print(0)
elif(0 not in s):
print(-1)
else:
a = sum(s)
s.sort(reverse = True)
#print(s,a)
if(a%3 == 0):
if(1 in s or 2 in s or 3 in s or 4 in s or 5 in s or 6 in s or 7 in s or 8 in s or 9 in s):
t = ''.join([str(i) for i in s])
print(t)
else:
print(0)
#print(t)
else:
rem = a%3
if(rem == 1):
a = s.copy()
for i in range(n):
if(s[i]%3 == 1):
a.remove(s[i])
break
if(len(a) == n):
a = s.copy()
count = 0
for i in range(n):
if(s[i]%3 == 2):
a.remove(s[i])
count += 1
if(count == 2):
break
s = a
if(len(s) > 0):
if(1 in s or 2 in s or 3 in s or 4 in s or 5 in s or 6 in s or 7 in s or 8 in s or 9 in s):
t = ''.join([str(i) for i in s])
print(t)
else:
print(0)
elif(rem == 2):
a = s.copy()
for i in range(n):
if(s[i]%3 == 2):
a.remove(s[i])
break
if(len(a) == n):
a = s.copy()
count = 0
for i in range(n):
if(s[i]%3 == 1):
a.remove(s[i])
count += 1
if(count == 2):
break
s = a
if(len(s) > 0):
if(1 in s or 2 in s or 3 in s or 4 in s or 5 in s or 6 in s or 7 in s or 8 in s or 9 in s):
t = ''.join([str(i) for i in s])
print(t)
else:
print(0)
| 101 | 186 | 13,004,800 |
197826043
|
input()
a = sorted(map(int, input().split()))
if a[0] != 0:
a = [-1]
else:
s = sum(a)
if s % 3 != 0:
flag = False
for i in a:
if i % 3 == s % 3:
flag = True
a.remove(i)
break
if(flag == False):
for i in a:
if i % 3:
a.remove(i)
break
for i in a:
if i % 3:
a.remove(i)
break
while len(a) > 1 and a[-1] == 0:
a.pop()
print(''.join(map(str, a[::-1])))
|
Codeforces Round 131 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Hometask
|
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
|
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
|
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
| null |
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
|
[{"input": "1\n0", "output": "0"}, {"input": "11\n3 4 5 4 5 3 5 3 4 4 0", "output": "5554443330"}, {"input": "8\n3 2 5 1 5 2 2 3", "output": "-1"}]
| 1,600 |
["brute force", "constructive algorithms", "greedy", "math"]
| 101 |
[{"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n3 4 5 4 5 3 5 3 4 4 0\r\n", "output": "5554443330\r\n"}, {"input": "8\r\n3 2 5 1 5 2 2 3\r\n", "output": "-1\r\n"}, {"input": "12\r\n5 3 3 3 2 5 5 1 2 1 4 1\r\n", "output": "-1\r\n"}, {"input": "8\r\n5 5 4 1 5 5 5 3\r\n", "output": "-1\r\n"}, {"input": "12\r\n3 1 2 3 2 0 2 2 2 0 2 3\r\n", "output": "33322222200\r\n"}, {"input": "12\r\n5 1 4 4 2 1 7 7 4 2 5 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n3 6 1 6 2\r\n", "output": "-1\r\n"}, {"input": "11\r\n3 9 9 6 4 3 6 4 9 6 0\r\n", "output": "999666330\r\n"}, {"input": "5\r\n9 6 6 6 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n2 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "10\r\n1 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 0 0 0\r\n", "output": "0\r\n"}, {"input": "5\r\n0 0 2 2 0\r\n", "output": "0\r\n"}, {"input": "6\r\n3 3 2 2 2 0\r\n", "output": "332220\r\n"}, {"input": "7\r\n3 3 2 2 2 2 0\r\n", "output": "332220\r\n"}, {"input": "6\r\n0 3 3 1 1 1\r\n", "output": "331110\r\n"}, {"input": "7\r\n0 3 3 1 1 1 1\r\n", "output": "331110\r\n"}, {"input": "7\r\n0 3 3 4 4 4 4\r\n", "output": "444330\r\n"}, {"input": "7\r\n0 3 3 2 2 4 4\r\n", "output": "4433220\r\n"}, {"input": "7\r\n4 2 3 3 0 0 0\r\n", "output": "4332000\r\n"}, {"input": "4\r\n1 1 0 3\r\n", "output": "30\r\n"}, {"input": "4\r\n3 0 2 2\r\n", "output": "30\r\n"}, {"input": "8\r\n3 3 3 5 5 0 0 0\r\n", "output": "333000\r\n"}, {"input": "8\r\n3 3 6 3 0 7 7 9\r\n", "output": "963330\r\n"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "-1\r\n"}, {"input": "9\r\n9 9 9 9 9 9 9 9 9\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n9 0\r\n", "output": "90\r\n"}, {"input": "10\r\n3 0 2 2 2 2 2 2 2 2\r\n", "output": "32222220\r\n"}, {"input": "10\r\n3 0 1 1 1 1 1 1 1 1\r\n", "output": "31111110\r\n"}, {"input": "10\r\n3 0 4 4 4 4 4 4 4 4\r\n", "output": "44444430\r\n"}, {"input": "10\r\n2 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "10\r\n2 2 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n5 5 0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n1 4 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n0 1 4 3\r\n", "output": "30\r\n"}, {"input": "3\r\n2 0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "3210\r\n"}, {"input": "4\r\n1 0 0 0\r\n", "output": "0\r\n"}, {"input": "5\r\n8 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "5\r\n0 0 8 5 6\r\n", "output": "600\r\n"}, {"input": "4\r\n5 8 3 0\r\n", "output": "30\r\n"}, {"input": "4\r\n1 4 0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "0\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "0\r\n"}, {"input": "4\r\n0 0 0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 0 4\r\n", "output": "0\r\n"}, {"input": "2\r\n0 1\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 0 0\r\n", "output": "0\r\n"}, {"input": "6\r\n2 2 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "5\r\n3 2 5 0 0\r\n", "output": "300\r\n"}, {"input": "4\r\n5 3 2 0\r\n", "output": "30\r\n"}, {"input": "5\r\n0 0 0 2 2\r\n", "output": "0\r\n"}, {"input": "5\r\n0 0 0 0 1\r\n", "output": "0\r\n"}, {"input": "4\r\n0 3 5 8\r\n", "output": "30\r\n"}]
| false |
stdio
| null | true |
984/B
|
984
|
B
|
Python 3
|
TESTS
| 4 | 46 | 0 |
155234325
|
n,m=map(int,input().split())
b=['.' for i in range(m+2)]
a=[b]
num='123456789'
def provjera(i,j):
if a[i][j] in num:
x=int(a[i][j])
else:
x=0
br=0
if a[i-1][j-1]=='*':
br+=1
if a[i-1][j]=='*':
br+=1
if a[i-1][j+1]=='*':
br+=1
if a[i][j+1]=='*':
br+=1
if a[i+1][j+1]=='*':
br+=1
if a[i+1][j]=='*':
br+=1
if a[i+1][j-1]=='*':
br+=1
if a[i][j-1]=='*':
br+=1
if br==x:
return True
else:
return False
for i in range(n):
inp=input()
c=['.']
for j in inp:
c.append(j)
c.append('.')
a.append(c)
a.append(b)
da=True
for i in range(1,n+1):
for j in range(1,m+1):
if provjera(i,j)==False:
da=False
break
if da:
print('YES')
else:
print('NO')
| 84 | 93 | 0 |
156188341
|
n, m = map(int, input().split())
g = [input().replace('.', '0') for i in [0] * n]
b = [[0] * m for i in [0] * n]
for i in range(n):
for j in range(m):
if g[i][j] != '*' : b[i][j] += int(g[i][j])
else :
for x in range(max(i-1,0),min(i+2,n)):
for y in range(max(j-1,0),min(j+2,m)):
b[x][y] -= 1
for i in range(n):
for j in range(m):
if b[i][j] != 0 and g[i][j] != '*':
print("NO"), exit()
print("YES")
|
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
|
CF
| 2,018 | 1 | 256 |
Minesweeper
|
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field.
The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to $$$8$$$, inclusive.
|
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
| null |
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
|
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
| 1,100 |
["implementation"]
| 84 |
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| false |
stdio
| null | true |
984/B
|
984
|
B
|
PyPy 3
|
TESTS
| 4 | 124 | 0 |
116205125
|
def is_safe(x, y, n, m):
return 0 <= x < n and 0 <= y < m
n, m = map(int, input().split())
grid = []
for i in range(n):
grid.append(list(input()))
new_grid = [[0]*m for i in range(n)]
directions = [[1, 0], [0, 1], [-1, 0], [0, -1],
[-1, -1], [1, 1], [-1, 1], [1, -1]]
for i in range(n):
for j in range(m):
if grid[i][j] == "*":
for k in directions:
if is_safe(i+k[0], j+k[1], n, m):
new_grid[i+k[0]][j+k[1]] += 1
r = True
for i in range(n):
if r:
for j in range(m):
if grid[i][j] == ".":
if new_grid[i][j] != 0:
r = False
break
elif grid[i][j] == "*":
if new_grid[i][j] != 0:
r = False
break
elif grid[i][j].isnumeric() and int(grid[i][j]) == new_grid[i][j]:
continue
else:
r = False
break
if r:
print("YES")
else:
print("NO")
| 84 | 93 | 2,969,600 |
146893279
|
def solve(matrix, n, m):
for r in range(n):
for c in range(m):
if matrix[r][c] == '*': continue
bombCnt = 0
if r>0 and matrix[r-1][c] == '*': bombCnt += 1
if r>0 and c<m-1 and matrix[r-1][c+1] == '*': bombCnt += 1
if c<m-1 and matrix[r][c+1] == '*': bombCnt += 1
if r<n-1 and c<m-1 and matrix[r+1][c+1] == '*': bombCnt += 1
if r<n-1 and matrix[r+1][c] == '*': bombCnt += 1
if r<n-1 and c>0 and matrix[r+1][c-1] == '*': bombCnt += 1
if c>0 and matrix[r][c-1] == '*': bombCnt += 1
if r>0 and c>0 and matrix[r-1][c-1] == '*': bombCnt += 1
if matrix[r][c] == '.':
if bombCnt: return "NO"
elif int(matrix[r][c]) != bombCnt: return "NO"
return "YES"
n, m = map(int, input().split())
matrix = [list(input()) for _ in range(n)]
print(solve(matrix, n, m))
|
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
|
CF
| 2,018 | 1 | 256 |
Minesweeper
|
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field.
The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to $$$8$$$, inclusive.
|
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
| null |
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
|
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
| 1,100 |
["implementation"]
| 84 |
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| false |
stdio
| null | true |
638/B
|
638
|
B
|
Python 3
|
TESTS
| 24 | 62 | 5,120,000 |
16853686
|
def cross(s1, s2):
# check lengths
if len(s1) > len(s2):
s1, s2 = s2, s1
if s1 in s2:
return True, s2
a = s2.find(s1[-1])
if a != -1:
return True, s1 + s2[(a + 1)::]
a = s2.rfind(s1[0])
if a != -1:
return True, s2[:a] + s1
return False, ""
def cross_all(ar):
all = set(range(len(ar)))
crossed = set()
different = [ar[0]]
crossed.add(0)
start = 0
while True:
se = all - crossed
if len(se) == 0:
break
changed = False
for i in se:
flag, new_s = cross(different[-1], ar[i])
if flag:
different[-1] = new_s
crossed.add(i)
else:
changed = True
start = i
if changed:
different.append(ar[start])
crossed.add(start)
s = ""
for i in different:
s += i
return s
def main():
n = int(input())
result = []
for i in range(n):
s = input()
crossed = False
for j in range(len(result)):
flag, new_s = cross(s, result[j])
if flag:
result[j] = new_s
crossed |= flag
if not crossed:
result.append(s)
print(cross_all(result))
main()
| 67 | 61 | 5,120,000 |
16842176
|
n = int(input())
a = {}
b = {}
w, e = set(), set()
for i in range(n):
s = input()
q = s[0]
if s[0] not in b.keys():
b[s[0]] = -1
e.add(s[0])
if s[-1] not in a.keys():
a[s[-1]] = -1
w.add(s[-1])
for j in range(1, len(s)):
if s[j-1] in w:
w.remove(s[j-1])
if s[j] in e:
e.remove(s[j])
a[s[j-1]] = s[j]
b[s[j]] = s[j-1]
while b[q[0]] != -1:
q = b[q[0]]+q
while a[q[-1]] != -1:
q = q+a[q[-1]]
while(len(e)!= 1 or len(w)!=1):
if(len(e)!= 1):
r = e.pop()
if q[0]==r:
i = e.pop()
e.add(r)
r = i
q+=r
a[q[-2]]=r
b[r]=q[-2]
if q[-2] in w:
w.remove(q[-2])
else:
r=w.pop()
if q[-1]==r:
i = w.pop()
w.add(r)
r = i
q = r+q
a[r]=q[1]
b[q[1]] = r
if q[1] in e:
e.remove(q[1])
while b[q[0]] != -1:
q = b[q[0]]+q
while a[q[-1]] != -1:
q = q+a[q[-1]]
print(q)
|
VK Cup 2016 - Qualification Round 2
|
CF
| 2,016 | 1 | 256 |
Making Genome in Berland
|
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.
Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.
You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.
|
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.
It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.
|
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
| null | null |
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
| 1,500 |
["*special", "dfs and similar", "strings"]
| 67 |
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijklmnopqrstuvwxyz\r\n"}, {"input": "1\r\nf\r\n", "output": "f\r\n"}, {"input": "1\r\nqwertyuiopzxcvbnmasdfghjkl\r\n", "output": "qwertyuiopzxcvbnmasdfghjkl\r\n"}, {"input": "3\r\ndfghj\r\nghjkl\r\nasdfg\r\n", "output": "asdfghjkl\r\n"}, {"input": "4\r\nab\r\nab\r\nab\r\nabc\r\n", "output": "abc\r\n"}, {"input": "3\r\nf\r\nn\r\nux\r\n", "output": "uxfn\r\n"}, {"input": "2\r\nfgs\r\nfgs\r\n", "output": "fgs\r\n"}, {"input": "96\r\nc\r\ndhf\r\no\r\nq\r\nry\r\nh\r\nr\r\nf\r\nji\r\nek\r\ndhf\r\np\r\nk\r\no\r\nf\r\nw\r\nc\r\nc\r\nfgw\r\nbps\r\nhfg\r\np\r\ni\r\nji\r\nto\r\nc\r\nou\r\ny\r\nfg\r\na\r\ne\r\nu\r\nc\r\ny\r\nhf\r\nqn\r\nu\r\nj\r\np\r\ns\r\no\r\nmr\r\na\r\nqn\r\nb\r\nlb\r\nn\r\nji\r\nji\r\na\r\no\r\nat\r\ns\r\nf\r\nb\r\ndh\r\nk\r\nl\r\nl\r\nvq\r\nt\r\nb\r\nc\r\nv\r\nc\r\nh\r\nh\r\ny\r\nh\r\nq\r\ne\r\nx\r\nd\r\no\r\nq\r\nm\r\num\r\nmr\r\nfg\r\ni\r\nl\r\na\r\nh\r\nt\r\num\r\nr\r\no\r\nn\r\nk\r\ne\r\nji\r\na\r\nc\r\nh\r\ne\r\nm\r\n", "output": "atoumrydhfgwekjilbpsvqncx\r\n"}, {"input": "3\r\npbi\r\nopbi\r\ngh\r\n", "output": "ghopbi\r\n"}, {"input": "4\r\ng\r\np\r\no\r\nop\r\n", "output": "opg\r\n"}, {"input": "5\r\np\r\nf\r\nu\r\nf\r\np\r\n", "output": "pfu\r\n"}, {"input": "4\r\nr\r\nko\r\nuz\r\nko\r\n", "output": "kouzr\r\n"}, {"input": "5\r\nzt\r\nted\r\nlzt\r\nted\r\ndyv\r\n", "output": "lztedyv\r\n"}, {"input": "6\r\ngul\r\ng\r\njrb\r\nul\r\nd\r\njr\r\n", "output": "guljrbd\r\n"}, {"input": "5\r\nlkyh\r\naim\r\nkyh\r\nm\r\nkyhai\r\n", "output": "lkyhaim\r\n"}, {"input": "4\r\nzrncsywd\r\nsywdx\r\ngqzrn\r\nqzrncsy\r\n", "output": "gqzrncsywdx\r\n"}, {"input": "5\r\ntbxzc\r\njrdtb\r\njrdtb\r\nflnj\r\nrdtbx\r\n", "output": "flnjrdtbxzc\r\n"}, {"input": "10\r\ng\r\nkagijn\r\nzxt\r\nhmkag\r\nhm\r\njnc\r\nxtqupw\r\npwhmk\r\ng\r\nagi\r\n", "output": "zxtqupwhmkagijnc\r\n"}, {"input": "20\r\nf\r\nf\r\nv\r\nbn\r\ne\r\nmr\r\ne\r\ne\r\nn\r\nj\r\nqfv\r\ne\r\ndpb\r\nj\r\nlc\r\nr\r\ndp\r\nf\r\na\r\nrt\r\n", "output": "dpbnlcmrtqfveja\r\n"}, {"input": "30\r\nxlo\r\nwx\r\ne\r\nf\r\nyt\r\nw\r\ne\r\nl\r\nxl\r\nojg\r\njg\r\niy\r\ngkz\r\ne\r\nw\r\nloj\r\ng\r\nfw\r\nl\r\nlo\r\nbe\r\ne\r\ngk\r\niyt\r\no\r\nb\r\nqv\r\nz\r\nb\r\nzq\r\n", "output": "befwxlojgkzqviyt\r\n"}, {"input": "50\r\nmd\r\nei\r\nhy\r\naz\r\nzr\r\nmd\r\nv\r\nz\r\nke\r\ny\r\nuk\r\nf\r\nhy\r\njm\r\nke\r\njm\r\ncn\r\nwf\r\nzr\r\nqj\r\ng\r\nzr\r\ndv\r\ni\r\ndv\r\nuk\r\nj\r\nwf\r\njm\r\nn\r\na\r\nqj\r\nei\r\nf\r\nzr\r\naz\r\naz\r\nke\r\na\r\nr\r\ndv\r\nei\r\nzr\r\ndv\r\nq\r\ncn\r\nyg\r\nqj\r\nnh\r\nhy\r\n", "output": "azrcnhygqjmdvukeiwf\r\n"}, {"input": "80\r\ni\r\nioh\r\nquc\r\nexioh\r\niohb\r\nex\r\nrwky\r\nz\r\nquc\r\nrw\r\nplnt\r\nq\r\nhbrwk\r\nexioh\r\ntv\r\nxioh\r\nlnt\r\nxi\r\nn\r\npln\r\niohbr\r\nwky\r\nhbr\r\nw\r\nyq\r\nrwky\r\nbrw\r\nplnt\r\nv\r\nkyq\r\nrwkyq\r\nt\r\nhb\r\ngplnt\r\np\r\nkyqu\r\nhbr\r\nrwkyq\r\nhbr\r\nve\r\nhbrwk\r\nkyq\r\nkyquc\r\ngpln\r\ni\r\nbr\r\ntvex\r\nwkyqu\r\nz\r\nlnt\r\ngp\r\nky\r\ngplnt\r\ne\r\nhbrwk\r\nbrw\r\nve\r\no\r\nplnt\r\nn\r\nntve\r\ny\r\nln\r\npln\r\ntvexi\r\nr\r\nzgp\r\nxiohb\r\nl\r\nn\r\nt\r\nplnt\r\nlntv\r\nexi\r\nexi\r\ngpl\r\nioh\r\nk\r\nwk\r\ni\r\n", "output": "zgplntvexiohbrwkyquc\r\n"}, {"input": "70\r\njp\r\nz\r\nz\r\nd\r\ndy\r\nk\r\nsn\r\nrg\r\nz\r\nsn\r\nh\r\nj\r\ns\r\nkx\r\npu\r\nkx\r\nm\r\njp\r\nbo\r\nm\r\ntk\r\ndy\r\no\r\nm\r\nsn\r\nv\r\nrg\r\nv\r\nn\r\no\r\ngh\r\np\r\no\r\nx\r\nq\r\nzv\r\nr\r\nbo\r\ng\r\noz\r\nu\r\nub\r\nnd\r\nh\r\ny\r\njp\r\no\r\nq\r\nbo\r\nhq\r\nhq\r\nkx\r\nx\r\ndy\r\nn\r\nb\r\nub\r\nsn\r\np\r\nub\r\ntk\r\nu\r\nnd\r\nvw\r\nt\r\nub\r\nbo\r\nyr\r\nyr\r\nub\r\n", "output": "jpubozvwsndyrghqtkxm\r\n"}, {"input": "100\r\nm\r\nj\r\nj\r\nf\r\nk\r\nq\r\ni\r\nu\r\ni\r\nl\r\nt\r\nt\r\no\r\nv\r\nk\r\nw\r\nr\r\nj\r\nh\r\nx\r\nc\r\nv\r\nu\r\nf\r\nh\r\nj\r\nb\r\ne\r\ni\r\nr\r\ng\r\nb\r\nl\r\nb\r\ng\r\nb\r\nf\r\nq\r\nv\r\na\r\nu\r\nn\r\ni\r\nl\r\nk\r\nc\r\nx\r\nu\r\nr\r\ne\r\ni\r\na\r\nc\r\no\r\nc\r\na\r\nx\r\nd\r\nf\r\nx\r\no\r\nx\r\nm\r\nl\r\nr\r\nc\r\nr\r\nc\r\nv\r\nj\r\ng\r\nu\r\nn\r\nn\r\nd\r\nl\r\nl\r\nc\r\ng\r\nu\r\nr\r\nu\r\nh\r\nl\r\na\r\nl\r\nr\r\nt\r\nm\r\nf\r\nm\r\nc\r\nh\r\nl\r\nd\r\na\r\nr\r\nh\r\nn\r\nc\r\n", "output": "mjfkqiultovwrhxcbegand\r\n"}, {"input": "99\r\nia\r\nz\r\nsb\r\ne\r\nnm\r\nd\r\nknm\r\nt\r\nm\r\np\r\nqvu\r\ne\r\nq\r\nq\r\ns\r\nmd\r\nz\r\nfh\r\ne\r\nwi\r\nn\r\nsb\r\nq\r\nw\r\ni\r\ng\r\nr\r\ndf\r\nwi\r\nl\r\np\r\nm\r\nb\r\ni\r\natj\r\nb\r\nwia\r\nx\r\nnm\r\nlk\r\nx\r\nfh\r\nh\r\np\r\nf\r\nzr\r\nz\r\nr\r\nsbz\r\nlkn\r\nsbz\r\nz\r\na\r\nwia\r\ntjx\r\nk\r\nj\r\nx\r\nl\r\nqvu\r\nzr\r\nfh\r\nbzrg\r\nz\r\nplk\r\nfhe\r\nn\r\njxqv\r\nrgp\r\ne\r\ndf\r\nz\r\ns\r\natj\r\ndf\r\nat\r\ngp\r\nw\r\new\r\nt\r\np\r\np\r\nfhe\r\nq\r\nxq\r\nt\r\nzr\r\nat\r\ndfh\r\nj\r\ns\r\nu\r\npl\r\np\r\nrg\r\nlk\r\nq\r\nwia\r\ng\r\n", "output": "sbzrgplknmdfhewiatjxqvu\r\n"}, {"input": "95\r\np\r\nk\r\nd\r\nr\r\nn\r\nz\r\nn\r\nb\r\np\r\nw\r\ni\r\nn\r\ny\r\ni\r\nn\r\nn\r\ne\r\nr\r\nu\r\nr\r\nb\r\ni\r\ne\r\np\r\nk\r\nc\r\nc\r\nh\r\np\r\nk\r\nh\r\ns\r\ne\r\ny\r\nq\r\nq\r\nx\r\nw\r\nh\r\ng\r\nt\r\nt\r\na\r\nt\r\nh\r\ni\r\nb\r\ne\r\np\r\nr\r\nu\r\nn\r\nn\r\nr\r\nq\r\nn\r\nu\r\ng\r\nw\r\nt\r\np\r\nt\r\nk\r\nd\r\nz\r\nh\r\nf\r\nd\r\ni\r\na\r\na\r\nf\r\ne\r\na\r\np\r\ns\r\nk\r\nt\r\ng\r\nf\r\ni\r\ng\r\ng\r\nt\r\nn\r\nn\r\nt\r\nt\r\nr\r\nx\r\na\r\nz\r\nc\r\nn\r\nk\r\n", "output": "pkdrnzbwiyeuchsqxgtaf\r\n"}, {"input": "3\r\nh\r\nx\r\np\r\n", "output": "hxp\r\n"}, {"input": "4\r\nrz\r\nvu\r\nxy\r\npg\r\n", "output": "pgrzvuxy\r\n"}, {"input": "5\r\ndrw\r\nu\r\nzq\r\npd\r\naip\r\n", "output": "aipdrwzqu\r\n"}, {"input": "70\r\ne\r\no\r\ng\r\ns\r\nsz\r\nyl\r\ns\r\nn\r\no\r\nq\r\np\r\nl\r\noa\r\ndq\r\ny\r\np\r\nn\r\nio\r\ng\r\nb\r\nk\r\nv\r\ny\r\nje\r\nc\r\ncb\r\nfx\r\ncbv\r\nfxp\r\nkt\r\nhm\r\nz\r\nrcb\r\np\r\nt\r\nu\r\nzh\r\ne\r\nb\r\na\r\nyl\r\nd\r\nv\r\nl\r\nrc\r\nq\r\nt\r\nt\r\nj\r\nl\r\nr\r\ny\r\nlg\r\np\r\nt\r\nd\r\nq\r\nje\r\nqwu\r\ng\r\nz\r\ngi\r\ndqw\r\nz\r\nvyl\r\nk\r\nt\r\nc\r\nb\r\nrc\r\n", "output": "dqwufxpjektrcbvylgioaszhmn\r\n"}, {"input": "3\r\ne\r\nw\r\nox\r\n", "output": "oxew\r\n"}, {"input": "100\r\npr\r\nfz\r\nru\r\ntk\r\nld\r\nvq\r\nef\r\ngj\r\ncp\r\nbm\r\nsn\r\nld\r\nua\r\nzl\r\ndw\r\nef\r\nua\r\nbm\r\nxb\r\nvq\r\nav\r\ncp\r\nko\r\nwc\r\nru\r\ni\r\ne\r\nav\r\nbm\r\nav\r\nxb\r\nog\r\ng\r\nme\r\ntk\r\nog\r\nxb\r\nef\r\ntk\r\nhx\r\nqt\r\nvq\r\ndw\r\nv\r\nxb\r\ndw\r\nko\r\nd\r\nbm\r\nua\r\nvq\r\nis\r\nwc\r\ntk\r\ntk\r\ngj\r\ng\r\ngj\r\nef\r\nqt\r\nvq\r\nbm\r\nog\r\nvq\r\ngj\r\nvq\r\nzl\r\ngj\r\nji\r\nvq\r\nhx\r\ng\r\nbm\r\nji\r\nqt\r\nef\r\nav\r\ntk\r\nxb\r\nru\r\nko\r\nny\r\nis\r\ncp\r\nxb\r\nog\r\nru\r\nhx\r\nwc\r\nko\r\nu\r\nfz\r\ndw\r\nji\r\nzl\r\nvq\r\nqt\r\nko\r\ngj\r\nis\r\n", "output": "hxbmefzldwcpruavqtkogjisny\r\n"}, {"input": "23\r\nw\r\nz\r\nk\r\nc\r\ne\r\np\r\nt\r\na\r\nx\r\nc\r\nq\r\nx\r\na\r\nf\r\np\r\nw\r\nh\r\nx\r\nf\r\nw\r\np\r\nw\r\nq\r\n", "output": "wzkceptaxqfh\r\n"}, {"input": "12\r\nu\r\na\r\nhw\r\na\r\ngh\r\nog\r\nr\r\nd\r\nw\r\nk\r\nl\r\ny\r\n", "output": "oghwuardkly\r\n"}, {"input": "2\r\ny\r\nd\r\n", "output": "yd\r\n"}, {"input": "1\r\nd\r\n", "output": "d\r\n"}, {"input": "100\r\nwm\r\nq\r\nhf\r\nwm\r\niz\r\ndl\r\nmiz\r\np\r\nzoa\r\nbk\r\nw\r\nxv\r\nfj\r\nd\r\nxvsg\r\nr\r\nx\r\nt\r\nyd\r\nbke\r\ny\r\neq\r\nx\r\nn\r\nry\r\nt\r\nc\r\nuh\r\nn\r\npw\r\nuhf\r\neq\r\nr\r\nw\r\nk\r\nt\r\nsg\r\njb\r\nd\r\nke\r\ne\r\nx\r\nh\r\ntuh\r\nan\r\nn\r\noa\r\nw\r\nq\r\nz\r\nk\r\noan\r\nbk\r\nj\r\nzoan\r\nyd\r\npwmi\r\nyd\r\nc\r\nry\r\nfj\r\nlx\r\nqr\r\nke\r\nizo\r\nm\r\nz\r\noan\r\nwmi\r\nl\r\nyd\r\nz\r\ns\r\nke\r\nw\r\nfjbk\r\nqry\r\nlxv\r\nhf\r\ns\r\nnc\r\nq\r\nlxv\r\nzoa\r\nn\r\nfj\r\np\r\nhf\r\nmiz\r\npwm\r\ntu\r\noan\r\ng\r\nd\r\nqr\r\na\r\nan\r\nxvs\r\ny\r\ntuhf\r\n", "output": "pwmizoanctuhfjbkeqrydlxvsg\r\n"}, {"input": "94\r\ncw\r\nm\r\nuhbk\r\ntfy\r\nsd\r\nu\r\ntf\r\ntfym\r\nfy\r\nbk\r\nx\r\nx\r\nxl\r\npu\r\noq\r\nkt\r\ny\r\nb\r\nj\r\nqxl\r\no\r\noqx\r\nr\r\nr\r\njr\r\nk\r\ne\r\nw\r\nsd\r\na\r\nljre\r\nhbk\r\nym\r\nxl\r\np\r\nreg\r\nktf\r\nre\r\nw\r\nhbk\r\nxlj\r\nzn\r\ne\r\nm\r\nms\r\nsdv\r\nr\r\nr\r\no\r\naoq\r\nzna\r\nymsd\r\nqx\r\nr\r\no\r\nlj\r\nm\r\nk\r\nu\r\nkt\r\nms\r\ne\r\nx\r\nh\r\ni\r\nz\r\nm\r\nc\r\nb\r\no\r\nm\r\nvcw\r\ndvc\r\nq\r\na\r\nb\r\nfyms\r\nv\r\nxl\r\nxl\r\ntfym\r\nx\r\nfy\r\np\r\nyms\r\nms\r\nb\r\nt\r\nu\r\nn\r\nq\r\nnaoqx\r\no\r\ne\r\n", "output": "puhbktfymsdvcwznaoqxljregi\r\n"}, {"input": "13\r\ngku\r\nzw\r\nstvqc\r\najy\r\njystvq\r\nfilden\r\nstvq\r\nfild\r\nqcporh\r\najys\r\nqcpor\r\nqcpor\r\ncporhm\r\n", "output": "ajystvqcporhmfildengkuzw\r\n"}, {"input": "2\r\not\r\nqu\r\n", "output": "otqu\r\n"}, {"input": "100\r\nv\r\nh\r\nj\r\nf\r\nr\r\ni\r\ns\r\nw\r\nv\r\nd\r\nv\r\np\r\nd\r\nu\r\ny\r\nd\r\nu\r\nx\r\nr\r\nu\r\ng\r\nm\r\ns\r\nf\r\nv\r\nx\r\na\r\ng\r\ng\r\ni\r\ny\r\ny\r\nv\r\nd\r\ni\r\nq\r\nq\r\nu\r\nx\r\nj\r\nv\r\nj\r\ne\r\no\r\nr\r\nh\r\nu\r\ne\r\nd\r\nv\r\nb\r\nv\r\nq\r\nk\r\ni\r\nr\r\ne\r\nm\r\na\r\nj\r\na\r\nu\r\nq\r\nx\r\nq\r\ny\r\ns\r\nw\r\nk\r\ni\r\ns\r\nr\r\np\r\ni\r\np\r\ns\r\nd\r\nj\r\nw\r\no\r\nm\r\ns\r\nr\r\nd\r\nf\r\ns\r\nw\r\nv\r\ne\r\ny\r\no\r\nx\r\na\r\np\r\nk\r\nr\r\ng\r\ng\r\nb\r\nq\r\n", "output": "vhjfriswdpuyxgmaqeobk\r\n"}, {"input": "99\r\ntnq\r\nep\r\nuk\r\nk\r\nx\r\nvhy\r\nepj\r\nx\r\nj\r\nhy\r\nukg\r\nsep\r\nquk\r\nr\r\nw\r\no\r\nxrwm\r\ndl\r\nh\r\no\r\nad\r\ng\r\ng\r\nhy\r\nxr\r\nad\r\nhyx\r\nkg\r\nvh\r\nb\r\nlovh\r\nuk\r\nl\r\ntn\r\nkg\r\ny\r\nu\r\nxr\r\nse\r\nyx\r\nmt\r\nlo\r\nm\r\nu\r\nukg\r\ngse\r\na\r\nuk\r\nn\r\nr\r\nlov\r\nep\r\nh\r\nadl\r\nyx\r\nt\r\nukg\r\nz\r\nepj\r\nz\r\nm\r\nx\r\nov\r\nyx\r\nxr\r\nep\r\nw\r\ny\r\nmtn\r\nsep\r\nep\r\nmt\r\nrwmt\r\nuk\r\nlo\r\nz\r\nnq\r\nj\r\ntn\r\nj\r\nkgs\r\ny\r\nb\r\nmtn\r\nsep\r\nr\r\ns\r\no\r\nr\r\nepjb\r\nadl\r\nrwmt\r\nyxrw\r\npj\r\nvhy\r\nk\r\ns\r\nx\r\nt\r\n", "output": "adlovhyxrwmtnqukgsepjbz\r\n"}, {"input": "95\r\nx\r\np\r\nk\r\nu\r\ny\r\nz\r\nt\r\na\r\ni\r\nj\r\nc\r\nh\r\nk\r\nn\r\nk\r\ns\r\nr\r\ny\r\nn\r\nv\r\nf\r\nb\r\nr\r\no\r\no\r\nu\r\nb\r\nj\r\no\r\nd\r\np\r\ns\r\nb\r\nt\r\nd\r\nq\r\nq\r\na\r\nm\r\ny\r\nq\r\nj\r\nz\r\nk\r\ne\r\nt\r\nv\r\nj\r\np\r\np\r\ns\r\nz\r\no\r\nk\r\nt\r\na\r\na\r\nc\r\np\r\nb\r\np\r\nx\r\nc\r\ny\r\nv\r\nj\r\na\r\np\r\nc\r\nd\r\nj\r\nt\r\nj\r\nt\r\nf\r\no\r\no\r\nn\r\nx\r\nq\r\nc\r\nk\r\np\r\nk\r\nq\r\na\r\ns\r\nl\r\na\r\nq\r\na\r\nb\r\ne\r\nj\r\nl\r\n", "output": "xpkuyztaijchnsrvfbodqmel\r\n"}, {"input": "96\r\not\r\njo\r\nvpr\r\nwi\r\ngx\r\nay\r\nzqf\r\nzq\r\npr\r\nigx\r\ntsb\r\nv\r\nr\r\ngxc\r\nigx\r\ngx\r\nvpr\r\nxc\r\nylk\r\nigx\r\nlkh\r\nvp\r\nuvp\r\nz\r\nbuv\r\njo\r\nvpr\r\npr\r\nprn\r\nwi\r\nqfw\r\nbuv\r\nd\r\npr\r\ndmj\r\nvpr\r\ng\r\nylk\r\nsbu\r\nhz\r\nk\r\nzqf\r\nylk\r\nxc\r\nwi\r\nvpr\r\nbuv\r\nzq\r\nmjo\r\nkh\r\nuv\r\nuvp\r\nts\r\nt\r\nylk\r\nnay\r\nbuv\r\nhzq\r\nts\r\njo\r\nsbu\r\nqfw\r\ngxc\r\ntsb\r\np\r\nhzq\r\nbuv\r\nsbu\r\nfwi\r\nkh\r\nmjo\r\nwig\r\nhzq\r\ndmj\r\ntsb\r\ntsb\r\nts\r\nylk\r\nyl\r\ngxc\r\not\r\nots\r\nuvp\r\nay\r\nay\r\nuvp\r\not\r\ny\r\np\r\nm\r\ngx\r\nkhz\r\ngxc\r\nkhz\r\ntsb\r\nrn\r\n", "output": "dmjotsbuvprnaylkhzqfwigxc\r\n"}, {"input": "3\r\nm\r\nu\r\nm\r\n", "output": "mu\r\n"}, {"input": "4\r\np\r\na\r\nz\r\nq\r\n", "output": "pazq\r\n"}, {"input": "5\r\ngtb\r\nnlu\r\nzjp\r\nk\r\nazj\r\n", "output": "azjpgtbnluk\r\n"}, {"input": "70\r\nxv\r\nlu\r\ntb\r\njx\r\nseh\r\nc\r\nm\r\ntbr\r\ntb\r\ndl\r\ne\r\nd\r\nt\r\np\r\nn\r\nse\r\nna\r\neh\r\nw\r\np\r\nzkj\r\nr\r\nk\r\nrw\r\nqf\r\ndl\r\ndl\r\ns\r\nat\r\nkjx\r\na\r\nz\r\nmig\r\nu\r\nse\r\npse\r\nd\r\ng\r\nc\r\nxv\r\nv\r\ngo\r\nps\r\ncd\r\nyqf\r\nyqf\r\nwzk\r\nxv\r\nat\r\nw\r\no\r\nl\r\nxvm\r\nfpse\r\nz\r\nk\r\nna\r\nv\r\nseh\r\nk\r\nl\r\nz\r\nd\r\nz\r\nn\r\nm\r\np\r\ng\r\nse\r\nat\r\n", "output": "cdlunatbrwzkjxvmigoyqfpseh\r\n"}, {"input": "3\r\nbmg\r\nwjah\r\nil\r\n", "output": "bmgilwjah\r\n"}, {"input": "100\r\ne\r\nbr\r\nls\r\nfb\r\nyx\r\nva\r\njm\r\nwn\r\nak\r\nhv\r\noq\r\nyx\r\nl\r\nm\r\nak\r\nce\r\nug\r\nqz\r\nug\r\ndf\r\nty\r\nhv\r\nmo\r\nxp\r\nyx\r\nkt\r\nak\r\nmo\r\niu\r\nxp\r\nce\r\nnd\r\noq\r\nbr\r\nty\r\nva\r\nce\r\nwn\r\nx\r\nsj\r\nel\r\npi\r\noq\r\ndf\r\niu\r\nc\r\nhv\r\npi\r\nsj\r\nhv\r\nmo\r\nbr\r\nxp\r\nce\r\nfb\r\nwn\r\nnd\r\nfb\r\npi\r\noq\r\nhv\r\nty\r\ngw\r\noq\r\nel\r\nw\r\nhv\r\nce\r\noq\r\nsj\r\nsj\r\nl\r\nwn\r\nqz\r\nty\r\nbr\r\nz\r\nel\r\nug\r\nce\r\nnd\r\nj\r\ndf\r\npi\r\niu\r\nnd\r\nls\r\niu\r\nrc\r\nbr\r\nug\r\nrc\r\nnd\r\nak\r\njm\r\njm\r\no\r\nls\r\nq\r\nfb\r\n", "output": "hvaktyxpiugwndfbrcelsjmoqz\r\n"}, {"input": "23\r\nq\r\ni\r\nj\r\nx\r\nz\r\nm\r\nt\r\ns\r\nu\r\ng\r\nc\r\nk\r\nh\r\nb\r\nx\r\nh\r\nt\r\no\r\ny\r\nh\r\nb\r\nn\r\na\r\n", "output": "qijxzmtsugckhboyna\r\n"}, {"input": "12\r\nkx\r\ng\r\nfo\r\nnt\r\nmf\r\nzv\r\nir\r\nds\r\nbz\r\nf\r\nlw\r\nx\r\n", "output": "bzvdsirkxlwmfontg\r\n"}, {"input": "2\r\na\r\nt\r\n", "output": "at\r\n"}, {"input": "1\r\ndm\r\n", "output": "dm\r\n"}, {"input": "100\r\nj\r\numj\r\ninc\r\nu\r\nsd\r\ntin\r\nw\r\nlf\r\nhs\r\nepk\r\nyg\r\nqhs\r\nh\r\nti\r\nf\r\nsd\r\ngepk\r\nu\r\nfw\r\nu\r\nsd\r\nvumj\r\num\r\ndt\r\nb\r\ng\r\nozl\r\nabvu\r\noz\r\nn\r\nw\r\nab\r\nge\r\nqh\r\nfwy\r\nsdti\r\ng\r\nyge\r\nepk\r\nabvu\r\nz\r\nlfw\r\nbv\r\nab\r\nyge\r\nqhs\r\nge\r\nhsdt\r\num\r\nl\r\np\r\na\r\nab\r\nd\r\nfw\r\ngep\r\nfwy\r\nbvu\r\nvumj\r\nzlfw\r\nk\r\nepk\r\ntin\r\npkab\r\nzl\r\nvum\r\nr\r\nf\r\nd\r\nsdt\r\nhs\r\nxoz\r\nlfwy\r\nfw\r\num\r\nep\r\nincx\r\na\r\nt\r\num\r\nh\r\nsdt\r\ngep\r\nlfw\r\nkab\r\ng\r\nmjr\r\nj\r\noz\r\ns\r\nwy\r\nnc\r\nlfw\r\nyg\r\nygep\r\nti\r\nyg\r\npk\r\nkab\r\nwyg\r\n", "output": "qhsdtincxozlfwygepkabvumjr\r\n"}, {"input": "94\r\nkmwbq\r\nmw\r\nwbq\r\ns\r\nlx\r\nf\r\npf\r\nl\r\nkmwb\r\na\r\nfoynt\r\nnt\r\nx\r\npf\r\npf\r\nep\r\nqs\r\nwbqse\r\nrl\r\nfoynt\r\nntzjd\r\nlxc\r\npfoy\r\nlx\r\nr\r\nagikm\r\nr\r\ntzjd\r\nep\r\nyntz\r\nu\r\nmw\r\nyntz\r\nfoynt\r\ntzjd\r\njdrlx\r\nwbqse\r\nr\r\nkmw\r\nwbq\r\nlx\r\nfoyn\r\nkm\r\nsepfo\r\nikmw\r\nf\r\nrlxch\r\nzjdrl\r\nyn\r\nhv\r\nynt\r\nbqs\r\nvu\r\nik\r\nqse\r\nxchvu\r\nmwbqs\r\ny\r\nlx\r\nx\r\nntzjd\r\nbq\r\nxchv\r\nwbqse\r\nkm\r\nse\r\nmwb\r\nxchvu\r\nwbq\r\nc\r\ngikm\r\nbq\r\nwb\r\nmwbq\r\nikmw\r\nag\r\ny\r\nchvu\r\nbqsep\r\nbqs\r\nrlx\r\ntzjd\r\nmwb\r\na\r\ndrlxc\r\ntzjd\r\nt\r\nsepf\r\nwbqse\r\nd\r\nbqs\r\nyn\r\nh\r\nepfo\r\n", "output": "agikmwbqsepfoyntzjdrlxchvu\r\n"}, {"input": "13\r\ndaq\r\nvcnexi\r\nlkp\r\nztvcne\r\naqozt\r\nztvcne\r\nprdaqo\r\ncnex\r\nnexijm\r\nztvcne\r\nfysh\r\nxijmb\r\naq\r\n", "output": "fyshlkprdaqoztvcnexijmb\r\n"}, {"input": "2\r\nnxqdblgac\r\nzpjou\r\n", "output": "nxqdblgaczpjou\r\n"}, {"input": "7\r\nfjr\r\ngk\r\nigkf\r\nret\r\nvx\r\nvxa\r\ncv\r\n", "output": "cvxaigkfjret\r\n"}, {"input": "7\r\nwer\r\nqwe\r\nw\r\nq\r\nert\r\ntyu\r\nrty\r\n", "output": "qwertyu\r\n"}, {"input": "4\r\na\r\nb\r\nab\r\nabc\r\n", "output": "abc\r\n"}, {"input": "4\r\nt\r\nwef\r\nqwe\r\nh\r\n", "output": "qwefth\r\n"}, {"input": "5\r\nabcd\r\nbc\r\ndef\r\nde\r\ncd\r\n", "output": "abcdef\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(input_path) as f:
n = int(f.readline().strip())
fragments = [line.strip() for line in f]
with open(output_path) as f:
correct_output = f.read().strip()
correct_length = len(correct_output)
with open(submission_path) as f:
submission_output = f.read().strip()
# Check length matches correct (minimal)
if len(submission_output) != correct_length:
print(0)
return
# Check all characters are unique
if len(set(submission_output)) != len(submission_output):
print(0)
return
# Check all fragments are present as substrings
sub = submission_output
for frag in fragments:
if frag not in sub:
print(0)
return
# All conditions met
print(1)
if __name__ == "__main__":
main()
| true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,529,600 |
32961828
|
n=int(input())
a=list(map(int,input().split()))
a.sort()
s1,s2=0,0
for x in a[::-1]:
if s1>s2:
s2+=x
else:
s1+=x
print(abs(s1-s2))
| 93 | 62 | 5,632,000 |
32839991
|
n=int(input())
l=[int(x) for x in input().split()]
ans=360
sum=0
j=0
i=0
while(i<n):
sum+=l[i]
while(sum>=180):
ans=min(ans,2*abs(180-sum))
sum-=l[j]
j+=1
ans=min(ans,2*abs(180-sum))
i+=1
print(ans)
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,632,000 |
32712634
|
n=int(input())
a=[int (i) for i in input().split()]
a=sorted(a)
x=0
y=a[-1]
a=a[:-1:]
for i in range(n-1):
if x>=y:
y+=a[-1]
else:
x+=a[-1]
a=a[:-1:]
print(x-y) if x>y else print(y-x)
| 93 | 77 | 0 |
182147142
|
#https://codeforces.com/contest/895/problem/A?f0a28=2
##important observation: continuous sectors , better approach using 2 pointers
from collections import deque
import sys
n=int(input())
A=list(map(int,input().split()))
def angle_diff(x):
return 2*abs(x-180)
mini=360
total=0
l,r=0,0
while r<n:
total+=A[r]
r=r+1
while total>=180:
mini=min(mini,angle_diff(total))
total-=A[l]
l=l+1
mini=min(mini,angle_diff(total))
print(mini)
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,529,600 |
32731313
|
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 27 22:34:44 2017
@author: rohit
"""
n = int(input())
angles = [int(x) for x in input().split()]
angles.sort(reverse=True)
A = 0
B = 0
for e in angles:
if A>B:
B+=e
else:
A+=e
print(abs(A-B))
| 93 | 77 | 0 |
216390389
|
#print('hello')
n = int(input())
lst = input()
array = list(map(int,lst.split()))
sum = 0
trac = []
trac.append(0)
for i in range(0,n):
trac.append(trac[i]+array[i])
res = []
sz = len(trac)
trac.sort()
#print(sz)
#print(trac)
fn = 360
for i in range(0,sz):
for j in range(0,sz):
r1 = trac[j]- trac[i-1]
r2 = 360- r1
r3 = abs(r1-r2)
if(r3<fn):
fn = r3
print(fn)
res.sort()
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 77 | 5,529,600 |
32986165
|
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
k=[]
sum1=a[0]
sum2=0
for i in range(1,n):
if sum1>sum2 :
sum2+=a[i]
elif sum2>sum1 :
sum1+=a[i]
elif sum1==sum2 :
k.append(a[i])
for i in range(len(k)):
if sum1>sum2 :
sum2+=k[i]
else :
sum1+=k[i]
print(abs(sum1-sum2))
| 93 | 77 | 1,740,800 |
161385163
|
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
c = 1e9
x = sum(w)
k = n
while k:
s = 0
for i in w:
s += i
c = min(c, abs(x-2*s))
k -= 1
w = w[1:] + [w[0]]
print(c)
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
895/A
|
895
|
A
|
Python 3
|
TESTS
| 49 | 62 | 5,632,000 |
32700080
|
import math
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
left, right = 0, 0
for i in range(len(a) - 1, -1, -1):
if left <= right:
left += a[i]
else:
right += a[i]
print(abs(left - right))
| 93 | 77 | 2,252,800 |
216134212
|
import sys, math, itertools, functools, collections
input = sys.stdin.readline
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split())
def msi(): return map(str,input().strip().split())
def li(): return list(mi())
def solve():
n = ii()
arr = li()
ans = 360
for i in range(n):
sum = 0
for j in range(i , n):
sum += arr[j]
ans = min(ans , 2 * abs(sum - 180))
print(ans)
for _ in range(1):
solve()
|
Codeforces Round 448 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Pizza Separation
|
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
|
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
|
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
| null |
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
|
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
| 1,200 |
["brute force", "implementation"]
| 93 |
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", "output": "0\r\n"}, {"input": "3\r\n120 120 120\r\n", "output": "120\r\n"}, {"input": "5\r\n110 90 70 50 40\r\n", "output": "40\r\n"}, {"input": "2\r\n170 190\r\n", "output": "20\r\n"}, {"input": "15\r\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\r\n", "output": "10\r\n"}, {"input": "5\r\n30 60 180 60 30\r\n", "output": "0\r\n"}, {"input": "2\r\n359 1\r\n", "output": "358\r\n"}, {"input": "5\r\n100 100 30 100 30\r\n", "output": "40\r\n"}, {"input": "5\r\n36 34 35 11 244\r\n", "output": "128\r\n"}, {"input": "5\r\n96 94 95 71 4\r\n", "output": "18\r\n"}, {"input": "2\r\n85 275\r\n", "output": "190\r\n"}, {"input": "3\r\n281 67 12\r\n", "output": "202\r\n"}, {"input": "5\r\n211 113 25 9 2\r\n", "output": "62\r\n"}, {"input": "13\r\n286 58 6 1 1 1 1 1 1 1 1 1 1\r\n", "output": "212\r\n"}, {"input": "15\r\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "20\r\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "92\r\n"}, {"input": "50\r\n148 53 32 11 4 56 8 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\r\n", "output": "0\r\n"}, {"input": "3\r\n1 1 358\r\n", "output": "356\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\r\n", "output": "322\r\n"}, {"input": "33\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328\r\n", "output": "296\r\n"}, {"input": "70\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291\r\n", "output": "222\r\n"}, {"input": "130\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\r\n", "output": "102\r\n"}, {"input": "200\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 161\r\n", "output": "0\r\n"}, {"input": "222\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 139\r\n", "output": "0\r\n"}, {"input": "10\r\n8 3 11 4 1 10 10 1 8 304\r\n", "output": "248\r\n"}, {"input": "12\r\n8 7 7 3 11 2 10 1 10 8 10 283\r\n", "output": "206\r\n"}, {"input": "13\r\n10 8 9 10 5 9 4 1 10 11 1 7 275\r\n", "output": "190\r\n"}, {"input": "14\r\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\r\n", "output": "200\r\n"}, {"input": "15\r\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\r\n", "output": "190\r\n"}, {"input": "30\r\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\r\n", "output": "18\r\n"}, {"input": "70\r\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "29\r\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\r\n", "output": "18\r\n"}, {"input": "35\r\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\r\n", "output": "0\r\n"}, {"input": "60\r\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\r\n", "output": "0\r\n"}, {"input": "71\r\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "63\r\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "81\r\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "47\r\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\r\n", "output": "0\r\n"}, {"input": "100\r\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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\r\n", "output": "0\r\n"}, {"input": "120\r\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "200\r\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 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 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\r\n", "output": "0\r\n"}, {"input": "220\r\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 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 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 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "6\r\n27 15 28 34 41 215\r\n", "output": "70\r\n"}, {"input": "7\r\n41 38 41 31 22 41 146\r\n", "output": "14\r\n"}, {"input": "8\r\n24 27 34 23 29 23 30 170\r\n", "output": "20\r\n"}, {"input": "9\r\n11 11 20 20 33 32 35 26 172\r\n", "output": "6\r\n"}, {"input": "10\r\n36 13 28 13 33 34 23 25 34 121\r\n", "output": "0\r\n"}, {"input": "11\r\n19 37 13 41 37 15 32 12 19 35 100\r\n", "output": "10\r\n"}, {"input": "12\r\n37 25 34 38 21 24 34 38 11 29 28 41\r\n", "output": "2\r\n"}, {"input": "13\r\n24 40 20 26 25 29 39 29 35 28 19 18 28\r\n", "output": "2\r\n"}, {"input": "14\r\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\r\n", "output": "4\r\n"}, {"input": "3\r\n95 91 174\r\n", "output": "12\r\n"}, {"input": "4\r\n82 75 78 125\r\n", "output": "46\r\n"}, {"input": "6\r\n87 75 88 94 15 1\r\n", "output": "4\r\n"}, {"input": "10\r\n27 52 58 64 45 64 1 19 2 28\r\n", "output": "12\r\n"}, {"input": "50\r\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\r\n", "output": "0\r\n"}, {"input": "100\r\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\r\n", "output": "0\r\n"}, {"input": "150\r\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\r\n", "output": "0\r\n"}, {"input": "200\r\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\r\n", "output": "0\r\n"}, {"input": "5\r\n35 80 45 100 100\r\n", "output": "40\r\n"}, {"input": "4\r\n90 179 90 1\r\n", "output": "2\r\n"}, {"input": "5\r\n50 50 20 160 80\r\n", "output": "0\r\n"}, {"input": "5\r\n30 175 30 5 120\r\n", "output": "10\r\n"}, {"input": "4\r\n170 30 10 150\r\n", "output": "20\r\n"}, {"input": "6\r\n90 30 90 30 90 30\r\n", "output": "60\r\n"}, {"input": "4\r\n70 80 110 100\r\n", "output": "20\r\n"}, {"input": "7\r\n35 45 70 100 10 10 90\r\n", "output": "0\r\n"}, {"input": "6\r\n50 90 10 90 20 100\r\n", "output": "20\r\n"}, {"input": "6\r\n10 155 162 1 26 6\r\n", "output": "18\r\n"}, {"input": "7\r\n80 90 80 45 10 10 45\r\n", "output": "20\r\n"}, {"input": "4\r\n18 36 162 144\r\n", "output": "36\r\n"}, {"input": "5\r\n20 50 50 160 80\r\n", "output": "40\r\n"}, {"input": "5\r\n10 30 140 20 160\r\n", "output": "0\r\n"}, {"input": "6\r\n90 80 60 50 40 40\r\n", "output": "20\r\n"}, {"input": "9\r\n40 20 20 20 20 20 20 40 160\r\n", "output": "40\r\n"}, {"input": "4\r\n90 54 90 126\r\n", "output": "72\r\n"}, {"input": "4\r\n150 170 30 10\r\n", "output": "20\r\n"}, {"input": "8\r\n130 12 13 85 41 67 5 7\r\n", "output": "26\r\n"}, {"input": "7\r\n70 170 20 10 30 30 30\r\n", "output": "20\r\n"}, {"input": "8\r\n100 100 50 50 15 15 15 15\r\n", "output": "40\r\n"}, {"input": "4\r\n100 70 80 110\r\n", "output": "20\r\n"}, {"input": "5\r\n160 130 40 20 10\r\n", "output": "20\r\n"}, {"input": "4\r\n20 149 151 40\r\n", "output": "22\r\n"}, {"input": "4\r\n100 10 100 150\r\n", "output": "60\r\n"}, {"input": "6\r\n19 64 105 168 1 3\r\n", "output": "16\r\n"}, {"input": "8\r\n10 10 70 70 90 90 10 10\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
984/B
|
984
|
B
|
PyPy 3
|
TESTS
| 4 | 140 | 0 |
71548017
|
n, m = list(map(int, input().strip().split()))
nums = []
for i in range(n):
row = input().strip()
nums.append(row)
ok = True
for i in range(n):
for j in range(m):
#
# continue
cur = 0
for x in range(-1, 2):
for y in range(-1, 2):
if x == 0 and y == 0:
continue
new_i, new_j = i + x, j + y
if new_i < 0 or new_i >= n or new_j < 0 or new_j >= m:
continue
if nums[new_i][new_j] == '*':
cur += 1
gt = 0
if nums[i][j] != '*' and nums[i][j] != '.':
gt = int(nums[i][j])
if cur != gt:
ok = False
break
if ok:
print('YES')
else:
print('NO')
| 84 | 93 | 3,584,000 |
147619465
|
r,c=map(int,input().split())
l=[]
for i in range(r):
s=input()
l.append(s)
f=0
for i in range(r):
for j in range(c):
temp=[]
if(l[i][j]!='*'):
if(i!=0):
temp.append(l[i-1][j])
if(i!=0 and j!=0):
temp.append(l[i-1][j-1])
if(i!=0 and j!=c-1):
temp.append(l[i-1][j+1])
if(j!=0):
temp.append(l[i][j-1])
if(j!=c-1):
temp.append(l[i][j+1])
if(i!=r-1 and j!=0):
temp.append(l[i+1][j-1])
if(i<r-1 and j<c-1):
temp.append(l[i+1][j+1])
if(i!=r-1):
temp.append(l[i+1][j])
count = temp.count('*')
if(l[i][j]=='.'):
if(count!=0):
f=1
elif(int(l[i][j])!=count):
f=1
if(f==1):
break
if(f==1):
break
if(f):
print('NO')
else:
print('YES')
|
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
|
CF
| 2,018 | 1 | 256 |
Minesweeper
|
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field.
The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to $$$8$$$, inclusive.
|
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
| null |
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
|
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
| 1,100 |
["implementation"]
| 84 |
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| false |
stdio
| null | true |
793/A
|
793
|
A
|
Python 3
|
TESTS
| 22 | 202 | 9,523,200 |
75937617
|
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 18:26:13 2020
@author: alexi
"""
#https://codeforces.com/problemset/problem/793/A --- Alexis Galvan
def check_disible(divisor, array):
aux = array[0] % divisor
zero = False
if aux == 0:
zero = True
for i in range(len(array)):
if zero:
if array[i] % divisor != 0:
return True
else:
if array[i] % divisor == 0:
return True
return False
def checks():
total = list(map(int, input().split()))
checks = list(map(int, input().split()))
if check_disible(total[1], checks):
return -1
output = 0
minimum = min(checks)
for i in range(len(checks)):
if checks[i] != minimum:
output += int((checks[i] - minimum) / total[1])
return output
A = checks()
print(A)
| 88 | 77 | 13,414,400 |
228827551
|
def main():
n, k = map(int, input().split())
prices = list(map(int, input().split()))
min_price = min(prices)
for price in prices:
diff = price - min_price
if diff % k != 0:
print(-1)
break
else:
print(sum((price - min_price) // k for price in prices))
if __name__ == "__main__":
main()
|
Tinkoff Challenge - Elimination Round
|
CF
| 2,017 | 1 | 256 |
Oleg and shares
|
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
|
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
|
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
| null |
Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
|
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
| 900 |
["implementation", "math"]
| 88 |
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151"}, {"input": "20 5\r\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54\r\n", "output": "-1"}, {"input": "100 10\r\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260\r\n", "output": "2157"}, {"input": "100 18\r\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354\r\n", "output": "-1"}, {"input": "4 2\r\n1 2 3 4\r\n", "output": "-1"}, {"input": "3 4\r\n3 5 5\r\n", "output": "-1"}, {"input": "3 2\r\n88888884 88888886 88888888\r\n", "output": "3"}, {"input": "2 1\r\n1000000000 1000000000\r\n", "output": "0"}, {"input": "4 2\r\n1000000000 100000000 100000000 100000000\r\n", "output": "450000000"}, {"input": "2 2\r\n1000000000 1000000000\r\n", "output": "0"}, {"input": "3 3\r\n3 2 1\r\n", "output": "-1"}, {"input": "3 4\r\n3 5 3\r\n", "output": "-1"}, {"input": "3 2\r\n1 2 2\r\n", "output": "-1"}, {"input": "4 2\r\n2 3 3 2\r\n", "output": "-1"}, {"input": "3 2\r\n1 2 4\r\n", "output": "-1"}, {"input": "3 2\r\n3 4 4\r\n", "output": "-1"}, {"input": "3 3\r\n4 7 10\r\n", "output": "3"}, {"input": "4 3\r\n2 2 5 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 3 5\r\n", "output": "-1"}, {"input": "2 5\r\n5 9\r\n", "output": "-1"}, {"input": "2 3\r\n5 7\r\n", "output": "-1"}, {"input": "3 137\r\n1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "5 1000000000\r\n1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "3 5\r\n1 2 5\r\n", "output": "-1"}, {"input": "3 3\r\n1000000000 1000000000 999999997\r\n", "output": "2"}, {"input": "2 4\r\n5 6\r\n", "output": "-1"}, {"input": "4 1\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "2 3\r\n5 8\r\n", "output": "1"}, {"input": "2 6\r\n8 16\r\n", "output": "-1"}, {"input": "5 3\r\n15 14 9 12 18\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 3\r\n", "output": "-1"}, {"input": "3 3\r\n3 4 5\r\n", "output": "-1"}, {"input": "2 5\r\n8 17\r\n", "output": "-1"}, {"input": "2 1\r\n1 2\r\n", "output": "1"}, {"input": "1 1\r\n1000000000\r\n", "output": "0"}, {"input": "3 3\r\n5 3 4\r\n", "output": "-1"}, {"input": "3 6\r\n10 14 12\r\n", "output": "-1"}, {"input": "2 2\r\n3 5\r\n", "output": "1"}, {"input": "3 5\r\n1 3 4\r\n", "output": "-1"}, {"input": "4 3\r\n1 6 6 6\r\n", "output": "-1"}, {"input": "2 3\r\n1 8\r\n", "output": "-1"}, {"input": "3 5\r\n6 11 17\r\n", "output": "-1"}, {"input": "2 2\r\n1 4\r\n", "output": "-1"}, {"input": "2 4\r\n6 8\r\n", "output": "-1"}, {"input": "2 1\r\n2 3\r\n", "output": "1"}, {"input": "4 4\r\n1 5 8 14\r\n", "output": "-1"}, {"input": "3 3\r\n1 5 3\r\n", "output": "-1"}, {"input": "4 3\r\n1 2 2 5\r\n", "output": "-1"}, {"input": "3 2\r\n1 4 6\r\n", "output": "-1"}, {"input": "2 3\r\n6 9\r\n", "output": "1"}, {"input": "3 3\r\n2 3 4\r\n", "output": "-1"}, {"input": "3 2\r\n9 10 10\r\n", "output": "-1"}, {"input": "2 2\r\n9 12\r\n", "output": "-1"}, {"input": "2 2\r\n100000003 100000005\r\n", "output": "1"}, {"input": "2 3\r\n2 4\r\n", "output": "-1"}, {"input": "3 2\r\n2 3 5\r\n", "output": "-1"}, {"input": "3 3\r\n1 3 4\r\n", "output": "-1"}, {"input": "10 2\r\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "4499999991"}, {"input": "3 5\r\n2 4 5\r\n", "output": "-1"}, {"input": "2 3\r\n7 10\r\n", "output": "1"}, {"input": "3 10\r\n10 13 17\r\n", "output": "-1"}, {"input": "2 3\r\n1 6\r\n", "output": "-1"}, {"input": "1 7\r\n1000000000\r\n", "output": "0"}, {"input": "2 4\r\n3 7\r\n", "output": "1"}, {"input": "2 3\r\n2 5\r\n", "output": "1"}, {"input": "20 1\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "3 3\r\n7 8 8\r\n", "output": "-1"}, {"input": "4 10\r\n1 11 100 11\r\n", "output": "-1"}]
| false |
stdio
| null | true |
847/D
|
847
|
D
|
PyPy 3
|
TESTS
| 5 | 93 | 23,040,000 |
33250428
|
from heapq import heappush, heappop
n, m = [int(i) for i in input().split()]
food = 0
tummy = []
dish = [ -int(i) for i in input().split()]
for i in range(1, min(m, n+1)):
while tummy and -tummy[0] >= m- i:
heappop(tummy)
if max(-dish[i-1], i) < m:
heappush(tummy, -(dish[i-1] - i))
food = max(len(tummy), food)
print(food)
| 151 | 342 | 16,998,400 |
173291126
|
import heapq
n, m = map(int, input().split())
arr, res, ans = [], 0, 0
in_arr = [int(x) for x in input().split()]
for i in range(1, min(m, n + 1)):
if in_arr[i-1] >= m:
continue
while arr and -arr[0] >= m - i:
heapq.heappop(arr)
res -= 1
heapq.heappush(arr, -(in_arr[i-1] - i))
res += 1
ans = max(res, ans)
print(ans)
|
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
|
ICPC
| 2,017 | 2 | 256 |
Dog Show
|
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as possible (bottomless stomach helps here). Dogs compete separately of each other and the rules are as follows:
At the start of the show the dog and the bowls are located on a line. The dog starts at position x = 0 and n bowls are located at positions x = 1, x = 2, ..., x = n. The bowls are numbered from 1 to n from left to right. After the show starts the dog immediately begins to run to the right to the first bowl.
The food inside bowls is not ready for eating at the start because it is too hot (dog's self-preservation instinct prevents eating). More formally, the dog can eat from the i-th bowl after ti seconds from the start of the show or later.
It takes dog 1 second to move from the position x to the position x + 1. The dog is not allowed to move to the left, the dog runs only to the right with the constant speed 1 distance unit per second. When the dog reaches a bowl (say, the bowl i), the following cases are possible:
- the food had cooled down (i.e. it passed at least ti seconds from the show start): the dog immediately eats the food and runs to the right without any stop,
- the food is hot (i.e. it passed less than ti seconds from the show start): the dog has two options: to wait for the i-th bowl, eat the food and continue to run at the moment ti or to skip the i-th bowl and continue to run to the right without any stop.
After T seconds from the start the show ends. If the dog reaches a bowl of food at moment T the dog can not eat it. The show stops before T seconds if the dog had run to the right of the last bowl.
You need to help your dog create a strategy with which the maximum possible number of bowls of food will be eaten in T seconds.
|
Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped.
On the next line numbers t1, t2, ..., tn (1 ≤ ti ≤ 109) are given, where ti is the moment of time when the i-th bowl of food is ready for eating.
|
Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds.
| null |
In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third).
|
[{"input": "3 5\n1 5 3", "output": "2"}, {"input": "1 2\n1", "output": "1"}, {"input": "1 1\n1", "output": "0"}]
| 2,200 |
["constructive algorithms", "data structures", "greedy"]
| 151 |
[{"input": "3 5\r\n1 5 3\r\n", "output": "2\r\n"}, {"input": "1 2\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 3\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 3\r\n2 3 2\r\n", "output": "1\r\n"}, {"input": "3 2\r\n2 3 4\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 1 2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n2 1 2 3\r\n", "output": "2\r\n"}, {"input": "4 3\r\n2 1 2 3\r\n", "output": "1\r\n"}, {"input": "4 6\r\n2 3 4 5\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 1 2 3 4\r\n", "output": "3\r\n"}, {"input": "5 3\r\n2 3 2 1 2\r\n", "output": "1\r\n"}, {"input": "5 7\r\n2 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "6 6\r\n2 3 2 3 4 3\r\n", "output": "4\r\n"}, {"input": "6 4\r\n2 3 2 3 4 3\r\n", "output": "2\r\n"}, {"input": "6 9\r\n2 1 2 1 2 3\r\n", "output": "6\r\n"}, {"input": "7 7\r\n2 3 4 5 6 5 6\r\n", "output": "5\r\n"}, {"input": "7 4\r\n2 1 2 3 2 3 2\r\n", "output": "2\r\n"}, {"input": "7 10\r\n2 3 4 3 2 3 2\r\n", "output": "7\r\n"}, {"input": "8 8\r\n2 3 2 3 4 5 4 5\r\n", "output": "6\r\n"}, {"input": "8 5\r\n2 3 2 3 4 3 4 3\r\n", "output": "3\r\n"}, {"input": "8 12\r\n2 3 2 3 4 3 4 3\r\n", "output": "8\r\n"}, {"input": "9 9\r\n2 3 4 5 4 5 6 7 6\r\n", "output": "7\r\n"}, {"input": "9 5\r\n2 3 4 3 2 3 4 5 6\r\n", "output": "3\r\n"}, {"input": "9 13\r\n2 1 2 3 4 5 4 5 6\r\n", "output": "9\r\n"}, {"input": "10 10\r\n2 1 2 3 4 3 4 3 4 3\r\n", "output": "8\r\n"}, {"input": "10 6\r\n2 3 4 3 4 5 6 7 6 7\r\n", "output": "4\r\n"}, {"input": "10 15\r\n2 1 2 1 2 3 4 5 6 7\r\n", "output": "10\r\n"}, {"input": "11 11\r\n2 3 4 5 6 5 4 5 4 3 4\r\n", "output": "9\r\n"}, {"input": "11 6\r\n2 3 4 3 4 3 4 5 4 3 2\r\n", "output": "4\r\n"}, {"input": "11 16\r\n2 3 2 1 2 3 4 5 4 3 4\r\n", "output": "11\r\n"}, {"input": "12 12\r\n2 3 4 5 6 7 6 7 8 9 10 11\r\n", "output": "10\r\n"}, {"input": "12 7\r\n2 3 4 3 4 3 2 3 4 3 4 5\r\n", "output": "5\r\n"}, {"input": "12 18\r\n2 1 2 3 4 5 6 5 6 5 6 5\r\n", "output": "12\r\n"}, {"input": "13 13\r\n2 1 2 3 4 3 2 3 4 5 6 5 4\r\n", "output": "11\r\n"}, {"input": "13 7\r\n2 1 2 3 2 3 2 3 4 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "13 19\r\n2 3 4 5 6 5 4 5 6 7 8 9 8\r\n", "output": "13\r\n"}, {"input": "14 14\r\n2 3 4 5 6 7 8 9 10 11 12 13 14 15\r\n", "output": "12\r\n"}, {"input": "14 8\r\n2 3 4 5 6 7 8 7 6 7 8 9 10 9\r\n", "output": "6\r\n"}, {"input": "14 21\r\n2 1 2 3 4 5 6 5 6 7 8 9 8 9\r\n", "output": "14\r\n"}, {"input": "15 15\r\n2 3 4 3 2 3 4 3 4 3 4 5 6 5 6\r\n", "output": "13\r\n"}, {"input": "15 8\r\n2 3 2 1 2 1 2 3 2 3 4 3 4 5 4\r\n", "output": "6\r\n"}, {"input": "15 22\r\n2 3 2 3 2 3 4 5 6 7 6 7 8 9 10\r\n", "output": "15\r\n"}, {"input": "16 16\r\n2 1 2 3 2 3 4 5 6 5 4 5 6 5 6 7\r\n", "output": "14\r\n"}, {"input": "16 9\r\n2 3 4 5 4 3 4 5 6 7 8 7 8 9 10 11\r\n", "output": "7\r\n"}, {"input": "16 24\r\n2 3 4 5 6 5 6 7 6 7 8 9 10 11 12 13\r\n", "output": "16\r\n"}, {"input": "17 17\r\n2 3 2 1 2 3 4 5 6 7 8 9 10 11 12 11 12\r\n", "output": "15\r\n"}, {"input": "17 9\r\n2 3 4 5 6 7 8 9 10 11 10 11 10 11 12 13 12\r\n", "output": "7\r\n"}, {"input": "17 25\r\n2 1 2 1 2 3 2 3 2 1 2 1 2 1 2 1 2\r\n", "output": "17\r\n"}, {"input": "18 18\r\n2 3 4 5 4 5 6 5 6 7 6 7 6 5 6 7 8 7\r\n", "output": "16\r\n"}, {"input": "18 10\r\n2 3 4 3 4 3 4 5 6 5 6 7 8 9 10 9 8 9\r\n", "output": "8\r\n"}, {"input": "18 27\r\n2 3 4 3 4 5 6 7 8 9 10 9 8 9 8 9 10 9\r\n", "output": "18\r\n"}, {"input": "19 19\r\n2 1 2 3 4 5 4 5 6 7 6 7 8 9 10 11 12 11 12\r\n", "output": "17\r\n"}, {"input": "19 10\r\n2 1 2 3 4 3 4 3 2 3 4 3 4 3 4 5 6 5 4\r\n", "output": "8\r\n"}, {"input": "19 28\r\n2 3 4 3 4 5 6 5 6 5 6 7 8 7 8 9 10 11 12\r\n", "output": "19\r\n"}, {"input": "20 20\r\n2 1 2 3 2 1 2 3 4 3 2 3 4 5 6 7 8 9 8 9\r\n", "output": "18\r\n"}, {"input": "20 11\r\n2 3 4 5 6 7 6 5 6 7 8 9 10 11 12 11 12 13 12 11\r\n", "output": "9\r\n"}, {"input": "20 30\r\n2 3 2 3 4 5 6 5 6 7 6 7 8 9 8 7 8 9 10 11\r\n", "output": "20\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 3\r\n2 3\r\n", "output": "1\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3 2\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 1 2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n2 3 2 3\r\n", "output": "2\r\n"}, {"input": "4 3\r\n2 1 2 3\r\n", "output": "1\r\n"}, {"input": "4 6\r\n2 3 4 5\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 1 2 3 4\r\n", "output": "3\r\n"}, {"input": "5 3\r\n2 3 4 5 6\r\n", "output": "1\r\n"}, {"input": "5 7\r\n2 3 4 5 6\r\n", "output": "5\r\n"}, {"input": "6 6\r\n2 1 2 3 4 5\r\n", "output": "4\r\n"}, {"input": "6 4\r\n2 3 4 5 6 7\r\n", "output": "2\r\n"}, {"input": "6 9\r\n2 3 4 5 6 7\r\n", "output": "6\r\n"}, {"input": "7 7\r\n2 1 2 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "7 4\r\n2 3 4 5 4 5 6\r\n", "output": "2\r\n"}, {"input": "7 10\r\n2 1 2 3 2 3 4\r\n", "output": "7\r\n"}, {"input": "8 8\r\n2 3 2 3 2 3 4 5\r\n", "output": "6\r\n"}, {"input": "8 5\r\n2 3 4 3 2 3 4 3\r\n", "output": "3\r\n"}, {"input": "8 12\r\n2 3 4 3 2 3 4 3\r\n", "output": "8\r\n"}, {"input": "9 9\r\n2 1 2 3 4 5 6 5 6\r\n", "output": "7\r\n"}, {"input": "9 5\r\n2 1 2 3 4 3 2 3 4\r\n", "output": "3\r\n"}, {"input": "9 13\r\n2 3 4 5 6 5 6 7 8\r\n", "output": "9\r\n"}, {"input": "10 10\r\n2 3 4 3 4 5 6 7 6 7\r\n", "output": "8\r\n"}, {"input": "10 6\r\n2 3 4 5 6 7 8 9 10 11\r\n", "output": "4\r\n"}, {"input": "10 15\r\n2 3 4 5 6 7 8 9 10 11\r\n", "output": "10\r\n"}, {"input": "11 11\r\n2 3 4 5 6 7 8 9 10 11 12\r\n", "output": "9\r\n"}, {"input": "11 6\r\n2 3 4 5 6 7 8 7 8 9 8\r\n", "output": "4\r\n"}, {"input": "11 16\r\n2 3 4 5 6 5 6 5 6 5 6\r\n", "output": "11\r\n"}, {"input": "12 12\r\n2 1 2 3 4 5 6 7 8 7 6 5\r\n", "output": "10\r\n"}, {"input": "12 7\r\n2 3 4 5 6 7 8 9 10 11 10 11\r\n", "output": "5\r\n"}, {"input": "12 18\r\n2 1 2 3 2 3 2 1 2 3 2 3\r\n", "output": "12\r\n"}, {"input": "13 13\r\n2 3 4 5 6 7 8 7 6 7 8 9 10\r\n", "output": "11\r\n"}, {"input": "13 7\r\n2 3 4 5 6 7 8 9 10 11 12 13 14\r\n", "output": "5\r\n"}, {"input": "13 19\r\n2 3 4 5 6 5 6 7 6 7 8 9 8\r\n", "output": "13\r\n"}, {"input": "14 14\r\n2 3 4 5 6 5 4 5 6 7 8 7 8 9\r\n", "output": "12\r\n"}, {"input": "14 8\r\n2 3 4 5 6 7 6 7 8 7 8 9 10 11\r\n", "output": "6\r\n"}, {"input": "14 21\r\n2 1 2 3 4 5 4 5 4 5 4 3 4 5\r\n", "output": "14\r\n"}, {"input": "15 15\r\n2 1 2 3 2 3 4 5 6 5 6 5 6 5 6\r\n", "output": "13\r\n"}, {"input": "15 8\r\n2 3 4 3 4 5 6 7 8 7 6 5 6 7 8\r\n", "output": "6\r\n"}, {"input": "15 22\r\n2 3 2 1 2 3 4 5 6 7 8 9 10 9 10\r\n", "output": "15\r\n"}, {"input": "16 16\r\n2 3 4 5 6 5 6 7 8 7 6 7 8 9 10 11\r\n", "output": "14\r\n"}, {"input": "16 9\r\n2 1 2 3 4 5 6 5 4 5 6 7 8 9 10 11\r\n", "output": "7\r\n"}, {"input": "16 24\r\n2 3 4 5 6 7 8 9 10 9 10 9 10 11 12 13\r\n", "output": "16\r\n"}, {"input": "17 17\r\n2 3 2 3 4 3 4 5 6 7 8 9 8 7 6 7 8\r\n", "output": "15\r\n"}, {"input": "17 9\r\n2 1 2 3 4 3 4 5 6 7 8 9 10 11 10 11 12\r\n", "output": "7\r\n"}, {"input": "17 25\r\n2 3 4 3 2 3 2 1 2 3 4 5 4 5 4 5 6\r\n", "output": "17\r\n"}, {"input": "18 18\r\n2 3 2 3 4 5 6 5 6 7 8 9 10 11 12 13 14 15\r\n", "output": "16\r\n"}, {"input": "18 10\r\n2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 10 11\r\n", "output": "8\r\n"}, {"input": "18 27\r\n2 3 4 5 6 7 8 9 10 9 10 9 10 11 10 9 10 11\r\n", "output": "18\r\n"}, {"input": "19 19\r\n2 3 4 5 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16\r\n", "output": "17\r\n"}, {"input": "19 10\r\n2 1 2 3 4 3 4 5 4 5 6 7 8 9 10 11 12 13 14\r\n", "output": "8\r\n"}, {"input": "19 28\r\n2 1 2 3 4 5 4 5 6 7 8 9 8 9 10 9 8 9 8\r\n", "output": "19\r\n"}, {"input": "20 20\r\n2 3 4 5 6 7 8 9 10 11 12 11 12 13 14 15 16 17 18 19\r\n", "output": "18\r\n"}, {"input": "20 11\r\n2 3 2 3 4 5 6 5 6 7 8 7 6 7 8 7 8 9 8 9\r\n", "output": "9\r\n"}, {"input": "20 30\r\n2 3 4 5 4 5 4 5 6 7 8 9 10 11 12 13 14 15 16 17\r\n", "output": "20\r\n"}, {"input": "100 180\r\n150 52 127 175 146 138 25 71 192 108 142 79 196 129 23 44 92 11 63 198 197 65 47 144 141 158 142 41 1 102 113 50 171 97 75 31 199 24 17 59 138 53 37 123 64 103 156 141 33 186 150 10 103 29 2 182 38 85 155 73 136 175 83 93 20 59 11 87 178 92 132 11 6 99 109 193 135 132 57 36 123 152 36 80 9 137 122 131 122 108 44 84 180 65 192 192 29 150 147 20\r\n", "output": "68\r\n"}, {"input": "100 154\r\n132 88 72 98 184 47 176 56 68 168 137 88 188 140 198 18 162 139 94 133 90 91 37 156 196 28 186 1 51 47 4 92 18 51 37 121 86 195 153 195 183 191 15 24 104 174 94 83 102 61 131 40 149 46 22 112 13 136 133 177 3 175 160 152 172 48 44 174 77 100 155 157 167 174 64 109 118 194 120 7 8 179 36 149 58 145 163 163 45 14 164 111 176 196 42 161 71 148 192 38\r\n", "output": "44\r\n"}, {"input": "7 11\r\n3 7 10 13 9 12 4\r\n", "output": "3\r\n"}, {"input": "10 20\r\n5 12 21 14 23 17 24 11 25 22\r\n", "output": "5\r\n"}]
| false |
stdio
| null | true |
762/C
|
762
|
C
|
PyPy 3
|
TESTS
| 3 | 92 | 0 |
103983470
|
class word:
def __init__(self,strin):
self.palabra=strin
def countLetter(self,letter):
return self.palabra.count(letter)
def letterBelongTo(self,letter):
return letter in self.palabra
stringa=input()
stringb=input()
word1=word(stringa)
word2=word(stringb)
staticword=word2.palabra
count=0
j=0
while count!=len(staticword):
i=staticword[count]
if word1.letterBelongTo(i)==False or word2.countLetter(i)>word1.countLetter(i):
word2.palabra=word2.palabra[:count-j]+word2.palabra[count-j+1:]
j+=1
count+=1
if len(word2.palabra)==0: word2.palabra="-"
print(word2.palabra)
| 99 | 342 | 5,939,200 |
55412519
|
a = list(input())
b = list(input())
s = [-1]
i = 0
j = 0
while i < len(a) and j < len(b):
if a[i] == b[j]:
s.append(i)
j += 1
i += 1
e = [10**6]
i = len(a) - 1
j = len(b) - 1
while i >= 0 and j >= 0:
if a[i] == b[j]:
e.append(i)
j -= 1
i -= 1
ans_len = 0
ans = ['-']
i = len(s) - 1
j = 0
while i >= 0 and j < len(e):
if s[i] < e[j] and i + j - 1< len(b):
new_len = j + i
if new_len > ans_len:
ans_len = new_len
if j > 0:
ans = b[:i] + b[-j:]
else:
ans = b[:i]
j += 1
else:
i -= 1
print(''.join(ans))
|
Educational Codeforces Round 17
|
ICPC
| 2,017 | 2 | 256 |
Two strings
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
|
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
| null |
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
|
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
| 2,100 |
["binary search", "hashing", "strings", "two pointers"]
| 99 |
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| false |
stdio
| null | true |
416/A
|
416
|
A
|
Python 3
|
TESTS
| 62 | 186 | 1,024,000 |
73505774
|
from enum import Enum
from collections import namedtuple
class Operator(Enum):
LT = "<"
LTE = "<="
GT = ">"
GTE = ">="
def inverse(self):
inverses = {
self.LT: self.GTE,
self.LTE: self.GT,
self.GT: self.LTE,
self.GTE: self.LT
}
return inverses[self]
Range = namedtuple('Range', ['op', 'number'])
def order_strictness_le_or_leq(a: Range):
return (a.number, a.op == Operator.LT and 0 or 1)
def order_strictness_ge_or_geq(a: Range):
return (a.number, a.op == Operator.GT and 1 or 0)
queries = int(input())
ranges_le_leq = [Range(op=Operator.LTE, number=2*(10**9))]
ranges_gt_gte = [Range(op=Operator.GTE, number=-2*(10**9))]
for i in range(queries):
operator, number, answer = input().split()
operator = Operator(operator)
number = int(number)
if answer == "N":
operator = operator.inverse()
r = Range(op=operator, number=number)
if operator in [Operator.LT, Operator.LTE]:
ranges_le_leq.append(r)
else:
ranges_gt_gte.append(r)
most_strict_lt = min(ranges_le_leq, key=order_strictness_le_or_leq)
most_strict_gt = max(ranges_gt_gte, key=order_strictness_ge_or_geq)
gt_number = most_strict_gt.number
if most_strict_gt.op == Operator.GT:
gt_number += 1
lt_number = most_strict_lt.number
if most_strict_lt.op == Operator.LT:
lt_number -= 1
if gt_number > lt_number:
print("Impossible")
else:
print(gt_number)
| 66 | 46 | 0 |
156241499
|
t = int(input())
lower_bound = -2*10**9
upper_bound = 2*10**9
for iq in range(t):
X = input().split()
if X[2] == 'Y':
if X[0] == '>=':
lower_bound = max(int(X[1]), lower_bound)
# print('lower bound:', lower_bound)
elif X[0] == '<=':
upper_bound = min(int(X[1]), upper_bound)
elif X[0] == '>':
lower_bound = max(int(X[1])+1, lower_bound)
elif X[0] == '<':
upper_bound = min(int(X[1])-1, upper_bound)
else:
if X[0] == '>=':
upper_bound = min(int(X[1])-1, upper_bound)
elif X[0] == '<=':
lower_bound = max(int(X[1])+1, lower_bound)
elif X[0] == '>':
upper_bound = min(int(X[1]), upper_bound)
elif X[0] == '<':
lower_bound = max(int(X[1]), lower_bound)
if lower_bound > upper_bound:
print("Impossible")
else:
print(lower_bound)
|
Codeforces Round 241 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Guess a number!
|
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictly larger than number x?
- Is it true that y is strictly smaller than number x?
- Is it true that y is larger than or equal to number x?
- Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
|
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries),
- ">=" (for the third type queries),
- "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
|
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
| null | null |
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
| 1,400 |
["greedy", "implementation", "two pointers"]
| 66 |
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 10 Y\r\n> -6 Y\r\n< 10 Y\r\n< -10 N\r\n", "output": "-5\r\n"}, {"input": "1\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1 Y\r\n", "output": "1361956\r\n"}, {"input": "4\r\n< 1 N\r\n< 1 N\r\n< 1 N\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 1 N\r\n>= 1 Y\r\n< 1 N\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "4\r\n> 1 N\r\n<= 1 Y\r\n<= 1 Y\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n>= 1 Y\r\n> 1 N\r\n>= 1 Y\r\n>= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 9 Y\r\n< 3 Y\r\n< 2 Y\r\n< 2 Y\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n< 0 N\r\n< -7 N\r\n>= 8 N\r\n>= -5 Y\r\n", "output": "3\r\n"}, {"input": "4\r\n<= -6 N\r\n<= -8 N\r\n<= 3 Y\r\n<= 7 Y\r\n", "output": "-2\r\n"}, {"input": "4\r\n>= 7 N\r\n<= -1 N\r\n>= 5 N\r\n<= -10 N\r\n", "output": "0\r\n"}, {"input": "4\r\n> 5 N\r\n>= -5 Y\r\n> -9 Y\r\n> -9 Y\r\n", "output": "-4\r\n"}, {"input": "10\r\n<= -60 N\r\n>= -59 Y\r\n> 22 Y\r\n> 95 N\r\n<= 91 Y\r\n> 77 Y\r\n>= -59 Y\r\n> -25 Y\r\n> -22 Y\r\n>= 52 Y\r\n", "output": "85\r\n"}, {"input": "10\r\n>= -18 Y\r\n>= -35 Y\r\n> -94 Y\r\n< -23 N\r\n< -69 N\r\n< -68 N\r\n< 82 Y\r\n> 92 N\r\n< 29 Y\r\n>= -25 Y\r\n", "output": "18\r\n"}, {"input": "10\r\n>= 18 Y\r\n<= -32 N\r\n>= 85 N\r\n<= 98 Y\r\n<= -43 N\r\n<= -79 N\r\n>= 97 N\r\n< -38 N\r\n< -55 N\r\n<= -93 N\r\n", "output": "64\r\n"}, {"input": "10\r\n<= 2 Y\r\n< -33 Y\r\n> 6 N\r\n> -6 N\r\n< -28 Y\r\n> -62 Y\r\n< 57 Y\r\n<= 24 Y\r\n> 23 N\r\n> -25 N\r\n", "output": "-54\r\n"}, {"input": "10\r\n<= -31 N\r\n>= 66 N\r\n<= 0 Y\r\n> -95 Y\r\n< 27 Y\r\n< -42 N\r\n> 3 N\r\n< 6 Y\r\n>= -42 Y\r\n> -70 Y\r\n", "output": "-29\r\n"}, {"input": "10\r\n>= 54 N\r\n<= -52 N\r\n>= 64 N\r\n> 65 N\r\n< 37 Y\r\n> -84 Y\r\n>= -94 Y\r\n>= -95 Y\r\n> -72 Y\r\n<= 18 N\r\n", "output": "22\r\n"}, {"input": "10\r\n> -24 N\r\n<= -5 Y\r\n<= -33 Y\r\n> 45 N\r\n> -59 Y\r\n> -21 N\r\n<= -48 N\r\n> 40 N\r\n< 12 Y\r\n>= 14 N\r\n", "output": "-47\r\n"}, {"input": "10\r\n>= 91 Y\r\n>= -68 Y\r\n< 92 N\r\n>= -15 Y\r\n> 51 Y\r\n<= 14 N\r\n> 17 Y\r\n< 94 Y\r\n>= 49 Y\r\n> -36 Y\r\n", "output": "93\r\n"}, {"input": "1\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= -999999999 Y\r\n", "output": "-998638044\r\n"}, {"input": "1\r\n> 100000 Y\r\n", "output": "1461956\r\n"}, {"input": "1\r\n<= 999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 N\r\n", "output": "1001361956\r\n"}, {"input": "4\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1000000000 Y\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 999999999 N\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1000000000 Y\r\n", "output": "1001361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 100 Y\r\n", "output": "1362056\r\n"}, {"input": "2\r\n< -1000000000 Y\r\n< 3 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "8\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 15 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 10000000 Y\r\n", "output": "11361956\r\n"}, {"input": "1\r\n< 0 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 5 Y\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n> 5 Y\r\n> 0 Y\r\n< 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n>= -1000000000 N\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n>= 1 Y\r\n<= 1 Y\r\n> 10 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n> 1 Y\r\n< 2 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 5 Y\r\n<= 5 Y\r\n< 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 5 N\r\n> 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 4 Y\r\n> 4 Y\r\n<= 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 4 Y\r\n> 4 Y\r\n", "output": "1361960\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = int(x_str)
if sign == '>':
if ans == 'Y':
new_low = x + 1
low = max(low, new_low)
else:
new_high = x
high = min(high, new_high)
elif sign == '<':
if ans == 'Y':
new_high = x - 1
high = min(high, new_high)
else:
new_low = x
low = max(low, new_low)
elif sign == '>=':
if ans == 'Y':
new_low = x
low = max(low, new_low)
else:
new_high = x - 1
high = min(high, new_high)
elif sign == '<=':
if ans == 'Y':
new_high = x
high = min(high, new_high)
else:
new_low = x + 1
low = max(low, new_low)
if low > high:
break
with open(submission_path) as f:
submission_lines = [line.strip() for line in f]
submission = submission_lines[0] if submission_lines else ''
if submission == "Impossible":
print(1 if low > high else 0)
else:
try:
y = int(submission)
if -2 * 10**9 <= y <= 2 * 10**9 and low <= y <= high:
print(1)
else:
print(0)
except:
print(0)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
main(input_path, output_path, submission_path)
| true |
711/B
|
711
|
B
|
Python 3
|
TESTS
| 92 | 358 | 12,800,000 |
86637839
|
n = int(input())
mat = []
for i in range(n):
tmp = list(map(int, input().split()))
mat.append(tmp)
sums = []
p_dia = 0
s_dia = 0
col_sum = 0
row_sum = 0
done = False
if n == 1:
print(1)
done = True
for i in range(n):
row_sum = 0
col_sum = 0
p_dia += mat[i][i]
s_dia += mat[i][n-1-i]
for j in range(n):
row_sum += mat[i][j]
col_sum += mat[j][i]
if row_sum not in sums:
sums.append(row_sum)
if col_sum not in sums:
sums.append(col_sum)
if p_dia not in sums: sums.append(p_dia)
if s_dia not in sums: sums.append(s_dia)
if len(sums) != 2 and not done:
print(-1)
elif not done:
print(abs(sums[0] - sums[1]))
| 147 | 218 | 6,041,600 |
109377968
|
def sum_row(arr):
ans = sum(arr[0])
for i in range(1,len(arr)):
if sum(arr[i])!=ans:
return [False]
return [True,ans]
def sum_col(arr):
ans = None
for i in range(len(arr)):
temp = 0
for j in range(len(arr[0])):
temp+=arr[j][i]
if ans==None:
ans = temp
else:
if temp!=ans:
return [False]
return [True,ans]
def sum_diagonal(arr):
ans = 0
ans1 = 0
for i in range(len(arr)):
ans+=arr[i][i]
ans1+=arr[i][len(arr)-i-1]
return [True,ans] if ans==ans1 else [False]
def calculate_value(arr,row):
return sum(arr[row])
n = int(input())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
if n==1:
print(1)
exit()
flag = False
for i in range(n):
for j in range(n):
if a[i][j]==0:
if i!=0:
want = calculate_value(a,i-1)-sum(a[i])
else:
want = calculate_value(a,i+1)-sum(a[i])
a[i][j] = want
flag = True
break
if flag:
break
row = sum_row(a)
col = sum_col(a)
dia = sum_diagonal(a)
if row[0] and col[0] and dia[0]:
if want<=0:
print(-1)
elif row[1]==col[1]==dia[1]:
print(want)
else:
print(-1)
else:
print(-1)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
PyPy 3
|
TESTS
| 92 | 358 | 29,900,800 |
128397629
|
n = int(input())
mat=[]
a=-1
b=-1
for i in range(n):
l = list(map(int,input().split()))
mat.append(l)
s =set()
for i in range(n):
sum=0
for j in range(n):
sum+=mat[i][j]
s.add(sum)
for i in range(n):
sum=0
for j in range(n):
sum+=mat[j][i]
s.add(sum)
sum=0
for i in range(n):
sum+=mat[i][i]
s.add(sum)
sum=0
for i in range(n):
sum+=mat[i][n-i-1]
s.add(sum)
if n==1:
print(1)
elif(len(s)==2):
print(max(s)-min(s))
else:
print(-1)
# print(s)
| 147 | 218 | 6,144,000 |
20744630
|
from sys import exit
def check_all(l, exclude):
result = 0
x, y = exclude
for i in range(n):
if i == x:
continue
s = sum(l[i])
if not result:
result = s
elif s != result:
return False, 0
for j in range(n):
if j == y:
continue
s = sum(row[j] for row in l)
if s != result:
return False, 0
if x != y:
s = sum(l[i][i] for i in range(n))
if s != result:
return False, 0
if y != n - x - 1:
s = sum(l[i][n - i - 1] for i in range(n))
if s != result:
return False, 0
return True, result
n = int(input())
sq = []
zero_position = None
for i in range(n):
row = list(map(int, input().split()))
if not zero_position:
if 0 in row:
zero_position = (i, row.index(0))
sq.append(row)
possible, s = check_all(sq, zero_position)
if not possible:
print(-1)
else:
x, y = zero_position
result = s - sum(sq[x])
number = s - sum(row[y] for row in sq)
if number != result:
print(-1)
exit(0)
if x == y:
number = s - sum(sq[i][i] for i in range(n))
if number != result:
print(-1)
exit(0)
if y == n - x - 1:
number = s - sum(sq[i][n-i-1] for i in range(n))
if number != result:
print(-1)
exit(0)
if n == 1:
print(1)
elif result <= 0:
print(-1)
else:
print(result)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
757/A
|
757
|
A
|
Python 3
|
TESTS
| 28 | 46 | 0 |
156771823
|
a = "Bulsar"#au
A = input()
D = {"B":0,"u":0,"l":0,"s":0,"a":0,"r":0}
for k in A:
if k in a:
D[k]+=1
D["a"]//=2
D["u"]//=2
print(min(D.values()))
| 107 | 46 | 0 |
165632834
|
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
w = input()
c = [w.count(l) for l in "Bulbasr"]
c[1] //= 2
c[4] //= 2
print(min(c))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
793/C
|
793
|
C
|
Python 3
|
TESTS
| 6 | 93 | 6,246,400 |
26625883
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
# Guide:
# 1. construct complex data types while reading (e.g. graph adj list)
# 2. avoid any non-necessary time/memory usage
# 3. avoid templates and write more from scratch
# 4. switch to "flat" implementations
def VI(): return list(map(int,input().split()))
def I(): return int(input())
def LIST(n,m=None): return [0]*n if m is None else [[0]*m for i in range(n)]
def ELIST(n): return [[] for i in range(n)]
def MI(n=None,m=None): # input matrix of integers
if n is None: n,m = VI()
arr = LIST(n)
for i in range(n): arr[i] = VI()
return arr
def MS(n=None,m=None): # input matrix of strings
if n is None: n,m = VI()
arr = LIST(n)
for i in range(n): arr[i] = input()
return arr
def MIT(n=None,m=None): # input transposed matrix/array of integers
if n is None: n,m = VI()
a = MI(n,m)
arr = LIST(m,n)
for i,l in enumerate(a):
for j,x in enumerate(l):
arr[j][i] = x
return arr
def main(info=0):
n = I()
x0, y0, x1, y1 = VI() # x0, y0, x1, y1
def inrange(x, x0, x1, inclusive=True):
if inclusive:
return x >= x0 and x <= x1
else:
return x > x0 and x < x1
def times(x, y, vx, vy):
ab = set([])
if (vx==0 and vy==0):
if x> x0 and x < x1 and y>y0 and y<y1:
return 0.0, float("inf")
elif vx==0:
if x> x0 and x < x1:
ab = (y0-y)/vy, (y1-y)/vy
elif vy==0:
if y>y0 and y<y1:
ab = (x0-x)/vx, (x1-x)/vx
else:
tx0 = (x0-x)/vx; tx0y = y+tx0*vy
tx1 = (x1-x)/vx; tx1y = y+tx1*vy
ty0 = (y0-y)/vy; ty0x = x+ty0*vx
ty1 = (y1-y)/vy; ty1x = x+ty1*vx
if inrange(tx0y, y0, y1): ab.add(tx0)
if inrange(tx1y, y0, y1): ab.add(tx1)
if inrange(ty0x, x0, x1): ab.add(ty0)
if inrange(ty1x, x0, x1): ab.add(ty1)
# if inrange(tx0y, y0, y1, True) and inrange(tx1y, y0, y1, True):
# ab.append(tx0)
# ab.append(tx1)
# print(x, y, vx, vy, tx0, tx1, ty0, ty1, ab)
if len(ab) == 1:
ab = []
return (None, None) if len(ab) ==0 else (min(ab), max(ab))
tmn, tmx = 0, float("inf")
for i in range(n):
m = VI()
t0, t1 = times(*m)
# print(t0, t1, tmn, tmx)
if t0 == None:
tmx = -1
else:
tmn = max(t0, tmn)
tmx = min(t1, tmx)
if tmn > tmx:
print("-1")
return
print(tmn)
if __name__ == "__main__":
main()
| 80 | 607 | 15,360,000 |
26702595
|
# In the name of Allah
def main() :
n = int(input())
x1, y1, x2, y2 = map(int, input().split())
st = [0]
ed = [1e11]
if x1 == x2 or y1 == y2 :
print(-1)
exit()
for i in range(n) :
a, b, c, d = map(int, input().split())
for x, v, s, e in ((a, c, x1, x2), (b, d, y1, y2)) :
if v == 0 :
if not(s < x < e) :
print(-1)
exit()
else :
t1 = (s - x) / v;
t2 = (e - x) / v;
st += [min(t1, t2)]
ed += [max(t1, t2)]
if max(st) < min(ed) and min(ed) > 0 :
print(max(max(st), 0))
else :
print(-1)
return 0
main()
|
Tinkoff Challenge - Elimination Round
|
CF
| 2,017 | 2 | 256 |
Mice problem
|
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.
The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2).
Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap.
Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once.
|
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk.
The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap.
The next n lines contain the information about mice.
The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≤ rix, riy ≤ 100 000, - 100 000 ≤ vix, viy ≤ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed.
|
In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1.
Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
| null |
Here is a picture of the first sample
Points A, B, C, D - start mice positions, segments are their paths.
Then, at first time when all mice will be in rectangle it will be looks like this:
Here is a picture of the second sample
Points A, D, B will never enter rectangle.
|
[{"input": "4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "output": "0.57142857142857139685"}, {"input": "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "output": "-1"}]
| 2,300 |
["geometry", "implementation", "math", "sortings"]
| 80 |
[{"input": "4\r\n7 7 9 8\r\n3 5 7 5\r\n7 5 2 4\r\n3 3 7 8\r\n6 6 3 2\r\n", "output": "0.57142857142857139685\r\n"}, {"input": "4\r\n7 7 9 8\r\n0 3 -5 4\r\n5 0 5 4\r\n9 9 -1 -6\r\n10 5 -7 -10\r\n", "output": "-1\r\n"}, {"input": "4\r\n8 42 60 54\r\n9 54 -58 -62\r\n46 47 52 -76\r\n15 50 -37 -40\r\n54 51 78 64\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "4\r\n17501 63318 51967 74514\r\n1305 84026 79493 -78504\r\n41159 81000 -44104 -42722\r\n31063 65435 25578 33487\r\n18330 79949 83467 -74531\r\n", "output": "0.20374120991785441004\r\n"}, {"input": "7\r\n24 38 44 47\r\n44 45 -50 -36\r\n33 48 -11 -39\r\n43 44 13 15\r\n42 47 24 -21\r\n40 41 19 7\r\n26 41 -20 -15\r\n42 40 43 19\r\n", "output": "0.02564102564102564014\r\n"}, {"input": "1\r\n0 0 100000 100000\r\n0 0 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 100000 100000\r\n0 0 0 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 100000 100000\r\n0 0 -1 -1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 100000 100000\r\n1 1 1 1\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "1\r\n0 0 10000 10000\r\n20000 2 -1 0\r\n", "output": "10000.00000000000000000000\r\n"}, {"input": "1\r\n0 0 10000 10000\r\n20000 2 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 10000 10000\r\n10001 10001 -1 -1\r\n", "output": "1.00000000000000000000\r\n"}, {"input": "1\r\n0 0 10000 10000\r\n10001 9999 -1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 10 10\r\n5 5 0 0\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "1\r\n0 0 10 10\r\n5 5 5 5\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "1\r\n0 1 2 1\r\n0 0 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 5 5\r\n1 0 0 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 2 2\r\n1 1 1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n2 2 5 5\r\n3 3 1 1\r\n10 3 -1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n99998 99998 99999 99999\r\n0 0 99999 100000\r\n", "output": "0.99998999989999903804\r\n"}, {"input": "1\r\n1 1 3 3\r\n2 2 0 0\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "2\r\n99999 99999 100000 100000\r\n1 1 100000 100000\r\n1 1 99999 99999\r\n", "output": "0.99998999989999903804\r\n"}, {"input": "1\r\n0 0 2 2\r\n1 1 0 0\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "1\r\n0 0 1 1\r\n0 0 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 1 1\r\n0 0 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n7 7 8 8\r\n7 7 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n4 4 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 2 2\r\n1 0 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 99999 1\r\n0 99999 100000 -99999\r\n", "output": "0.99998999989999903804\r\n"}, {"input": "1\r\n1 0 2 0\r\n0 0 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 11 11\r\n5 5 0 0\r\n", "output": "0.00000000000000000000\r\n"}, {"input": "1\r\n1 1 1 1\r\n1 1 0 0\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 49998 2 50002\r\n1 50000 0 0\r\n1 50000 0 0\r\n1 0 0 1\r\n1 100000 0 -1\r\n", "output": "49998.00000000000000000000\r\n"}, {"input": "1\r\n0 0 10 10\r\n0 0 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 11 11\r\n1 2 0 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 100 100\r\n0 0 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 0 1 2\r\n0 0 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n1 1 0 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 0 5 5\r\n5 3 0 1\r\n3 3 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n1 1 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n10 10 20 20\r\n0 10 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n5 5 10 10\r\n4 6 1 0\r\n", "output": "1.00000000000000000000\r\n"}, {"input": "1\r\n0 0 5 5\r\n2 5 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 2 2\r\n0 2 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n0 1 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 2 2\r\n1 1 0 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n10 0 12 2\r\n9 1 1 0\r\n7 1 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n2 2 4 4\r\n3 1 1 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1 3 3\r\n2 10 0 -1\r\n10000 2 -1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n2 0 1 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 0 2 100000\r\n1 1 0 100000\r\n100000 1 -99999 0\r\n", "output": "0.99998999989999903804\r\n"}, {"input": "2\r\n1 1 2 2\r\n0 0 1 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 2 2\r\n0 1 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 2 2\r\n0 0 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 10 10\r\n0 0 0 1337\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n1 1 0 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 2 2\r\n0 1 0 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 1 3 3\r\n2 1 0 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 3 3\r\n1 3 1 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n0 0 100 100\r\n0 0 100 0\r\n", "output": "-1\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
with open(submission_path, 'r') as f:
sub_line = f.readline().strip()
if ref_line == '-1':
print(1 if sub_line == '-1' else 0)
return
if sub_line == '-1':
print(0)
return
try:
a = float(sub_line)
b = float(ref_line)
except:
print(0)
return
if a < -1e-12:
print(0)
return
error = abs(a - b)
if b != 0:
error /= max(1.0, b)
print(1 if error <= 1e-6 else 0)
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: checker.py input_path output_path submission_output_path")
sys.exit(1)
main(sys.argv[1], sys.argv[2], sys.argv[3])
| true |
416/A
|
416
|
A
|
Python 3
|
TESTS
| 63 | 93 | 0 |
6336422
|
n = int(input())
mi = -2*10**9
ma = 2*10**9
for i in range(n):
tp,nn,ans = input().split()
nn = int(nn)
if tp=="<":
if ans == "Y":
ma = min(ma,nn-1)
else:
mi = max(mi,nn)
elif tp == "<=":
if ans == "Y":
ma = min(ma,nn)
else:
mi = max(mi,nn+1)
elif tp==">":
if ans == "Y":
mi = max(mi,nn+1)
else:
ma = min(ma,nn)
elif tp==">=":
if ans == "Y":
mi = max(mi,nn)
else:
ma = min(ma,nn+1)
if mi>ma:
print("Impossible")
else:
print (mi)
| 66 | 62 | 0 |
10532029
|
import sys
import math
n = int(input())
k1 = -2 * (10 ** 9)
k2 = 2 * (10 ** 9)
for i in range(n):
st = (sys.stdin.readline()).split()
if(st[2] == "N"):
if(st[0] == ">"):
st[0] = "<="
elif(st[0] == "<"):
st[0] = ">="
elif(st[0] == "<="):
st[0] = ">"
elif(st[0] == ">="):
st[0] = "<"
if(st[0] == ">="):
if(int(st[1]) > k1):
k1 = int(st[1])
elif(st[0] == ">"):
if(int(st[1]) + 1 > k1):
k1 = int(st[1]) + 1
elif(st[0] == "<="):
if(int(st[1]) < k2):
k2 = int(st[1])
elif(st[0] == "<"):
if(int(st[1]) - 1 < k2):
k2 = int(st[1]) - 1
if(k1 > k2):
print("Impossible")
else:
print(k1)
|
Codeforces Round 241 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Guess a number!
|
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictly larger than number x?
- Is it true that y is strictly smaller than number x?
- Is it true that y is larger than or equal to number x?
- Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
|
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries),
- ">=" (for the third type queries),
- "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
|
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
| null | null |
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
| 1,400 |
["greedy", "implementation", "two pointers"]
| 66 |
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 10 Y\r\n> -6 Y\r\n< 10 Y\r\n< -10 N\r\n", "output": "-5\r\n"}, {"input": "1\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1 Y\r\n", "output": "1361956\r\n"}, {"input": "4\r\n< 1 N\r\n< 1 N\r\n< 1 N\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 1 N\r\n>= 1 Y\r\n< 1 N\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "4\r\n> 1 N\r\n<= 1 Y\r\n<= 1 Y\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n>= 1 Y\r\n> 1 N\r\n>= 1 Y\r\n>= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 9 Y\r\n< 3 Y\r\n< 2 Y\r\n< 2 Y\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n< 0 N\r\n< -7 N\r\n>= 8 N\r\n>= -5 Y\r\n", "output": "3\r\n"}, {"input": "4\r\n<= -6 N\r\n<= -8 N\r\n<= 3 Y\r\n<= 7 Y\r\n", "output": "-2\r\n"}, {"input": "4\r\n>= 7 N\r\n<= -1 N\r\n>= 5 N\r\n<= -10 N\r\n", "output": "0\r\n"}, {"input": "4\r\n> 5 N\r\n>= -5 Y\r\n> -9 Y\r\n> -9 Y\r\n", "output": "-4\r\n"}, {"input": "10\r\n<= -60 N\r\n>= -59 Y\r\n> 22 Y\r\n> 95 N\r\n<= 91 Y\r\n> 77 Y\r\n>= -59 Y\r\n> -25 Y\r\n> -22 Y\r\n>= 52 Y\r\n", "output": "85\r\n"}, {"input": "10\r\n>= -18 Y\r\n>= -35 Y\r\n> -94 Y\r\n< -23 N\r\n< -69 N\r\n< -68 N\r\n< 82 Y\r\n> 92 N\r\n< 29 Y\r\n>= -25 Y\r\n", "output": "18\r\n"}, {"input": "10\r\n>= 18 Y\r\n<= -32 N\r\n>= 85 N\r\n<= 98 Y\r\n<= -43 N\r\n<= -79 N\r\n>= 97 N\r\n< -38 N\r\n< -55 N\r\n<= -93 N\r\n", "output": "64\r\n"}, {"input": "10\r\n<= 2 Y\r\n< -33 Y\r\n> 6 N\r\n> -6 N\r\n< -28 Y\r\n> -62 Y\r\n< 57 Y\r\n<= 24 Y\r\n> 23 N\r\n> -25 N\r\n", "output": "-54\r\n"}, {"input": "10\r\n<= -31 N\r\n>= 66 N\r\n<= 0 Y\r\n> -95 Y\r\n< 27 Y\r\n< -42 N\r\n> 3 N\r\n< 6 Y\r\n>= -42 Y\r\n> -70 Y\r\n", "output": "-29\r\n"}, {"input": "10\r\n>= 54 N\r\n<= -52 N\r\n>= 64 N\r\n> 65 N\r\n< 37 Y\r\n> -84 Y\r\n>= -94 Y\r\n>= -95 Y\r\n> -72 Y\r\n<= 18 N\r\n", "output": "22\r\n"}, {"input": "10\r\n> -24 N\r\n<= -5 Y\r\n<= -33 Y\r\n> 45 N\r\n> -59 Y\r\n> -21 N\r\n<= -48 N\r\n> 40 N\r\n< 12 Y\r\n>= 14 N\r\n", "output": "-47\r\n"}, {"input": "10\r\n>= 91 Y\r\n>= -68 Y\r\n< 92 N\r\n>= -15 Y\r\n> 51 Y\r\n<= 14 N\r\n> 17 Y\r\n< 94 Y\r\n>= 49 Y\r\n> -36 Y\r\n", "output": "93\r\n"}, {"input": "1\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= -999999999 Y\r\n", "output": "-998638044\r\n"}, {"input": "1\r\n> 100000 Y\r\n", "output": "1461956\r\n"}, {"input": "1\r\n<= 999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 N\r\n", "output": "1001361956\r\n"}, {"input": "4\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1000000000 Y\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 999999999 N\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1000000000 Y\r\n", "output": "1001361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 100 Y\r\n", "output": "1362056\r\n"}, {"input": "2\r\n< -1000000000 Y\r\n< 3 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "8\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 15 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 10000000 Y\r\n", "output": "11361956\r\n"}, {"input": "1\r\n< 0 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 5 Y\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n> 5 Y\r\n> 0 Y\r\n< 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n>= -1000000000 N\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n>= 1 Y\r\n<= 1 Y\r\n> 10 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n> 1 Y\r\n< 2 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 5 Y\r\n<= 5 Y\r\n< 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 5 N\r\n> 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 4 Y\r\n> 4 Y\r\n<= 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 4 Y\r\n> 4 Y\r\n", "output": "1361960\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = int(x_str)
if sign == '>':
if ans == 'Y':
new_low = x + 1
low = max(low, new_low)
else:
new_high = x
high = min(high, new_high)
elif sign == '<':
if ans == 'Y':
new_high = x - 1
high = min(high, new_high)
else:
new_low = x
low = max(low, new_low)
elif sign == '>=':
if ans == 'Y':
new_low = x
low = max(low, new_low)
else:
new_high = x - 1
high = min(high, new_high)
elif sign == '<=':
if ans == 'Y':
new_high = x
high = min(high, new_high)
else:
new_low = x + 1
low = max(low, new_low)
if low > high:
break
with open(submission_path) as f:
submission_lines = [line.strip() for line in f]
submission = submission_lines[0] if submission_lines else ''
if submission == "Impossible":
print(1 if low > high else 0)
else:
try:
y = int(submission)
if -2 * 10**9 <= y <= 2 * 10**9 and low <= y <= high:
print(1)
else:
print(0)
except:
print(0)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
main(input_path, output_path, submission_path)
| true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 63 | 92 | 409,600 |
231386059
|
number_of_groups = int(input())
kids_per_group = input()
groups_with_four_kids = kids_per_group.count('4')
groups_with_three_kids = kids_per_group.count('3')
groups_with_two_kids = kids_per_group.count('2')
groups_with_one_kid = kids_per_group.count('1')
number_of_cars = groups_with_four_kids + groups_with_two_kids // 2
groups_with_two_kids = groups_with_two_kids % 2 # check if any groups with two kids left
if groups_with_three_kids >= groups_with_one_kid:
# add number of groups with three kids because the leftover three-kid-groups cannot sit with anyone else
number_of_cars += groups_with_three_kids
# add leftover two-kid-group (if any) because they cannot sit with anyone else
number_of_cars += groups_with_two_kids
else:
# add number of groups with three kids because they can each sit with a one-kid-group
number_of_cars += groups_with_three_kids
groups_with_one_kid -= groups_with_three_kids
# put leftover two-kid-group (if any) together with leftover one-kid-groups (if any)
number_of_cars += (groups_with_two_kids + groups_with_one_kid) // 4
# add leftover kids if any
number_of_cars += (groups_with_two_kids + groups_with_one_kid) % 4 != 0
print(number_of_cars)
| 105 | 92 | 409,600 |
226742382
|
a=[*open(0)][1].count;print(a('4')+a('3')+(a('2')*2+max(0,a('1')-a('3'))+3)//4)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
158/B
|
158
|
B
|
PyPy 3-64
|
TESTS
| 60 | 154 | 12,492,800 |
227160926
|
import math
n=int(input())
l=list(map(int,input().split()))
if sum(l)%4==0:
if l.count(3)>=math.ceil(len(l)/2) and l.count(1)==0:
print((sum(l)//4)+1)
else:
print((sum(l)//4))
else:print((sum(l)//4)+1)
| 105 | 92 | 409,600 |
231325047
|
n=int(input())
a,b,c,d=map(input().count,('1','2','3','4'))
print(d+c+(b*2+max(0,a-c)+3)//4)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
158/B
|
158
|
B
|
PyPy 3
|
TESTS
| 63 | 248 | 7,065,600 |
228060291
|
# 4 = 1
# 3 = 1, 3
# 2 = 2, 2 1, 2 2, 1, 1
from collections import Counter
from math import ceil
n = int(input())
lst = list(map(int, input().split()))
lst_count = dict(Counter(lst))
taxies = lst_count.get(4, 0)
for i in range(lst_count.get(3, 0)):
taxies += 1
if 1 in lst_count:
lst_count[1] = max(lst_count[1]-1, 0)
if lst_count.get(2):
taxies += lst_count[2]//2
lst_count[2] = lst_count[2]%2
summ = lst_count.get(2, 0) + lst_count.get(1, 0)
taxies += ceil(summ/4)
print(taxies)
| 105 | 124 | 2,560,000 |
227965580
|
import math
n=int(input())
li=[int(_) for _ in input().split()]
ans=li.count(4)
b,c,d=li.count(3),li.count(2),li.count(1)
ans+=b+math.ceil(c/2)
forone=b
if c%2 !=0:
forone+=2
if forone < d:
ans+=math.ceil((d-forone)/4)
print(ans)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
PyPy 3
|
TESTS
| 92 | 342 | 9,728,000 |
231060961
|
import sys
input = sys.stdin.readline
l2=[]
lsum=[]
n=int(input())
ld1=[]
ld2=[]
for i in range(n):
l1=list(map(int,input().split()))
ld1.append(l1[i])
ld2.append(l1[n-i-1])
l2.append(l1)
lsum.append(sum(l1))
for j in range(n):
s=0
for k in range(n):
s=s+l2[k][j]
lsum.append(s)
lsum.append(sum(ld1))
lsum.append(sum(ld2))
l5=list(set(lsum))
if n==1:
print(1)
else:
if len(l5)!=2:
print(-1)
else:
print(max(l5)-min(l5))
| 147 | 218 | 6,246,400 |
20310383
|
n = int(input())
MagKvad = list(list(map(int, input().split())) for i in range(n))
def f(sm):
global n
global MagKvad
s1,s2 = 0,0
for i in range(n):
s1 += MagKvad[i][i]
s2 += MagKvad[i][n-i-1]
if s1 != s2:
return False
if s1 != sm:
return False
for i in range(n):
if sum(MagKvad[i]) != sm:
return False
st = 0
for y in range(n):
st += MagKvad[y][i]
if st != sm:
return False
return True
if n == 1:
print(1)
else:
for i in range(n):
if 0 in MagKvad[i]:
cor = (i,MagKvad[i].index(0))
if cor[0] == 0:
sm = sum(MagKvad[1])
else:
sm = sum(MagKvad[0])
MagKvad[cor[0]][cor[1]] = sm - sum(MagKvad[cor[0]])
if f(sm) and MagKvad[cor[0]][cor[1]] > 0:
print(MagKvad[cor[0]][cor[1]])
else:
print(-1)
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
757/A
|
757
|
A
|
Python 3
|
TESTS
| 28 | 77 | 4,710,400 |
23796337
|
s=input()
d=[]
d.append(s.count('B'))
d.append(int((s.count('u'))/2))
d.append(s.count('l'))
d.append(int((s.count('a'))/2))
d.append(s.count('s'))
d.append(s.count('r'))
print(int(min(d)))
| 107 | 46 | 102,400 |
205326592
|
s = input().strip()
counts = {'B': 0, 'u': 0, 'l': 0, 'b': 0, 'a': 0, 's': 0, 'r': 0}
for c in s:
if c in counts:
counts[c] += 1
counts['u'] //= 2
counts['a'] //= 2
print(min(counts.values()))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
757/A
|
757
|
A
|
Python 3
|
TESTS
| 28 | 62 | 4,710,400 |
23796378
|
s=input()
d=[]
d.append(s.count('B'))
d.append(int((s.count('u'))/2))
d.append(s.count('l'))
d.append(int((s.count('a'))/2))
d.append(s.count('s'))
d.append(s.count('r'))
min=d[0]
for i in range(len(d)):
if d[i] >= min:
min=min
else:
min=d[i]
print(min)
| 107 | 46 | 102,400 |
208494590
|
def solve(s):
letter_to_count = build_letter_to_count(s)
return min(letter_to_count.get(letter, 0) // count for letter, count in build_letter_to_count("Bulbasaur").items())
def build_letter_to_count(string):
letter_to_count = {}
for letter in string:
letter_to_count[letter] = letter_to_count.get(letter, 0) + 1
return letter_to_count
if __name__ == "__main__":
s = input()
print(solve(s))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
416/A
|
416
|
A
|
Python 3
|
TESTS
| 63 | 77 | 4,608,000 |
29248480
|
n = int(input())
min_y = -2000000000
max_y = 2000000000
Impossible = False
def opposite(sign):
if sign == '>':
return '<='
if sign == '<':
return '>='
if sign == '<=':
return '>'
if sign == '<=':
return '<'
for i in range(n):
sign, number, ans = input().split(' ')
if ans == 'N':
sign = opposite(sign)
if sign == '>':
min_y = max(min_y, int(number) + 1)
if sign == '<':
max_y = min(max_y, int(number) - 1)
if sign == '>=':
min_y = max(min_y, int(number))
if sign == '<=':
max_y = min(max_y, int(number))
if max_y < min_y:
Impossible = True
break
if Impossible == True:
print('Impossible')
else:
print(min_y)
| 66 | 62 | 0 |
138344556
|
n=int(input())
k=-2000000000
l=2000000000
for x in range(n):
a,z,b=input().split()
a=a
z=int(z)
b=b
if(a=='>'and b=='Y'and k<z+1):
k=z+1
elif(a=='>='and b=='Y'and k<z):
k=z
elif(a=='>'and b=='N'and l>z):
l=z
elif(a=='>='and b=='N'and l>z-1):
l=z-1
elif(a=='<'and b=='Y'and l>z-1):
l=z-1
elif(a=='<='and b=='Y'and l>z):
l=z
elif(a=='<'and b=='N'and k<z):
k=z
elif(a=='<='and b=='N'and k<z+1):
k=z+1
if (k<=l):
print(k)
else:
print('Impossible')
|
Codeforces Round 241 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Guess a number!
|
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that y is strictly larger than number x?
- Is it true that y is strictly smaller than number x?
- Is it true that y is larger than or equal to number x?
- Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
|
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries),
- "<" (for the second type queries),
- ">=" (for the third type queries),
- "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
|
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
| null | null |
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
| 1,400 |
["greedy", "implementation", "two pointers"]
| 66 |
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 10 Y\r\n> -6 Y\r\n< 10 Y\r\n< -10 N\r\n", "output": "-5\r\n"}, {"input": "1\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1 Y\r\n", "output": "1361956\r\n"}, {"input": "4\r\n< 1 N\r\n< 1 N\r\n< 1 N\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n< 1 N\r\n>= 1 Y\r\n< 1 N\r\n< 1 N\r\n", "output": "1361956\r\n"}, {"input": "4\r\n> 1 N\r\n<= 1 Y\r\n<= 1 Y\r\n> 1 N\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n>= 1 Y\r\n> 1 N\r\n>= 1 Y\r\n>= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 9 Y\r\n< 3 Y\r\n< 2 Y\r\n< 2 Y\r\n", "output": "-1998638045\r\n"}, {"input": "4\r\n< 0 N\r\n< -7 N\r\n>= 8 N\r\n>= -5 Y\r\n", "output": "3\r\n"}, {"input": "4\r\n<= -6 N\r\n<= -8 N\r\n<= 3 Y\r\n<= 7 Y\r\n", "output": "-2\r\n"}, {"input": "4\r\n>= 7 N\r\n<= -1 N\r\n>= 5 N\r\n<= -10 N\r\n", "output": "0\r\n"}, {"input": "4\r\n> 5 N\r\n>= -5 Y\r\n> -9 Y\r\n> -9 Y\r\n", "output": "-4\r\n"}, {"input": "10\r\n<= -60 N\r\n>= -59 Y\r\n> 22 Y\r\n> 95 N\r\n<= 91 Y\r\n> 77 Y\r\n>= -59 Y\r\n> -25 Y\r\n> -22 Y\r\n>= 52 Y\r\n", "output": "85\r\n"}, {"input": "10\r\n>= -18 Y\r\n>= -35 Y\r\n> -94 Y\r\n< -23 N\r\n< -69 N\r\n< -68 N\r\n< 82 Y\r\n> 92 N\r\n< 29 Y\r\n>= -25 Y\r\n", "output": "18\r\n"}, {"input": "10\r\n>= 18 Y\r\n<= -32 N\r\n>= 85 N\r\n<= 98 Y\r\n<= -43 N\r\n<= -79 N\r\n>= 97 N\r\n< -38 N\r\n< -55 N\r\n<= -93 N\r\n", "output": "64\r\n"}, {"input": "10\r\n<= 2 Y\r\n< -33 Y\r\n> 6 N\r\n> -6 N\r\n< -28 Y\r\n> -62 Y\r\n< 57 Y\r\n<= 24 Y\r\n> 23 N\r\n> -25 N\r\n", "output": "-54\r\n"}, {"input": "10\r\n<= -31 N\r\n>= 66 N\r\n<= 0 Y\r\n> -95 Y\r\n< 27 Y\r\n< -42 N\r\n> 3 N\r\n< 6 Y\r\n>= -42 Y\r\n> -70 Y\r\n", "output": "-29\r\n"}, {"input": "10\r\n>= 54 N\r\n<= -52 N\r\n>= 64 N\r\n> 65 N\r\n< 37 Y\r\n> -84 Y\r\n>= -94 Y\r\n>= -95 Y\r\n> -72 Y\r\n<= 18 N\r\n", "output": "22\r\n"}, {"input": "10\r\n> -24 N\r\n<= -5 Y\r\n<= -33 Y\r\n> 45 N\r\n> -59 Y\r\n> -21 N\r\n<= -48 N\r\n> 40 N\r\n< 12 Y\r\n>= 14 N\r\n", "output": "-47\r\n"}, {"input": "10\r\n>= 91 Y\r\n>= -68 Y\r\n< 92 N\r\n>= -15 Y\r\n> 51 Y\r\n<= 14 N\r\n> 17 Y\r\n< 94 Y\r\n>= 49 Y\r\n> -36 Y\r\n", "output": "93\r\n"}, {"input": "1\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= -999999999 Y\r\n", "output": "-998638044\r\n"}, {"input": "1\r\n> 100000 Y\r\n", "output": "1461956\r\n"}, {"input": "1\r\n<= 999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 N\r\n", "output": "1001361956\r\n"}, {"input": "4\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n>= 1000000000 Y\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 999999999 N\r\n", "output": "1001361955\r\n"}, {"input": "1\r\n<= 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 1000000000 Y\r\n", "output": "1001361956\r\n"}, {"input": "1\r\n<= 1 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -999999999 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 100 Y\r\n", "output": "1362056\r\n"}, {"input": "2\r\n< -1000000000 Y\r\n< 3 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= -1000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "8\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n< -1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 15 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 1000000000 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n> 10000000 Y\r\n", "output": "11361956\r\n"}, {"input": "1\r\n< 0 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n< 100 Y\r\n", "output": "-1998638045\r\n"}, {"input": "1\r\n<= 5 Y\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n> 5 Y\r\n> 0 Y\r\n< 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "1\r\n>= -1000000000 N\r\n", "output": "-1998638045\r\n"}, {"input": "3\r\n>= 1 Y\r\n<= 1 Y\r\n> 10 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n> 1 Y\r\n< 2 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 5 Y\r\n<= 5 Y\r\n< 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 5 N\r\n> 5 Y\r\n", "output": "Impossible\r\n"}, {"input": "3\r\n>= 4 Y\r\n> 4 Y\r\n<= 4 Y\r\n", "output": "Impossible\r\n"}, {"input": "2\r\n>= 4 Y\r\n> 4 Y\r\n", "output": "1361960\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
n = int(lines[0].strip())
queries = [line.strip().split() for line in lines[1:n+1]]
low = -2 * 10**9
high = 2 * 10**9
for sign, x_str, ans in queries:
x = int(x_str)
if sign == '>':
if ans == 'Y':
new_low = x + 1
low = max(low, new_low)
else:
new_high = x
high = min(high, new_high)
elif sign == '<':
if ans == 'Y':
new_high = x - 1
high = min(high, new_high)
else:
new_low = x
low = max(low, new_low)
elif sign == '>=':
if ans == 'Y':
new_low = x
low = max(low, new_low)
else:
new_high = x - 1
high = min(high, new_high)
elif sign == '<=':
if ans == 'Y':
new_high = x
high = min(high, new_high)
else:
new_low = x + 1
low = max(low, new_low)
if low > high:
break
with open(submission_path) as f:
submission_lines = [line.strip() for line in f]
submission = submission_lines[0] if submission_lines else ''
if submission == "Impossible":
print(1 if low > high else 0)
else:
try:
y = int(submission)
if -2 * 10**9 <= y <= 2 * 10**9 and low <= y <= high:
print(1)
else:
print(0)
except:
print(0)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
main(input_path, output_path, submission_path)
| true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 36 | 92 | 0 |
232083603
|
user = input()
group = input().split(" ")
sum = 0
for i in group:
sum+=int(i)
if sum%4 == 0:
print(sum//4)
else:
cal = sum//4
print(cal+1)
| 105 | 124 | 2,560,000 |
231402681
|
n = int(input())
e = list(map(int, input().split()))
x = [0] * 5
for var in e:
x[var] += 1
t = x[4] + x[3] + (x[2] + 1) // 2
x[1] -= x[3]
if x[2] % 2 == 1:
x[1] -= 2
if x[1] > 0:
t += (x[1] + 3) // 4
print(t)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 36 | 92 | 0 |
231653193
|
x=int(input())
y=list(map(int,input().split()))
if sum(y)%4==0:
print(sum(y)//4)
else:
print((sum(y)//4)+1)
| 105 | 124 | 2,560,000 |
231421768
|
def min_taxis(n, s):
counts = [0]*5
for i in s:
counts[i] += 1
taxis = counts[4] + counts[3] + counts[2] // 2
counts[1] -= counts[3]
if counts[2] % 2:
taxis += 1
counts[1] -= 2
if counts[1] > 0:
taxis += (counts[1] + 3) // 4
return taxis
n = int(input())
s = list(map(int, input().split()))
print(min_taxis(n, s))
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
220/A
|
220
|
A
|
PyPy 3-64
|
TESTS
| 32 | 139 | 237,465,600 |
157426627
|
import math
import sys
sys.setrecursionlimit(150000)
def main():
n = int(input())
a = [int(x) for x in input().split()]
dips = []
for i in range(n-1):
if a[i+1] < a[i]:
dips.append(i)
#print(dips)
if len(dips) > 2:
print("NO")
elif len(dips) == 2:
n2 = a[dips[1]+1]
n1 = a[dips[0]]
if (dips[0] == 0 or n2 >= a[dips[0] - 1]) and n2 <= a[dips[0] + 1] and a[dips[1]] <= n1 and (dips[1]+2 >= n or n1 <= a[dips[1] + 2]):
print("YES")
else:
print("NO")
elif len(dips) == 1:
flag = True
for i in range(dips[0]+1,n-1):
if a[i] != a[i+1]:
flag = False
break
if flag:
print("YES")
return
prev = dips[0]
while prev > 0 and a[prev-1] == a[prev]:
prev -= 1
n1 = a[dips[0]+1]
if (prev == 0 or n1 >= a[prev-1]) and (dips[0]+2 >= n or a[dips[0]+2] >= a[dips[0]]):
print("YES")
return
print("NO")
else:
print("YES")
main()
| 96 | 93 | 8,396,800 |
161712159
|
input();a=list(map(int,input().split()))
print("YNEOS"[sum(i!=j for i,j in zip(a,sorted(a)))>2::2])
|
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 |
623/A
|
623
|
A
|
Python 3
|
TESTS
| 25 | 608 | 12,185,600 |
15823362
|
n, m = (int(_) for _ in input().split())
e = [set() for i in range(n + 1)]
deg = [0 for i in range(n + 1)]
for i in range(m):
x, y = (int(_) for _ in input().split())
deg[x] += 1
deg[y] += 1
e[x].add(y)
e[y].add(x)
s = ['' for i in range(n + 1)]
b = []
ans = 2
for i in range(1, n + 1):
if deg[i] == n - 1:
s[i] = 'b'
for i in range(1, n + 1):
if deg[i] != n - 1 and s[i] == '':
s[i] = 'a' if ans == 2 else 'c'
if ans == 2:
for j in e[i]:
if s[j] == '':
s[j] = 'a'
elif ans == 1:
for j in e[i]:
if s[j] == 'a':
ans = -1
elif s[j] == '':
s[j] = 'c'
ans -= 1
for i in s[1:]:
if i == '':
ans = -1
if ans >= 0:
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if (s[i] == 'a' and s[j] == 'c') or (s[i] == 'c' and s[j] == 'a'):
continue
if j not in e[i] or i not in e[j]:
ans = -1
break
if ans == -1:
break
if ans >= 0:
print('Yes')
print(''.join(s[1:]))
else:
print('No')
| 106 | 405 | 4,505,600 |
66424406
|
def bfs(k):
fila=[k]
flag=[0]*(n+1)
flag[k]=1
while len(fila) != 0:
v=fila[0]
mark[v]=mark[k]
fila.pop(0)
for i in g[v]:
if flag[i]==0 and mark[i]!='b':
fila.append(i)
flag[i]=1
n,m=[int(x) for x in input().split()]
g=[[] for i in range(n+1)]
res=1
for i in range(m):
u,v=[int(x) for x in input().split()]
g[u].append(v)
g[v].append(u)
deg=[0]*(n+1)
mark=[0]*(n+1)
contb=0
for i in range(n+1):
deg[i]=len(g[i])
if deg[i]==(n-1):
mark[i]='b'
contb+=1
for i in range(1,n+1):
if mark[i]==0:
mark[i]='a'
bfs(i)
break
for i in range(1,n+1):
if mark[i]==0:
mark[i]='c'
bfs(i)
break
conta=0
contc=0
for i in mark:
if i=='a':
conta+=1
for i in mark:
if i=='c':
contc+=1
for i in range(1,n+1):
if mark[i]=='a' and deg[i]!=(conta-1+contb):
res=0
if mark[i]=='c' and deg[i]!=(contc-1+contb):
res=0
if mark[i]==0:
res=0
if res==0:
print("No")
else:
mark.pop(0)
r=''.join(mark)
print("Yes")
print(r)
|
AIM Tech Round (Div. 1)
|
CF
| 2,016 | 2 | 256 |
Graph and String
|
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:
- G has exactly n vertices, numbered from 1 to n.
- For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.
|
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
|
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.
| null |
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.
|
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
| 1,800 |
["constructive algorithms", "graphs"]
| 106 |
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r\n6 5\r\n5 3\r\n7 1\r\n5 8\r\n5 4\r\n6 1\r\n6 4\r\n2 1\r\n4 1\r\n8 2\r\n7 2\r\n6 8\r\n8 4\r\n6 7\r\n3 1\r\n7 8\r\n3 8\r\n5 7\r\n5 2\r\n6 2\r\n", "output": "Yes\r\naaaaaaaa\r\n"}, {"input": "4 3\r\n4 3\r\n2 4\r\n2 3\r\n", "output": "Yes\r\naccc\r\n"}, {"input": "4 2\r\n4 3\r\n1 2\r\n", "output": "Yes\r\naacc\r\n"}, {"input": "5 3\r\n1 2\r\n1 3\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n4 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n3 2\r\n1 3\r\n6 5\r\n4 6\r\n", "output": "No\r\n"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 6\r\n5 6\r\n", "output": "No\r\n"}, {"input": "7 13\r\n1 2\r\n2 3\r\n1 3\r\n4 5\r\n5 6\r\n4 6\r\n2 5\r\n2 7\r\n3 7\r\n7 4\r\n7 6\r\n7 1\r\n7 5\r\n", "output": "No\r\n"}, {"input": "8 18\r\n3 7\r\n2 5\r\n5 3\r\n3 8\r\n8 6\r\n6 3\r\n6 4\r\n4 8\r\n1 2\r\n6 1\r\n2 7\r\n2 4\r\n4 5\r\n4 3\r\n6 5\r\n1 4\r\n5 7\r\n3 1\r\n", "output": "No\r\n"}, {"input": "20 55\r\n20 11\r\n14 5\r\n4 9\r\n17 5\r\n16 5\r\n20 16\r\n11 17\r\n2 14\r\n14 19\r\n9 15\r\n20 19\r\n5 18\r\n15 20\r\n1 16\r\n12 20\r\n4 7\r\n16 19\r\n17 19\r\n16 12\r\n19 9\r\n11 13\r\n18 17\r\n10 8\r\n20 1\r\n16 8\r\n1 13\r\n11 12\r\n13 18\r\n4 13\r\n14 10\r\n9 13\r\n8 9\r\n6 9\r\n2 13\r\n10 16\r\n19 1\r\n7 17\r\n20 4\r\n12 8\r\n3 2\r\n18 10\r\n6 13\r\n14 9\r\n7 9\r\n19 7\r\n8 15\r\n20 6\r\n16 13\r\n14 13\r\n19 8\r\n7 14\r\n6 2\r\n9 1\r\n7 1\r\n10 6\r\n", "output": "No\r\n"}, {"input": "15 84\r\n11 9\r\n3 11\r\n13 10\r\n2 12\r\n5 9\r\n1 7\r\n14 4\r\n14 2\r\n14 1\r\n11 8\r\n1 8\r\n14 10\r\n4 15\r\n10 5\r\n5 12\r\n13 11\r\n6 14\r\n5 7\r\n12 11\r\n9 1\r\n10 15\r\n2 6\r\n7 15\r\n14 9\r\n9 7\r\n11 14\r\n8 15\r\n12 7\r\n13 6\r\n2 9\r\n9 6\r\n15 3\r\n12 15\r\n6 15\r\n4 6\r\n4 1\r\n9 12\r\n10 7\r\n6 1\r\n11 10\r\n2 3\r\n5 2\r\n13 2\r\n13 3\r\n12 6\r\n4 3\r\n5 8\r\n12 1\r\n9 15\r\n14 5\r\n12 14\r\n10 1\r\n9 4\r\n7 13\r\n3 6\r\n15 1\r\n13 9\r\n11 1\r\n10 4\r\n9 3\r\n8 12\r\n13 12\r\n6 7\r\n12 10\r\n4 12\r\n13 15\r\n2 10\r\n3 8\r\n1 5\r\n15 2\r\n4 11\r\n2 1\r\n10 8\r\n14 3\r\n14 8\r\n8 7\r\n13 1\r\n5 4\r\n11 2\r\n6 8\r\n5 15\r\n2 4\r\n9 8\r\n9 10\r\n", "output": "No\r\n"}, {"input": "15 13\r\n13 15\r\n13 3\r\n14 3\r\n10 7\r\n2 5\r\n5 12\r\n12 11\r\n9 2\r\n13 7\r\n7 4\r\n12 10\r\n15 7\r\n6 13\r\n", "output": "No\r\n"}, {"input": "6 6\r\n1 4\r\n3 4\r\n6 4\r\n2 6\r\n5 3\r\n3 2\r\n", "output": "No\r\n"}, {"input": "4 6\r\n4 2\r\n3 1\r\n3 4\r\n3 2\r\n4 1\r\n2 1\r\n", "output": "Yes\r\naaaa\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n1 2\r\n3 4\r\n", "output": "Yes\r\nabcc\r\n"}, {"input": "4 3\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacaa\r\n"}, {"input": "4 4\r\n1 2\r\n4 1\r\n3 4\r\n3 1\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "4 4\r\n4 2\r\n3 4\r\n3 1\r\n2 3\r\n", "output": "Yes\r\nacbc\r\n"}, {"input": "4 5\r\n3 1\r\n2 1\r\n3 4\r\n2 4\r\n3 2\r\n", "output": "Yes\r\nabbc\r\n"}, {"input": "4 4\r\n4 1\r\n3 1\r\n3 2\r\n3 4\r\n", "output": "Yes\r\nacba\r\n"}, {"input": "4 5\r\n3 4\r\n2 1\r\n3 1\r\n4 1\r\n2 3\r\n", "output": "Yes\r\nbabc\r\n"}, {"input": "4 4\r\n1 3\r\n3 4\r\n2 1\r\n3 2\r\n", "output": "Yes\r\naabc\r\n"}, {"input": "4 3\r\n2 1\r\n1 4\r\n2 4\r\n", "output": "Yes\r\naaca\r\n"}, {"input": "4 4\r\n2 4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "Yes\r\nbaca\r\n"}, {"input": "4 2\r\n3 1\r\n2 4\r\n", "output": "Yes\r\nacac\r\n"}, {"input": "4 4\r\n4 2\r\n2 1\r\n3 2\r\n1 4\r\n", "output": "Yes\r\nabca\r\n"}, {"input": "4 5\r\n4 1\r\n2 4\r\n2 1\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbbac\r\n"}, {"input": "4 4\r\n1 2\r\n3 1\r\n2 4\r\n2 3\r\n", "output": "Yes\r\nabac\r\n"}, {"input": "4 2\r\n2 3\r\n1 4\r\n", "output": "Yes\r\nacca\r\n"}, {"input": "4 4\r\n2 1\r\n1 4\r\n2 3\r\n3 1\r\n", "output": "Yes\r\nbaac\r\n"}, {"input": "4 3\r\n3 2\r\n1 2\r\n1 3\r\n", "output": "Yes\r\naaac\r\n"}, {"input": "4 4\r\n3 2\r\n2 4\r\n3 4\r\n4 1\r\n", "output": "Yes\r\naccb\r\n"}, {"input": "4 5\r\n4 2\r\n3 2\r\n4 3\r\n4 1\r\n2 1\r\n", "output": "Yes\r\nabcb\r\n"}, {"input": "4 4\r\n3 1\r\n2 4\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nacab\r\n"}, {"input": "4 5\r\n3 1\r\n4 3\r\n4 1\r\n2 1\r\n2 4\r\n", "output": "Yes\r\nbacb\r\n"}, {"input": "4 4\r\n2 4\r\n3 4\r\n1 2\r\n4 1\r\n", "output": "Yes\r\naacb\r\n"}, {"input": "4 5\r\n1 4\r\n4 3\r\n4 2\r\n3 2\r\n1 3\r\n", "output": "Yes\r\nacbb\r\n"}, {"input": "2 0\r\n", "output": "Yes\r\nac\r\n"}, {"input": "3 0\r\n", "output": "No\r\n"}, {"input": "3 1\r\n1 2\r\n", "output": "Yes\r\naac\r\n"}, {"input": "3 2\r\n1 2\r\n3 2\r\n", "output": "Yes\r\nabc\r\n"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "Yes\r\naaa\r\n"}, {"input": "3 1\r\n2 3\r\n", "output": "Yes\r\nacc\r\n"}, {"input": "3 1\r\n1 3\r\n", "output": "Yes\r\naca\r\n"}, {"input": "4 3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "No\r\n"}, {"input": "5 9\r\n4 3\r\n4 2\r\n3 1\r\n5 1\r\n4 1\r\n2 1\r\n5 2\r\n3 2\r\n5 4\r\n", "output": "Yes\r\nbbabc\r\n"}, {"input": "6 9\r\n1 4\r\n1 6\r\n3 6\r\n5 4\r\n2 6\r\n3 5\r\n4 6\r\n1 5\r\n5 6\r\n", "output": "No\r\n"}, {"input": "8 21\r\n4 7\r\n7 8\r\n6 4\r\n8 5\r\n8 1\r\n3 4\r\n4 8\r\n4 5\r\n6 7\r\n6 8\r\n7 1\r\n4 2\r\n1 5\r\n6 5\r\n8 2\r\n3 6\r\n5 2\r\n7 5\r\n1 2\r\n7 2\r\n4 1\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 4\r\n1 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n3 4\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 3\r\n2 4\r\n1 4\r\n", "output": "No\r\n"}, {"input": "5 6\r\n1 2\r\n2 4\r\n2 5\r\n3 4\r\n3 5\r\n4 5\r\n", "output": "No\r\n"}, {"input": "6 10\r\n1 5\r\n1 4\r\n3 4\r\n3 6\r\n1 2\r\n3 5\r\n2 5\r\n2 6\r\n1 6\r\n4 6\r\n", "output": "No\r\n"}, {"input": "4 3\r\n1 2\r\n3 4\r\n2 3\r\n", "output": "No\r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, m = map(int, f.readline().split())
edges = []
for _ in range(m):
u, v = map(int, f.readline().split())
edges.append((u, v))
# Read reference output
with open(ref_output_path) as f:
ref_lines = [line.strip() for line in f.readlines()]
# Read submission output
with open(sub_output_path) as f:
sub_lines = [line.strip() for line in f.readlines()]
# Check submission lines
if not ref_lines or not sub_lines:
print(0)
return
ref_first = ref_lines[0]
sub_first = sub_lines[0]
if ref_first != sub_first:
print(0)
return
if ref_first == 'Yes':
if len(sub_lines) != 2:
print(0)
return
s = sub_lines[1]
if len(s) != n:
print(0)
return
for c in s:
if c not in {'a', 'b', 'c'}:
print(0)
return
# Create adjacency set
adj = set()
for u, v in edges:
u_idx = u - 1
v_idx = v - 1
adj.add((u_idx, v_idx))
adj.add((v_idx, u_idx))
# Check all pairs
valid = True
for i in range(n):
for j in range(n):
if i == j:
continue
edge_exists = (i, j) in adj
c1 = s[i]
c2 = s[j]
allowed = (c1 == c2) or (abs(ord(c1) - ord(c2)) == 1)
if edge_exists != allowed:
valid = False
break
if not valid:
break
if valid:
print(1)
else:
print(0)
else:
if len(sub_lines) != 1:
print(0)
else:
print(1)
if __name__ == "__main__":
main()
| true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 36 | 92 | 0 |
227188726
|
n = int(input())
ss = input().split()
s = 0
for e in ss:
s += int(e)
if s % 4 == 0:
print(int(s / 4))
else:
print(int(s/4)+1)
| 105 | 124 | 3,686,400 |
232586128
|
def min_number_of_taxis(n, groups):
count = [0] * 5
for group in groups:
count[group] += 1
taxis = count[4]
taxis += count[3]
count[1] = max(0, count[1] - count[3])
taxis += count[2] // 2
count[2] %= 2
if count[2] == 1:
taxis += 1
count[1] = max(0, count[1] - 2)
taxis += (count[1] + 3) // 4
return taxis
n = int(input())
groups = list(map(int, input().split()))
result = min_number_of_taxis(n, groups)
print(result)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 36 | 92 | 0 |
231496629
|
a=int(input())
b=list(map(int,input().split()))
n=sum(b)
if n%4>0: print(n//4+1)
else: print(n//4)
| 105 | 154 | 819,200 |
20557842
|
l = int(input())
s = str(input())
a = int(s.count("1"))
b = s.count("2")
c = s.count("3")
count = int(s.count("4"))
count += c
a -= c
if b%2 == 0:
count += b/2
else:
count += (b+1)/2
a -= 2
if a > 0:
if a%4 == 0:
count += a/4
else:
count += (a - a%4 + 4)/4
print(int(count))
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
158/B
|
158
|
B
|
Python 3
|
TESTS
| 36 | 92 | 0 |
231614513
|
n,count,su = int(input()),0,0
c = list(map(int,input().split()))
for i in c:
if i==4:
count+=1
else:
su=su+i
a=su//4
b=su-a*4
if b>0:
print(count+a+1)
else:
print(count+a)
| 105 | 154 | 2,560,000 |
227788953
|
group_num=int(input())
num_1=0
num_2=0
num_3=0
num_4=0
num=0
for i in input().split():
num_i=int(i)
if num_i == 1:
num_1 += 1
elif num_i == 2:
num_2 += 1
elif num_i == 3:
num_3 += 1
elif num_i == 4:
num_4 += 1
"""数学思路写这道题"""
if num_2 % 2 == 0:
num_2_modified = num_2 // 2
else:
num_2_modified = num_2 // 2 + 1
if num_3 >= num_1:
num+=num_4+num_3+num_2_modified
else:
if num_2 % 2 == 0:
if (num_1 - num_3) % 4 ==0:
num_modified = (num_1 - num_3) // 4
else:
num_modified = (num_1 - num_3) // 4 + 1
num+=num_4+num_3+num_2_modified+num_modified
else:
if (num_1 - num_3 + 2) % 4 ==0:
num_modified = (num_1 - num_3 + 2) // 4
else:
num_modified = (num_1 - num_3 + 2) // 4 + 1
num+=num_4+num_3+num_2_modified-1+num_modified
print(num)
|
VK Cup 2012 Qualification Round 1
|
CF
| 2,012 | 3 | 256 |
Taxi
|
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
|
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
| null |
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children),
- the fourth group (consisting of three children),
- the fifth group (consisting of three children),
- the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
|
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
| 1,100 |
["*special", "greedy", "implementation"]
| 105 |
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 1 3\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2\r\n3 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "2\r\n4 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n3 1 3 1\r\n", "output": "2\r\n"}, {"input": "4\r\n1 4 1 4\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 3 3\r\n", "output": "3\r\n"}, {"input": "4\r\n2 4 4 2\r\n", "output": "3\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "4\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n2 4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 4 3\r\n", "output": "3\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 4 1\r\n", "output": "3\r\n"}, {"input": "3\r\n3 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n4 2 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3\r\n3 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n2 1 4\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "2\r\n"}, {"input": "4\r\n4 4 3 2\r\n", "output": "4\r\n"}, {"input": "4\r\n1 4 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n3 2 1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n2 4 2 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 2 4 2\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 2\r\n", "output": "3\r\n"}, {"input": "8\r\n1 1 2 1 1 1 3 2\r\n", "output": "3\r\n"}, {"input": "78\r\n2 2 2 2 3 3 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 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "39\r\n"}, {"input": "7\r\n2 2 2 1 2 1 2\r\n", "output": "3\r\n"}, {"input": "9\r\n3 1 2 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "10\r\n3 1 2 2 2 2 2 2 1 2\r\n", "output": "5\r\n"}, {"input": "18\r\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1\r\n", "output": "9\r\n"}, {"input": "26\r\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1\r\n", "output": "13\r\n"}]
| false |
stdio
| null | true |
540/B
|
540
|
B
|
Python 3
|
TESTS
| 11 | 124 | 409,600 |
84122725
|
import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
n, k, p, x, y = I()
a = I()
s = max(0, x - sum(a))
for i in range(n - k):
a.append(max(1, min(1, s)))
s -= 1
if s > 0:
for i in range(k, n):
if s <= 0:
break
ok = min(p - 1, s)
s -= ok
a[i] += ok
if sorted(a)[n // 2] < y or sum(a) > x:
print(-1)
else:
# print(a)
print(*a[k: ])
| 78 | 62 | 1,740,800 |
210829379
|
n,k,p,x,y=list(map(int,input().split()))
a=list(map(int,input().split()))
tot=sum(a)
if (n-k)+tot>x:
print(-1)
else:
a.sort()
pre,post=0,0
for i in range(k):
if a[i]>=y:
post+=1
else:
pre+=1
req=n-k
lim=n//2
if pre>lim:
print(-1)
else:
rem=lim-pre
ans=[]
for i in range(min(req,rem)):
ans.append(1)
if req>rem:
for i in range(req-rem):
ans.append(y)
if sum(ans)+tot>x:
print(-1)
else:
print(*ans)
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
School Marks
|
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.
Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.
|
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.
The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.
|
If Vova cannot achieve the desired result, print "-1".
Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
| null |
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.
In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.
Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.
In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
|
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
| 1,700 |
["greedy", "implementation"]
| 78 |
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5 2 4 5\r\n", "output": "-1\r\n"}, {"input": "7 4 5 27 5\r\n5 2 4 5\r\n", "output": "5 5 1\r\n"}, {"input": "1 0 1000 999 1000\r\n\r\n", "output": "-1\r\n"}, {"input": "1 0 1000 1000 1000\r\n\r\n", "output": "1000\r\n"}, {"input": "1 0 1000 1000 999\r\n\r\n", "output": "999\r\n"}, {"input": "995 1 1000 1772 2\r\n1\r\n", "output": "2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1\n"}, {"input": "993 0 1000 63930 1\r\n\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "5 3 5 25 4\r\n3 3 3\r\n", "output": "-1\r\n"}, {"input": "7 4 5 25 5\r\n5 5 4 5\r\n", "output": "-1\r\n"}, {"input": "7 4 5 26 5\r\n5 5 4 5\r\n", "output": "5 1 1\r\n"}, {"input": "7 4 5 26 5\r\n5 5 4 5\r\n", "output": "5 1 1\r\n"}, {"input": "5 3 5 17 4\r\n3 3 4\r\n", "output": "-1\r\n"}, {"input": "5 3 5 18 4\r\n3 3 4\r\n", "output": "4 4\r\n"}, {"input": "5 3 5 5 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "5 3 5 6 1\r\n1 1 2\r\n", "output": "1 1\r\n"}, {"input": "3 0 2 3 1\r\n\r\n", "output": "1 1 1\r\n"}, {"input": "3 0 2 4 2\r\n\r\n", "output": "-1\r\n"}, {"input": "3 0 2 5 2\r\n\r\n", "output": "2 2 1\r\n"}, {"input": "9 7 3 16 2\r\n1 3 1 3 1 3 1\r\n", "output": "-1\r\n"}, {"input": "9 7 3 17 2\r\n1 3 1 3 1 3 1\r\n", "output": "2 2\r\n"}, {"input": "9 7 3 18 2\r\n1 3 1 3 1 3 1\r\n", "output": "2 2\r\n"}, {"input": "9 7 3 18 3\r\n1 3 1 3 1 3 1\r\n", "output": "-1\r\n"}, {"input": "9 7 3 19 3\r\n1 3 1 3 1 3 1\r\n", "output": "3 3\r\n"}, {"input": "9 7 3 20 3\r\n1 3 1 3 1 3 1\r\n", "output": "3 3\r\n"}, {"input": "9 6 3 27 2\r\n1 1 1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "9 6 3 13 2\r\n1 1 1 2 1 2\r\n", "output": "-1\r\n"}, {"input": "9 6 3 14 2\r\n1 1 1 2 1 2\r\n", "output": "2 2 2\r\n"}, {"input": "5 0 5 13 4\r\n\r\n", "output": "-1\r\n"}, {"input": "5 0 5 14 4\r\n\r\n", "output": "4 4 4 1 1\r\n"}, {"input": "5 0 5 5 1\r\n\r\n", "output": "1 1 1 1 1\r\n"}, {"input": "5 0 5 7 2\r\n\r\n", "output": "-1\r\n"}, {"input": "5 0 5 8 2\r\n\r\n", "output": "2 2 2 1 1\r\n"}, {"input": "9 7 2 18 2\r\n1 1 1 2 2 1 1\r\n", "output": "-1\r\n"}, {"input": "9 7 2 13 1\r\n2 2 2 1 1 2 2\r\n", "output": "-1\r\n"}, {"input": "9 7 2 14 1\r\n2 2 2 1 1 2 2\r\n", "output": "1 1\r\n"}, {"input": "993 0 3 993 2\r\n\r\n", "output": "-1\r\n"}, {"input": "995 1 3 2877 3\r\n3\r\n", "output": "1 3 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1\n"}, {"input": "997 100 3 1102 2\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 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 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 3\r\n", "output": "-1\r\n"}, {"input": "993 0 42 12022 1\r\n\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "995 1 42 28887 42\r\n13\r\n", "output": "42 42 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1 42 1\n"}, {"input": "997 100 42 3151 1\r\n27 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 22 1 1 1 32 1 1 1 1 1 1 1 16 42 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 38 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 38 1 1 1\r\n", "output": "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 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 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 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 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 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 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 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 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 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 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 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 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 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 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\n"}, {"input": "11 8 10 110 5\r\n9 9 9 9 9 9 9 9\r\n", "output": "1 1 1\r\n"}, {"input": "9 8 10 90 2\r\n1 1 1 1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3 2 10 30 2\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "3 2 10 30 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "5 4 100 14 4\r\n4 4 4 4\r\n", "output": "-1\r\n"}, {"input": "5 4 2 8 2\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "5 4 2 7 2\r\n1 1 1 2\r\n", "output": "-1\r\n"}, {"input": "11 10 1000 101 5\r\n10 10 10 10 10 10 10 10 10 10\r\n", "output": "1\r\n"}, {"input": "7 5 100 100 5\r\n7 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "5 4 5 25 2\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "9 8 10 89 5\r\n8 8 8 8 8 8 8 8\r\n", "output": "1\r\n"}, {"input": "5 3 5 18 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "11 10 1000 100 5\r\n10 10 10 10 10 10 10 10 10 10\r\n", "output": "-1\r\n"}, {"input": "9 7 10 30 2\r\n3 3 3 3 3 3 3\r\n", "output": "1 1\r\n"}, {"input": "5 4 2 10 2\r\n2 2 2 2\r\n", "output": "1\r\n"}, {"input": "7 6 1000 31 5\r\n5 5 5 5 5 5\r\n", "output": "1\r\n"}, {"input": "9 8 100 100 2\r\n1 1 1 1 1 1 1 1\r\n", "output": "-1\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
with open(input_path, 'r') as f_in:
n, k, p, x, y = map(int, f_in.readline().split())
existing = list(map(int, f_in.readline().split()))
with open(submission_path, 'r') as f_sub:
submission_line = f_sub.read().strip()
if submission_line == "-1":
sum_existing = sum(existing)
m = (n + 1) // 2
cnt_ge_y = sum(1 for mark in existing if mark >= y)
required = max(0, m - cnt_ge_y)
remaining = n - k
if required > remaining or (sum_existing + required * y + (remaining - required) * 1) > x:
print(100)
else:
print(0)
else:
try:
parts = list(map(int, submission_line.split()))
except:
print(0)
return
if len(parts) != n - k:
print(0)
return
for num in parts:
if not (1 <= num <= p):
print(0)
return
total_marks = existing + parts
sum_total = sum(total_marks)
if sum_total > x:
print(0)
return
sorted_marks = sorted(total_marks)
median = sorted_marks[(n - 1) // 2]
if median >= y:
print(100)
else:
print(0)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
main(input_path, output_path, submission_path)
| true |
757/A
|
757
|
A
|
Python 3
|
TESTS
| 27 | 109 | 5,324,800 |
24516197
|
from collections import Counter
c=Counter({'a': 0, 'l': 0, 'r': 0, 'B': 0, 's': 0, 'b': 0, 'u': 0})
c.update(input())
c["a"]=c["a"]//2
c["u"]=c["u"]//2
print(min(c.values()))
| 107 | 61 | 0 |
164714793
|
#import io, os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
s=input()
B=s.count("B")
b=s.count("b")
u=s.count("u")
l=s.count("l")
a=s.count("a")
st=s.count("s")
r=s.count("r")
print(min(B,u//2,l,b,a//2,st,r))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
757/B
|
757
|
B
|
Python 3
|
TESTS
| 70 | 1,653 | 11,980,800 |
23828867
|
n = int(input())
pkmns = list(map(int, input().split()))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317]
if n == 1:
print(1)
else:
prime = [True for i in range(n)]
best = 0
for pr in primes:
count = 0
for i in range(n):
if pkmns[i] % pr == 0:
count += 1
prime[i] = False
if count > best:
best = count
count = 0
for i in prime:
if i:
count += 1
if count <= best:
print(best)
else:
prime_count = dict()
for i in range(n):
if prime[i]:
if pkmns[i] in prime_count:
prime_count[pkmns[i]] += 1
else:
prime_count[pkmns[i]] = 1
for i in prime_count:
if prime_count[i] > best:
best = prime_count[i]
print(best)
| 134 | 218 | 32,972,800 |
115835583
|
import math
def seive(a):
l=[0]*a
for i in range(a):
l[i]=i
for i in range(2,a,2):
l[i]=2
for i in range(3,int(math.sqrt(a))+1):
if(l[i]==i):
for j in range(i*i,a,i):
if(l[j]==j):
l[j]=i
return l
def cal(a,d,p):
s=set()
while(a!=1):
if(p[a] not in s):
s.add(p[a])
d[p[a]]=d[p[a]]+1
a=a//p[a]
n=int(input())
arr=[int(i) for i in input().split()]
d=dict()
for i in range(2,10**5+1):
d[i]=0
p=seive(10**5+1)
for i in range(n):
cal(arr[i],d,p)
maxi=1
for i in range(2,10**5+1):
if(maxi<d[i]):
maxi=d[i]
print(maxi)
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 2 | 512 |
Bash's Big Day
|
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
The input consists of two lines.
The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab.
The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.
|
Print single integer — the maximum number of Pokemons Bash can take.
| null |
gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.
In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.
|
[{"input": "3\n2 3 4", "output": "2"}, {"input": "5\n2 3 4 6 7", "output": "3"}]
| 1,400 |
["greedy", "math", "number theory"]
| 134 |
[{"input": "3\r\n2 3 4\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 6 7\r\n", "output": "3\r\n"}, {"input": "3\r\n5 6 4\r\n", "output": "2\r\n"}, {"input": "8\r\n41 74 4 27 85 39 100 36\r\n", "output": "4\r\n"}, {"input": "6\r\n89 20 86 81 62 23\r\n", "output": "3\r\n"}, {"input": "71\r\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| false |
stdio
| null | true |
900/A
|
900
|
A
|
Python 3
|
TESTS
| 26 | 295 | 1,740,800 |
117486166
|
from collections import Counter
n=int(input())
l1=[]
l2=[]
for i in range(n):
a,b=map(int,input().split())
if a<0:
l1.append('n')
else:
l1.append('p')
if b<0:
l2.append('n')
else:
l2.append('p')
l1=list(Counter(l1).values())
l2=list(Counter(l2).values())
if 1 in l1 or 1 in l2 or (len(l1)==1 and len(l2))==1:
print("Yes")
else:
print("No")
| 71 | 109 | 6,553,600 |
179373864
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
u, v = 0, 0
for _ in range(n):
x, y = map(int, input().split())
if x < 0:
u += 1
else:
v += 1
ans = "Yes" if min(u, v) <= 1 else "No"
print(ans)
|
Codeforces Round 450 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Find Extra One
|
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
|
The first line contains a single positive integer n (2 ≤ n ≤ 105).
The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
|
Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower).
| null |
In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed.
|
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
| 800 |
["geometry", "implementation"]
| 71 |
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000000 -1000000000\r\n1000000000 1000000000\r\n", "output": "Yes"}, {"input": "23\r\n-1 1\r\n-1 2\r\n-2 4\r\n-7 -8\r\n-3 3\r\n-9 -14\r\n-5 3\r\n-6 2\r\n-7 11\r\n-4 4\r\n-8 5\r\n1 1\r\n-1 -1\r\n-1 -2\r\n-2 -4\r\n-7 8\r\n-3 -3\r\n-9 14\r\n-5 -3\r\n-6 -2\r\n-7 -11\r\n-4 -4\r\n-8 -5\r\n", "output": "Yes"}, {"input": "4\r\n-1000000000 -1000000000\r\n1000000000 1000000000\r\n-1000000000 1000000000\r\n1000000000 -1000000000\r\n", "output": "No"}, {"input": "2\r\n-1000000000 1000000000\r\n-1000000000 -1000000000\r\n", "output": "Yes"}, {"input": "5\r\n-1 -1\r\n-2 2\r\n2 2\r\n2 -2\r\n3 2\r\n", "output": "No"}, {"input": "2\r\n1 0\r\n-1 0\r\n", "output": "Yes"}, {"input": "4\r\n-1 1\r\n-1 2\r\n-1 3\r\n-1 4\r\n", "output": "Yes"}, {"input": "2\r\n-1 0\r\n1 0\r\n", "output": "Yes"}, {"input": "2\r\n1 2\r\n-1 2\r\n", "output": "Yes"}, {"input": "2\r\n8 0\r\n7 0\r\n", "output": "Yes"}, {"input": "6\r\n-1 0\r\n-2 0\r\n-1 -1\r\n-1 5\r\n1 0\r\n1 1\r\n", "output": "No"}, {"input": "4\r\n1 0\r\n2 0\r\n-1 0\r\n-2 0\r\n", "output": "No"}, {"input": "4\r\n-2 0\r\n-1 0\r\n1 0\r\n2 0\r\n", "output": "No"}, {"input": "2\r\n1 1\r\n-1 1\r\n", "output": "Yes"}, {"input": "4\r\n-1 0\r\n-2 0\r\n1 0\r\n2 0\r\n", "output": "No"}, {"input": "2\r\n4 3\r\n-4 -2\r\n", "output": "Yes"}, {"input": "4\r\n1 0\r\n2 0\r\n-1 1\r\n-1 2\r\n", "output": "No"}, {"input": "5\r\n1 1\r\n2 1\r\n3 1\r\n-1 1\r\n-2 1\r\n", "output": "No"}, {"input": "2\r\n1 1\r\n-1 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 2\r\n1 0\r\n1 -2\r\n-1 2\r\n", "output": "Yes"}, {"input": "5\r\n-2 3\r\n-3 3\r\n4 2\r\n3 2\r\n1 2\r\n", "output": "No"}, {"input": "3\r\n2 0\r\n3 0\r\n4 0\r\n", "output": "Yes"}, {"input": "5\r\n-3 1\r\n-2 1\r\n-1 1\r\n1 1\r\n2 1\r\n", "output": "No"}, {"input": "4\r\n-3 0\r\n1 0\r\n2 0\r\n3 0\r\n", "output": "Yes"}, {"input": "2\r\n1 0\r\n-1 1\r\n", "output": "Yes"}, {"input": "3\r\n-1 0\r\n1 0\r\n2 0\r\n", "output": "Yes"}, {"input": "5\r\n1 0\r\n3 0\r\n-1 0\r\n-6 0\r\n-4 1\r\n", "output": "No"}, {"input": "5\r\n-1 2\r\n-2 2\r\n-3 1\r\n1 2\r\n2 3\r\n", "output": "No"}, {"input": "3\r\n1 0\r\n-1 0\r\n-2 0\r\n", "output": "Yes"}, {"input": "4\r\n1 0\r\n2 0\r\n3 1\r\n4 1\r\n", "output": "Yes"}, {"input": "4\r\n1 0\r\n1 2\r\n1 3\r\n-1 5\r\n", "output": "Yes"}, {"input": "4\r\n2 2\r\n2 5\r\n-2 3\r\n-2 0\r\n", "output": "No"}, {"input": "4\r\n1 1\r\n-1 1\r\n-1 0\r\n-1 -1\r\n", "output": "Yes"}, {"input": "4\r\n2 0\r\n3 0\r\n-3 -3\r\n-3 -4\r\n", "output": "No"}, {"input": "4\r\n-1 0\r\n-2 0\r\n-3 0\r\n-4 0\r\n", "output": "Yes"}, {"input": "2\r\n-1 1\r\n1 1\r\n", "output": "Yes"}, {"input": "5\r\n1 1\r\n2 2\r\n3 3\r\n-4 -4\r\n-5 -5\r\n", "output": "No"}, {"input": "5\r\n2 0\r\n3 0\r\n4 0\r\n5 0\r\n6 0\r\n", "output": "Yes"}, {"input": "2\r\n-1 2\r\n1 2\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 1\r\n-3 0\r\n-4 0\r\n", "output": "No"}, {"input": "4\r\n-1 0\r\n-2 0\r\n3 0\r\n4 0\r\n", "output": "No"}, {"input": "3\r\n3 0\r\n2 0\r\n1 0\r\n", "output": "Yes"}, {"input": "4\r\n-2 0\r\n-3 0\r\n1 -1\r\n3 1\r\n", "output": "No"}, {"input": "3\r\n-1 -1\r\n1 1\r\n2 2\r\n", "output": "Yes"}, {"input": "4\r\n-2 0\r\n-1 0\r\n2 0\r\n1 0\r\n", "output": "No"}, {"input": "2\r\n-3 5\r\n3 5\r\n", "output": "Yes"}, {"input": "2\r\n-1 5\r\n1 5\r\n", "output": "Yes"}, {"input": "4\r\n2 0\r\n3 0\r\n-2 0\r\n-3 0\r\n", "output": "No"}, {"input": "3\r\n-1 1\r\n1 1\r\n1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1 0\r\n2 0\r\n", "output": "Yes"}, {"input": "4\r\n-1 1\r\n-2 1\r\n2 -1\r\n3 -1\r\n", "output": "No"}, {"input": "5\r\n1 0\r\n2 0\r\n3 0\r\n-1 0\r\n-2 0\r\n", "output": "No"}, {"input": "4\r\n-3 0\r\n-4 0\r\n-5 0\r\n-6 0\r\n", "output": "Yes"}, {"input": "6\r\n-3 0\r\n-2 0\r\n-1 0\r\n1 0\r\n2 0\r\n3 0\r\n", "output": "No"}, {"input": "4\r\n5 0\r\n5 1\r\n6 0\r\n6 1\r\n", "output": "Yes"}]
| false |
stdio
| null | true |
711/B
|
711
|
B
|
Python 3
|
TESTS
| 91 | 124 | 5,734,400 |
138306321
|
# Time Complexity: O(n^2)
# Space Complexity: O(n^2)
# The program checks the next row and next column to determine the number to
# fill in and, then, it checks if the diagonal sums are correct.
n = int(input())
if n == 1:
print(1)
exit()
mat = []
i, j = 0, 0
for x in range(n):
row = list(map(int, input().split()))
if 0 in row:
i, j = x, row.index(0)
mat.append(row)
a = sum(mat[(i + 1) % n])
b = sum(mat[i])
ans1 = a - b
a = sum([row[(j + 1) % n] for row in mat])
b = sum([row[j] for row in mat])
ans2 = a - b
exp = a
def checkDiagonal(mat, expected):
a = sum([row[j] for j, row in enumerate(mat)])
if a != expected:
return False
a = sum([row[n-j-1] for j, row in enumerate(mat)])
if a != expected:
return False
return True
if ans1 == ans2 and ans1 != 0:
mat[i][j] = ans1
if checkDiagonal(mat, exp):
print(ans1)
else:
print(-1)
else:
print(-1)
| 147 | 218 | 6,348,800 |
20247363
|
def main():
n = int(input())
matrix = []
s = None
found = False
col = 0
row = 0
if n == 1:
i = input()
return 1
for i in range(n):
line = [int(k) for k in input().split(' ')]
matrix.append(line)
if not found:
try:
index = line.index(0)
row = i
col = index
continue
except ValueError:
pass
if s is None:
s = sum(line)
else:
if s != sum(line):
return -1
res = s - sum(matrix[row])
if res < 1:
return -1
else:
matrix[row][col] = res
for i in range(n):
t = 0
for j in range(n):
t += matrix[j][i]
if t != s:
return -1
d1 = 0
d2 = 0
for i in range(n):
d1 += matrix[i][i]
d2 += matrix[i][n-1-i]
if d1 != s or d2 != s:
return -1
return res
if __name__ == "__main__":
print(main())
|
Codeforces Round 369 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Chris and Magic Square
|
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid.
n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead.
If there are multiple solutions, you may print any of them.
| null |
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
| 1,400 |
["constructive algorithms", "implementation"]
| 147 |
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
757/A
|
757
|
A
|
PyPy 3
|
TESTS
| 75 | 140 | 512,000 |
91686808
|
st = input()
B = st.count("B") # 1
u = st.count("u") # 2
l = st.count("l") # 1
b = st.count("b") # 1
a = st.count("a") # 2
r = st.count("r") # 1
s = st.count("s") # 1
print(int(min(2*B,u,2*b,a,2*r,s*2)/2))
| 107 | 62 | 0 |
183823124
|
s = input()
c = [s.count(x) for x in "Bulbasur"]
c[1] //= 2
c[4] //= 2
print(min(c))
|
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
|
CF
| 2,017 | 1 | 256 |
Gotta Catch Em' All!
|
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
|
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.
The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
|
Output a single integer, the answer to the problem.
| null |
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
|
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
| 1,000 |
["implementation"]
| 107 |
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr\r\n", "output": "10\r\n"}, {"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\r\n", "output": "20\r\n"}, {"input": "CeSlSwec\r\n", "output": "0\r\n"}, {"input": "PnMrWPBGzVcmRcO\r\n", "output": "0\r\n"}, {"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC\r\n", "output": "6\r\n"}, {"input": "bulsar\r\n", "output": "0\r\n"}, {"input": "Bblsar\r\n", "output": "0\r\n"}, {"input": "Bbusar\r\n", "output": "0\r\n"}, {"input": "Bbular\r\n", "output": "0\r\n"}, {"input": "Bbulsr\r\n", "output": "0\r\n"}, {"input": "Bbulsa\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "Bbulsar\r\n", "output": "0\r\n"}, {"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh\r\n", "output": "2\r\n"}, {"input": "Bulbasaur\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasaur\r\n", "output": "2\r\n"}, {"input": "Bulbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasur\r\n", "output": "0\r\n"}, {"input": "Bulbsaur\r\n", "output": "0\r\n"}, {"input": "BulbsurBulbsurBulbsurBulbsur\r\n", "output": "0\r\n"}, {"input": "Blbbasar\r\n", "output": "0\r\n"}, {"input": "Bulbasar\r\n", "output": "0\r\n"}, {"input": "BBullllbbaassaauurr\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbasar\r\n", "output": "1\r\n"}, {"input": "BulbasaurBulbsaur\r\n", "output": "1\r\n"}, {"input": "Bubasaur\r\n", "output": "0\r\n"}, {"input": "ulbasaurulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbasr\r\n", "output": "0\r\n"}, {"input": "BBBuuulllbbbaaasssaaauuurrr\r\n", "output": "3\r\n"}, {"input": "BBuuuullbbaaaassrr\r\n", "output": "2\r\n"}, {"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr\r\n", "output": "4\r\n"}, {"input": "BBuullbbaassaarr\r\n", "output": "1\r\n"}, {"input": "Bulbasau\r\n", "output": "0\r\n"}, {"input": "BBuullbbaassaauurr\r\n", "output": "2\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "Blbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasaurd\r\n", "output": "2\r\n"}, {"input": "ulbasaur\r\n", "output": "0\r\n"}, {"input": "Bulbaaur\r\n", "output": "0\r\n"}, {"input": "BBuuuullbbbbbbbbbbbbbbbaassrr\r\n", "output": "1\r\n"}, {"input": "Bulbasua\r\n", "output": "0\r\n"}, {"input": "Bubbasaur\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr\r\n", "output": "3\r\n"}, {"input": "BulbasaurBubasaur\r\n", "output": "1\r\n"}, {"input": "Baab\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasau\r\n", "output": "1\r\n"}, {"input": "Bulbasauu\r\n", "output": "0\r\n"}, {"input": "BulbasauBulbasau\r\n", "output": "0\r\n"}, {"input": "BBBBBBBBBBB\r\n", "output": "0\r\n"}, {"input": "Bulbbasau\r\n", "output": "0\r\n"}, {"input": "BulbbasaurBulbbasar\r\n", "output": "1\r\n"}, {"input": "Bulaaaasaur\r\n", "output": "0\r\n"}, {"input": "BulbasaurBulbasauBulbasauBulbasau\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
419/A
|
420
|
A
|
Python 3
|
TESTS
| 28 | 62 | 716,800 |
173334285
|
import re
regex = re.compile('[B|C|D|E|F|G|J|K|L|N|P|Q|R|S|Z]')
s = input()
if regex.match(s):
print("NO")
else:
length = len(s)
middle = length // 2
if length % 2 == 0:
left = s[0:middle]
right = s[middle:length][::-1]
if s[0:middle] == s[middle:length][::-1]:
print("YES")
else:
print("NO")
elif s[0:middle] == s[middle + 1:length][::-1]:
print("YES")
else:
print("NO")
| 80 | 46 | 0 |
179761557
|
#Ana Clara Lacaze
#193858
name = input()
mirrorLetters = ['A','H','I','M','O','T','U','V','W','X','Y']
isMirror = True
for letter in name:
if letter not in mirrorLetters:
isMirror = False
break
if isMirror and name==name[::-1]:
print("YES")
else:
print("NO")
|
Coder-Strike 2014 - Finals
|
CF
| 2,014 | 1 | 256 |
Start Up
|
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
|
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
| null | null |
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
| 1,000 |
[]
| 80 |
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\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.