contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
689
B
Mike and Shortcuts
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "greedy", "shortest paths" ]
null
null
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*).
In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*.
[ "3\n2 2 3\n", "5\n1 2 3 4 5\n", "7\n4 4 4 4 7 7 7\n" ]
[ "0 1 2 \n", "0 1 2 3 4 \n", "0 1 2 1 2 3 3 \n" ]
In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
1,000
[ { "input": "3\n2 2 3", "output": "0 1 2 " }, { "input": "5\n1 2 3 4 5", "output": "0 1 2 3 4 " }, { "input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3 " }, { "input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 90 90 90 90 90 90 90 90 90 90 90 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 95 95 95 95 95 97 98 98", "output": "0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 4 4 5 6 5 6 7 8 " }, { "input": "91\n4 6 23 23 23 23 23 28 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 47 47 47 54 54 54 54 54 54 54 58 58 58 58 58 58 69 69 69 69 69 69 69 69 69 69 69 69 70 70 70 70 70 70 70 70 70 70 71 72 72 72 73 75 77 77 77 82 82 84 84 84 84 84 85 86 87 89 89 90 91", "output": "0 1 2 1 2 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 3 4 5 6 5 6 7 8 9 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 10 9 8 7 6 5 4 5 6 7 6 7 8 9 10 11 10 9 8 7 6 5 6 6 7 8 9 10 11 11 12 13 14 14 13 14 14 15 16 17 18 19 20 21 " }, { "input": "82\n1 5 11 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 39 39 39 39 39 45 45 45 45 45 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 69 71 71 71 71 71 71 71 73 73 75 75 76 77 79 81 81 81 82", "output": "0 1 2 3 2 3 4 5 5 4 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 4 5 6 7 8 9 10 9 9 8 7 6 5 4 5 6 7 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 6 6 7 8 9 10 11 12 13 14 15 15 16 " }, { "input": "4\n2 3 3 4", "output": "0 1 2 3 " } ]
1,620,854,223
2,147,483,647
Python 3
OK
TESTS
54
561
35,328,000
def bfs(): while len(fila) > 0: atual = fila.pop(0) if atual < n and e[atual + 1] > e[atual] + 1: e[atual+1]=e[atual]+1 fila.append(atual + 1) if atual > 1 and e[atual - 1] > e[atual]+1: e[atual - 1] = e[atual] + 1 fila.append(atual - 1) if e[ cruzamentos[atual] ] > e[atual] + 1: e[cruzamentos[atual]] = e[atual]+1 fila.append(cruzamentos[atual]) n = int(input()) entrada = input().split() cruzamentos = [0] + [int(x) for x in entrada] e = [float('inf') for x in range( n + 1 )] e[1] = 0 fila=[1] bfs() print(' '.join(str(i) for i in e[1:]))
Title: Mike and Shortcuts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*). Output Specification: In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. Demo Input: ['3\n2 2 3\n', '5\n1 2 3 4 5\n', '7\n4 4 4 4 7 7 7\n'] Demo Output: ['0 1 2 \n', '0 1 2 3 4 \n', '0 1 2 1 2 3 3 \n'] Note: In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
```python def bfs(): while len(fila) > 0: atual = fila.pop(0) if atual < n and e[atual + 1] > e[atual] + 1: e[atual+1]=e[atual]+1 fila.append(atual + 1) if atual > 1 and e[atual - 1] > e[atual]+1: e[atual - 1] = e[atual] + 1 fila.append(atual - 1) if e[ cruzamentos[atual] ] > e[atual] + 1: e[cruzamentos[atual]] = e[atual]+1 fila.append(cruzamentos[atual]) n = int(input()) entrada = input().split() cruzamentos = [0] + [int(x) for x in entrada] e = [float('inf') for x in range( n + 1 )] e[1] = 0 fila=[1] bfs() print(' '.join(str(i) for i in e[1:])) ```
3
505
B
Mr. Kitayuta's Colorful Graph
PROGRAMMING
1,400
[ "dfs and similar", "dp", "dsu", "graphs" ]
null
null
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
For each query, print the answer in a separate line.
[ "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n" ]
[ "2\n1\n0\n", "1\n1\n1\n1\n2\n" ]
Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
1,000
[ { "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0" }, { "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4", "output": "1\n1\n1\n1\n2" }, { "input": "2 1\n1 2 1\n1\n1 2", "output": "1" }, { "input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2", "output": "3" }, { "input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2", "output": "5" } ]
1,633,086,268
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
186
27,750,400
import os import sys from io import BytesIO, IOBase import math as mt import itertools as it import operator as op import bisect as bs import heapq as hp from functools import reduce from io import BytesIO, IOBase import pprint import logging from logging import getLogger import array from collections import deque, defaultdict, OrderedDict, Counter, ChainMap, _chain maxx, localsys, mod = 1 << 60, 0, int(1e9 + 7) def nCr(n, r): return reduce(op.mul, range(n - r + 1, n + 1), 1) // mt.factorial(r) def ceil(a, b): return (a + b - 1) // b def lcm(a, b): return a * b // mt.gcd(a, b) gcdm = lambda *args: reduce(mt.gcd, args, 0) def lcm(a, b): return a * b // mt.gcd(a, b) lcmm = lambda *args: reduce(lcm, args, 1) logging.basicConfig( format="%(message)s", level=logging.WARNING, ) logger = getLogger(__name__) logger.setLevel(logging.INFO) def debug(msg, *args): logger.info(f'{msg}={pprint.pformat(args)}') _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() 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) def input(): return sys.stdin.readline().rstrip("\r\n") # end region def maps(): return map(int, input().split()) # THINK ABOUT THE EDGE CASES .......... # DON'T SUBMIT UNLESS YOU ARE ABSOLUTELY SURE !!!!! class DisjointSetUnion: def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n self.numsets = n def find(self, x): xcopy = x while self.parent[x] != x: x = self.parent[x] while xcopy != x: xcopy, self.parent[xcopy] = self.parent[xcopy], x return x def union(self, x, y): a, b = self.find(x), self.find(y) if a != b: if self.size[a] < self.size[b]: a, b = b, a self.size[a] += self.size[b] # sz.a > sz.b self.parent[b] = a self.numsets -= 1 def get_size(self, x): return self.size[self.find(x)] def __len__(self, x): # number of components return self.numsets def solve(): n, m = maps() gr = [[] for _ in range(n + 1)] for _ in range(m): u, v, ci = maps() gr[u].append(ci) gr[v].append(ci) q, = maps() while q: q -= 1 u, v = maps() x = set(gr[u]).intersection(gr[v]) print(len(x)) solve()
Title: Mr. Kitayuta's Colorful Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you to process the following *q* queries. In the *i*-th query, he gives you two integers — *u**i* and *v**i*. Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. Input Specification: The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively. The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*). The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries. Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. Output Specification: For each query, print the answer in a separate line. Demo Input: ['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n'] Demo Output: ['2\n1\n0\n', '1\n1\n1\n1\n2\n'] Note: Let's consider the first sample. - Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color.
```python import os import sys from io import BytesIO, IOBase import math as mt import itertools as it import operator as op import bisect as bs import heapq as hp from functools import reduce from io import BytesIO, IOBase import pprint import logging from logging import getLogger import array from collections import deque, defaultdict, OrderedDict, Counter, ChainMap, _chain maxx, localsys, mod = 1 << 60, 0, int(1e9 + 7) def nCr(n, r): return reduce(op.mul, range(n - r + 1, n + 1), 1) // mt.factorial(r) def ceil(a, b): return (a + b - 1) // b def lcm(a, b): return a * b // mt.gcd(a, b) gcdm = lambda *args: reduce(mt.gcd, args, 0) def lcm(a, b): return a * b // mt.gcd(a, b) lcmm = lambda *args: reduce(lcm, args, 1) logging.basicConfig( format="%(message)s", level=logging.WARNING, ) logger = getLogger(__name__) logger.setLevel(logging.INFO) def debug(msg, *args): logger.info(f'{msg}={pprint.pformat(args)}') _str = str str = lambda x=b"": x if type(x) is bytes else _str(x).encode() 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) def input(): return sys.stdin.readline().rstrip("\r\n") # end region def maps(): return map(int, input().split()) # THINK ABOUT THE EDGE CASES .......... # DON'T SUBMIT UNLESS YOU ARE ABSOLUTELY SURE !!!!! class DisjointSetUnion: def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n self.numsets = n def find(self, x): xcopy = x while self.parent[x] != x: x = self.parent[x] while xcopy != x: xcopy, self.parent[xcopy] = self.parent[xcopy], x return x def union(self, x, y): a, b = self.find(x), self.find(y) if a != b: if self.size[a] < self.size[b]: a, b = b, a self.size[a] += self.size[b] # sz.a > sz.b self.parent[b] = a self.numsets -= 1 def get_size(self, x): return self.size[self.find(x)] def __len__(self, x): # number of components return self.numsets def solve(): n, m = maps() gr = [[] for _ in range(n + 1)] for _ in range(m): u, v, ci = maps() gr[u].append(ci) gr[v].append(ci) q, = maps() while q: q -= 1 u, v = maps() x = set(gr[u]).intersection(gr[v]) print(len(x)) solve() ```
0
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
1,558,768,459
2,147,483,647
PyPy 3
OK
TESTS
46
140
0
n, m = map(int, input().split()) ans = 0 while n > 0 and m > 0: ans += n//m n, m = m, n % m print(ans)
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python n, m = map(int, input().split()) ans = 0 while n > 0 and m > 0: ans += n//m n, m = m, n % m print(ans) ```
3
939
A
Love Triangle
PROGRAMMING
800
[ "graphs" ]
null
null
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.
[ "5\n2 4 5 1 3\n", "5\n5 5 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
500
[ { "input": "5\n2 4 5 1 3", "output": "YES" }, { "input": "5\n5 5 5 5 1", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "10\n4 10 9 5 3 1 5 10 6 4", "output": "NO" }, { "input": "10\n5 5 4 9 10 9 9 5 3 1", "output": "YES" }, { "input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43", "output": "NO" }, { "input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50", "output": "YES" }, { "input": "2\n2 1", "output": "NO" }, { "input": "3\n2 3 1", "output": "YES" }, { "input": "5\n2 1 4 5 3", "output": "YES" }, { "input": "5\n5 4 5 5 2", "output": "YES" } ]
1,676,531,571
2,147,483,647
Python 3
OK
TESTS
16
31
102,400
n = int(input()) planes = dict(enumerate([int(i) for i in input().split()], start=1)) for p in planes: if planes[p] != p and planes[planes[planes[p]]] == p: print('YES') break else: print('NO')
Title: Love Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. Output Specification: Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Demo Input: ['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
```python n = int(input()) planes = dict(enumerate([int(i) for i in input().split()], start=1)) for p in planes: if planes[p] != p and planes[planes[planes[p]]] == p: print('YES') break else: print('NO') ```
3
349
A
Cinema Line
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "input": "10\n50 50 50 50 50 50 50 50 50 50", "output": "NO" }, { "input": "10\n100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "7\n25 25 25 25 50 100 50", "output": "YES" }, { "input": "2\n25 25", "output": "YES" }, { "input": "3\n50 100 100", "output": "NO" }, { "input": "3\n25 50 50", "output": "NO" }, { "input": "2\n50 25", "output": "NO" }, { "input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100", "output": "NO" }, { "input": "5\n25 25 25 100 100", "output": "NO" }, { "input": "7\n25 50 25 50 25 50 100", "output": "NO" }, { "input": "5\n25 50 25 50 100", "output": "NO" }, { "input": "5\n25 25 50 50 50", "output": "NO" }, { "input": "5\n25 25 50 100 50", "output": "NO" }, { "input": "5\n25 25 50 50 100", "output": "NO" }, { "input": "1\n50", "output": "NO" } ]
1,673,273,825
2,147,483,647
Python 3
OK
TESTS
40
186
5,324,800
n = int(input()) l_r = list(map(int, input().split())) l_b = list([0, 0, 0]) for r in l_r: if r == 100: l_b[0] += 1 if l_b[1] > 0: l_b[1] -= 1 l_b[2] -= 1 else: l_b[2] -= 3 elif r == 50: l_b[1] += 1 l_b[2] -= 1 else: l_b[2] += 1 if l_b[1] < 0 or l_b[2] < 0: print("NO") quit() print("YES")
Title: Cinema Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. Output Specification: Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Demo Input: ['4\n25 25 50 50\n', '2\n25 100\n', '4\n50 50 25 25\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python n = int(input()) l_r = list(map(int, input().split())) l_b = list([0, 0, 0]) for r in l_r: if r == 100: l_b[0] += 1 if l_b[1] > 0: l_b[1] -= 1 l_b[2] -= 1 else: l_b[2] -= 3 elif r == 50: l_b[1] += 1 l_b[2] -= 1 else: l_b[2] += 1 if l_b[1] < 0 or l_b[2] < 0: print("NO") quit() print("YES") ```
3
70
A
Cookies
PROGRAMMING
1,300
[ "math" ]
A. Cookies
1
256
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=×<=2*n*, divided into blocks 1<=×<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure: To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end.
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000).
Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3.
[ "3\n" ]
[ "9" ]
If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner:
500
[ { "input": "3", "output": "9" }, { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "4", "output": "27" }, { "input": "6", "output": "243" }, { "input": "11", "output": "59049" }, { "input": "14", "output": "594320" }, { "input": "15", "output": "782957" }, { "input": "7", "output": "729" }, { "input": "0", "output": "1" }, { "input": "1000", "output": "691074" }, { "input": "657", "output": "874011" }, { "input": "561", "output": "842553" }, { "input": "823", "output": "858672" }, { "input": "850", "output": "557186" }, { "input": "298", "output": "999535" }, { "input": "262", "output": "946384" }, { "input": "910", "output": "678945" }, { "input": "617", "output": "247876" }, { "input": "857", "output": "562128" }, { "input": "69", "output": "327984" }, { "input": "589", "output": "889192" }, { "input": "928", "output": "794863" }, { "input": "696", "output": "695035" }, { "input": "226", "output": "376094" } ]
1,476,934,129
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
9
77
4,608,000
print(pow(3,int(input())-1,1000003))
Title: Cookies Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=×<=2*n*, divided into blocks 1<=×<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure: To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end. Input Specification: The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). Output Specification: Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. Demo Input: ['3\n'] Demo Output: ['9'] Note: If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner:
```python print(pow(3,int(input())-1,1000003)) ```
-1
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,610,957,822
2,147,483,647
PyPy 3
OK
TESTS
32
186
0
n=int(input()) l=list(map(int, input().split())) co=0 ce=0 col=[] cel=[] for i in l: if(i%2==0): ce+=1 cel.append(i) else: co+=1 col.append(i) if(ce==1): print(l.index(cel[0])+1) else: print(l.index(col[0])+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) l=list(map(int, input().split())) co=0 ce=0 col=[] cel=[] for i in l: if(i%2==0): ce+=1 cel.append(i) else: co+=1 col.append(i) if(ce==1): print(l.index(cel[0])+1) else: print(l.index(col[0])+1) ```
3.9535
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100", "output": "10" }, { "input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9", "output": "4" }, { "input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54", "output": "12" }, { "input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68", "output": "10" }, { "input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30", "output": "8" }, { "input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14", "output": "7" }, { "input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28", "output": "22" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2", "output": "0" }, { "input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2", "output": "68" }, { "input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8", "output": "5" }, { "input": "1\n0 0", "output": "0" }, { "input": "1\n100 100", "output": "0" }, { "input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73", "output": "42" }, { "input": "3\n1 3\n2 7\n8 9", "output": "2" }, { "input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53", "output": "0" }, { "input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54", "output": "0" }, { "input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60", "output": "12" }, { "input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3", "output": "8" } ]
1,689,977,943
2,147,483,647
PyPy 3-64
OK
TESTS
27
62
0
num = int(input()) count = 0 for i in range(num): entrada = list(map(int, input().split())) if abs(entrada[0] - entrada[1]) >= 2: count += 1 print(count)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. Output Specification: Print a single integer — the number of rooms where George and Alex can move in. Demo Input: ['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n'] Demo Output: ['0\n', '2\n'] Note: none
```python num = int(input()) count = 0 for i in range(num): entrada = list(map(int, input().split())) if abs(entrada[0] - entrada[1]) >= 2: count += 1 print(count) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,693,453,688
2,147,483,647
Python 3
OK
TESTS
20
31
0
number=input() i=1 while i <= int(number): word=input() length=len(word)-2 if len(word) <= 10: print(word) else: print(word[0]+str(length)+word[-1]) i += 1
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python number=input() i=1 while i <= int(number): word=input() length=len(word)-2 if len(word) <= 10: print(word) else: print(word[0]+str(length)+word[-1]) i += 1 ```
3.9845
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,596,395,771
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
124
20,172,800
n, m = map(int, input().split()) seq1 = list(map(int,input().split())) seq2 = list(map(int,input().split())) if max(seq1) > 0: seq1.remove(max(seq1)) else: seq1.remove(min(seq1)) print(max(seq1)*max(seq2))
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python n, m = map(int, input().split()) seq1 = list(map(int,input().split())) seq2 = list(map(int,input().split())) if max(seq1) > 0: seq1.remove(max(seq1)) else: seq1.remove(min(seq1)) print(max(seq1)*max(seq2)) ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,679,615,022
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
num = int(input()) quo7 = num/7 rest7 = num%7 quo4 = num/4 rest4 = num%4 if rest7 == 0: print("7" * quo7) elif rest4 == 0: print("4" * quo4) elif rest7 == rest4 == 0: print("7" * quo7 + "4" * quo4) elif rest7 > rest4: print("7" * (quo7 - 1) + "4" * (quo4 + 2)) elif rest4 > rest7: print("7" * (quo7 + 2) + "4" * (quo4 - 1)) else: print(-1)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python num = int(input()) quo7 = num/7 rest7 = num%7 quo4 = num/4 rest4 = num%4 if rest7 == 0: print("7" * quo7) elif rest4 == 0: print("4" * quo4) elif rest7 == rest4 == 0: print("7" * quo7 + "4" * quo4) elif rest7 > rest4: print("7" * (quo7 - 1) + "4" * (quo4 + 2)) elif rest4 > rest7: print("7" * (quo7 + 2) + "4" * (quo4 - 1)) else: print(-1) ```
-1
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,592,937,337
2,147,483,647
PyPy 3
OK
TESTS
51
1,746
27,955,200
x=int(input()) ans=0 while len(str(x))>1: curSum=0 for a in str(x): curSum+=int(a) x=curSum ans+=1 print(ans)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python x=int(input()) ans=0 while len(str(x))>1: curSum=0 for a in str(x): curSum+=int(a) x=curSum ans+=1 print(ans) ```
3.513198
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,680,749,100
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
x = "helo" hello = ["h", "e", "l", "l", "o"] for i in x: if i == hello[0]: hello.pop(0) if len(hello) != 0: print("no") else: print("yes")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python x = "helo" hello = ["h", "e", "l", "l", "o"] for i in x: if i == hello[0]: hello.pop(0) if len(hello) != 0: print("no") else: print("yes") ```
0
922
C
Cave Painting
PROGRAMMING
1,600
[ "brute force", "number theory" ]
null
null
Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that: - 1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*.
The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018).
Print "Yes", if all the remainders are distinct, and "No" otherwise. You can print each letter in arbitrary case (lower or upper).
[ "4 4\n", "5 3\n" ]
[ "No\n", "Yes\n" ]
In the first sample remainders modulo 1 and 4 coincide.
1,250
[ { "input": "4 4", "output": "No" }, { "input": "5 3", "output": "Yes" }, { "input": "1 1", "output": "Yes" }, { "input": "744 18", "output": "No" }, { "input": "47879 10", "output": "Yes" }, { "input": "1000000000000000000 1000000000000000000", "output": "No" }, { "input": "657180569218773599 42", "output": "Yes" }, { "input": "442762254977842799 30", "output": "Yes" }, { "input": "474158606260730555 1", "output": "Yes" }, { "input": "807873101233533988 39", "output": "No" }, { "input": "423 7", "output": "No" }, { "input": "264306177888923090 5", "output": "No" }, { "input": "998857801526481788 87", "output": "No" }, { "input": "999684044704565212 28", "output": "No" }, { "input": "319575605003866172 71", "output": "No" }, { "input": "755804560577415016 17", "output": "No" }, { "input": "72712630136142067 356370939", "output": "No" }, { "input": "807264258068668062 33080422", "output": "No" }, { "input": "808090496951784190 311661970", "output": "No" }, { "input": "808916740129867614 180178111", "output": "No" }, { "input": "1 2", "output": "Yes" }, { "input": "2 1", "output": "Yes" }, { "input": "57334064998850639 19", "output": "Yes" }, { "input": "144353716412182199 11", "output": "Yes" }, { "input": "411002215096001759 11", "output": "Yes" }, { "input": "347116374613371527 3", "output": "Yes" }, { "input": "518264351335130399 37", "output": "Yes" }, { "input": "192435891235905239 11", "output": "Yes" }, { "input": "491802505049361659 7", "output": "Yes" }, { "input": "310113769227703889 3", "output": "Yes" }, { "input": "876240758958364799 41", "output": "Yes" }, { "input": "173284263472319999 33", "output": "Yes" }, { "input": "334366426725130799 29", "output": "Yes" }, { "input": "415543470272330399 26", "output": "Yes" }, { "input": "631689521541558479 22", "output": "Yes" }, { "input": "581859366558790319 14", "output": "Yes" }, { "input": "224113913709159599 10", "output": "Yes" }, { "input": "740368848764104559 21", "output": "Yes" }, { "input": "895803074828822159 17", "output": "Yes" }, { "input": "400349974997012039 13", "output": "Yes" }, { "input": "205439024252247599 5", "output": "Yes" }, { "input": "197688463911338399 39", "output": "Yes" }, { "input": "283175367224349599 39", "output": "Yes" }, { "input": "893208176423362799 31", "output": "Yes" }, { "input": "440681012669897999 27", "output": "Yes" }, { "input": "947403664618451039 19", "output": "Yes" }, { "input": "232435556779345919 19", "output": "Yes" }, { "input": "504428493840551279 23", "output": "Yes" }, { "input": "30019549241681999 20", "output": "Yes" }, { "input": "648000813924303839 16", "output": "Yes" }, { "input": "763169499725761451 488954176053755860", "output": "No" }, { "input": "199398459594277592 452260924647536414", "output": "No" }, { "input": "635627415167826436 192195636386541160", "output": "No" }, { "input": "71856370741375281 155502380685354417", "output": "No" }, { "input": "731457367464667229 118809129279134971", "output": "No" }, { "input": "167686318743248777 858743836723172421", "output": "No" }, { "input": "603915274316797622 822050585316952974", "output": "No" }, { "input": "647896534275160623 65689274138731296", "output": "No" }, { "input": "648722777453244047 501918229712280140", "output": "No" }, { "input": "649549020631327471 41923378183538525", "output": "No" }, { "input": "650375259514443599 597748177714153637", "output": "No" }, { "input": "651201506987494319 33977137582669778", "output": "No" }, { "input": "652027745870610447 470206093156218622", "output": "No" }, { "input": "652853989048693871 906435048729767466", "output": "No" }, { "input": "653680227931809999 342664004303316311", "output": "No" }, { "input": "654506475404860719 375019787446735639", "output": "No" }, { "input": "655332714287976847 438493956600157103", "output": "No" }, { "input": "166512305365727033 900267947832156186", "output": "No" }, { "input": "167338548543810457 336496907700672326", "output": "No" }, { "input": "168164787426926585 772725863274221171", "output": "No" }, { "input": "523 3", "output": "No" }, { "input": "39211 6", "output": "No" }, { "input": "22151 9", "output": "No" }, { "input": "1 3", "output": "No" }, { "input": "47 5", "output": "No" }, { "input": "999999998999999999 1000000000", "output": "No" }, { "input": "11 6", "output": "No" }, { "input": "7 4", "output": "No" }, { "input": "1 10", "output": "No" }, { "input": "9 5", "output": "No" }, { "input": "2519 20", "output": "No" }, { "input": "700001 3", "output": "Yes" }, { "input": "13 7", "output": "No" }, { "input": "999999 10000", "output": "No" }, { "input": "1 4", "output": "No" }, { "input": "232792559 30", "output": "No" }, { "input": "1 5", "output": "No" }, { "input": "5 4", "output": "No" }, { "input": "5 8", "output": "No" }, { "input": "55 4", "output": "No" } ]
1,600,336,222
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
81,510,400
n,k=[int(n) for n in input().split()] s=set() for i in range(1,k+1): s.add(n%i) if(len(s)==k): print("Yes") else: print("No")
Title: Cave Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that: - 1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*. Input Specification: The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). Output Specification: Print "Yes", if all the remainders are distinct, and "No" otherwise. You can print each letter in arbitrary case (lower or upper). Demo Input: ['4 4\n', '5 3\n'] Demo Output: ['No\n', 'Yes\n'] Note: In the first sample remainders modulo 1 and 4 coincide.
```python n,k=[int(n) for n in input().split()] s=set() for i in range(1,k+1): s.add(n%i) if(len(s)==k): print("Yes") else: print("No") ```
0
868
B
Race Against Time
PROGRAMMING
1,400
[ "implementation" ]
null
null
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds. Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand.
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "12 30 45 3 11\n", "12 0 1 12 1\n", "3 47 0 4 9\n" ]
[ "NO\n", "YES\n", "YES\n" ]
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
500
[ { "input": "12 30 45 3 11", "output": "NO" }, { "input": "12 0 1 12 1", "output": "YES" }, { "input": "3 47 0 4 9", "output": "YES" }, { "input": "10 22 59 6 10", "output": "YES" }, { "input": "3 1 13 12 3", "output": "NO" }, { "input": "11 19 28 9 10", "output": "YES" }, { "input": "9 38 22 6 1", "output": "NO" }, { "input": "5 41 11 5 8", "output": "NO" }, { "input": "11 2 53 10 4", "output": "YES" }, { "input": "9 41 17 10 1", "output": "YES" }, { "input": "6 54 48 12 6", "output": "YES" }, { "input": "12 55 9 5 1", "output": "NO" }, { "input": "8 55 35 9 3", "output": "NO" }, { "input": "3 21 34 3 10", "output": "YES" }, { "input": "2 52 1 12 3", "output": "NO" }, { "input": "7 17 11 1 7", "output": "NO" }, { "input": "11 6 37 6 4", "output": "YES" }, { "input": "9 6 22 8 1", "output": "NO" }, { "input": "3 10 5 5 9", "output": "YES" }, { "input": "7 12 22 11 2", "output": "YES" }, { "input": "7 19 4 7 3", "output": "NO" }, { "input": "11 36 21 4 6", "output": "NO" }, { "input": "10 32 49 1 3", "output": "YES" }, { "input": "1 9 43 11 3", "output": "NO" }, { "input": "1 8 33 4 8", "output": "NO" }, { "input": "3 0 33 9 4", "output": "NO" }, { "input": "7 15 9 10 3", "output": "NO" }, { "input": "8 3 57 11 1", "output": "NO" }, { "input": "1 33 49 5 9", "output": "NO" }, { "input": "3 40 0 5 7", "output": "YES" }, { "input": "5 50 9 2 7", "output": "NO" }, { "input": "10 0 52 6 1", "output": "YES" }, { "input": "3 10 4 1 11", "output": "NO" }, { "input": "2 41 53 4 6", "output": "YES" }, { "input": "10 29 30 4 7", "output": "NO" }, { "input": "5 13 54 9 11", "output": "NO" }, { "input": "1 0 23 3 9", "output": "NO" }, { "input": "1 0 41 12 1", "output": "NO" }, { "input": "6 30 30 3 9", "output": "YES" }, { "input": "3 7 32 11 10", "output": "YES" }, { "input": "1 0 25 12 4", "output": "NO" }, { "input": "12 0 0 5 6", "output": "YES" }, { "input": "1 5 4 3 2", "output": "YES" }, { "input": "6 30 30 9 10", "output": "YES" }, { "input": "6 0 0 2 8", "output": "NO" }, { "input": "10 50 59 9 10", "output": "YES" }, { "input": "12 59 59 12 6", "output": "NO" }, { "input": "3 0 30 3 4", "output": "NO" }, { "input": "2 10 10 1 11", "output": "YES" }, { "input": "10 5 30 1 12", "output": "YES" }, { "input": "5 29 31 5 10", "output": "YES" }, { "input": "5 2 2 11 2", "output": "NO" }, { "input": "5 15 46 3 10", "output": "YES" }, { "input": "1 30 50 1 2", "output": "NO" }, { "input": "5 26 14 1 12", "output": "YES" }, { "input": "1 58 43 12 1", "output": "YES" }, { "input": "12 0 12 11 1", "output": "NO" }, { "input": "6 52 41 6 5", "output": "YES" }, { "input": "5 8 2 1 3", "output": "NO" }, { "input": "2 0 0 1 3", "output": "NO" }, { "input": "1 5 6 2 1", "output": "YES" }, { "input": "9 5 5 11 12", "output": "YES" }, { "input": "12 5 19 3 4", "output": "NO" }, { "input": "6 14 59 1 3", "output": "NO" }, { "input": "10 38 34 4 12", "output": "YES" }, { "input": "2 54 14 2 12", "output": "YES" }, { "input": "5 31 0 6 7", "output": "NO" }, { "input": "6 15 30 3 9", "output": "YES" }, { "input": "3 54 41 8 10", "output": "NO" }, { "input": "3 39 10 10 12", "output": "YES" }, { "input": "1 11 50 1 2", "output": "NO" }, { "input": "5 40 24 8 1", "output": "NO" }, { "input": "9 5 59 1 3", "output": "NO" }, { "input": "5 0 0 6 7", "output": "YES" }, { "input": "4 40 59 6 8", "output": "YES" }, { "input": "10 13 55 12 1", "output": "YES" }, { "input": "6 50 0 5 6", "output": "YES" }, { "input": "7 59 3 7 4", "output": "YES" }, { "input": "6 0 1 6 7", "output": "NO" }, { "input": "6 15 55 3 5", "output": "NO" }, { "input": "12 9 55 10 2", "output": "YES" }, { "input": "2 0 1 11 2", "output": "NO" }, { "input": "8 45 17 12 9", "output": "NO" }, { "input": "5 30 31 11 3", "output": "YES" }, { "input": "6 43 0 10 6", "output": "NO" }, { "input": "6 30 30 1 11", "output": "YES" }, { "input": "11 59 59 11 12", "output": "YES" }, { "input": "5 45 35 9 5", "output": "NO" }, { "input": "2 43 4 9 7", "output": "NO" }, { "input": "12 30 50 6 9", "output": "NO" }, { "input": "1 10 1 2 3", "output": "NO" }, { "input": "10 5 55 9 1", "output": "NO" }, { "input": "1 59 59 2 3", "output": "YES" }, { "input": "1 49 14 10 3", "output": "NO" }, { "input": "3 15 15 2 4", "output": "YES" }, { "input": "10 5 55 1 5", "output": "NO" }, { "input": "6 33 45 12 6", "output": "YES" }, { "input": "1 20 20 11 1", "output": "YES" }, { "input": "2 30 45 1 11", "output": "YES" }, { "input": "1 55 1 11 10", "output": "YES" }, { "input": "3 0 1 11 1", "output": "NO" }, { "input": "1 5 6 1 12", "output": "YES" }, { "input": "12 10 5 11 4", "output": "YES" }, { "input": "6 5 59 12 1", "output": "YES" }, { "input": "12 0 20 11 12", "output": "YES" }, { "input": "3 25 30 4 5", "output": "YES" }, { "input": "2 15 18 11 1", "output": "YES" }, { "input": "12 5 48 11 9", "output": "NO" }, { "input": "6 30 30 10 2", "output": "YES" }, { "input": "1 0 11 1 2", "output": "NO" }, { "input": "10 0 1 10 11", "output": "NO" }, { "input": "3 30 45 10 1", "output": "YES" }, { "input": "11 21 56 3 12", "output": "YES" }, { "input": "3 16 16 3 4", "output": "YES" }, { "input": "11 55 55 1 12", "output": "YES" }, { "input": "12 12 12 11 12", "output": "YES" }, { "input": "3 5 1 1 2", "output": "NO" }, { "input": "3 30 45 10 11", "output": "YES" }, { "input": "10 0 1 9 10", "output": "YES" }, { "input": "3 0 5 3 6", "output": "NO" }, { "input": "1 1 49 1 10", "output": "NO" }, { "input": "9 45 15 11 12", "output": "YES" }, { "input": "12 15 59 3 8", "output": "NO" }, { "input": "5 0 5 3 6", "output": "NO" }, { "input": "3 30 45 1 2", "output": "YES" }, { "input": "2 10 11 2 4", "output": "YES" }, { "input": "2 10 10 4 3", "output": "YES" }, { "input": "3 30 59 1 2", "output": "YES" }, { "input": "11 59 59 12 11", "output": "YES" }, { "input": "10 25 50 5 6", "output": "NO" }, { "input": "6 30 30 9 3", "output": "YES" }, { "input": "8 14 40 12 3", "output": "NO" }, { "input": "2 10 10 1 6", "output": "YES" } ]
1,507,189,376
2,276
Python 3
WRONG_ANSWER
TESTS
9
62
0
def main(): h, m, s, t1, t2 = map(int, input().split()) m = (m + s / 60) / 5 s = s / 5 h = (h + m / 60) times = [h, m, s] times.sort() if (times[0] < t1 < times[1] and times[0] < t2 < times[1])\ or (times[1] < t1 < times[2] and times[1] < t2 < times[2])\ or (times[2] < t1 < (times[0] + 12) and times[2] < t2 < (times[0] + 12)): print('YES') else: print('NO') if __name__ == '__main__': main()
Title: Race Against Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds. Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. Input Specification: Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2). Misha's position and the target time do not coincide with the position of any hand. Output Specification: Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n'] Note: The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
```python def main(): h, m, s, t1, t2 = map(int, input().split()) m = (m + s / 60) / 5 s = s / 5 h = (h + m / 60) times = [h, m, s] times.sort() if (times[0] < t1 < times[1] and times[0] < t2 < times[1])\ or (times[1] < t1 < times[2] and times[1] < t2 < times[2])\ or (times[2] < t1 < (times[0] + 12) and times[2] < t2 < (times[0] + 12)): print('YES') else: print('NO') if __name__ == '__main__': main() ```
0
675
B
Restoring Painting
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "math" ]
null
null
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Print one integer — the number of distinct valid squares.
[ "2 1 1 1 2\n", "3 3 1 2 3\n" ]
[ "2\n", "6\n" ]
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 1 1 1 2", "output": "2" }, { "input": "3 3 1 2 3", "output": "6" }, { "input": "1 1 1 1 1", "output": "1" }, { "input": "1000 522 575 426 445", "output": "774000" }, { "input": "99000 52853 14347 64237 88869", "output": "1296306000" }, { "input": "100000 2 2 2 2", "output": "10000000000" }, { "input": "2 1 1 2 2", "output": "0" }, { "input": "10 9 10 8 10", "output": "70" }, { "input": "100 19 16 35 83", "output": "1700" }, { "input": "1000 102 583 606 929", "output": "150000" }, { "input": "10000 1816 3333 6908 7766", "output": "4750000" }, { "input": "100000 80015 84290 50777 30497", "output": "1696900000" }, { "input": "100000 64022 49026 55956 88430", "output": "6866200000" }, { "input": "100000 10263 46628 10268 22948", "output": "5095500000" }, { "input": "100000 81311 81584 51625 57276", "output": "4600600000" }, { "input": "100000 77594 3226 21255 8541", "output": "1291800000" }, { "input": "100000 65131 35523 58220 87645", "output": "5478900000" }, { "input": "100000 83958 32567 91083 95317", "output": "3012500000" }, { "input": "100000 36851 54432 21164 85520", "output": "1806300000" }, { "input": "100000 55732 17473 23832 75148", "output": "7422500000" }, { "input": "100000 60789 25296 49585 25237", "output": "4015900000" }, { "input": "100000 92060 77234 58709 36956", "output": "2637100000" }, { "input": "100000 87223 66046 27153 40823", "output": "1470700000" }, { "input": "100000 3809 35468 34556 51158", "output": "5173900000" }, { "input": "100000 35038 37363 95275 88903", "output": "0" }, { "input": "100000 45274 9250 36558 49486", "output": "6848000000" }, { "input": "100000 1 1 1 1", "output": "10000000000" }, { "input": "100000 1 1 1 100000", "output": "100000" }, { "input": "100000 1 1 100000 1", "output": "100000" }, { "input": "100000 1 1 100000 100000", "output": "0" }, { "input": "100000 1 100000 1 1", "output": "100000" }, { "input": "100000 1 100000 1 100000", "output": "0" }, { "input": "100000 1 100000 100000 1", "output": "10000000000" }, { "input": "100000 1 100000 100000 100000", "output": "100000" }, { "input": "100000 100000 1 1 1", "output": "100000" }, { "input": "100000 100000 1 1 100000", "output": "10000000000" }, { "input": "100000 100000 1 100000 1", "output": "0" }, { "input": "100000 100000 1 100000 100000", "output": "100000" }, { "input": "100000 100000 100000 1 1", "output": "0" }, { "input": "100000 100000 100000 1 100000", "output": "100000" }, { "input": "100000 100000 100000 100000 1", "output": "100000" }, { "input": "100000 100000 100000 100000 100000", "output": "10000000000" }, { "input": "3 3 3 1 1", "output": "0" }, { "input": "10 1 2 5 10", "output": "0" }, { "input": "5 1 1 5 5", "output": "0" }, { "input": "4 4 4 1 1", "output": "0" }, { "input": "10 10 10 1 1", "output": "0" }, { "input": "5 5 5 1 1", "output": "0" }, { "input": "100 100 100 1 1", "output": "0" }, { "input": "3 1 1 3 3", "output": "0" }, { "input": "10 2 10 1 10", "output": "0" }, { "input": "7 7 7 1 1", "output": "0" }, { "input": "5 5 3 4 1", "output": "0" }, { "input": "7 1 1 7 7", "output": "0" }, { "input": "100 1 1 100 100", "output": "0" }, { "input": "123 1 2 3 100", "output": "2829" }, { "input": "10 1 1 10 10", "output": "0" }, { "input": "803 525 6 623 8", "output": "0" } ]
1,464,036,891
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Input: n a b c d v a w b x c y d z Sum of all 2x2 square is same as top left 2x2 square """ import sys myInput = sys.stdin.readline().strip().split() n = int(myInput[0]) a = int(myInput[1]) b = int(myInput[2]) c = int(myInput[3]) d = int(myInput[4]) """ a+b+v=c+d+z v-z=c+d-a-b a+b+v=b+d+y v-y = d-a v = 1 ... n v = 1 ... d-a+y ... n v = 1 ... c+d-a-b+z ... n v = 1 ... c-b+w ... n y = c - b + z """ def faster(): v = 0 w = 0 x = 0 y = 0 z = 0 numSolution = 0 for i in range(1, n+1): v = i w = v+a+b-a-c y = v+a+b-b-d z = v+a+b-c-d if (w >= 1 and w <= n and y >= 1 and y <= n and z >= 1 and z <= n): numSolution+=1 return numSolution*n def accurate(): v = 0 w = 0 x = 0 y = 0 z = 0 numSolution = 0 for i in range(1, n+1): for j in range(1, n+1): v = i x = j w = v+x+a+b-a-x-c y = v+x+a+b-b-x-d z = v+x+a+b-x-c-d if (w >= 1 and w <= n and y >= 1 and y <= n and z >= 1 and z <= n): numSolution+=1 return numSolution # print ("Accurate: ", accurate()) # print ("Faster: ", faster()) print str(faster())
Title: Restoring Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. Input Specification: The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. Output Specification: Print one integer — the number of distinct valid squares. Demo Input: ['2 1 1 1 2\n', '3 3 1 2 3\n'] Demo Output: ['2\n', '6\n'] Note: Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python #!/usr/bin/env python # -*- coding: utf-8 -*- """ Input: n a b c d v a w b x c y d z Sum of all 2x2 square is same as top left 2x2 square """ import sys myInput = sys.stdin.readline().strip().split() n = int(myInput[0]) a = int(myInput[1]) b = int(myInput[2]) c = int(myInput[3]) d = int(myInput[4]) """ a+b+v=c+d+z v-z=c+d-a-b a+b+v=b+d+y v-y = d-a v = 1 ... n v = 1 ... d-a+y ... n v = 1 ... c+d-a-b+z ... n v = 1 ... c-b+w ... n y = c - b + z """ def faster(): v = 0 w = 0 x = 0 y = 0 z = 0 numSolution = 0 for i in range(1, n+1): v = i w = v+a+b-a-c y = v+a+b-b-d z = v+a+b-c-d if (w >= 1 and w <= n and y >= 1 and y <= n and z >= 1 and z <= n): numSolution+=1 return numSolution*n def accurate(): v = 0 w = 0 x = 0 y = 0 z = 0 numSolution = 0 for i in range(1, n+1): for j in range(1, n+1): v = i x = j w = v+x+a+b-a-x-c y = v+x+a+b-b-x-d z = v+x+a+b-x-c-d if (w >= 1 and w <= n and y >= 1 and y <= n and z >= 1 and z <= n): numSolution+=1 return numSolution # print ("Accurate: ", accurate()) # print ("Faster: ", faster()) print str(faster()) ```
-1
847
G
University Classes
PROGRAMMING
900
[ "implementation" ]
null
null
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups. Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Print minimum number of rooms needed to hold all groups classes on Monday.
[ "2\n0101010\n1010101\n", "3\n0101011\n0011001\n0110111\n" ]
[ "1\n", "3\n" ]
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
0
[ { "input": "2\n0101010\n1010101", "output": "1" }, { "input": "3\n0101011\n0011001\n0110111", "output": "3" }, { "input": "1\n0111000", "output": "1" }, { "input": "1\n0000000", "output": "0" }, { "input": "1\n1111111", "output": "1" }, { "input": "2\n1000000\n0101000", "output": "1" }, { "input": "3\n0101111\n1101011\n1010011", "output": "3" }, { "input": "5\n0100101\n0000001\n0110000\n0010000\n0011110", "output": "3" }, { "input": "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100", "output": "6" }, { "input": "10\n0000000\n0010000\n0000000\n0000010\n0000000\n0100001\n1000000\n0000000\n0000000\n0000000", "output": "1" }, { "input": "20\n1111111\n1101011\n1111011\n0111111\n1111111\n1110111\n1111111\n1111111\n1111111\n1111111\n1110111\n1111111\n0111111\n1011111\n1111111\n1111111\n1101110\n1111111\n1111111\n1111111", "output": "20" } ]
1,680,878,479
2,147,483,647
Python 3
OK
TESTS
21
46
0
N = int(input()) ans = 7*[0] for i in range(N): vals = input() for i in range(7): ans[i]+=int(vals[i]) print(max(ans))
Title: University Classes Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups. Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot. Output Specification: Print minimum number of rooms needed to hold all groups classes on Monday. Demo Input: ['2\n0101010\n1010101\n', '3\n0101011\n0011001\n0110111\n'] Demo Output: ['1\n', '3\n'] Note: In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group. In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
```python N = int(input()) ans = 7*[0] for i in range(N): vals = input() for i in range(7): ans[i]+=int(vals[i]) print(max(ans)) ```
3
897
B
Chtholly's request
PROGRAMMING
1,300
[ "brute force" ]
null
null
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output single integer — answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "75615 376679484", "output": "373089399" }, { "input": "22951 23793302", "output": "1898631" }, { "input": "12785 993582106", "output": "286204743" }, { "input": "60276 428978808", "output": "376477293" }, { "input": "84776 104860385", "output": "10209596" }, { "input": "41984 653766991", "output": "17823101" }, { "input": "100000 1000000000", "output": "495495496" }, { "input": "41163 472310076", "output": "207304047" }, { "input": "6983 765352180", "output": "586866999" }, { "input": "33493 967727004", "output": "305705165" }, { "input": "90898 94010922", "output": "65928728" }, { "input": "67298 349286579", "output": "156435206" }, { "input": "92452 296773064", "output": "229486976" }, { "input": "58832 563860457", "output": "16775206" }, { "input": "90234 156145441", "output": "44023160" }, { "input": "91454 977186148", "output": "681779748" }, { "input": "11108 444095250", "output": "188075844" }, { "input": "46304 584475527", "output": "275627129" }, { "input": "1 1", "output": "0" }, { "input": "1 1000000000", "output": "11" }, { "input": "100000 1", "output": "0" } ]
1,645,090,261
2,147,483,647
Python 3
OK
TESTS
26
124
0
a, k = map(int, input().split()) sm = 0 for i in range(1, a + 1): r = str(i) sm += int(r + r[::-1]) sm %= k print(sm % k) # Thu Feb 17 2022 09:30:59 GMT+0000 (Coordinated Universal Time)
Title: Chtholly's request Time Limit: None seconds Memory Limit: None megabytes Problem Description: — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! Input Specification: The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). Output Specification: Output single integer — answer to the problem. Demo Input: ['2 100\n', '5 30\n'] Demo Output: ['33\n', '15\n'] Note: In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a, k = map(int, input().split()) sm = 0 for i in range(1, a + 1): r = str(i) sm += int(r + r[::-1]) sm %= k print(sm % k) # Thu Feb 17 2022 09:30:59 GMT+0000 (Coordinated Universal Time) ```
3
839
A
Arya and Bran
PROGRAMMING
900
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
500
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99", "output": "18" }, { "input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5", "output": "30" }, { "input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47", "output": "40" }, { "input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9", "output": "-1" }, { "input": "37 30\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", "output": "30" }, { "input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "57" }, { "input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100", "output": "38" }, { "input": "7 43\n4 3 7 9 3 8 10", "output": "-1" }, { "input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8", "output": "-1" }, { "input": "30 177\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 8", "output": "-1" }, { "input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5", "output": "-1" }, { "input": "100 100\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", "output": "100" }, { "input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69", "output": "13" }, { "input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53", "output": "85" }, { "input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5", "output": "100" }, { "input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6", "output": "98" }, { "input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1", "output": "18" }, { "input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2", "output": "21" }, { "input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1", "output": "-1" }, { "input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91", "output": "45" }, { "input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90", "output": "-1" }, { "input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50", "output": "97" }, { "input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9", "output": "24" }, { "input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42", "output": "21" }, { "input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100", "output": "1" }, { "input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5", "output": "13" }, { "input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92", "output": "14" }, { "input": "2 16\n10 6", "output": "2" }, { "input": "2 8\n7 8", "output": "2" }, { "input": "2 9\n4 8", "output": "2" }, { "input": "3 19\n9 9 1", "output": "3" }, { "input": "4 32\n9 9 9 5", "output": "4" }, { "input": "2 15\n14 1", "output": "2" }, { "input": "2 3\n3 3", "output": "1" }, { "input": "3 10\n10 1 1", "output": "2" }, { "input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4", "output": "4" }, { "input": "4 15\n14 3 3 3", "output": "2" }, { "input": "5 40\n10 10 10 10 1", "output": "5" }, { "input": "4 31\n9 9 8 5", "output": "4" }, { "input": "4 31\n20 7 1 1", "output": "-1" }, { "input": "2 10\n9 1", "output": "2" }, { "input": "10 50\n100 10 1 1 1 1 1 1 1 1", "output": "7" }, { "input": "2 11\n10 2", "output": "2" }, { "input": "3 21\n10 10 1", "output": "3" }, { "input": "2 2\n1 2", "output": "2" }, { "input": "3 2\n1 8 8", "output": "2" }, { "input": "2 11\n10 1", "output": "2" }, { "input": "2 16\n12 4", "output": "2" }, { "input": "3 11\n9 2 2", "output": "2" }, { "input": "3 11\n4 3 4", "output": "3" }, { "input": "2 13\n7 6", "output": "2" }, { "input": "3 24\n14 3 4", "output": "-1" }, { "input": "2 13\n10 3", "output": "2" }, { "input": "3 11\n9 2 1", "output": "2" }, { "input": "2 15\n12 3", "output": "2" }, { "input": "2 14\n11 4", "output": "2" } ]
1,594,241,054
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
6,656,000
n, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 candy = 0 # code for i in range(n): if candy >= k: break ans += 1 if a[i] < 8: candy += a[i] else: candy += 8 if ans >= k: print(ans) else: print(-11)
Title: Arya and Bran Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*). Print -1 if she can't give him *k* candies during *n* given days. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Demo Input: ['2 3\n1 2\n', '3 17\n10 10 10\n', '1 9\n10\n'] Demo Output: ['2', '3', '-1'] Note: In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
```python n, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 candy = 0 # code for i in range(n): if candy >= k: break ans += 1 if a[i] < 8: candy += a[i] else: candy += 8 if ans >= k: print(ans) else: print(-11) ```
0
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "output": "33" }, { "input": "4", "output": "2" }, { "input": "3", "output": "1" }, { "input": "5", "output": "2" }, { "input": "19", "output": "3" }, { "input": "20", "output": "4" }, { "input": "9880", "output": "38" }, { "input": "9879", "output": "37" }, { "input": "7770", "output": "35" }, { "input": "7769", "output": "34" }, { "input": "2925", "output": "25" }, { "input": "220", "output": "10" }, { "input": "219", "output": "9" }, { "input": "3046", "output": "25" }, { "input": "7590", "output": "34" }, { "input": "1014", "output": "17" }, { "input": "7142", "output": "34" }, { "input": "9999", "output": "38" }, { "input": "10000", "output": "38" } ]
1,696,083,688
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
483
1,024,000
n = int(input()) all = [] app = [] for i in range(10000): all.append(i) for x in range(1, 10000+1): a = all[:x] app.append(sum(a)) an =[] for k in app: if k <= n: an.append(k) print(an[-1])
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. Output Specification: Print the maximum possible height of the pyramid in the single line. Demo Input: ['1\n', '25\n'] Demo Output: ['1\n', '4\n'] Note: Illustration to the second sample:
```python n = int(input()) all = [] app = [] for i in range(10000): all.append(i) for x in range(1, 10000+1): a = all[:x] app.append(sum(a)) an =[] for k in app: if k <= n: an.append(k) print(an[-1]) ```
0
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" }, { "input": "8", "output": "1641" }, { "input": "9", "output": "4920" }, { "input": "10", "output": "14763" }, { "input": "15", "output": "3587226" }, { "input": "30", "output": "782663359" }, { "input": "10000000", "output": "192336614" }, { "input": "100", "output": "721510432" }, { "input": "300", "output": "327873818" }, { "input": "900", "output": "295068084" }, { "input": "1500", "output": "451187545" }, { "input": "3000", "output": "645417275" }, { "input": "5000", "output": "755610910" }, { "input": "10000", "output": "723907367" }, { "input": "50000", "output": "969527595" }, { "input": "90000", "output": "548978368" }, { "input": "99999", "output": "909741855" }, { "input": "100000", "output": "729225554" }, { "input": "300000", "output": "93822635" }, { "input": "800000", "output": "178940616" }, { "input": "1000000", "output": "266233856" }, { "input": "4000000", "output": "882155933" }, { "input": "9000000", "output": "295060537" }, { "input": "9999999", "output": "730778875" }, { "input": "1000000", "output": "266233856" }, { "input": "9999999", "output": "730778875" }, { "input": "10000000", "output": "192336614" }, { "input": "9999998", "output": "576926295" }, { "input": "30", "output": "782663359" }, { "input": "31", "output": "347990060" } ]
1,618,475,456
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
184
0
n = int(input()) res1 = 0 res2 = 3 ans = 0 mod = 1000000007 if(n == 1): print(0) elif(n==2): print(3) else: for i in range(3,n+1): ans = (res1*3%mod + res2*2%mod) % mod print(ans)
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. Output Specification: Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '21\n'] Note: The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
```python n = int(input()) res1 = 0 res2 = 3 ans = 0 mod = 1000000007 if(n == 1): print(0) elif(n==2): print(3) else: for i in range(3,n+1): ans = (res1*3%mod + res2*2%mod) % mod print(ans) ```
0
290
B
QR code
PROGRAMMING
1,500
[ "*special", "implementation" ]
null
null
The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space.
Output a single integer.
[ "1 1\n", "3 7\n", "13 10\n" ]
[ "0\n", "0\n", "1\n" ]
none
0
[ { "input": "1 1", "output": "0" }, { "input": "3 7", "output": "0" }, { "input": "13 10", "output": "1" }, { "input": "6 12", "output": "1" }, { "input": "14 14", "output": "0" }, { "input": "19 14", "output": "0" }, { "input": "21 18", "output": "1" }, { "input": "29 18", "output": "0" }, { "input": "0 24", "output": "0" }, { "input": "16 24", "output": "1" }, { "input": "20 28", "output": "1" }, { "input": "23 30", "output": "0" }, { "input": "23 7", "output": "1" }, { "input": "27 13", "output": "1" }, { "input": "0 13", "output": "0" }, { "input": "12 14", "output": "1" }, { "input": "21 18", "output": "1" }, { "input": "25 20", "output": "0" }, { "input": "29 24", "output": "1" }, { "input": "2 24", "output": "0" }, { "input": "14 28", "output": "0" }, { "input": "23 30", "output": "0" }, { "input": "17 32", "output": "0" }, { "input": "25 5", "output": "0" }, { "input": "29 5", "output": "0" }, { "input": "0 5", "output": "1" }, { "input": "16 11", "output": "1" }, { "input": "19 11", "output": "0" }, { "input": "27 15", "output": "1" }, { "input": "31 15", "output": "0" }, { "input": "0 0", "output": "1" }, { "input": "32 0", "output": "1" }, { "input": "0 32", "output": "1" }, { "input": "32 32", "output": "1" }, { "input": "0 31", "output": "1" }, { "input": "1 31", "output": "0" } ]
1,617,207,776
4,376
Python 3
OK
TESTS
36
124
0
x,y = map(int, input().split()) a = [ '111111101010101111100101001111111', '100000100000000001010110001000001', '101110100110110000011010001011101', '101110101011001001111101001011101', '101110101100011000111100101011101', '100000101010101011010000101000001', '111111101010101010101010101111111', '000000001111101111100111100000000', '100010111100100001011110111111001', '110111001111111100100001000101100', '011100111010000101000111010001010', '011110000110001111110101100000011', '111111111111111000111001001011000', '111000010111010011010011010100100', '101010100010110010110101010000010', '101100000101010001111101000000000', '000010100011001101000111101011010', '101001001111101111000101010001110', '101101111111000100100001110001000', '000010011000100110000011010000010', '001101101001101110010010011011000', '011101011010001000111101010100110', '111010100110011101001101000001110', '110001010010101111000101111111000', '001000111011100001010110111110000', '000000001110010110100010100010110', '111111101000101111000110101011010', '100000100111010101111100100011011', '101110101001010000101000111111000', '101110100011010010010111111011010', '101110100100011011110110101110000', '100000100110011001111100111100000', '111111101101000101001101110010001',] print(a[x][y])
Title: QR code Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=32), separated by a single space. Output Specification: Output a single integer. Demo Input: ['1 1\n', '3 7\n', '13 10\n'] Demo Output: ['0\n', '0\n', '1\n'] Note: none
```python x,y = map(int, input().split()) a = [ '111111101010101111100101001111111', '100000100000000001010110001000001', '101110100110110000011010001011101', '101110101011001001111101001011101', '101110101100011000111100101011101', '100000101010101011010000101000001', '111111101010101010101010101111111', '000000001111101111100111100000000', '100010111100100001011110111111001', '110111001111111100100001000101100', '011100111010000101000111010001010', '011110000110001111110101100000011', '111111111111111000111001001011000', '111000010111010011010011010100100', '101010100010110010110101010000010', '101100000101010001111101000000000', '000010100011001101000111101011010', '101001001111101111000101010001110', '101101111111000100100001110001000', '000010011000100110000011010000010', '001101101001101110010010011011000', '011101011010001000111101010100110', '111010100110011101001101000001110', '110001010010101111000101111111000', '001000111011100001010110111110000', '000000001110010110100010100010110', '111111101000101111000110101011010', '100000100111010101111100100011011', '101110101001010000101000111111000', '101110100011010010010111111011010', '101110100100011011110110101110000', '100000100110011001111100111100000', '111111101101000101001101110010001',] print(a[x][y]) ```
3
430
B
Balls Game
PROGRAMMING
1,400
[ "brute force", "two pointers" ]
null
null
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls. Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Print a single integer — the maximum number of balls Iahub can destroy.
[ "6 2 2\n1 1 2 2 1 1\n", "1 1 1\n1\n" ]
[ "6\n", "0\n" ]
none
1,000
[ { "input": "6 2 2\n1 1 2 2 1 1", "output": "6" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 2 1\n2 1 2 2 1 2 2 1 1 2", "output": "5" }, { "input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2", "output": "15" }, { "input": "75 5 5\n1 1 5 5 3 5 2 3 3 2 2 1 1 5 4 4 3 4 5 4 3 3 1 2 2 1 2 1 2 5 5 2 1 3 2 2 3 1 2 1 1 5 5 1 1 2 1 1 2 2 5 2 2 1 1 2 1 2 1 1 3 3 5 4 4 3 3 4 4 5 5 1 1 2 2", "output": "6" }, { "input": "100 3 2\n1 1 2 3 1 3 2 1 1 3 3 2 2 1 1 2 2 1 1 3 2 2 3 2 3 2 2 3 3 1 1 2 2 1 2 2 1 3 3 1 3 3 1 2 1 2 2 1 2 3 2 1 1 2 1 1 3 3 1 3 3 1 1 2 2 1 1 2 1 3 2 2 3 2 2 3 3 1 2 1 2 2 1 1 2 3 1 3 3 1 2 3 2 2 1 3 2 2 3 3", "output": "6" }, { "input": "100 2 1\n2 2 1 2 1 2 1 2 2 1 1 2 1 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 2 1 2 2 1 1 2 1", "output": "15" }, { "input": "100 2 2\n1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 1 2 1 1 2 2 1 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2", "output": "14" }, { "input": "100 2 2\n1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 1 2 2", "output": "17" }, { "input": "100 2 2\n2 1 1 2 2 1 1 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2", "output": "17" }, { "input": "100 2 2\n1 2 2 1 2 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 2 1 2 1 2 1 2 1", "output": "28" }, { "input": "100 2 2\n1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2", "output": "8" }, { "input": "100 100 50\n15 44 5 7 75 40 52 82 78 90 48 32 16 53 69 2 21 84 7 21 21 87 29 8 42 54 10 21 38 55 54 88 48 63 3 17 45 82 82 91 7 11 11 24 24 79 1 32 32 38 41 41 4 4 74 17 26 26 96 96 3 3 50 50 96 26 26 17 17 74 74 4 41 38 38 32 1 1 79 79 24 11 11 7 7 91 91 82 45 45 97 9 74 60 32 91 61 64 100 26", "output": "2" }, { "input": "100 50 22\n15 2 18 15 48 35 46 33 32 39 39 5 5 27 27 50 50 47 47 10 10 6 3 3 7 8 7 17 17 29 14 10 10 46 13 13 31 32 31 22 22 32 31 31 32 13 13 46 46 10 10 14 14 29 29 17 7 7 8 3 6 6 10 47 50 50 27 5 5 39 39 21 47 4 40 47 21 28 21 21 40 27 34 17 3 36 5 7 21 14 25 49 40 34 32 13 23 29 2 4", "output": "2" }, { "input": "100 3 3\n3 1 1 2 1 1 3 1 3 3 1 3 3 1 2 1 1 2 2 3 3 2 3 2 2 3 1 3 3 2 2 1 3 3 2 2 1 2 3 3 1 3 1 3 1 2 2 1 2 1 2 3 1 3 1 3 2 1 3 2 3 3 2 3 2 3 1 3 2 2 1 2 1 2 1 1 3 1 3 1 2 1 2 1 2 3 2 2 3 3 2 2 3 2 2 3 1 1 2 3", "output": "6" }, { "input": "100 100 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "0" }, { "input": "100 2 2\n1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2", "output": "98" }, { "input": "6 20 10\n10 2 10 10 2 2", "output": "5" } ]
1,585,017,456
2,147,483,647
Python 3
OK
TESTS
18
109
307,200
n, k, bola = [int(x) for x in input().split()] fila = [int(x) for x in input().split()] removidas = 0 for i in range(n): copia = fila.copy() copia.insert(i, bola) while len(copia) > 2: tmp = len(copia) for j in range(len(copia)-2): if copia[j] == copia[j+1] == copia[j+2]: p = j + 3 while p < len(copia): if copia[j] != copia[p]: break p += 1 copia = copia[:j] + copia[p:] break if tmp == len(copia): break removidas = max(removidas, n - len(copia)) print(removidas)
Title: Balls Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls. Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy. Input Specification: The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color. Output Specification: Print a single integer — the maximum number of balls Iahub can destroy. Demo Input: ['6 2 2\n1 1 2 2 1 1\n', '1 1 1\n1\n'] Demo Output: ['6\n', '0\n'] Note: none
```python n, k, bola = [int(x) for x in input().split()] fila = [int(x) for x in input().split()] removidas = 0 for i in range(n): copia = fila.copy() copia.insert(i, bola) while len(copia) > 2: tmp = len(copia) for j in range(len(copia)-2): if copia[j] == copia[j+1] == copia[j+2]: p = j + 3 while p < len(copia): if copia[j] != copia[p]: break p += 1 copia = copia[:j] + copia[p:] break if tmp == len(copia): break removidas = max(removidas, n - len(copia)) print(removidas) ```
3
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
1,645,886,274
2,147,483,647
PyPy 3-64
OK
TESTS
19
122
0
s = [i for i in input().split('/') if len(i) > 0] print('/' + '/'.join(s))
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python s = [i for i in input().split('/') if len(i) > 0] print('/' + '/'.join(s)) ```
3.9695
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
1,621,092,139
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
124
0
n = int(input()) if n<=10: print("0") elif n<=19: print("4") elif n==20: print("15") elif n==21: print("4")
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. Input Specification: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. Output Specification: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Demo Input: ['12\n', '20\n', '10\n'] Demo Output: ['4', '15', '0'] Note: In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
```python n = int(input()) if n<=10: print("0") elif n<=19: print("4") elif n==20: print("15") elif n==21: print("4") ```
0
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,689,441,427
2,147,483,647
Python 3
OK
TESTS
36
62
0
n=int(input()) a=[4,7,44,47,74,77,444,447,474,477,744,747,777] flag=False for i in a: if n%i==0: flag=True break if flag: print("YES") else: print("NO")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python n=int(input()) a=[4,7,44,47,74,77,444,447,474,477,744,747,777] flag=False for i in a: if n%i==0: flag=True break if flag: print("YES") else: print("NO") ```
3
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 87 200 62 168 51 185 192 118", "output": "48" }, { "input": "1 1\n10000", "output": "5000" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "2 2\n2 2", "output": "1" } ]
1,490,804,324
824
PyPy 3
WRONG_ANSWER
PRETESTS
6
171
29,900,800
n, m = map(int, input().split()) li = list(map(int, input().split())) count = 0 for i in range(n): if li[i] % m == 0: count = count + (li[i] // m) else: count = count + (li[i] // m) + 1 if (count % m == 0): print(count // 2) else: print((count // 2) + 1)
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. Output Specification: The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. Demo Input: ['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n'] Demo Output: ['3\n', '5\n'] Note: In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
```python n, m = map(int, input().split()) li = list(map(int, input().split())) count = 0 for i in range(n): if li[i] % m == 0: count = count + (li[i] // m) else: count = count + (li[i] // m) + 1 if (count % m == 0): print(count // 2) else: print((count // 2) + 1) ```
0
0
none
none
none
0
[ "none" ]
null
null
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor decided to share it with Sasha. Sasha knows that Teodor likes to show off so he never trusts him. Teodor wants to prove that he can be trusted sometimes, so he decided to convince Sasha that there is no such integer point in his picture, which belongs to each segment. However Teodor is lazy person and neither wills to tell Sasha all coordinates of segments' ends nor wills to tell him their amount, so he suggested Sasha to ask him series of questions 'Given the integer point *x**i*, how many segments in Fedya's picture contain that point?', promising to tell correct answers for this questions. Both boys are very busy studying and don't have much time, so they ask you to find out how many questions can Sasha ask Teodor, that having only answers on his questions, Sasha can't be sure that Teodor isn't lying to him. Note that Sasha doesn't know amount of segments in Teodor's picture. Sure, Sasha is smart person and never asks about same point twice.
First line of input contains two integer numbers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about. *i*th of next *n* lines contains two integer numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — left and right ends of *i*th segment in the picture. Note that that left and right ends of segment can be the same point. It is guaranteed that there is no integer point, that belongs to all segments.
Single line of output should contain one integer number *k* – size of largest set (*x**i*,<=*cnt*(*x**i*)) where all *x**i* are different, 1<=≤<=*x**i*<=≤<=*m*, and *cnt*(*x**i*) is amount of segments, containing point with coordinate *x**i*, such that one can't be sure that there doesn't exist point, belonging to all of segments in initial picture, if he knows only this set(and doesn't know *n*).
[ "2 4\n1 2\n3 4\n", "4 6\n1 3\n2 3\n4 6\n5 6\n" ]
[ "4\n", "5\n" ]
First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows *cnt*(*x*<sub class="lower-index">*i*</sub>) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment. In second example Sasha can ask about 5 points e.g. 1, 2, 3, 5, 6, still not being sure if Teodor haven't lied to him. But once he knows information about all points in [1;6] segment, Sasha can be sure that Teodor haven't lied to him.
0
[]
1,691,750,764
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1691750764.7986965")# 1691750764.7987127
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor decided to share it with Sasha. Sasha knows that Teodor likes to show off so he never trusts him. Teodor wants to prove that he can be trusted sometimes, so he decided to convince Sasha that there is no such integer point in his picture, which belongs to each segment. However Teodor is lazy person and neither wills to tell Sasha all coordinates of segments' ends nor wills to tell him their amount, so he suggested Sasha to ask him series of questions 'Given the integer point *x**i*, how many segments in Fedya's picture contain that point?', promising to tell correct answers for this questions. Both boys are very busy studying and don't have much time, so they ask you to find out how many questions can Sasha ask Teodor, that having only answers on his questions, Sasha can't be sure that Teodor isn't lying to him. Note that Sasha doesn't know amount of segments in Teodor's picture. Sure, Sasha is smart person and never asks about same point twice. Input Specification: First line of input contains two integer numbers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about. *i*th of next *n* lines contains two integer numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — left and right ends of *i*th segment in the picture. Note that that left and right ends of segment can be the same point. It is guaranteed that there is no integer point, that belongs to all segments. Output Specification: Single line of output should contain one integer number *k* – size of largest set (*x**i*,<=*cnt*(*x**i*)) where all *x**i* are different, 1<=≤<=*x**i*<=≤<=*m*, and *cnt*(*x**i*) is amount of segments, containing point with coordinate *x**i*, such that one can't be sure that there doesn't exist point, belonging to all of segments in initial picture, if he knows only this set(and doesn't know *n*). Demo Input: ['2 4\n1 2\n3 4\n', '4 6\n1 3\n2 3\n4 6\n5 6\n'] Demo Output: ['4\n', '5\n'] Note: First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows *cnt*(*x*<sub class="lower-index">*i*</sub>) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment. In second example Sasha can ask about 5 points e.g. 1, 2, 3, 5, 6, still not being sure if Teodor haven't lied to him. But once he knows information about all points in [1;6] segment, Sasha can be sure that Teodor haven't lied to him.
```python print("_RANDOM_GUESS_1691750764.7986965")# 1691750764.7987127 ```
0
495
B
Modular Equations
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation. Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations. Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has.
In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given.
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation .
[ "21 5\n", "9435152 272\n", "10 10\n" ]
[ "2\n", "282\n", "infinity\n" ]
In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "21 5", "output": "2" }, { "input": "9435152 272", "output": "282" }, { "input": "10 10", "output": "infinity" }, { "input": "0 1000000000", "output": "0" }, { "input": "11 2", "output": "2" }, { "input": "1 0", "output": "1" }, { "input": "0 0", "output": "infinity" }, { "input": "121 0", "output": "3" }, { "input": "772930485 686893955", "output": "0" }, { "input": "257424 24", "output": "127" }, { "input": "295138437 589952171", "output": "0" }, { "input": "223093836 966", "output": "399" }, { "input": "233758336 10665466", "output": "13" }, { "input": "223092887 17", "output": "500" }, { "input": "223094728 1858", "output": "371" }, { "input": "223092899 29", "output": "495" }, { "input": "997920 0", "output": "240" }, { "input": "887043 3", "output": "213" }, { "input": "124 24", "output": "3" }, { "input": "982901 101", "output": "193" }, { "input": "357987 35", "output": "45" }, { "input": "954374 1030", "output": "32" }, { "input": "49106 46", "output": "15" }, { "input": "325508499 119510657", "output": "1" }, { "input": "89768760 885778845", "output": "0" }, { "input": "944387968 700818251", "output": "0" }, { "input": "12 3", "output": "1" }, { "input": "1000000000 1", "output": "19" }, { "input": "923456789 3", "output": "14" }, { "input": "1000000000 6", "output": "6" }, { "input": "1000000000 333333300", "output": "2" }, { "input": "5 2", "output": "1" }, { "input": "1 10", "output": "0" }, { "input": "15 3", "output": "3" }, { "input": "2 0", "output": "2" }, { "input": "77 75", "output": "0" }, { "input": "1000000000 1000000000", "output": "infinity" } ]
1,643,881,156
2,147,483,647
PyPy 3
OK
TESTS
37
77
1,228,800
a,b=map(int,input().split()) if a<b: print(0) elif a==b: print("infinity") else: x=a-b ans=0 for i in range(1,int(x**(0.5))+1): if x%i==0: j=x//i #print(i,j) if a%i==b: ans+=1 if a%j==b and i!=j: ans+=1 print(ans)
Title: Modular Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation. Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations. Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has. Input Specification: In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. Output Specification: If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . Demo Input: ['21 5\n', '9435152 272\n', '10 10\n'] Demo Output: ['2\n', '282\n', 'infinity\n'] Note: In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a,b=map(int,input().split()) if a<b: print(0) elif a==b: print("infinity") else: x=a-b ans=0 for i in range(1,int(x**(0.5))+1): if x%i==0: j=x//i #print(i,j) if a%i==b: ans+=1 if a%j==b and i!=j: ans+=1 print(ans) ```
3
631
A
Interview
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
[ "5\n1 2 4 3 2\n2 3 3 12 1\n", "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n" ]
[ "22", "46" ]
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
500
[ { "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22" }, { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46" }, { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116", "output": "254" }, { "input": "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64", "output": "128" }, { "input": "1\n1000000000\n1000000000", "output": "2000000000" }, { "input": "1\n0\n0", "output": "0" }, { "input": "2\n7 16\n16 7", "output": "46" }, { "input": "4\n6 0 0 0\n0 0 0 1", "output": "7" }, { "input": "8\n1 2 4 8 16 32 64 128\n1 2 4 8 16 32 64 128", "output": "510" }, { "input": "1\n2\n3", "output": "5" }, { "input": "1\n4\n3", "output": "7" }, { "input": "1\n1\n1", "output": "2" } ]
1,458,250,017
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def interview(st): sum=0 for i in st: sum|=i return sum n=int(input()) a = list(map(int,raw_input().split(" "))) b = list(map(int,raw_input().split(" "))) print(interview(a)+interview(b))
Title: Interview Time Limit: None seconds Memory Limit: None megabytes Problem Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). Output Specification: Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Demo Input: ['5\n1 2 4 3 2\n2 3 3 12 1\n', '10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n'] Demo Output: ['22', '46'] Note: Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5. In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9.
```python def interview(st): sum=0 for i in st: sum|=i return sum n=int(input()) a = list(map(int,raw_input().split(" "))) b = list(map(int,raw_input().split(" "))) print(interview(a)+interview(b)) ```
-1
864
A
Fair Game
PROGRAMMING
1,000
[ "implementation", "sortings" ]
null
null
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
[ "4\n11\n27\n27\n11\n", "2\n6\n6\n", "6\n10\n20\n30\n20\n10\n20\n", "6\n1\n1\n2\n2\n3\n3\n" ]
[ "YES\n11 27\n", "NO\n", "NO\n", "NO\n" ]
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
500
[ { "input": "4\n11\n27\n27\n11", "output": "YES\n11 27" }, { "input": "2\n6\n6", "output": "NO" }, { "input": "6\n10\n20\n30\n20\n10\n20", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n3\n3", "output": "NO" }, { "input": "2\n1\n100", "output": "YES\n1 100" }, { "input": "2\n1\n1", "output": "NO" }, { "input": "2\n100\n100", "output": "NO" }, { "input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43", "output": "NO" }, { "input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32", "output": "YES\n14 32" }, { "input": "2\n50\n100", "output": "YES\n50 100" }, { "input": "2\n99\n100", "output": "YES\n99 100" }, { "input": "4\n4\n4\n5\n5", "output": "YES\n4 5" }, { "input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23", "output": "YES\n10 23" }, { "input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11", "output": "YES\n11 34" }, { "input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30", "output": "YES\n20 30" }, { "input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES\n1 100" }, { "input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99", "output": "YES\n2 99" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\n1 100" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2", "output": "YES\n1 2" }, { "input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 49" }, { "input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94", "output": "YES\n15 94" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42", "output": "YES\n33 42" }, { "input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35", "output": "YES\n16 35" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44", "output": "YES\n33 44" }, { "input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98", "output": "YES\n54 98" }, { "input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 81" }, { "input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "NO" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30", "output": "NO" }, { "input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2", "output": "NO" }, { "input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100", "output": "NO" }, { "input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100", "output": "NO" }, { "input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1", "output": "NO" }, { "input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100", "output": "NO" }, { "input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43", "output": "NO" }, { "input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88", "output": "NO" }, { "input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100", "output": "NO" }, { "input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45", "output": "NO" }, { "input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12", "output": "NO" }, { "input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2", "output": "NO" }, { "input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100", "output": "NO" }, { "input": "4\n1\n3\n3\n3", "output": "NO" }, { "input": "6\n1\n1\n1\n1\n2\n2", "output": "NO" }, { "input": "4\n1\n1\n1\n2", "output": "NO" }, { "input": "4\n1\n2\n2\n2", "output": "NO" }, { "input": "4\n1\n2\n3\n4", "output": "NO" }, { "input": "8\n1\n1\n2\n2\n3\n3\n4\n4", "output": "NO" }, { "input": "4\n1\n3\n2\n4", "output": "NO" }, { "input": "4\n10\n10\n10\n20", "output": "NO" }, { "input": "4\n11\n12\n13\n13", "output": "NO" }, { "input": "4\n1\n1\n1\n3", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n2\n2", "output": "NO" }, { "input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4", "output": "NO" } ]
1,642,747,843
2,147,483,647
PyPy 3
OK
TESTS
54
93
0
n = int(input()) data = [int(input()) for _ in range(n)] if len(set(data)) == 2: if len(data) / 2 == data.count(data[0]): print("YES") print(*list(set(data))) else: print("NO") else: print("NO")
Title: Fair Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. Output Specification: If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. Demo Input: ['4\n11\n27\n27\n11\n', '2\n6\n6\n', '6\n10\n20\n30\n20\n10\n20\n', '6\n1\n1\n2\n2\n3\n3\n'] Demo Output: ['YES\n11 27\n', 'NO\n', 'NO\n', 'NO\n'] Note: In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
```python n = int(input()) data = [int(input()) for _ in range(n)] if len(set(data)) == 2: if len(data) / 2 == data.count(data[0]): print("YES") print(*list(set(data))) else: print("NO") else: print("NO") ```
3
624
A
Save Luke
PROGRAMMING
800
[ "math" ]
null
null
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.
The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=&lt;<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.
Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "2 6 2 2\n", "1 9 1 2\n" ]
[ "1.00000000000000000000\n", "2.66666666666666650000\n" ]
In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed. In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time.
500
[ { "input": "2 6 2 2", "output": "1.00000000000000000000" }, { "input": "1 9 1 2", "output": "2.66666666666666650000" }, { "input": "1 10000 1 1", "output": "4999.50000000000000000000" }, { "input": "9999 10000 10000 10000", "output": "0.00005000000000000000" }, { "input": "1023 2340 1029 3021", "output": "0.32518518518518519000" }, { "input": "2173 2176 10000 9989", "output": "0.00015008254539996998" }, { "input": "1 2 123 1", "output": "0.00806451612903225780" }, { "input": "123 1242 12 312", "output": "3.45370370370370370000" }, { "input": "2 9997 3 12", "output": "666.33333333333337000000" }, { "input": "1 10000 10000 10000", "output": "0.49995000000000001000" }, { "input": "3274 4728 888 4578", "output": "0.26600804976216613000" }, { "input": "4600 9696 5634 8248", "output": "0.36709407866301685000" }, { "input": "2255 7902 8891 429", "output": "0.60590128755364803000" }, { "input": "6745 9881 2149 9907", "output": "0.26011944260119441000" }, { "input": "4400 8021 6895 2089", "output": "0.40304986642920748000" }, { "input": "5726 9082 7448 3054", "output": "0.31955817939440107000" }, { "input": "3381 9769 4898 2532", "output": "0.85975773889636609000" }, { "input": "1036 6259 5451 4713", "output": "0.51387249114521838000" }, { "input": "5526 6455 197 4191", "output": "0.21171376481312670000" }, { "input": "1196 4082 4071 9971", "output": "0.20552627830793335000" }, { "input": "8850 9921 8816 9449", "output": "0.05863673692855187600" }, { "input": "3341 7299 2074 8927", "output": "0.35978547404781386000" }, { "input": "7831 8609 6820 2596", "output": "0.08262531860662701600" }, { "input": "2322 7212 77 4778", "output": "1.00720906282183310000" }, { "input": "9976 9996 4823 4255", "output": "0.00220312844238819110" }, { "input": "7631 9769 5377 6437", "output": "0.18097172845776197000" }, { "input": "8957 9525 8634 107", "output": "0.06498112344125385500" }, { "input": "6612 9565 3380 2288", "output": "0.52099505998588569000" }, { "input": "1103 6256 3934 9062", "output": "0.39650661742074483000" }, { "input": "1854 3280 1481 2140", "output": "0.39381386357359843000" } ]
1,632,858,727
2,147,483,647
PyPy 3
OK
TESTS
30
93
20,172,800
d, l, v1, v2 = map(int, input().split()) distance = l - d time = v1 + v2 ans = distance / time print("%.10f" % ans)
Title: Save Luke Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. Input Specification: The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=&lt;<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. Output Specification: Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['2 6 2 2\n', '1 9 1 2\n'] Demo Output: ['1.00000000000000000000\n', '2.66666666666666650000\n'] Note: In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed. In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time.
```python d, l, v1, v2 = map(int, input().split()) distance = l - d time = v1 + v2 ans = distance / time print("%.10f" % ans) ```
3
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,626,368,376
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
6,963,200
n = int(input()) def rec(x): res = sum(map(int, str(x))) if x > 10 **9 or res > 10 ** 6: return -1 if res == n: return x res = rec(x*10+4) if res != -1: return res res = rec(x*10+7) if res != -1: return res return -1 print(rec(0))
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python n = int(input()) def rec(x): res = sum(map(int, str(x))) if x > 10 **9 or res > 10 ** 6: return -1 if res == n: return x res = rec(x*10+4) if res != -1: return res res = rec(x*10+7) if res != -1: return res return -1 print(rec(0)) ```
0
52
A
123-sequence
PROGRAMMING
900
[ "implementation" ]
A. 123-sequence
2
256
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
[ "9\n1 3 2 2 2 1 1 2 3\n" ]
[ "5\n" ]
In the example all the numbers equal to 1 and 3 should be replaced by 2.
500
[ { "input": "9\n1 3 2 2 2 1 1 2 3", "output": "5" }, { "input": "6\n3 3 2 2 1 3", "output": "3" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n3 2", "output": "1" }, { "input": "2\n3 1", "output": "1" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2", "output": "10" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1", "output": "19" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" } ]
1,599,910,445
2,147,483,647
Python 3
OK
TESTS
23
1,310
14,848,000
def calculate(list1): ones=0 twos=0 threes=0 for i in list1: if i==1: ones=ones+1 elif i==2: twos= twos+1 else: threes += 1 if (ones>twos and ones> threes): return 1 elif (twos>ones and twos>threes): return 2 elif (threes>ones and threes>twos): return 3 elif (ones==threes): return 3 elif (twos==threes): return 2 elif(ones==twos): return 1 N=int(input()) numbers=[] replacements=0 numbers =list(map(int, input().split()[:N])) most= calculate(numbers) for i in range(N): if numbers[i]!= most: numbers[i] = most replacements+=1 print(replacements)
Title: 123-sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). Output Specification: Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Demo Input: ['9\n1 3 2 2 2 1 1 2 3\n'] Demo Output: ['5\n'] Note: In the example all the numbers equal to 1 and 3 should be replaced by 2.
```python def calculate(list1): ones=0 twos=0 threes=0 for i in list1: if i==1: ones=ones+1 elif i==2: twos= twos+1 else: threes += 1 if (ones>twos and ones> threes): return 1 elif (twos>ones and twos>threes): return 2 elif (threes>ones and threes>twos): return 3 elif (ones==threes): return 3 elif (twos==threes): return 2 elif(ones==twos): return 1 N=int(input()) numbers=[] replacements=0 numbers =list(map(int, input().split()[:N])) most= calculate(numbers) for i in range(N): if numbers[i]!= most: numbers[i] = most replacements+=1 print(replacements) ```
3.644843
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,613,539,246
2,147,483,647
PyPy 3
OK
TESTS
64
108
0
n= int(input()) i=0 l=[] while(i<n): s=input() l.append(s) i=i+1 d={'red':'Reality','blue':'Space', 'yellow':'Mind','orange':'Soul','green':'Time' ,'purple':'Power'} l1 = [] for k,v in d.items(): h=0 for j in l: if k==j: h=h+1 if h==0: l1.append(v) print(len(l1)) for i in l1: print(i)
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python n= int(input()) i=0 l=[] while(i<n): s=input() l.append(s) i=i+1 d={'red':'Reality','blue':'Space', 'yellow':'Mind','orange':'Soul','green':'Time' ,'purple':'Power'} l1 = [] for k,v in d.items(): h=0 for j in l: if k==j: h=h+1 if h==0: l1.append(v) print(len(l1)) for i in l1: print(i) ```
3
285
A
Slightly Decreasing Permutations
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=&lt;<=*n*), that *p**i*<=&gt;<=*p**i*<=+<=1. You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*.
The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=&lt;<=*n*) — the permutation length and the decreasing coefficient.
In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.
[ "5 2\n", "3 0\n", "3 2\n" ]
[ "1 5 2 4 3\n", "1 2 3\n", "3 2 1\n" ]
none
500
[ { "input": "5 2", "output": "1 5 2 4 3" }, { "input": "3 0", "output": "1 2 3" }, { "input": "3 2", "output": "3 2 1" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "1 2" }, { "input": "2 1", "output": "2 1" }, { "input": "10 4", "output": "10 9 8 7 1 2 3 4 5 6" }, { "input": "56893 5084", "output": "56893 56892 56891 56890 56889 56888 56887 56886 56885 56884 56883 56882 56881 56880 56879 56878 56877 56876 56875 56874 56873 56872 56871 56870 56869 56868 56867 56866 56865 56864 56863 56862 56861 56860 56859 56858 56857 56856 56855 56854 56853 56852 56851 56850 56849 56848 56847 56846 56845 56844 56843 56842 56841 56840 56839 56838 56837 56836 56835 56834 56833 56832 56831 56830 56829 56828 56827 56826 56825 56824 56823 56822 56821 56820 56819 56818 56817 56816 56815 56814 56813 56812 56811 56810 56809 5..." }, { "input": "6 3", "output": "6 5 4 1 2 3" }, { "input": "1 0", "output": "1" }, { "input": "310 186", "output": "310 309 308 307 306 305 304 303 302 301 300 299 298 297 296 295 294 293 292 291 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183..." }, { "input": "726 450", "output": "726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599..." }, { "input": "438 418", "output": "438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311..." }, { "input": "854 829", "output": "854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727..." }, { "input": "214 167", "output": "214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 ..." }, { "input": "85705 56268", "output": "85705 85704 85703 85702 85701 85700 85699 85698 85697 85696 85695 85694 85693 85692 85691 85690 85689 85688 85687 85686 85685 85684 85683 85682 85681 85680 85679 85678 85677 85676 85675 85674 85673 85672 85671 85670 85669 85668 85667 85666 85665 85664 85663 85662 85661 85660 85659 85658 85657 85656 85655 85654 85653 85652 85651 85650 85649 85648 85647 85646 85645 85644 85643 85642 85641 85640 85639 85638 85637 85636 85635 85634 85633 85632 85631 85630 85629 85628 85627 85626 85625 85624 85623 85622 85621 8..." }, { "input": "11417 4583", "output": "11417 11416 11415 11414 11413 11412 11411 11410 11409 11408 11407 11406 11405 11404 11403 11402 11401 11400 11399 11398 11397 11396 11395 11394 11393 11392 11391 11390 11389 11388 11387 11386 11385 11384 11383 11382 11381 11380 11379 11378 11377 11376 11375 11374 11373 11372 11371 11370 11369 11368 11367 11366 11365 11364 11363 11362 11361 11360 11359 11358 11357 11356 11355 11354 11353 11352 11351 11350 11349 11348 11347 11346 11345 11344 11343 11342 11341 11340 11339 11338 11337 11336 11335 11334 11333 1..." }, { "input": "53481 20593", "output": "53481 53480 53479 53478 53477 53476 53475 53474 53473 53472 53471 53470 53469 53468 53467 53466 53465 53464 53463 53462 53461 53460 53459 53458 53457 53456 53455 53454 53453 53452 53451 53450 53449 53448 53447 53446 53445 53444 53443 53442 53441 53440 53439 53438 53437 53436 53435 53434 53433 53432 53431 53430 53429 53428 53427 53426 53425 53424 53423 53422 53421 53420 53419 53418 53417 53416 53415 53414 53413 53412 53411 53410 53409 53408 53407 53406 53405 53404 53403 53402 53401 53400 53399 53398 53397 5..." }, { "input": "79193 77281", "output": "79193 79192 79191 79190 79189 79188 79187 79186 79185 79184 79183 79182 79181 79180 79179 79178 79177 79176 79175 79174 79173 79172 79171 79170 79169 79168 79167 79166 79165 79164 79163 79162 79161 79160 79159 79158 79157 79156 79155 79154 79153 79152 79151 79150 79149 79148 79147 79146 79145 79144 79143 79142 79141 79140 79139 79138 79137 79136 79135 79134 79133 79132 79131 79130 79129 79128 79127 79126 79125 79124 79123 79122 79121 79120 79119 79118 79117 79116 79115 79114 79113 79112 79111 79110 79109 7..." }, { "input": "42607 42144", "output": "42607 42606 42605 42604 42603 42602 42601 42600 42599 42598 42597 42596 42595 42594 42593 42592 42591 42590 42589 42588 42587 42586 42585 42584 42583 42582 42581 42580 42579 42578 42577 42576 42575 42574 42573 42572 42571 42570 42569 42568 42567 42566 42565 42564 42563 42562 42561 42560 42559 42558 42557 42556 42555 42554 42553 42552 42551 42550 42549 42548 42547 42546 42545 42544 42543 42542 42541 42540 42539 42538 42537 42536 42535 42534 42533 42532 42531 42530 42529 42528 42527 42526 42525 42524 42523 4..." }, { "input": "100000 0", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "100000 99999", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "100000 53860", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "4 0", "output": "1 2 3 4" }, { "input": "4 1", "output": "4 1 2 3" }, { "input": "4 2", "output": "4 3 1 2" }, { "input": "4 3", "output": "4 3 2 1" }, { "input": "3 1", "output": "3 1 2" } ]
1,547,468,346
2,147,483,647
Python 3
OK
TESTS
28
280
7,475,200
n, k = map(int, input().split()) R = [] for i in range(1, n - k): R.append(i) for i in range(n, n - k - 1, -1): R.append(i) print(" ".join(map(str, R)))
Title: Slightly Decreasing Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=&lt;<=*n*), that *p**i*<=&gt;<=*p**i*<=+<=1. You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. Input Specification: The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=&lt;<=*n*) — the permutation length and the decreasing coefficient. Output Specification: In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Demo Input: ['5 2\n', '3 0\n', '3 2\n'] Demo Output: ['1 5 2 4 3\n', '1 2 3\n', '3 2 1\n'] Note: none
```python n, k = map(int, input().split()) R = [] for i in range(1, n - k): R.append(i) for i in range(n, n - k - 1, -1): R.append(i) print(" ".join(map(str, R))) ```
3
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,652,438,496
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a,b = map(int,input().split()) if(a//b)%2 == 0: print("YES") else: print("NO") #aedfjkwefew
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python a,b = map(int,input().split()) if(a//b)%2 == 0: print("YES") else: print("NO") #aedfjkwefew ```
0
519
C
A and B and Team Training
PROGRAMMING
1,300
[ "greedy", "implementation", "math", "number theory" ]
null
null
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants. A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people. However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience. As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible. There are *n* experienced members and *m* newbies on the training session. Can you calculate what maximum number of teams can be formed?
The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session.
Print the maximum number of teams that can be formed.
[ "2 6\n", "4 5\n" ]
[ "2\n", "3\n" ]
Let's represent the experienced players as XP and newbies as NB. In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB). In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).
1,500
[ { "input": "2 6", "output": "2" }, { "input": "4 5", "output": "3" }, { "input": "1 1", "output": "0" }, { "input": "3 3", "output": "2" }, { "input": "500000 500000", "output": "333333" }, { "input": "70 100", "output": "56" }, { "input": "5 12525", "output": "5" }, { "input": "10 5", "output": "5" }, { "input": "5 10", "output": "5" }, { "input": "0 0", "output": "0" }, { "input": "0 1", "output": "0" }, { "input": "1 0", "output": "0" }, { "input": "0 21233", "output": "0" }, { "input": "12523 0", "output": "0" }, { "input": "1231 1253", "output": "828" }, { "input": "500000 0", "output": "0" }, { "input": "1 500000", "output": "1" }, { "input": "250000 500000", "output": "250000" }, { "input": "500000 250000", "output": "250000" }, { "input": "33333 77777", "output": "33333" }, { "input": "30900 174529", "output": "30900" }, { "input": "89979 57154", "output": "49044" }, { "input": "231646 398487", "output": "210044" }, { "input": "332019 281112", "output": "204377" }, { "input": "473686 122443", "output": "122443" }, { "input": "481245 86879", "output": "86879" }, { "input": "39935 123534", "output": "39935" }, { "input": "10000 20000", "output": "10000" }, { "input": "10000 20001", "output": "10000" }, { "input": "10000 20002", "output": "10000" }, { "input": "10000 20003", "output": "10000" }, { "input": "10000 20004", "output": "10000" }, { "input": "10001 20000", "output": "10000" }, { "input": "10001 20001", "output": "10000" }, { "input": "10001 20002", "output": "10001" }, { "input": "10001 20003", "output": "10001" }, { "input": "10001 20004", "output": "10001" }, { "input": "20000 10000", "output": "10000" }, { "input": "20001 10000", "output": "10000" }, { "input": "20002 10000", "output": "10000" }, { "input": "20003 10000", "output": "10000" }, { "input": "20004 10000", "output": "10000" }, { "input": "20000 10001", "output": "10000" }, { "input": "20001 10001", "output": "10000" }, { "input": "20002 10001", "output": "10001" }, { "input": "20003 10001", "output": "10001" }, { "input": "20004 10001", "output": "10001" }, { "input": "10 0", "output": "0" }, { "input": "0 6", "output": "0" }, { "input": "2 3", "output": "1" }, { "input": "1 2", "output": "1" }, { "input": "0 0", "output": "0" } ]
1,686,525,746
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
a, b = list(map(int, input().split())) c = a d = b g = 0 while c or d < 0: if c >= 1 and d > 1: c -= 1 d -= 2 g += 1 elif c > 1 and d < 2: c -= 2 d -= 1 g += 1 print(g)
Title: A and B and Team Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants. A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people. However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience. As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible. There are *n* experienced members and *m* newbies on the training session. Can you calculate what maximum number of teams can be formed? Input Specification: The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session. Output Specification: Print the maximum number of teams that can be formed. Demo Input: ['2 6\n', '4 5\n'] Demo Output: ['2\n', '3\n'] Note: Let's represent the experienced players as XP and newbies as NB. In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB). In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).
```python a, b = list(map(int, input().split())) c = a d = b g = 0 while c or d < 0: if c >= 1 and d > 1: c -= 1 d -= 2 g += 1 elif c > 1 and d < 2: c -= 2 d -= 1 g += 1 print(g) ```
0
44
D
Hyperdrive
PROGRAMMING
1,800
[ "math" ]
D. Hyperdrive
2
256
In a far away galaxy there are *n* inhabited planets, numbered with numbers from 1 to *n*. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, *n*<=-<=1 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention. Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That's why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of *s* hyperyears in *s* years). When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make *n*<=-<=2 identical to it ships with a hyperdrive and send them to other *n*<=-<=2 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new *n*<=-<=2 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues. However the hyperdrive creators hurried to spread the news about their invention so much that they didn't study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy! Your task is to find the time the galaxy will continue to exist from the moment of the ships' launch from the first planet.
The first line contains a number *n* (3<=≤<=*n*<=≤<=5000) — the number of inhabited planets in the galaxy. The next *n* lines contain integer coordinates of the planets in format "*x**i* *y**i* *z**i*" (<=-<=104<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=104).
Print the single number — the solution to the task with an absolute or relative error not exceeding 10<=-<=6.
[ "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n" ]
[ "1.7071067812\n" ]
none
0
[ { "input": "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0", "output": "1.7071067812" }, { "input": "3\n5 -5 4\n-5 -4 2\n-1 1 2", "output": "12.6839364452" }, { "input": "3\n28 -69 72\n-36 9 -49\n94 83 95", "output": "266.2401228107" }, { "input": "4\n-7 -72 93\n-40 42 49\n31 76 -36\n-56 12 -1", "output": "161.1452860862" }, { "input": "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7", "output": "166.1019364256" }, { "input": "10\n-3461 4259 -7268\n9964 2370 6622\n4530 5607 -6609\n-3777 4888 6057\n-5403 7982 -651\n4828 -6712 1070\n9886 -1287 -6864\n-369 -7105 1602\n-7603 5424 -3396\n1202 9528 9042", "output": "8987.4152877289" }, { "input": "15\n-4743 -119 3104\n8014 4585 -1756\n-360 4466 -4425\n7157 -5142 -2483\n1691 -505 5849\n9632 6178 4631\n4531 -3438 -4361\n-172 1508 4593\n198 8647 3400\n6904 -188 4830\n-7101 -7911 -4407\n-4366 3174 8353\n4636 -9577 -4017\n1055 5875 1289\n-7014 -7983 1874", "output": "7548.8503523162" }, { "input": "25\n-10000 10000 -10000\n9979 -9960 9950\n9996 -9986 9952\n9953 -9961 9978\n9999 -9981 9967\n9953 -9983 9982\n9974 -9959 9972\n9960 -9956 9983\n9955 -9991 9952\n9976 -9987 9967\n9960 -9973 9987\n9998 -9952 9968\n9964 -9958 9961\n9957 -9984 9982\n9966 -9986 9963\n9985 -9997 9967\n9993 -9979 9953\n9979 -9965 9975\n9979 -9965 9983\n9997 -9989 9957\n9983 -9996 9969\n9959 -9962 9952\n9986 -9966 9966\n9980 -9961 9975\n9965 -9960 9950", "output": "34571.5878668720" }, { "input": "20\n-10000 10000 -10000\n9940 -9947 10000\n9968 -9977 9918\n9975 -9908 9901\n9948 -9923 9989\n10000 -9966 9906\n9981 -9910 9911\n9962 -9905 9999\n9981 -9977 9949\n9974 -9956 9952\n9986 -9942 9937\n9922 -9913 9984\n9978 -9925 9945\n9974 -9962 9990\n9921 -9985 9998\n9949 -9976 9924\n9991 -9946 9920\n9966 -9987 9993\n9910 -9930 9914\n9927 -9937 9915", "output": "34515.4142208477" }, { "input": "20\n-10000 10000 -10000\n9973 -9963 9996\n9968 -9972 9968\n9958 -9956 9991\n9982 -9971 9958\n9975 -9957 9985\n9971 -9950 9986\n9996 -9956 9985\n9952 -9977 9989\n9996 -10000 9961\n9971 -9969 9967\n9984 -10000 9973\n9962 -9993 9992\n9951 -9970 9987\n9969 -9970 9962\n9979 -9953 9981\n9975 -9950 9986\n9971 -9973 9954\n9954 -9973 9962\n9993 -9953 9976", "output": "34587.3817821709" }, { "input": "8\n-10000 -10000 -10000\n-10000 -10000 10000\n-10000 10000 -10000\n-10000 10000 10000\n10000 -10000 -10000\n10000 -10000 10000\n10000 10000 -10000\n10000 10000 10000", "output": "34142.1356237310" } ]
1,641,552,860
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
184
0
def r(c1, c2): return sum([(c1[i] - c2[i]) ** 2 for i in range(3)]) ** 0.5 n = int(input()) cords = [] for i in range(n): x, y, z = map(int, input().split()) cords.append([x, y, z]) res = 10 ** 10 for p1 in range(1, n): for p2 in range(p1 + 1, n): r1 = r(cords[0], cords[p1]) r2 = r(cords[0], cords[p2]) r12 = r(cords[p1], cords[p2]) v = min(r1, r1) + (r12 - abs(r1 - r2)) / 2 res = min(res, v) print("%.12f" % res)
Title: Hyperdrive Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away galaxy there are *n* inhabited planets, numbered with numbers from 1 to *n*. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, *n*<=-<=1 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention. Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That's why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of *s* hyperyears in *s* years). When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make *n*<=-<=2 identical to it ships with a hyperdrive and send them to other *n*<=-<=2 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new *n*<=-<=2 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues. However the hyperdrive creators hurried to spread the news about their invention so much that they didn't study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy! Your task is to find the time the galaxy will continue to exist from the moment of the ships' launch from the first planet. Input Specification: The first line contains a number *n* (3<=≤<=*n*<=≤<=5000) — the number of inhabited planets in the galaxy. The next *n* lines contain integer coordinates of the planets in format "*x**i* *y**i* *z**i*" (<=-<=104<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=104). Output Specification: Print the single number — the solution to the task with an absolute or relative error not exceeding 10<=-<=6. Demo Input: ['4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n'] Demo Output: ['1.7071067812\n'] Note: none
```python def r(c1, c2): return sum([(c1[i] - c2[i]) ** 2 for i in range(3)]) ** 0.5 n = int(input()) cords = [] for i in range(n): x, y, z = map(int, input().split()) cords.append([x, y, z]) res = 10 ** 10 for p1 in range(1, n): for p2 in range(p1 + 1, n): r1 = r(cords[0], cords[p1]) r2 = r(cords[0], cords[p2]) r12 = r(cords[p1], cords[p2]) v = min(r1, r1) + (r12 - abs(r1 - r2)) / 2 res = min(res, v) print("%.12f" % res) ```
0
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3 d g\n5 5 h h\n2 8 g d\n8 9 a f\n5 9 c e\n1 7 f d\n1 6 e e\n5 7 c a\n8 9 b b\n2 6 e b\n6 6 g h\n1 2 b b\n1 5 a f\n5 8 f h\n1 5 e g\n3 9 f h\n6 8 g a\n4 6 h g\n1 5 f a\n5 6 a c\n4 8 e d\n1 4 d g\n7 8 b f\n5 6 h b\n3 9 c e\n1 9 b a", "output": "aahaddddh" }, { "input": "28 45\ndcbbaddjhbeefjadjchgkhgggfha\n10 25 c a\n13 19 a f\n12 28 e d\n12 27 e a\n9 20 b e\n7 17 g d\n22 26 j j\n8 16 c g\n14 16 a d\n3 10 f c\n10 26 d b\n8 17 i e\n10 19 d i\n6 21 c j\n7 22 b k\n17 19 a i\n4 18 j k\n8 25 a g\n10 27 j e\n9 18 g d\n16 23 h a\n17 26 k e\n8 16 h f\n1 15 d f\n22 28 k k\n11 20 c k\n6 11 b h\n17 17 e i\n15 22 g h\n8 18 c f\n4 16 e a\n8 25 b c\n6 24 d g\n5 9 f j\n12 19 i h\n4 25 e f\n15 25 c j\n15 27 e e\n11 20 b f\n19 27 e k\n2 21 d a\n9 27 k e\n14 24 b a\n3 6 i g\n2 26 k f", "output": "fcbbajjfjaaefefehfahfagggfha" }, { "input": "87 5\nnfinedeojadjmgafnaogekfjkjfncnliagfchjfcmellgigjjcaaoeakdolchjcecljdeblmheimkibkgdkcdml\n47 56 a k\n51 81 o d\n5 11 j h\n48 62 j d\n16 30 k m", "output": "nfinedeohadjmgafnaogemfjmjfncnliagfchjfcmellgigddckkdekkddlchdcecljdeblmheimkibkgdkcdml" }, { "input": "5 16\nacfbb\n1 2 e f\n2 5 a f\n2 3 b e\n4 4 f a\n2 3 f a\n1 2 b e\n4 5 c d\n2 4 e c\n1 4 e a\n1 3 d c\n3 5 e b\n3 5 e b\n2 2 e d\n1 3 e c\n3 3 a e\n1 5 a a", "output": "acebb" }, { "input": "94 13\nbcaaaaaaccacddcdaacbdaabbcbaddbccbccbbbddbadddcccbddadddaadbdababadaacdcdbcdadabdcdcbcbcbcbbcd\n52 77 d d\n21 92 d b\n45 48 c b\n20 25 d a\n57 88 d b\n3 91 b d\n64 73 a a\n5 83 b d\n2 69 c c\n28 89 a b\n49 67 c b\n41 62 a c\n49 87 b c", "output": "bcaaaaaaccacddcdaacddaaddcdbdddccdccddddddbdddddcdddcdddccdddcdcdcdcccdcddcdcdcddcdcdcdcdcdbcd" }, { "input": "67 39\nacbcbccccbabaabcabcaaaaaaccbcbbcbaaaacbbcccbcbabbcacccbbabbabbabaac\n4 36 a b\n25 38 a a\n3 44 b c\n35 57 b a\n4 8 a c\n20 67 c a\n30 66 b b\n27 40 a a\n2 56 a b\n10 47 c a\n22 65 c b\n29 42 a b\n1 46 c b\n57 64 b c\n20 29 b a\n14 51 c a\n12 55 b b\n20 20 a c\n2 57 c a\n22 60 c b\n16 51 c c\n31 64 a c\n17 30 c a\n23 36 c c\n28 67 a c\n37 40 a c\n37 50 b c\n29 48 c b\n2 34 b c\n21 53 b a\n26 63 a c\n23 28 c a\n51 56 c b\n32 61 b b\n64 67 b b\n21 67 b c\n8 53 c c\n40 62 b b\n32 38 c c", "output": "accccccccaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccc" }, { "input": "53 33\nhhcbhfafeececbhadfbdbehdfacfchbhdbfebdfeghebfcgdhehfh\n27 41 h g\n18 35 c b\n15 46 h f\n48 53 e g\n30 41 b c\n12 30 b f\n10 37 e f\n18 43 a h\n10 52 d a\n22 48 c e\n40 53 f d\n7 12 b h\n12 51 f a\n3 53 g a\n19 41 d h\n22 29 b h\n2 30 a b\n26 28 e h\n25 35 f a\n19 31 h h\n44 44 d e\n19 22 e c\n29 44 d h\n25 33 d h\n3 53 g c\n18 44 h b\n19 28 f e\n3 22 g h\n8 17 c a\n37 51 d d\n3 28 e h\n27 50 h h\n27 46 f b", "output": "hhcbhfbfhfababbbbbbbbbbbbbbbbbeaaeaaeaaeabebdeaahahdh" }, { "input": "83 10\nfhbecdgadecabbbecedcgfdcefcbgechbedagecgdgfgdaahchdgchbeaedgafdefecdchceececfcdhcdh\n9 77 e e\n26 34 b g\n34 70 b a\n40 64 e g\n33 78 h f\n14 26 a a\n17 70 d g\n56 65 a c\n8 41 d c\n11 82 c b", "output": "fhbecdgacebabbbebegbgfgbefbggebhgegagebgggfggaafbfggbfagbgggbfggfebgbfbeebebfbdhbdh" }, { "input": "1 4\ne\n1 1 c e\n1 1 e a\n1 1 e c\n1 1 d a", "output": "a" }, { "input": "71 21\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n61 61 a a\n32 56 a a\n10 67 a a\n7 32 a a\n26 66 a a\n41 55 a a\n49 55 a a\n4 61 a a\n53 59 a a\n37 58 a a\n7 63 a a\n39 40 a a\n51 64 a a\n27 37 a a\n22 71 a a\n4 45 a a\n7 8 a a\n43 46 a a\n19 28 a a\n51 54 a a\n14 67 a a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "30 4\neaaddabedcbbcccddbabdecadcecce\n2 17 c a\n16 29 e e\n16 21 c b\n7 11 b c", "output": "eaaddacedacbaaaddbabdecadcecce" }, { "input": "48 30\naaaabaabbaababbbaabaabaababbabbbaabbbaabaaaaaaba\n3 45 a b\n1 14 a a\n15 32 a b\n37 47 a b\n9 35 a b\n36 39 b b\n6 26 a b\n36 44 a a\n28 44 b a\n29 31 b a\n20 39 a a\n45 45 a b\n21 32 b b\n7 43 a b\n14 48 a b\n14 33 a b\n39 44 a a\n9 36 b b\n4 23 b b\n9 42 b b\n41 41 b a\n30 47 a b\n8 42 b a\n14 38 b b\n3 15 a a\n35 47 b b\n14 34 a b\n38 43 a b\n1 35 b a\n16 28 b a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbb" }, { "input": "89 29\nbabaabaaabaaaababbbbbbbabbbaaaaababbaababababbababaaabbababaaabbbbaaabaaaaaabaaabaabbabab\n39 70 b b\n3 56 b b\n5 22 b a\n4 39 a b\n41 87 b b\n34 41 a a\n10 86 a b\n29 75 a b\n2 68 a a\n27 28 b b\n42 51 b a\n18 61 a a\n6 67 b a\n47 63 a a\n8 68 a b\n4 74 b a\n19 65 a b\n8 55 a b\n5 30 a a\n3 65 a b\n16 57 a b\n34 56 b a\n1 70 a b\n59 68 b b\n29 57 b a\n47 49 b b\n49 73 a a\n32 61 b b\n29 42 a a", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaabbbbbbbbbbbbbab" }, { "input": "59 14\nfbebcfabdefbaaedcefdeecababcabebadfbccaaedaebfdaefdbbcbebbe\n5 32 e f\n8 46 e e\n31 43 e f\n3 10 e a\n53 54 f d\n55 59 d a\n39 58 e b\n54 56 f a\n9 40 b e\n28 37 d a\n7 35 e b\n7 56 c f\n23 26 e a\n15 44 e d", "output": "fbabcfabdffbaafdfffdfffababfabfbaafdffaafdabbfdabfdbbfbbbbe" }, { "input": "7 17\nbbaabab\n3 5 a b\n5 7 a a\n5 5 a a\n4 4 b a\n7 7 a a\n5 6 b b\n1 3 b a\n6 7 a b\n4 6 a b\n6 6 a a\n2 4 b a\n1 7 b a\n4 6 b b\n2 5 b b\n2 5 a b\n1 4 a a\n4 4 b a", "output": "abbabaa" }, { "input": "100 1\ndebaaagbfdgehagadabfgheegggfghghgeeeabgceffeffggcbcegfgebbdhebhfagcgadcbdbabddbcadgbgdebdfehceehcaef\n13 99 f c", "output": "debaaagbfdgehagadabcgheegggcghghgeeeabgcecceccggcbcegcgebbdhebhcagcgadcbdbabddbcadgbgdebdcehceehcaef" }, { "input": "1 1\na\n1 1 a b", "output": "b" }, { "input": "100 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1 100 a b", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "2 2\naa\n1 2 a b\n1 2 b c", "output": "cc" }, { "input": "3 3\naaa\n1 3 a b\n1 3 b c\n1 3 c d", "output": "ddd" }, { "input": "2 2\naa\n2 2 a b\n1 1 a b", "output": "bb" } ]
1,678,157,808
2,147,483,647
Python 3
OK
TESTS
47
62
0
n, m = map(int, input(). split()) s = list(input()) for i in range(m): l, r, c1, c2 = map(str, input(). split()) l, r = int(l), int(r) for j in range(l - 1, r): if s[j] == c1: s[j] = c2 for l in s: print(l, end = '')
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space. Output Specification: Output string *s* after performing *m* operations described above. Demo Input: ['3 1\nioi\n1 1 i n\n', '5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n'] Demo Output: ['noi', 'gaaak'] Note: For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
```python n, m = map(int, input(). split()) s = list(input()) for i in range(m): l, r, c1, c2 = map(str, input(). split()) l, r = int(l), int(r) for j in range(l - 1, r): if s[j] == c1: s[j] = c2 for l in s: print(l, end = '') ```
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
1,514,893,376
2,147,483,647
Python 3
OK
TESTS
87
140
13,926,400
n=int(input()) l=list(map(int,input().split())) odd=[] for j in l: if j%2!=0: odd.append(j) jam=0 for i in l: jam=jam+i if jam%2==0: print(jam) else: while jam%2!=0: jam=jam-min(odd) print(jam)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python n=int(input()) l=list(map(int,input().split())) odd=[] for j in l: if j%2!=0: odd.append(j) jam=0 for i in l: jam=jam+i if jam%2==0: print(jam) else: while jam%2!=0: jam=jam-min(odd) print(jam) ```
3
846
B
Math Show
PROGRAMMING
1,800
[ "brute force", "greedy" ]
null
null
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order. By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1. Polycarp has *M* minutes of time. What is the maximum number of points he can earn?
The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109). The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task.
Print the maximum amount of points Polycarp can earn in *M* minutes.
[ "3 4 11\n1 2 3 4\n", "5 5 10\n1 2 4 8 16\n" ]
[ "6\n", "7\n" ]
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute. In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
0
[ { "input": "3 4 11\n1 2 3 4", "output": "6" }, { "input": "5 5 10\n1 2 4 8 16", "output": "7" }, { "input": "1 1 0\n2", "output": "0" }, { "input": "1 1 1\n1", "output": "2" }, { "input": "2 1 0\n2", "output": "0" }, { "input": "2 2 2\n2 3", "output": "1" }, { "input": "4 2 15\n1 4", "output": "9" }, { "input": "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856", "output": "677" }, { "input": "5 3 10\n1 3 6", "output": "6" }, { "input": "5 3 50\n1 3 6", "output": "20" }, { "input": "5 3 2000000000\n1 3 6", "output": "20" }, { "input": "5 3 49\n1 3 6", "output": "18" }, { "input": "3 4 16\n1 2 3 4", "output": "9" }, { "input": "11 2 20\n1 9", "output": "13" }, { "input": "11 3 38\n1 9 9", "output": "15" }, { "input": "5 3 11\n1 1 2", "output": "11" }, { "input": "5 4 36\n1 3 7 7", "output": "13" }, { "input": "1 13 878179\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091", "output": "5" }, { "input": "1 9 262522\n500878 36121 420012 341288 139726 362770 462113 261122 394426", "output": "2" }, { "input": "45 32 252252766\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300", "output": "1094" }, { "input": "44 41 93891122\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941", "output": "1084" }, { "input": "12 45 2290987\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616", "output": "95" }, { "input": "42 9 4354122\n47443 52983 104606 84278 5720 55971 100555 90845 91972", "output": "124" }, { "input": "45 28 33631968\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983", "output": "979" }, { "input": "18 3 36895\n877 2054 4051", "output": "28" }, { "input": "13 30 357\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312", "output": "31" }, { "input": "44 11 136\n77 38 12 71 81 15 66 47 29 22 71", "output": "11" }, { "input": "32 6 635\n3 4 2 1 7 7", "output": "195" }, { "input": "30 19 420\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2", "output": "309" }, { "input": "37 40 116\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", "output": "118" }, { "input": "7 37 133\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", "output": "136" }, { "input": "40 1 8\n3", "output": "4" }, { "input": "1 28 1\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3", "output": "1" }, { "input": "12 1 710092\n145588", "output": "8" }, { "input": "1 7 47793\n72277 45271 85507 39251 45440 101022 105165", "output": "1" }, { "input": "1 1 0\n4", "output": "0" }, { "input": "1 2 3\n2 2", "output": "1" }, { "input": "1 1 0\n5", "output": "0" }, { "input": "1 1 3\n5", "output": "0" }, { "input": "1 3 0\n6 3 4", "output": "0" }, { "input": "1 2 0\n1 2", "output": "0" }, { "input": "1 1 3\n5", "output": "0" }, { "input": "1 1 0\n5", "output": "0" }, { "input": "2 2 3\n7 2", "output": "1" }, { "input": "2 4 5\n1 2 8 6", "output": "3" }, { "input": "2 1 0\n3", "output": "0" }, { "input": "1 3 3\n16 4 5", "output": "0" }, { "input": "2 1 0\n1", "output": "0" }, { "input": "3 2 2\n6 1", "output": "2" }, { "input": "3 2 1\n1 1", "output": "1" }, { "input": "1 3 19\n12 15 6", "output": "2" }, { "input": "2 2 8\n12 1", "output": "2" }, { "input": "1 6 14\n15 2 6 13 14 4", "output": "3" }, { "input": "4 1 0\n1", "output": "0" }, { "input": "1 1 0\n2", "output": "0" }, { "input": "1 1 0\n2", "output": "0" }, { "input": "2 2 5\n5 6", "output": "1" }, { "input": "1 3 8\n5 4 4", "output": "2" }, { "input": "1 5 44\n2 19 18 6 8", "output": "4" }, { "input": "1 1 0\n4", "output": "0" }, { "input": "3 2 7\n5 1", "output": "4" }, { "input": "4 2 9\n8 6", "output": "1" }, { "input": "4 3 3\n6 12 7", "output": "0" }, { "input": "4 1 2\n1", "output": "4" }, { "input": "2 4 15\n8 3 7 8", "output": "3" }, { "input": "6 1 2\n4", "output": "0" }, { "input": "2 1 1\n1", "output": "2" }, { "input": "1 1 2\n3", "output": "0" }, { "input": "2 2 2\n1 4", "output": "2" }, { "input": "6 2 78\n12 10", "output": "10" }, { "input": "1 3 10\n17 22 15", "output": "0" }, { "input": "6 3 13\n1 2 3", "output": "10" }, { "input": "21 3 26\n1 2 3", "output": "24" }, { "input": "3 7 20012\n1 1 1 1 1 1 10000", "output": "20" }, { "input": "5 4 40\n4 2 3 3", "output": "17" }, { "input": "4 5 40\n4 1 3 2 4", "output": "18" }, { "input": "3 5 22\n1 1 4 1 1", "output": "16" }, { "input": "5 2 17\n3 4", "output": "7" }, { "input": "5 4 32\n4 2 1 1", "output": "21" }, { "input": "5 5 34\n4 1 1 2 4", "output": "20" }, { "input": "3 3 15\n1 2 1", "output": "12" }, { "input": "3 2 11\n1 2", "output": "9" }, { "input": "5 4 11\n2 1 3 4", "output": "8" }, { "input": "45 45 2000000000\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", "output": "2070" } ]
1,505,223,578
2,147,483,647
Python 3
OK
TESTS
84
62
716,800
n,k,m = list(map(int,input().split())) t = list(map(int,input().split())) t.sort() s = sum(t) mmm = 0 for i in range(n+1): if i*s > m : break tm = m-i*s c = k*i+i for j in range(k): c+=min(tm//t[j],n-i) tm-=min(tm//t[j],n-i)*t[j] mmm = max(mmm,c) print(mmm)
Title: Math Show Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order. By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1. Polycarp has *M* minutes of time. What is the maximum number of points he can earn? Input Specification: The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109). The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. Output Specification: Print the maximum amount of points Polycarp can earn in *M* minutes. Demo Input: ['3 4 11\n1 2 3 4\n', '5 5 10\n1 2 4 8 16\n'] Demo Output: ['6\n', '7\n'] Note: In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute. In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
```python n,k,m = list(map(int,input().split())) t = list(map(int,input().split())) t.sort() s = sum(t) mmm = 0 for i in range(n+1): if i*s > m : break tm = m-i*s c = k*i+i for j in range(k): c+=min(tm//t[j],n-i) tm-=min(tm//t[j],n-i)*t[j] mmm = max(mmm,c) print(mmm) ```
3
358
A
Dima and Continuous Line
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
[ "4\n0 10 5 15\n", "4\n0 15 5 10\n" ]
[ "yes\n", "no\n" ]
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
500
[ { "input": "4\n0 10 5 15", "output": "yes" }, { "input": "4\n0 15 5 10", "output": "no" }, { "input": "5\n0 1000 2000 3000 1500", "output": "yes" }, { "input": "5\n-724093 710736 -383722 -359011 439613", "output": "no" }, { "input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696", "output": "yes" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "no" }, { "input": "11\n1 11 10 2 3 9 8 4 5 7 6", "output": "no" }, { "input": "10\n3 2 4 5 1 6 9 7 8 10", "output": "yes" }, { "input": "11\n3 4 2 5 1 6 11 7 10 8 9", "output": "no" }, { "input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8", "output": "no" }, { "input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3", "output": "yes" }, { "input": "1\n0", "output": "no" }, { "input": "4\n3 1 4 2", "output": "yes" }, { "input": "5\n0 2 4 -2 5", "output": "no" }, { "input": "5\n1 9 8 7 0", "output": "yes" }, { "input": "3\n5 10 0", "output": "no" }, { "input": "6\n1 3 -1 5 2 4", "output": "yes" }, { "input": "4\n3 2 4 1", "output": "no" }, { "input": "4\n10 5 15 0", "output": "no" }, { "input": "2\n-5 -10", "output": "no" }, { "input": "3\n1 0 3", "output": "no" }, { "input": "4\n-2 -4 1 -3", "output": "yes" }, { "input": "4\n3 6 0 2", "output": "no" }, { "input": "4\n-9 10 -10 0", "output": "yes" }, { "input": "4\n5 10 1 15", "output": "no" }, { "input": "3\n1 0 2", "output": "no" }, { "input": "4\n2 3 4 1", "output": "no" }, { "input": "4\n7 5 9 12", "output": "no" } ]
1,531,863,772
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
124
0
n = int(input()) pos = [int(k) for k in input().split()] sigue = True if len(pos)>2: for i in range(len(pos)-2): x1 = pos[i] x2 = pos[i+1] for k in range(i+2,len(pos)-1): x3 = pos[k] x4 = pos[k+1] if x1<x3<x2<x4 or x3<x1<x4<x2: print("yes") sigue = False break if sigue: print("no")
Title: Dima and Continuous Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. Output Specification: In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). Demo Input: ['4\n0 10 5 15\n', '4\n0 15 5 10\n'] Demo Output: ['yes\n', 'no\n'] Note: The first test from the statement is on the picture to the left, the second test is on the picture to the right.
```python n = int(input()) pos = [int(k) for k in input().split()] sigue = True if len(pos)>2: for i in range(len(pos)-2): x1 = pos[i] x2 = pos[i+1] for k in range(i+2,len(pos)-1): x3 = pos[k] x4 = pos[k+1] if x1<x3<x2<x4 or x3<x1<x4<x2: print("yes") sigue = False break if sigue: print("no") ```
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "26" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,698,789,699
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
n, k = map(int, input().split()) scores = list(map(int, input().split())) count = 0 def func(): if k >= n: print(0) for a in scores: if a == 0: break elif a >= scores[k]: count += 1 print(count)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python n, k = map(int, input().split()) scores = list(map(int, input().split())) count = 0 def func(): if k >= n: print(0) for a in scores: if a == 0: break elif a >= scores[k]: count += 1 print(count) ```
0
0
none
none
none
0
[ "none" ]
null
null
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined as follows: In the above formula, 1<=≤<=*l*<=&lt;<=*r*<=≤<=*n* must hold, where *n* is the size of the Main Uzhlyandian Array *a*, and |*x*| means absolute value of *x*. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of *f* among all possible values of *l* and *r* for the given array *a*.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements.
Print the only integer — the maximum value of *f*.
[ "5\n1 4 2 3 1\n", "4\n1 5 4 7\n" ]
[ "3", "6" ]
In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5]. In the second case maximal value of *f* is reachable only on the whole array.
0
[ { "input": "5\n1 4 2 3 1", "output": "3" }, { "input": "4\n1 5 4 7", "output": "6" }, { "input": "8\n16 14 12 10 8 100 50 0", "output": "92" }, { "input": "2\n1 1", "output": "0" }, { "input": "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -40 -15 -28 38 -40 -42 -42 7 -43 5 2 -11 10 43 9 49 -13 36 2 24 46 50 -15 -26 -6 -6 8 4 -44 -3", "output": "208" }, { "input": "100\n23 64 60 -45 -36 -64 -59 15 -75 69 -30 -7 -20 17 -77 58 93 -76 -98 -22 -31 16 -50 6 -20 -85 1 64 -88 -8 -15 -6 -57 25 91 10 2 -90 74 -66 -42 73 28 49 -85 59 96 79 -25 49 -59 -89 -75 12 -96 -33 -65 -8 -100 -81 17 99 -91 -5 7 -21 1 85 63 86 -26 85 -31 11 -75 35 -82 15 98 93 -55 66 70 36 -38 8 92 -63 -5 60 -78 -7 -22 -1 4 54 36 16 32 -20", "output": "632" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "3\n0 1 -1", "output": "2" }, { "input": "5\n1000000000 0 0 1000000000 -1000000000", "output": "2000000000" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000" }, { "input": "4\n1000000000 0 0 -1000000000", "output": "2000000000" }, { "input": "4\n1 0 1 0", "output": "1" }, { "input": "5\n0 10 20 30 40", "output": "10" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000" }, { "input": "2\n1 2", "output": "1" }, { "input": "9\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000", "output": "4000000000" }, { "input": "16\n-1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000", "output": "16000000000" }, { "input": "6\n1000000000 0 0 1000000000 1000000000 0", "output": "3000000000" }, { "input": "17\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000", "output": "8000000000" }, { "input": "11\n1000000000 0 1 1000000000 999999999 1 0 1000000000 999999999 1 1000000000", "output": "4999999991" }, { "input": "4\n1000000000 -1000000000 -1000000000 1000000000", "output": "4000000000" }, { "input": "10\n1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000", "output": "10000000000" } ]
1,490,810,193
6,693
PyPy 3
OK
TESTS
52
280
34,611,200
import sys def solve(): n = int(input()) a = [int(i) for i in input().split()] a_dif = [abs(a[i + 1] - a[i]) for i in range(n - 1)] a1 = [a_dif[i] * (-1)**i for i in range(n - 1)] md1 = 0 m1 = 0 v = 0 for i in range(n - 1): v += a1[i] if v < m1: m1 = v else: md1 = max(v - m1, md1) a2 = [a1[i]*(-1) for i in range(n -1)] md2 = 0 m2 = 0 v = 0 for i in range(n - 1): v += a2[i] if v < m2: m2 = v else: md2 = max(v - m2, md2) ans = max(md1, md2) print(ans) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined as follows: In the above formula, 1<=≤<=*l*<=&lt;<=*r*<=≤<=*n* must hold, where *n* is the size of the Main Uzhlyandian Array *a*, and |*x*| means absolute value of *x*. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of *f* among all possible values of *l* and *r* for the given array *a*. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements. Output Specification: Print the only integer — the maximum value of *f*. Demo Input: ['5\n1 4 2 3 1\n', '4\n1 5 4 7\n'] Demo Output: ['3', '6'] Note: In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5]. In the second case maximal value of *f* is reachable only on the whole array.
```python import sys def solve(): n = int(input()) a = [int(i) for i in input().split()] a_dif = [abs(a[i + 1] - a[i]) for i in range(n - 1)] a1 = [a_dif[i] * (-1)**i for i in range(n - 1)] md1 = 0 m1 = 0 v = 0 for i in range(n - 1): v += a1[i] if v < m1: m1 = v else: md1 = max(v - m1, md1) a2 = [a1[i]*(-1) for i in range(n -1)] md2 = 0 m2 = 0 v = 0 for i in range(n - 1): v += a2[i] if v < m2: m2 = v else: md2 = max(v - m2, md2) ans = max(md1, md2) print(ans) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve() ```
3
849
B
Tell Your World
PROGRAMMING
1,600
[ "brute force", "geometry" ]
null
null
Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
[ "5\n7 5 8 6 9\n", "5\n-1 -2 0 0 -5\n", "5\n5 4 3 2 1\n", "5\n1000000000 0 0 0 0\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n" ]
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
1,000
[ { "input": "5\n7 5 8 6 9", "output": "Yes" }, { "input": "5\n-1 -2 0 0 -5", "output": "No" }, { "input": "5\n5 4 3 2 1", "output": "No" }, { "input": "5\n1000000000 0 0 0 0", "output": "Yes" }, { "input": "5\n1000000000 1 0 -999999999 -1000000000", "output": "Yes" }, { "input": "3\n998 244 353", "output": "Yes" }, { "input": "3\n-1000000000 0 1000000000", "output": "No" }, { "input": "5\n-1 -1 -1 -1 1", "output": "Yes" }, { "input": "4\n-9763 530 3595 6660", "output": "Yes" }, { "input": "4\n-253090305 36298498 374072642 711846786", "output": "Yes" }, { "input": "5\n-186772848 -235864239 -191561068 -193955178 -243046569", "output": "Yes" }, { "input": "5\n-954618456 -522919664 -248330428 -130850748 300848044", "output": "Yes" }, { "input": "10\n4846 6705 2530 5757 5283 -944 -2102 -3260 -4418 2913", "output": "No" }, { "input": "10\n-6568 -5920 -5272 -4624 -2435 -635 -2680 -2032 -1384 6565", "output": "No" }, { "input": "20\n319410377 286827025 254243673 221660321 189076969 156493617 123910265 91326913 58743561 26160209 -6423143 -39006495 -71589847 -104173199 -136756551 -169339903 -201923255 -234506607 -267089959 -299673311", "output": "No" }, { "input": "20\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 758268836 -975467175 758268835 -975467176 758268834 -975467177 758268833 -975467178 758268832 -975467179 758268831", "output": "Yes" }, { "input": "4\n1 0 3 0", "output": "No" }, { "input": "4\n100 2 3 4", "output": "Yes" }, { "input": "5\n7 5 8 6 3", "output": "No" }, { "input": "3\n1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "4\n1 0 1 4", "output": "Yes" }, { "input": "7\n1 2 -1 0 1 6 7", "output": "Yes" }, { "input": "4\n0 0 4 0", "output": "Yes" }, { "input": "7\n0 0 2 3 4 5 5", "output": "Yes" }, { "input": "5\n7 5 8 6 8", "output": "No" }, { "input": "5\n1 2 9 4 5", "output": "Yes" }, { "input": "8\n1 12 3 14 5 16 7 8", "output": "Yes" }, { "input": "5\n1 6 7 4 9", "output": "Yes" }, { "input": "5\n2 1 0 1 2", "output": "No" }, { "input": "4\n0 0 1 3", "output": "Yes" }, { "input": "4\n100 50 50 10000000", "output": "No" }, { "input": "5\n1 2 3 3 3", "output": "No" }, { "input": "5\n1 2 6 10 17", "output": "Yes" }, { "input": "4\n1 3 4 4", "output": "Yes" }, { "input": "4\n100 50 50 1000000", "output": "No" }, { "input": "6\n1 2 4 5 7 9", "output": "No" }, { "input": "6\n0 0 1 2 3 4", "output": "Yes" }, { "input": "5\n7 5 9 10 8", "output": "Yes" }, { "input": "7\n1 2 2 1 2 2 1", "output": "Yes" }, { "input": "4\n2 2 4 5", "output": "Yes" }, { "input": "6\n1 2 1 3 4 5", "output": "No" }, { "input": "4\n1 3 3 6", "output": "No" }, { "input": "5\n1 2 -3 4 -1", "output": "Yes" } ]
1,508,461,364
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
5,529,600
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools """ created by shhuan at 2017/10/20 08:46 """ N = int(input()) A = [int(x) for x in input().split()] ks = collections.defaultdict(int) for i in range(N): for j in range(i+1, N): k = (A[j]-A[i])/(j-i) ks[k] += 1 K = [(k, v) for k,v in ks.items() if v == max(ks.values())][0][0] vis = [0] * N vis[0] = 1 for i in range(1, N): if (A[i]-A[0])/i == K: vis[i] = 1 b = 0 for i in range(N): if vis[i] == 0: b = i break if b == 0: print('No') else: vis[b] = 2 for i in range(b+1, N): if (A[i]-A[b])/(i-b) == K: vis[i] = 2 print(vis) c1 = vis.count(1) c2 = vis.count(2) if c1 > 0 and c2 > 0 and c1+c2==N: print('Yes') else: print('No')
Title: Tell Your World Time Limit: None seconds Memory Limit: None megabytes Problem Description: Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. Input Specification: The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point. Output Specification: Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['5\n7 5 8 6 9\n', '5\n-1 -2 0 0 -5\n', '5\n5 4 3 2 1\n', '5\n1000000000 0 0 0 0\n'] Demo Output: ['Yes\n', 'No\n', 'No\n', 'Yes\n'] Note: In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
```python # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools """ created by shhuan at 2017/10/20 08:46 """ N = int(input()) A = [int(x) for x in input().split()] ks = collections.defaultdict(int) for i in range(N): for j in range(i+1, N): k = (A[j]-A[i])/(j-i) ks[k] += 1 K = [(k, v) for k,v in ks.items() if v == max(ks.values())][0][0] vis = [0] * N vis[0] = 1 for i in range(1, N): if (A[i]-A[0])/i == K: vis[i] = 1 b = 0 for i in range(N): if vis[i] == 0: b = i break if b == 0: print('No') else: vis[b] = 2 for i in range(b+1, N): if (A[i]-A[b])/(i-b) == K: vis[i] = 2 print(vis) c1 = vis.count(1) c2 = vis.count(2) if c1 > 0 and c2 > 0 and c1+c2==N: print('Yes') else: print('No') ```
0
765
C
Table Tennis Game 2
PROGRAMMING
1,200
[ "math" ]
null
null
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets.
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
[ "11 11 5\n", "11 2 3\n" ]
[ "1\n", "-1\n" ]
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
1,250
[ { "input": "11 11 5", "output": "1" }, { "input": "11 2 3", "output": "-1" }, { "input": "1 5 9", "output": "14" }, { "input": "2 3 3", "output": "2" }, { "input": "1 1000000000 1000000000", "output": "2000000000" }, { "input": "2 3 5", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "2" }, { "input": "1 0 1", "output": "1" }, { "input": "101 99 97", "output": "-1" }, { "input": "1000000000 0 1", "output": "-1" }, { "input": "137 137 136", "output": "1" }, { "input": "255 255 255", "output": "2" }, { "input": "1 0 1000000000", "output": "1000000000" }, { "input": "123 456 789", "output": "9" }, { "input": "666666 6666666 666665", "output": "-1" }, { "input": "1000000000 999999999 999999999", "output": "-1" }, { "input": "100000000 100000001 99999999", "output": "-1" }, { "input": "3 2 1000000000", "output": "-1" }, { "input": "999999999 1000000000 999999998", "output": "-1" }, { "input": "12938621 192872393 102739134", "output": "21" }, { "input": "666666666 1230983 666666666", "output": "1" }, { "input": "123456789 123456789 123456787", "output": "1" }, { "input": "5 6 0", "output": "-1" }, { "input": "11 0 12", "output": "-1" }, { "input": "2 11 0", "output": "-1" }, { "input": "2 1 0", "output": "-1" }, { "input": "10 11 12", "output": "2" }, { "input": "11 12 5", "output": "-1" }, { "input": "11 12 3", "output": "-1" }, { "input": "11 15 4", "output": "-1" }, { "input": "2 3 1", "output": "-1" }, { "input": "11 12 0", "output": "-1" }, { "input": "11 13 2", "output": "-1" }, { "input": "11 23 22", "output": "4" }, { "input": "10 21 0", "output": "-1" }, { "input": "11 23 1", "output": "-1" }, { "input": "11 10 12", "output": "-1" }, { "input": "11 1 12", "output": "-1" }, { "input": "11 5 12", "output": "-1" }, { "input": "11 8 12", "output": "-1" }, { "input": "11 12 1", "output": "-1" }, { "input": "5 4 6", "output": "-1" }, { "input": "10 1 22", "output": "-1" }, { "input": "2 3 0", "output": "-1" }, { "input": "11 23 2", "output": "-1" }, { "input": "2 1000000000 1000000000", "output": "1000000000" }, { "input": "11 0 15", "output": "-1" }, { "input": "11 5 0", "output": "-1" }, { "input": "11 5 15", "output": "-1" }, { "input": "10 0 13", "output": "-1" }, { "input": "4 7 0", "output": "-1" }, { "input": "10 2 8", "output": "-1" }, { "input": "11 5 22", "output": "2" }, { "input": "11 13 0", "output": "-1" }, { "input": "2 0 3", "output": "-1" }, { "input": "10 10 0", "output": "1" }, { "input": "10 11 10", "output": "2" }, { "input": "3 5 4", "output": "2" }, { "input": "11 22 3", "output": "2" }, { "input": "11 12 10", "output": "-1" }, { "input": "10 2 13", "output": "-1" }, { "input": "5 6 1", "output": "-1" }, { "input": "10 21 5", "output": "-1" }, { "input": "10 11 9", "output": "-1" }, { "input": "10 17 7", "output": "-1" }, { "input": "3 4 1", "output": "-1" }, { "input": "4 5 3", "output": "-1" }, { "input": "11 3 23", "output": "-1" }, { "input": "11 3 12", "output": "-1" }, { "input": "2 5 0", "output": "-1" }, { "input": "10 21 2", "output": "-1" }, { "input": "5 1 6", "output": "-1" }, { "input": "10 11 0", "output": "-1" }, { "input": "10 9 11", "output": "-1" }, { "input": "7 10 5", "output": "-1" }, { "input": "5 7 2", "output": "-1" }, { "input": "6 5 7", "output": "-1" }, { "input": "11 16 2", "output": "-1" }, { "input": "11 1000000000 10", "output": "-1" }, { "input": "10 2 21", "output": "-1" }, { "input": "10 15 1", "output": "-1" }, { "input": "5 2 8", "output": "-1" }, { "input": "11 10000000 10", "output": "-1" }, { "input": "10 1 101", "output": "-1" }, { "input": "20 24 2", "output": "-1" }, { "input": "11 24 0", "output": "-1" }, { "input": "11 17 4", "output": "-1" }, { "input": "11 13 1", "output": "-1" }, { "input": "10 11 2", "output": "-1" }, { "input": "11 23 3", "output": "-1" }, { "input": "10 99 0", "output": "-1" }, { "input": "6 7 4", "output": "-1" }, { "input": "11 1 22", "output": "2" }, { "input": "11 2 13", "output": "-1" }, { "input": "2 1 3", "output": "-1" }, { "input": "11 6 18", "output": "-1" }, { "input": "11 122 4", "output": "-1" }, { "input": "11 21 10", "output": "-1" }, { "input": "3 2 4", "output": "-1" }, { "input": "9 11 2", "output": "-1" }, { "input": "11 0 7", "output": "-1" }, { "input": "5 9 4", "output": "-1" }, { "input": "100 105 5", "output": "-1" }, { "input": "11 15 0", "output": "-1" }, { "input": "5 6 4", "output": "-1" }, { "input": "3 4 2", "output": "-1" }, { "input": "2 9 0", "output": "-1" }, { "input": "11 13 11", "output": "2" }, { "input": "11 15 5", "output": "-1" }, { "input": "11 4 15", "output": "-1" }, { "input": "10 1 0", "output": "-1" }, { "input": "11 16 8", "output": "-1" }, { "input": "10 43 0", "output": "-1" }, { "input": "11 13 5", "output": "-1" }, { "input": "11 22 0", "output": "2" }, { "input": "5 6 3", "output": "-1" }, { "input": "2 1 11", "output": "-1" }, { "input": "4 5 1", "output": "-1" }, { "input": "11 23 0", "output": "-1" }, { "input": "11 4 12", "output": "-1" }, { "input": "12 13 1", "output": "-1" }, { "input": "10 19 9", "output": "-1" }, { "input": "3 7 2", "output": "-1" }, { "input": "12 18 0", "output": "-1" }, { "input": "11 25 3", "output": "-1" }, { "input": "11 23 5", "output": "-1" }, { "input": "2 1 5", "output": "-1" }, { "input": "2 0 5", "output": "-1" }, { "input": "11 24 1", "output": "-1" }, { "input": "10 11 4", "output": "-1" }, { "input": "2 0 1", "output": "-1" }, { "input": "10 0 21", "output": "-1" }, { "input": "3 0 7", "output": "-1" }, { "input": "18 11 21", "output": "-1" }, { "input": "3 7 0", "output": "-1" }, { "input": "5 11 0", "output": "-1" }, { "input": "11 5 13", "output": "-1" }, { "input": "11 9 34", "output": "-1" }, { "input": "11 13 9", "output": "-1" }, { "input": "10 0 22", "output": "-1" }, { "input": "5 1 12", "output": "-1" }, { "input": "11 2 12", "output": "-1" }, { "input": "11 9 12", "output": "-1" }, { "input": "11 24 2", "output": "-1" }, { "input": "11 23 6", "output": "-1" }, { "input": "11 20 4", "output": "-1" }, { "input": "2 5 1", "output": "-1" }, { "input": "120 132 133", "output": "2" }, { "input": "11 111 4", "output": "-1" }, { "input": "10 7 11", "output": "-1" }, { "input": "6 13 0", "output": "-1" }, { "input": "5 11 1", "output": "-1" }, { "input": "11 5 27", "output": "-1" }, { "input": "11 15 3", "output": "-1" }, { "input": "11 0 13", "output": "-1" }, { "input": "11 13 10", "output": "-1" }, { "input": "11 25 5", "output": "-1" }, { "input": "4 3 5", "output": "-1" }, { "input": "100 199 100", "output": "2" }, { "input": "11 2 22", "output": "2" }, { "input": "10 20 2", "output": "2" }, { "input": "5 5 0", "output": "1" }, { "input": "10 11 1", "output": "-1" }, { "input": "11 12 2", "output": "-1" }, { "input": "5 16 3", "output": "-1" }, { "input": "12 14 1", "output": "-1" }, { "input": "10 22 2", "output": "-1" }, { "input": "2 4 0", "output": "2" }, { "input": "11 34 7", "output": "-1" }, { "input": "6 13 1", "output": "-1" }, { "input": "11 0 23", "output": "-1" }, { "input": "20 21 19", "output": "-1" }, { "input": "11 33 22", "output": "5" }, { "input": "10 4 41", "output": "-1" }, { "input": "3 4 0", "output": "-1" }, { "input": "11 15 7", "output": "-1" }, { "input": "5 0 6", "output": "-1" }, { "input": "11 3 22", "output": "2" }, { "input": "2 6 0", "output": "3" }, { "input": "10 11 11", "output": "2" }, { "input": "11 33 0", "output": "3" }, { "input": "4 6 2", "output": "-1" }, { "input": "11 76 2", "output": "-1" }, { "input": "7 9 4", "output": "-1" }, { "input": "10 43 1", "output": "-1" }, { "input": "22 25 5", "output": "-1" }, { "input": "3 5 2", "output": "-1" }, { "input": "11 1 24", "output": "-1" }, { "input": "12 25 3", "output": "-1" }, { "input": "11 0 22", "output": "2" }, { "input": "4 2 5", "output": "-1" }, { "input": "11 13 3", "output": "-1" }, { "input": "11 12 9", "output": "-1" }, { "input": "11 35 1", "output": "-1" }, { "input": "5 3 6", "output": "-1" }, { "input": "5 11 4", "output": "-1" }, { "input": "12 8 14", "output": "-1" }, { "input": "10 12 9", "output": "-1" }, { "input": "11 12 13", "output": "2" }, { "input": "11 15 2", "output": "-1" }, { "input": "11 23 4", "output": "-1" }, { "input": "5 3 11", "output": "-1" }, { "input": "6 13 2", "output": "-1" }, { "input": "4 1 0", "output": "-1" }, { "input": "11 32 10", "output": "-1" }, { "input": "2 11 1", "output": "-1" }, { "input": "10 11 7", "output": "-1" }, { "input": "11 26 0", "output": "-1" }, { "input": "100 205 5", "output": "-1" }, { "input": "4 0 2", "output": "-1" }, { "input": "10 11 8", "output": "-1" }, { "input": "11 22 5", "output": "2" }, { "input": "4 0 5", "output": "-1" }, { "input": "11 87 22", "output": "9" }, { "input": "4 8 0", "output": "2" }, { "input": "9 8 17", "output": "-1" }, { "input": "10 20 0", "output": "2" }, { "input": "10 9 19", "output": "-1" }, { "input": "12 2 13", "output": "-1" }, { "input": "11 24 5", "output": "-1" }, { "input": "10 1 11", "output": "-1" }, { "input": "4 0 9", "output": "-1" }, { "input": "3 0 1", "output": "-1" }, { "input": "11 12 4", "output": "-1" }, { "input": "3 8 2", "output": "-1" }, { "input": "11 17 10", "output": "-1" }, { "input": "6 1 13", "output": "-1" }, { "input": "11 25 0", "output": "-1" }, { "input": "12 0 13", "output": "-1" }, { "input": "10 5 20", "output": "2" }, { "input": "11 89 2", "output": "-1" }, { "input": "2 4 1", "output": "2" }, { "input": "10 31 0", "output": "-1" }, { "input": "11 34 1", "output": "-1" }, { "input": "999 6693 8331", "output": "14" }, { "input": "10 55 1", "output": "-1" }, { "input": "11 12 8", "output": "-1" }, { "input": "1 9 22", "output": "31" }, { "input": "7572 9186 895", "output": "-1" }, { "input": "3 2 11", "output": "-1" }, { "input": "2 1 4", "output": "2" }, { "input": "11 10 19", "output": "-1" }, { "input": "100 199 99", "output": "-1" }, { "input": "2537 8926 1523", "output": "-1" }, { "input": "11 0 5", "output": "-1" }, { "input": "5 1 11", "output": "-1" }, { "input": "12 13 5", "output": "-1" }, { "input": "10 12 0", "output": "-1" }, { "input": "5 4 7", "output": "-1" }, { "input": "12 25 1", "output": "-1" }, { "input": "7 9 0", "output": "-1" }, { "input": "4 15 0", "output": "-1" }, { "input": "5 11 2", "output": "-1" }, { "input": "11 58 3", "output": "-1" }, { "input": "10 11 5", "output": "-1" }, { "input": "10 3 1003", "output": "-1" }, { "input": "11 14 0", "output": "-1" }, { "input": "11 8 23", "output": "-1" }, { "input": "11 22 4", "output": "2" }, { "input": "5 2 0", "output": "-1" }, { "input": "11 1 35", "output": "-1" }, { "input": "12 25 5", "output": "-1" }, { "input": "11 37 4", "output": "-1" }, { "input": "20 42 3", "output": "-1" }, { "input": "10 12 2", "output": "-1" }, { "input": "4 1 5", "output": "-1" }, { "input": "5 16 0", "output": "-1" }, { "input": "11 13 7", "output": "-1" }, { "input": "5 0 3", "output": "-1" }, { "input": "11 2 11", "output": "1" }, { "input": "3 2 2000", "output": "-1" }, { "input": "3 0 4241", "output": "-1" }, { "input": "2 12 11", "output": "11" }, { "input": "10 2 82", "output": "-1" }, { "input": "11 0 11", "output": "1" }, { "input": "11 20 20", "output": "2" }, { "input": "5 0 10", "output": "2" }, { "input": "11 1 0", "output": "-1" }, { "input": "11 13 13", "output": "2" } ]
1,493,392,405
2,147,483,647
Python 3
OK
TESTS
279
77
5,529,600
#!/usr/bin/env python3 from sys import stdin,stdout def ri(): return map(int, stdin.readline().split()) k, a, b = ri() an = a//k ar = a%k bn = b//k br = b%k if an == 0 and br or bn == 0 and ar: print(-1) exit() ans = an+bn if ans: print(ans) else: print(-1)
Title: Table Tennis Game 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets. Input Specification: The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0). Output Specification: If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. Demo Input: ['11 11 5\n', '11 2 3\n'] Demo Output: ['1\n', '-1\n'] Note: Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
```python #!/usr/bin/env python3 from sys import stdin,stdout def ri(): return map(int, stdin.readline().split()) k, a, b = ri() an = a//k ar = a%k bn = b//k br = b%k if an == 0 and br or bn == 0 and ar: print(-1) exit() ans = an+bn if ans: print(ans) else: print(-1) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "input": "1000\n999", "output": "1" }, { "input": "1000\n1", "output": "250000" }, { "input": "2\n1", "output": "1" }, { "input": "2\n999", "output": "249001" }, { "input": "2\n998", "output": "248502" }, { "input": "999\n2", "output": "249001" }, { "input": "998\n2", "output": "248502" }, { "input": "2\n1000", "output": "249500" }, { "input": "1000\n2", "output": "249500" }, { "input": "1\n999", "output": "249500" }, { "input": "999\n1", "output": "249500" }, { "input": "188\n762", "output": "82656" }, { "input": "596\n777", "output": "8281" }, { "input": "773\n70", "output": "123904" }, { "input": "825\n729", "output": "2352" }, { "input": "944\n348", "output": "89102" }, { "input": "352\n445", "output": "2209" }, { "input": "529\n656", "output": "4096" }, { "input": "19\n315", "output": "22052" }, { "input": "138\n370", "output": "13572" }, { "input": "546\n593", "output": "576" }, { "input": "285\n242", "output": "484" }, { "input": "773\n901", "output": "4160" }, { "input": "892\n520", "output": "34782" }, { "input": "864\n179", "output": "117649" }, { "input": "479\n470", "output": "25" }, { "input": "967\n487", "output": "57840" }, { "input": "648\n106", "output": "73712" }, { "input": "58\n765", "output": "125316" }, { "input": "235\n56", "output": "8100" }, { "input": "285\n153", "output": "4422" }, { "input": "943\n13", "output": "216690" }, { "input": "675\n541", "output": "4556" }, { "input": "4\n912", "output": "206570" } ]
1,635,761,139
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
4,300,800
a=int(input()) b=int(input()) tierdness=0 if a!=b: x=(max(a,b)) y=(min(a,b)) print(x-y)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python a=int(input()) b=int(input()) tierdness=0 if a!=b: x=(max(a,b)) y=(min(a,b)) print(x-y) ```
0
92
B
Binary Number
PROGRAMMING
1,300
[ "greedy" ]
B. Binary Number
1
256
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time. How many actions should Fangy perform to get a number one from number *x*?
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Print the required number of actions.
[ "1\n", "1001001\n", "101110\n" ]
[ "0\n", "12\n", "8\n" ]
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.
1,000
[ { "input": "1", "output": "0" }, { "input": "1001001", "output": "12" }, { "input": "101110", "output": "8" }, { "input": "11", "output": "3" }, { "input": "11110001101", "output": "16" }, { "input": "1010101001001111000111110011111000010101011111101010", "output": "74" }, { "input": "1100000010010100111011100011110101111", "output": "55" }, { "input": "11000111111110110110100110110101111100010100110110010", "output": "74" }, { "input": "11100000110100011110101001101111100000011001111000011110000000111110111", "output": "106" }, { "input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111", "output": "133" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000", "output": "72" }, { "input": "10000100000", "output": "16" } ]
1,474,670,195
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
3,174,400
import fileinput,sys binary_int = int(fileinput.input().readline(),2) num = 0 while binary_int != 1: if binary_int%2==0: binary_int = binary_int // 2 else: binary_int = binary_int + 1 num += 1 print(num)
Title: Binary Number Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations. Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time. How many actions should Fangy perform to get a number one from number *x*? Input Specification: The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. Output Specification: Print the required number of actions. Demo Input: ['1\n', '1001001\n', '101110\n'] Demo Output: ['0\n', '12\n', '8\n'] Note: Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.
```python import fileinput,sys binary_int = int(fileinput.input().readline(),2) num = 0 while binary_int != 1: if binary_int%2==0: binary_int = binary_int // 2 else: binary_int = binary_int + 1 num += 1 print(num) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,658,857,335
2,147,483,647
Python 3
OK
TESTS
51
154
0
num = input() count = 0 while len(num) > 1: result = 0 for i in num: result += int(i) count += 1 num = str(result) print(count)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python num = input() count = 0 while len(num) > 1: result = 0 for i in num: result += int(i) count += 1 num = str(result) print(count) ```
3.9615
940
B
Our Tanya is Crying Out Loud
PROGRAMMING
1,400
[ "dp", "greedy" ]
null
null
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
[ "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n" ]
[ "6\n", "8\n", "12\n" ]
In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
1,250
[ { "input": "9\n2\n3\n1", "output": "6" }, { "input": "5\n5\n2\n20", "output": "8" }, { "input": "19\n3\n4\n2", "output": "12" }, { "input": "1845999546\n999435865\n1234234\n2323423", "output": "1044857680578777" }, { "input": "1604353664\n1604353665\n9993432\n1", "output": "16032999235141416" }, { "input": "777888456\n1\n98\n43", "output": "76233068590" }, { "input": "1162261467\n3\n1\n2000000000", "output": "1162261466" }, { "input": "1000000000\n1999999999\n789987\n184569875", "output": "789986999210013" }, { "input": "2000000000\n2\n1\n2000000000", "output": "1999999999" }, { "input": "1999888325\n3\n2\n2000000000", "output": "3333258884" }, { "input": "1897546487\n687\n89798979\n879876541", "output": "110398404423" }, { "input": "20\n1\n20\n1", "output": "380" }, { "input": "16\n5\n17\n3", "output": "54" }, { "input": "19\n19\n19\n1", "output": "1" }, { "input": "18\n2\n3\n16", "output": "40" }, { "input": "1\n11\n8\n9", "output": "0" }, { "input": "9\n10\n1\n20", "output": "8" }, { "input": "19\n10\n19\n2", "output": "173" }, { "input": "16\n9\n14\n2", "output": "100" }, { "input": "15\n2\n5\n2", "output": "21" }, { "input": "14\n7\n13\n1", "output": "14" }, { "input": "43\n3\n45\n3", "output": "189" }, { "input": "99\n1\n98\n1", "output": "9604" }, { "input": "77\n93\n100\n77", "output": "7600" }, { "input": "81\n3\n91\n95", "output": "380" }, { "input": "78\n53\n87\n34", "output": "2209" }, { "input": "80\n3\n15\n1", "output": "108" }, { "input": "97\n24\n4\n24", "output": "40" }, { "input": "100\n100\n1\n100", "output": "99" }, { "input": "87\n4\n17\n7", "output": "106" }, { "input": "65\n2\n3\n6", "output": "36" }, { "input": "1000000\n1435\n3\n999999", "output": "1005804" }, { "input": "783464\n483464\n2\n966928", "output": "1566926" }, { "input": "248035\n11\n3\n20", "output": "202" }, { "input": "524287\n2\n945658\n999756", "output": "34963354" }, { "input": "947352\n78946\n85\n789654", "output": "790589" }, { "input": "1000000\n1\n999899\n60", "output": "999898000101" }, { "input": "753687\n977456\n6547\n456", "output": "4934382242" }, { "input": "1000000\n500000\n1\n999997", "output": "999998" }, { "input": "997458\n843596\n1\n843596", "output": "997457" }, { "input": "821109\n92\n6547\n98787", "output": "394566" }, { "input": "1073741823\n2\n9543\n8923453", "output": "188412866" }, { "input": "1000999777\n1934999345\n2356346\n34534565", "output": "2358701818178496" }, { "input": "2000000000\n1\n2000000000\n98", "output": "3999999998000000000" }, { "input": "1999324353\n978435356\n1\n978435356", "output": "1020888998" }, { "input": "2000000000\n2\n2000000000\n2000000000", "output": "84000000000" }, { "input": "241375690\n17\n2\n1998789654", "output": "482751378" }, { "input": "171507000\n350\n789\n6548687", "output": "14216965" }, { "input": "1100220011\n10001\n2\n1999778654", "output": "1999998674" }, { "input": "1867622656\n43216\n789644\n12315468", "output": "24630936" }, { "input": "1867622656\n43216\n1\n1879865413", "output": "1867622655" }, { "input": "1999999999\n1000000000\n789987\n184569875", "output": "789987183779888" }, { "input": "1987987897\n103546\n7\n98754563", "output": "98946650" }, { "input": "10\n2\n2\n5", "output": "13" }, { "input": "7\n2\n1\n100000", "output": "6" }, { "input": "7\n2\n3\n1", "output": "8" }, { "input": "2000000000\n666666667\n1\n1", "output": "666666668" }, { "input": "1999999997\n666666666\n2\n2", "output": "1333333334" } ]
1,645,271,890
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
110,182,400
from sys import stdin, maxsize from collections import defaultdict def rei(): return list(map(int, stdin.readline().strip().split(' '))) def res(): return stdin.readline().rstrip() def prno(): print('NO') def pryes(): print('YES') def solve(): n=rei()[0] k=rei()[0] a=rei()[0] b=rei()[0] dp=defaultdict(lambda: maxsize) dp[1]=0 for i in range(1, n+1): dp[i+1]=min(dp[i+1], dp[i]+a) dp[i*k]=min(dp[i*k], dp[i]+b) print(dp[n]) if __name__ == '__main__': solve()
Title: Our Tanya is Crying Out Loud Time Limit: None seconds Memory Limit: None megabytes Problem Description: Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). Output Specification: Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. Demo Input: ['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n'] Demo Output: ['6\n', '8\n', '12\n'] Note: In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
```python from sys import stdin, maxsize from collections import defaultdict def rei(): return list(map(int, stdin.readline().strip().split(' '))) def res(): return stdin.readline().rstrip() def prno(): print('NO') def pryes(): print('YES') def solve(): n=rei()[0] k=rei()[0] a=rei()[0] b=rei()[0] dp=defaultdict(lambda: maxsize) dp[1]=0 for i in range(1, n+1): dp[i+1]=min(dp[i+1], dp[i]+a) dp[i*k]=min(dp[i*k], dp[i]+b) print(dp[n]) if __name__ == '__main__': solve() ```
0
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong.
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 4", "output": "YES" }, { "input": "43 5", "output": "YES" }, { "input": "47 7", "output": "NO" }, { "input": "50 5", "output": "YES" }, { "input": "57 6", "output": "YES" }, { "input": "60 8", "output": "NO" }, { "input": "62 7", "output": "YES" }, { "input": "76 9", "output": "NO" }, { "input": "69 7", "output": "YES" }, { "input": "113 10", "output": "YES" }, { "input": "141 11", "output": "YES" }, { "input": "207 16", "output": "NO" }, { "input": "231 18", "output": "NO" }, { "input": "296 19", "output": "YES" }, { "input": "332 20", "output": "YES" }, { "input": "378 24", "output": "NO" }, { "input": "428 23", "output": "YES" }, { "input": "497 27", "output": "NO" }, { "input": "640 32", "output": "YES" }, { "input": "798 35", "output": "YES" }, { "input": "802 35", "output": "YES" }, { "input": "864 40", "output": "NO" }, { "input": "953 44", "output": "NO" }, { "input": "995 44", "output": "YES" }, { "input": "1000 44", "output": "YES" }, { "input": "1000 0", "output": "YES" }, { "input": "1000 1000", "output": "NO" }, { "input": "2 1000", "output": "NO" }, { "input": "2 0", "output": "YES" } ]
1,649,789,833
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
2,252,800
def sieveE(n): primes = [True] * (n + 1) primes[0] = False primes[1] = False prime_nums = [] for i in range(2, int(n ** 0.5) + 1): if primes[i]: prime_nums.append(i) for j in range(i * i, n + 1 ,i): primes[j] = False return prime_nums + [i for i in range(int(n**0.5)+1, n+1) if primes[i]], primes # Prime integers, Truth values in a table def noldbach(): primes, primes_table = sieveE(3500) # 1000+ primes n, k = map(int, input().split()) res = 0 for i in range(len(primes)): if i > n: break if primes_table[primes[i] + primes[i+1] + 1]: res += 1 if res >= k: print("YES") else: print("NO") if __name__=="__main__": noldbach()
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong. Input Specification: The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). Output Specification: Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. Demo Input: ['27 2\n', '45 7\n'] Demo Output: ['YES', 'NO'] Note: In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
```python def sieveE(n): primes = [True] * (n + 1) primes[0] = False primes[1] = False prime_nums = [] for i in range(2, int(n ** 0.5) + 1): if primes[i]: prime_nums.append(i) for j in range(i * i, n + 1 ,i): primes[j] = False return prime_nums + [i for i in range(int(n**0.5)+1, n+1) if primes[i]], primes # Prime integers, Truth values in a table def noldbach(): primes, primes_table = sieveE(3500) # 1000+ primes n, k = map(int, input().split()) res = 0 for i in range(len(primes)): if i > n: break if primes_table[primes[i] + primes[i+1] + 1]: res += 1 if res >= k: print("YES") else: print("NO") if __name__=="__main__": noldbach() ```
0
0
none
none
none
0
[ "none" ]
null
null
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal. Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*. If there are multiple solutions, print any of them.
[ "5\n", "2\n" ]
[ "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n", "-1\n" ]
In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In Sample 2, you can easily notice that no lucky permutation triple exists.
0
[ { "input": "5", "output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3" }, { "input": "2", "output": "-1" }, { "input": "8", "output": "-1" }, { "input": "9", "output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 " }, { "input": "2", "output": "-1" }, { "input": "77", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 4..." }, { "input": "6", "output": "-1" }, { "input": "87", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n0 2 4..." }, { "input": "72", "output": "-1" }, { "input": "1", "output": "0 \n0 \n0 " }, { "input": "23", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 " }, { "input": "52", "output": "-1" }, { "input": "32", "output": "-1" }, { "input": "25", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 1 3 5 7 9 11 13 15 17 19 21 23 " }, { "input": "54", "output": "-1" }, { "input": "39", "output": "0 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 \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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 " }, { "input": "20", "output": "-1" }, { "input": "53", "output": "0 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 \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 \n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 " }, { "input": "34", "output": "-1" }, { "input": "23", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n0 2 4 6 8 10 12 14 16 18 20 22 1 3 5 7 9 11 13 15 17 19 21 " }, { "input": "37123", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "41904", "output": "-1" }, { "input": "46684", "output": "-1" }, { "input": "67817", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "72598", "output": "-1" }, { "input": "85891", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "74320", "output": "-1" }, { "input": "11805", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "16586", "output": "-1" }, { "input": "5014", "output": "-1" }, { "input": "73268", "output": "-1" }, { "input": "61697", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99182", "output": "-1" }, { "input": "79771", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "68199", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "5684", "output": "-1" }, { "input": "10465", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "31598", "output": "-1" }, { "input": "36379", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "16968", "output": "-1" }, { "input": "93061", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "73650", "output": "-1" }, { "input": "94783", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99564", "output": "-1" }, { "input": "37049", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "25478", "output": "-1" }, { "input": "30259", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "43551", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "31980", "output": "-1" }, { "input": "69465", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "1", "output": "0 \n0 \n0 " }, { "input": "100000", "output": "-1" }, { "input": "99999", "output": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1..." }, { "input": "99998", "output": "-1" } ]
1,676,978,927
2,147,483,647
Python 3
OK
TESTS
54
748
5,324,800
def main(): n = int(input()) if n % 2 == 0: print(-1) return A = [i for i in range(n)] A1 = [A[n - 1]] for i in A: A1.append(A[i]) A1.pop(-1) A2 = [] for i in range(n): A2.append((A[i] + A1[i]) % n) print(*A) print(*A1) print(*A2) if __name__ == '__main__': main()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal. Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). Output Specification: If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*. If there are multiple solutions, print any of them. Demo Input: ['5\n', '2\n'] Demo Output: ['1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n', '-1\n'] Note: In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds: - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/48cc13134296b68f459f69d78e0240859aaec702.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ac44412de7b46833e90348a6b3298f9796e3977c.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3825b0bb758208dda2ead1c5224c05d89ad9ab55.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0a72e2da40048a507839927a211267ac01c9bf89.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In Sample 2, you can easily notice that no lucky permutation triple exists.
```python def main(): n = int(input()) if n % 2 == 0: print(-1) return A = [i for i in range(n)] A1 = [A[n - 1]] for i in A: A1.append(A[i]) A1.pop(-1) A2 = [] for i in range(n): A2.append((A[i] + A1[i]) % n) print(*A) print(*A1) print(*A2) if __name__ == '__main__': main() ```
3
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,699,254,666
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
sh,coin=map(int,input().split()) sho=0 cnt=0 for x in range(100): cnt=cnt+1 sho=sh*cnt if sho%10==coin: print(cnt) break
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python sh,coin=map(int,input().split()) sho=0 cnt=0 for x in range(100): cnt=cnt+1 sho=sh*cnt if sho%10==coin: print(cnt) break ```
0
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3 d g\n5 5 h h\n2 8 g d\n8 9 a f\n5 9 c e\n1 7 f d\n1 6 e e\n5 7 c a\n8 9 b b\n2 6 e b\n6 6 g h\n1 2 b b\n1 5 a f\n5 8 f h\n1 5 e g\n3 9 f h\n6 8 g a\n4 6 h g\n1 5 f a\n5 6 a c\n4 8 e d\n1 4 d g\n7 8 b f\n5 6 h b\n3 9 c e\n1 9 b a", "output": "aahaddddh" }, { "input": "28 45\ndcbbaddjhbeefjadjchgkhgggfha\n10 25 c a\n13 19 a f\n12 28 e d\n12 27 e a\n9 20 b e\n7 17 g d\n22 26 j j\n8 16 c g\n14 16 a d\n3 10 f c\n10 26 d b\n8 17 i e\n10 19 d i\n6 21 c j\n7 22 b k\n17 19 a i\n4 18 j k\n8 25 a g\n10 27 j e\n9 18 g d\n16 23 h a\n17 26 k e\n8 16 h f\n1 15 d f\n22 28 k k\n11 20 c k\n6 11 b h\n17 17 e i\n15 22 g h\n8 18 c f\n4 16 e a\n8 25 b c\n6 24 d g\n5 9 f j\n12 19 i h\n4 25 e f\n15 25 c j\n15 27 e e\n11 20 b f\n19 27 e k\n2 21 d a\n9 27 k e\n14 24 b a\n3 6 i g\n2 26 k f", "output": "fcbbajjfjaaefefehfahfagggfha" }, { "input": "87 5\nnfinedeojadjmgafnaogekfjkjfncnliagfchjfcmellgigjjcaaoeakdolchjcecljdeblmheimkibkgdkcdml\n47 56 a k\n51 81 o d\n5 11 j h\n48 62 j d\n16 30 k m", "output": "nfinedeohadjmgafnaogemfjmjfncnliagfchjfcmellgigddckkdekkddlchdcecljdeblmheimkibkgdkcdml" }, { "input": "5 16\nacfbb\n1 2 e f\n2 5 a f\n2 3 b e\n4 4 f a\n2 3 f a\n1 2 b e\n4 5 c d\n2 4 e c\n1 4 e a\n1 3 d c\n3 5 e b\n3 5 e b\n2 2 e d\n1 3 e c\n3 3 a e\n1 5 a a", "output": "acebb" }, { "input": "94 13\nbcaaaaaaccacddcdaacbdaabbcbaddbccbccbbbddbadddcccbddadddaadbdababadaacdcdbcdadabdcdcbcbcbcbbcd\n52 77 d d\n21 92 d b\n45 48 c b\n20 25 d a\n57 88 d b\n3 91 b d\n64 73 a a\n5 83 b d\n2 69 c c\n28 89 a b\n49 67 c b\n41 62 a c\n49 87 b c", "output": "bcaaaaaaccacddcdaacddaaddcdbdddccdccddddddbdddddcdddcdddccdddcdcdcdcccdcddcdcdcddcdcdcdcdcdbcd" }, { "input": "67 39\nacbcbccccbabaabcabcaaaaaaccbcbbcbaaaacbbcccbcbabbcacccbbabbabbabaac\n4 36 a b\n25 38 a a\n3 44 b c\n35 57 b a\n4 8 a c\n20 67 c a\n30 66 b b\n27 40 a a\n2 56 a b\n10 47 c a\n22 65 c b\n29 42 a b\n1 46 c b\n57 64 b c\n20 29 b a\n14 51 c a\n12 55 b b\n20 20 a c\n2 57 c a\n22 60 c b\n16 51 c c\n31 64 a c\n17 30 c a\n23 36 c c\n28 67 a c\n37 40 a c\n37 50 b c\n29 48 c b\n2 34 b c\n21 53 b a\n26 63 a c\n23 28 c a\n51 56 c b\n32 61 b b\n64 67 b b\n21 67 b c\n8 53 c c\n40 62 b b\n32 38 c c", "output": "accccccccaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccc" }, { "input": "53 33\nhhcbhfafeececbhadfbdbehdfacfchbhdbfebdfeghebfcgdhehfh\n27 41 h g\n18 35 c b\n15 46 h f\n48 53 e g\n30 41 b c\n12 30 b f\n10 37 e f\n18 43 a h\n10 52 d a\n22 48 c e\n40 53 f d\n7 12 b h\n12 51 f a\n3 53 g a\n19 41 d h\n22 29 b h\n2 30 a b\n26 28 e h\n25 35 f a\n19 31 h h\n44 44 d e\n19 22 e c\n29 44 d h\n25 33 d h\n3 53 g c\n18 44 h b\n19 28 f e\n3 22 g h\n8 17 c a\n37 51 d d\n3 28 e h\n27 50 h h\n27 46 f b", "output": "hhcbhfbfhfababbbbbbbbbbbbbbbbbeaaeaaeaaeabebdeaahahdh" }, { "input": "83 10\nfhbecdgadecabbbecedcgfdcefcbgechbedagecgdgfgdaahchdgchbeaedgafdefecdchceececfcdhcdh\n9 77 e e\n26 34 b g\n34 70 b a\n40 64 e g\n33 78 h f\n14 26 a a\n17 70 d g\n56 65 a c\n8 41 d c\n11 82 c b", "output": "fhbecdgacebabbbebegbgfgbefbggebhgegagebgggfggaafbfggbfagbgggbfggfebgbfbeebebfbdhbdh" }, { "input": "1 4\ne\n1 1 c e\n1 1 e a\n1 1 e c\n1 1 d a", "output": "a" }, { "input": "71 21\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n61 61 a a\n32 56 a a\n10 67 a a\n7 32 a a\n26 66 a a\n41 55 a a\n49 55 a a\n4 61 a a\n53 59 a a\n37 58 a a\n7 63 a a\n39 40 a a\n51 64 a a\n27 37 a a\n22 71 a a\n4 45 a a\n7 8 a a\n43 46 a a\n19 28 a a\n51 54 a a\n14 67 a a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "30 4\neaaddabedcbbcccddbabdecadcecce\n2 17 c a\n16 29 e e\n16 21 c b\n7 11 b c", "output": "eaaddacedacbaaaddbabdecadcecce" }, { "input": "48 30\naaaabaabbaababbbaabaabaababbabbbaabbbaabaaaaaaba\n3 45 a b\n1 14 a a\n15 32 a b\n37 47 a b\n9 35 a b\n36 39 b b\n6 26 a b\n36 44 a a\n28 44 b a\n29 31 b a\n20 39 a a\n45 45 a b\n21 32 b b\n7 43 a b\n14 48 a b\n14 33 a b\n39 44 a a\n9 36 b b\n4 23 b b\n9 42 b b\n41 41 b a\n30 47 a b\n8 42 b a\n14 38 b b\n3 15 a a\n35 47 b b\n14 34 a b\n38 43 a b\n1 35 b a\n16 28 b a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbb" }, { "input": "89 29\nbabaabaaabaaaababbbbbbbabbbaaaaababbaababababbababaaabbababaaabbbbaaabaaaaaabaaabaabbabab\n39 70 b b\n3 56 b b\n5 22 b a\n4 39 a b\n41 87 b b\n34 41 a a\n10 86 a b\n29 75 a b\n2 68 a a\n27 28 b b\n42 51 b a\n18 61 a a\n6 67 b a\n47 63 a a\n8 68 a b\n4 74 b a\n19 65 a b\n8 55 a b\n5 30 a a\n3 65 a b\n16 57 a b\n34 56 b a\n1 70 a b\n59 68 b b\n29 57 b a\n47 49 b b\n49 73 a a\n32 61 b b\n29 42 a a", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaabbbbbbbbbbbbbab" }, { "input": "59 14\nfbebcfabdefbaaedcefdeecababcabebadfbccaaedaebfdaefdbbcbebbe\n5 32 e f\n8 46 e e\n31 43 e f\n3 10 e a\n53 54 f d\n55 59 d a\n39 58 e b\n54 56 f a\n9 40 b e\n28 37 d a\n7 35 e b\n7 56 c f\n23 26 e a\n15 44 e d", "output": "fbabcfabdffbaafdfffdfffababfabfbaafdffaafdabbfdabfdbbfbbbbe" }, { "input": "7 17\nbbaabab\n3 5 a b\n5 7 a a\n5 5 a a\n4 4 b a\n7 7 a a\n5 6 b b\n1 3 b a\n6 7 a b\n4 6 a b\n6 6 a a\n2 4 b a\n1 7 b a\n4 6 b b\n2 5 b b\n2 5 a b\n1 4 a a\n4 4 b a", "output": "abbabaa" }, { "input": "100 1\ndebaaagbfdgehagadabfgheegggfghghgeeeabgceffeffggcbcegfgebbdhebhfagcgadcbdbabddbcadgbgdebdfehceehcaef\n13 99 f c", "output": "debaaagbfdgehagadabcgheegggcghghgeeeabgcecceccggcbcegcgebbdhebhcagcgadcbdbabddbcadgbgdebdcehceehcaef" }, { "input": "1 1\na\n1 1 a b", "output": "b" }, { "input": "100 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1 100 a b", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "2 2\naa\n1 2 a b\n1 2 b c", "output": "cc" }, { "input": "3 3\naaa\n1 3 a b\n1 3 b c\n1 3 c d", "output": "ddd" }, { "input": "2 2\naa\n2 2 a b\n1 1 a b", "output": "bb" } ]
1,649,938,288
2,147,483,647
Python 3
OK
TESTS
47
46
0
n,m=list(map(int,input().split())) s=input() k=list(s) ans="" for i in range(m): l,r,c1,c2=list(map(str,input().split())) for j in range(int(l)-1,int(r)): if(k[j]==c1): k[j]=c2 # print(k) ans="" for ele in k: ans+=ele print(ans)
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space. Output Specification: Output string *s* after performing *m* operations described above. Demo Input: ['3 1\nioi\n1 1 i n\n', '5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n'] Demo Output: ['noi', 'gaaak'] Note: For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
```python n,m=list(map(int,input().split())) s=input() k=list(s) ans="" for i in range(m): l,r,c1,c2=list(map(str,input().split())) for j in range(int(l)-1,int(r)): if(k[j]==c1): k[j]=c2 # print(k) ans="" for ele in k: ans+=ele print(ans) ```
3
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }, { "input": "2\n8 2", "output": "1 1" }, { "input": "3\n6 8 4", "output": "1 2" }, { "input": "4\n4 3 2 8", "output": "3 1" }, { "input": "5\n1 9 8 2 7", "output": "2 3" }, { "input": "6\n1 4 7 3 2 1", "output": "3 3" }, { "input": "11\n7 9 1 8 7 1 7 1 4 8 1", "output": "4 7" }, { "input": "12\n4 2 7 1 9 5 6 2 7 8 5 7", "output": "7 5" }, { "input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "7 6" } ]
1,575,810,325
2,147,483,647
Python 3
OK
TESTS
40
342
7,168,000
n=int(input()) p=[int(x) for x in input().split()] s=sum(p) t=0 e=0 if n==1: print(1,0) else: for i in range (0,n): t=t+p[i] if t<s/2 and t+p[i+1]>=s/2: e=i break if s/2-t<t+p[e+1]-s/2: print(e+1,n-e-1) else: print(e+2,n-e-2)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). Output Specification: Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. Demo Input: ['5\n2 9 8 2 7\n'] Demo Output: ['2 3\n'] Note: none
```python n=int(input()) p=[int(x) for x in input().split()] s=sum(p) t=0 e=0 if n==1: print(1,0) else: for i in range (0,n): t=t+p[i] if t<s/2 and t+p[i+1]>=s/2: e=i break if s/2-t<t+p[e+1]-s/2: print(e+1,n-e-1) else: print(e+2,n-e-2) ```
3.861094
220
A
Little Elephant and Problem
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
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.
[ "2\n1 2\n", "3\n3 2 1\n", "4\n4 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
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".
500
[ { "input": "2\n1 2", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "4\n4 3 2 1", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "2\n2 1", "output": "YES" }, { "input": "9\n7 7 8 8 10 10 10 10 1000000000", "output": "YES" }, { "input": "10\n1 2 9 4 5 6 7 8 3 10", "output": "YES" }, { "input": "4\n2 2 2 1", "output": "YES" }, { "input": "10\n1 2 4 4 4 5 5 7 7 10", "output": "YES" }, { "input": "10\n4 5 11 12 13 14 16 16 16 18", "output": "YES" }, { "input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321", "output": "YES" }, { "input": "47\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", "output": "YES" }, { "input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5", "output": "NO" }, { "input": "100\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", "output": "NO" }, { "input": "128\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", "output": "NO" }, { "input": "4\n5 12 12 6", "output": "YES" }, { "input": "5\n1 3 3 3 2", "output": "YES" }, { "input": "4\n2 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "YES" }, { "input": "4\n1000000000 1 1000000000 1", "output": "YES" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 1", "output": "YES" }, { "input": "6\n1 2 3 4 5 3", "output": "NO" }, { "input": "9\n3 3 3 2 2 2 1 1 1", "output": "NO" }, { "input": "4\n4 1 2 3", "output": "NO" }, { "input": "6\n3 4 5 6 7 2", "output": "NO" }, { "input": "4\n4 2 1 3", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "4\n3 2 1 1", "output": "NO" }, { "input": "4\n4 5 1 1", "output": "NO" }, { "input": "6\n1 6 2 4 3 5", "output": "NO" }, { "input": "5\n1 4 5 2 3", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n1 4 3 2 1", "output": "NO" }, { "input": "5\n1 4 2 2 3", "output": "NO" }, { "input": "6\n1 2 3 1 2 3", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "5\n5 1 2 3 4", "output": "NO" }, { "input": "5\n3 3 3 2 2", "output": "NO" }, { "input": "5\n100 5 6 10 7", "output": "NO" }, { "input": "3\n2 3 1", "output": "NO" }, { "input": "5\n4 4 1 1 1", "output": "NO" }, { "input": "5\n1 2 5 3 4", "output": "NO" }, { "input": "4\n3 4 1 2", "output": "NO" }, { "input": "4\n2 4 1 5", "output": "NO" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "5\n1 5 4 4 4", "output": "YES" }, { "input": "7\n3 2 1 2 3 5 4", "output": "NO" }, { "input": "5\n1 1 3 2 2", "output": "YES" }, { "input": "9\n1 8 7 7 7 7 7 8 3", "output": "YES" }, { "input": "5\n1 3 2 3 3", "output": "YES" }, { "input": "10\n4 4 4 4 10 4 4 4 4 4", "output": "YES" }, { "input": "8\n3 6 6 6 6 6 4 9", "output": "YES" }, { "input": "4\n4 4 3 3", "output": "NO" }, { "input": "4\n3 2 2 4", "output": "YES" }, { "input": "5\n2 2 1 3 3", "output": "YES" }, { "input": "5\n1 2 7 3 5", "output": "NO" }, { "input": "5\n2 3 4 5 1", "output": "NO" }, { "input": "6\n1 4 3 6 2 5", "output": "NO" }, { "input": "5\n3 3 1 5 4", "output": "NO" }, { "input": "4\n1 2 1 2", "output": "YES" }, { "input": "6\n4 5 3 4 2 6", "output": "NO" }, { "input": "11\n1 2 3 4 5 1 2 3 4 5 1", "output": "NO" }, { "input": "6\n6 1 2 3 4 5", "output": "NO" }, { "input": "5\n4 1 1 1 1", "output": "YES" }, { "input": "9\n1 2 3 5 4 6 7 8 9", "output": "YES" }, { "input": "6\n6 1 2 3 4 2", "output": "NO" }, { "input": "6\n2 2 2 2 3 2", "output": "YES" }, { "input": "3\n2 1 1", "output": "YES" }, { "input": "5\n1 2 1 1 2", "output": "YES" }, { "input": "5\n1 2 2 1 2", "output": "YES" }, { "input": "8\n5 5 5 5 5 5 1 1", "output": "NO" } ]
1,590,600,388
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
0
n=int(input()) a=list(map(int,input().split(" "))) c=0 f=0 for i in range(0,n,1): if a[i]!=i+1: c+=1 if c>2: print("NO") f=1 break if f==0: print("YES")
Title: Little Elephant and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers. Output Specification: 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. Demo Input: ['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
```python n=int(input()) a=list(map(int,input().split(" "))) c=0 f=0 for i in range(0,n,1): if a[i]!=i+1: c+=1 if c>2: print("NO") f=1 break if f==0: print("YES") ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,530,086,075
2,147,483,647
Python 3
OK
TESTS
102
93
0
str1 = list(input()) str2 = list(input()) res = [] for i in range(len(str1)): res.append(int(str1[i]) ^ int(str2[i])) r = ''.join(str(e) for e in res) print(r)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python str1 = list(input()) str2 = list(input()) res = [] for i in range(len(str1)): res.append(int(str1[i]) ^ int(str2[i])) r = ''.join(str(e) for e in res) print(r) ```
3.97675
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "output": "4" }, { "input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "3" } ]
1,694,792,433
2,147,483,647
Python 3
OK
TESTS
25
92
0
rows = 5 matrix = [] for i in range(rows): row = list(map(int, input().split())) if 1 in row: my_row = i my_col = row.index(1) matrix.append(row) to_beauty = 0 if my_row > 2: to_beauty = to_beauty + (my_row - 2) elif my_row < 2: to_beauty = to_beauty + (2 - my_row) if my_col > 2: to_beauty = to_beauty + (my_col - 2) elif my_col < 2: to_beauty = to_beauty + (2 - my_col) print(to_beauty)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python rows = 5 matrix = [] for i in range(rows): row = list(map(int, input().split())) if 1 in row: my_row = i my_col = row.index(1) matrix.append(row) to_beauty = 0 if my_row > 2: to_beauty = to_beauty + (my_row - 2) elif my_row < 2: to_beauty = to_beauty + (2 - my_row) if my_col > 2: to_beauty = to_beauty + (my_col - 2) elif my_col < 2: to_beauty = to_beauty + (2 - my_col) print(to_beauty) ```
3
610
B
Vika and Squares
PROGRAMMING
1,300
[ "constructive algorithms", "implementation" ]
null
null
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color *x*, then the next square will be painted in color *x*<=+<=1. In case of *x*<==<=*n*, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops. Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has. The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. the number of liters of color *i* that Vika has.
The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.
[ "5\n2 4 2 3 3\n", "3\n5 5 5\n", "6\n10 10 10 1 10 10\n" ]
[ "12\n", "15\n", "11\n" ]
In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5. In the second sample Vika can start to paint using any color. In the third sample Vika should start painting using color number 5.
1,000
[ { "input": "5\n2 4 2 3 3", "output": "12" }, { "input": "3\n5 5 5", "output": "15" }, { "input": "6\n10 10 10 1 10 10", "output": "11" }, { "input": "1\n167959139", "output": "167959139" }, { "input": "10\n896619242 805194919 844752453 848347723 816995848 856813612 805194919 833406689 816255448 805194919", "output": "8051949194" }, { "input": "2\n2 3", "output": "5" }, { "input": "2\n10 10", "output": "20" }, { "input": "2\n1111 1110", "output": "2221" }, { "input": "3\n100 101 100", "output": "301" }, { "input": "3\n100 100 101", "output": "301" }, { "input": "3\n101 100 100", "output": "301" }, { "input": "4\n2 3 2 2", "output": "9" }, { "input": "4\n1 1 1 1", "output": "4" }, { "input": "4\n100 100 100 101", "output": "401" }, { "input": "4\n101 100 100 101", "output": "402" }, { "input": "4\n100 101 101 100", "output": "402" }, { "input": "4\n200 201 200 201", "output": "801" }, { "input": "4\n201 200 201 200", "output": "801" }, { "input": "4\n300 302 302 300", "output": "1202" }, { "input": "8\n5 4 3 2 1 1 1 1", "output": "12" }, { "input": "8\n2 2 1 2 2 1 2 2", "output": "12" }, { "input": "10\n2 1 2 1 2 2 2 2 2 1", "output": "15" }, { "input": "13\n2 2 2 1 1 1 1 1 1 1 2 2 2", "output": "19" } ]
1,669,473,949
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
18,841,600
n = int(input()) arr = list(map(int, input().split())) minX = min(arr) arr = [x - minX for x in arr] ans = minX * n add = 0 for i in range(n): if arr[i] != 0: cnt = 0 j = i while arr[j] != 0: cnt += 1 j = (j + 1) % n add = max(add, cnt) print(ans + add)
Title: Vika and Squares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color *x*, then the next square will be painted in color *x*<=+<=1. In case of *x*<==<=*n*, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops. Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has. The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. the number of liters of color *i* that Vika has. Output Specification: The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. Demo Input: ['5\n2 4 2 3 3\n', '3\n5 5 5\n', '6\n10 10 10 1 10 10\n'] Demo Output: ['12\n', '15\n', '11\n'] Note: In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5. In the second sample Vika can start to paint using any color. In the third sample Vika should start painting using color number 5.
```python n = int(input()) arr = list(map(int, input().split())) minX = min(arr) arr = [x - minX for x in arr] ans = minX * n add = 0 for i in range(n): if arr[i] != 0: cnt = 0 j = i while arr[j] != 0: cnt += 1 j = (j + 1) % n add = max(add, cnt) print(ans + add) ```
0
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n2 5", "output": "181" }, { "input": "6\n22 9 87 89 57\n1 6", "output": "264" }, { "input": "7\n52 36 31 23 74 78\n2 7", "output": "242" }, { "input": "8\n82 14 24 5 91 49 94\n3 8", "output": "263" }, { "input": "9\n12 40 69 39 59 21 59 5\n4 6", "output": "98" }, { "input": "10\n95 81 32 59 71 30 50 61 100\n1 6", "output": "338" }, { "input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14", "output": "617" }, { "input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17", "output": "399" }, { "input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23", "output": "846" }, { "input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16", "output": "730" }, { "input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35", "output": "1663" }, { "input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26", "output": "862" }, { "input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40", "output": "1061" }, { "input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28", "output": "344" }, { "input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60", "output": "1502" }, { "input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41", "output": "1767" }, { "input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24", "output": "219" }, { "input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44", "output": "1713" }, { "input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15", "output": "570" }, { "input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26", "output": "328" }, { "input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68", "output": "3385" }, { "input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77", "output": "3319" }, { "input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36", "output": "514" }, { "input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92", "output": "2599" }, { "input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27", "output": "618" }, { "input": "2\n3\n1 2", "output": "3" }, { "input": "5\n6 8 22 22\n2 3", "output": "8" }, { "input": "6\n3 12 27 28 28\n3 4", "output": "27" }, { "input": "9\n1 2 2 2 2 3 3 5\n3 7", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 1\n6 8", "output": "2" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17", "output": "23" }, { "input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8", "output": "23" }, { "input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31", "output": "2" }, { "input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45", "output": "30" }, { "input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17", "output": "285" }, { "input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58", "output": "173" }, { "input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65", "output": "126" }, { "input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65", "output": "326" }, { "input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48", "output": "784" }, { "input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93", "output": "1636" }, { "input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96", "output": "898" }, { "input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90", "output": "3016" }, { "input": "99\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\n66 95", "output": "29" }, { "input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52", "output": "82" }, { "input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44", "output": "2268" } ]
1,631,500,963
2,147,483,647
Python 3
OK
TESTS
50
124
6,758,400
n = int(input()) d = list(map(int, input().split())) a, b = map(int, input().split()) ans = 0 while(b>a): ans += d[b-2] b -= 1 print(ans)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. Input Specification: The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated. Output Specification: Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. Demo Input: ['3\n5 6\n1 2\n', '3\n5 6\n1 3\n'] Demo Output: ['5\n', '11\n'] Note: none
```python n = int(input()) d = list(map(int, input().split())) a, b = map(int, input().split()) ans = 0 while(b>a): ans += d[b-2] b -= 1 print(ans) ```
3.956411
94
B
Friends
PROGRAMMING
1,300
[ "graphs", "implementation", "math" ]
B. Friends
1
256
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.
The first line contains an integer *m* (0<=≤<=*m*<=≤<=10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=5;*a**i*<=≠<=*b**i*), where (*a**i*,<=*b**i*) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if *x* is acquainted with *y*, then *y* is also acquainted with *x*.
Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN".
[ "4\n1 3\n2 3\n1 4\n5 3\n", "5\n1 2\n2 3\n3 4\n4 5\n5 1\n" ]
[ "WIN\n", "FAIL\n" ]
none
1,000
[ { "input": "4\n1 3\n2 3\n1 4\n5 3", "output": "WIN" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "FAIL" }, { "input": "1\n4 3", "output": "WIN" }, { "input": "6\n1 3\n2 3\n1 2\n5 3\n4 2\n4 5", "output": "WIN" }, { "input": "2\n1 3\n2 5", "output": "WIN" }, { "input": "3\n5 3\n4 3\n4 5", "output": "WIN" }, { "input": "5\n1 3\n3 2\n2 4\n5 4\n1 5", "output": "FAIL" }, { "input": "7\n1 3\n5 1\n1 4\n2 1\n5 3\n4 5\n2 5", "output": "WIN" }, { "input": "5\n5 1\n4 1\n2 3\n4 5\n3 1", "output": "WIN" }, { "input": "0", "output": "WIN" }, { "input": "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "output": "WIN" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "WIN" }, { "input": "1\n2 1", "output": "WIN" }, { "input": "1\n2 5", "output": "WIN" }, { "input": "2\n2 1\n1 5", "output": "WIN" }, { "input": "2\n4 2\n1 5", "output": "WIN" }, { "input": "2\n3 4\n5 2", "output": "WIN" }, { "input": "2\n1 5\n4 3", "output": "WIN" }, { "input": "3\n4 1\n4 5\n2 1", "output": "WIN" }, { "input": "3\n5 1\n5 3\n2 5", "output": "WIN" }, { "input": "3\n1 2\n4 2\n1 3", "output": "WIN" }, { "input": "3\n3 2\n1 5\n5 3", "output": "WIN" }, { "input": "3\n1 2\n2 4\n3 2", "output": "WIN" }, { "input": "3\n2 1\n1 3\n5 4", "output": "WIN" }, { "input": "4\n4 2\n2 5\n1 4\n4 5", "output": "WIN" }, { "input": "4\n5 2\n2 4\n5 3\n1 5", "output": "WIN" }, { "input": "4\n2 5\n1 3\n4 3\n4 2", "output": "WIN" }, { "input": "4\n1 4\n3 1\n2 3\n1 2", "output": "WIN" }, { "input": "4\n5 4\n2 3\n1 5\n5 2", "output": "WIN" }, { "input": "4\n2 5\n5 4\n1 4\n5 3", "output": "WIN" }, { "input": "4\n2 1\n2 4\n5 1\n4 1", "output": "WIN" }, { "input": "4\n1 2\n1 5\n4 5\n2 3", "output": "WIN" }, { "input": "5\n4 1\n2 4\n3 2\n5 3\n1 5", "output": "FAIL" }, { "input": "5\n1 3\n4 1\n5 2\n2 4\n3 5", "output": "FAIL" }, { "input": "5\n3 5\n4 2\n1 3\n2 1\n5 4", "output": "FAIL" }, { "input": "5\n5 2\n1 3\n4 5\n2 1\n3 4", "output": "FAIL" }, { "input": "5\n2 3\n3 5\n1 2\n4 1\n5 4", "output": "FAIL" }, { "input": "5\n1 2\n4 5\n5 3\n3 1\n2 4", "output": "FAIL" }, { "input": "5\n5 3\n3 2\n2 4\n1 5\n4 1", "output": "FAIL" }, { "input": "5\n3 2\n4 1\n2 5\n1 3\n5 4", "output": "FAIL" }, { "input": "5\n3 5\n1 4\n5 1\n2 3\n4 2", "output": "FAIL" }, { "input": "5\n4 2\n5 3\n2 1\n3 4\n1 5", "output": "FAIL" }, { "input": "5\n3 1\n5 1\n4 5\n2 4\n5 3", "output": "WIN" }, { "input": "5\n5 4\n5 3\n3 1\n1 4\n2 3", "output": "WIN" }, { "input": "5\n4 1\n3 5\n3 4\n5 4\n5 2", "output": "WIN" }, { "input": "5\n4 1\n5 2\n3 1\n4 2\n5 1", "output": "WIN" }, { "input": "5\n2 3\n1 5\n5 3\n2 4\n1 4", "output": "FAIL" }, { "input": "5\n5 4\n5 3\n2 3\n5 2\n5 1", "output": "WIN" }, { "input": "5\n2 4\n3 4\n1 4\n2 1\n3 2", "output": "WIN" }, { "input": "5\n2 3\n3 4\n1 3\n4 1\n5 2", "output": "WIN" }, { "input": "5\n1 2\n2 5\n4 2\n4 3\n3 1", "output": "WIN" }, { "input": "5\n2 1\n2 5\n4 5\n2 3\n3 5", "output": "WIN" }, { "input": "5\n4 1\n5 1\n5 4\n4 3\n5 2", "output": "WIN" }, { "input": "5\n1 3\n2 4\n1 5\n5 2\n4 1", "output": "WIN" }, { "input": "5\n1 5\n3 5\n2 3\n4 1\n3 1", "output": "WIN" }, { "input": "5\n5 2\n3 2\n2 1\n4 3\n4 2", "output": "WIN" }, { "input": "5\n1 3\n4 5\n3 4\n3 5\n5 1", "output": "WIN" }, { "input": "5\n4 5\n2 5\n5 3\n4 2\n4 1", "output": "WIN" }, { "input": "5\n2 5\n1 5\n1 3\n3 5\n1 2", "output": "WIN" }, { "input": "5\n2 4\n1 2\n5 2\n5 3\n4 5", "output": "WIN" }, { "input": "5\n2 1\n4 5\n5 3\n1 5\n1 4", "output": "WIN" }, { "input": "5\n1 3\n2 5\n4 2\n3 4\n4 1", "output": "WIN" }, { "input": "6\n3 2\n2 4\n3 1\n3 5\n5 2\n1 2", "output": "WIN" }, { "input": "6\n2 1\n5 1\n5 4\n3 5\n3 4\n4 1", "output": "WIN" }, { "input": "6\n3 1\n1 4\n5 4\n2 1\n4 2\n1 5", "output": "WIN" }, { "input": "6\n5 1\n5 4\n3 4\n1 3\n1 4\n4 2", "output": "WIN" }, { "input": "6\n1 3\n5 4\n4 2\n2 1\n4 1\n2 3", "output": "WIN" }, { "input": "6\n4 3\n5 3\n4 1\n1 3\n1 2\n2 4", "output": "WIN" }, { "input": "6\n4 1\n3 5\n4 5\n3 1\n4 3\n5 2", "output": "WIN" }, { "input": "6\n2 1\n1 4\n4 5\n5 2\n1 3\n3 2", "output": "WIN" }, { "input": "7\n5 1\n3 5\n2 5\n4 5\n2 3\n3 1\n4 3", "output": "WIN" }, { "input": "7\n5 3\n5 1\n4 2\n4 5\n3 2\n3 4\n1 3", "output": "WIN" }, { "input": "7\n3 5\n1 4\n5 2\n1 5\n1 3\n4 2\n4 3", "output": "WIN" }, { "input": "7\n5 1\n5 4\n2 4\n2 3\n3 5\n2 5\n4 1", "output": "WIN" }, { "input": "7\n1 3\n2 5\n4 3\n2 1\n2 3\n4 5\n2 4", "output": "WIN" }, { "input": "7\n3 1\n4 5\n3 5\n5 1\n2 4\n1 2\n1 4", "output": "WIN" }, { "input": "8\n1 5\n3 1\n2 5\n4 2\n2 1\n4 5\n4 3\n4 1", "output": "WIN" }, { "input": "8\n4 2\n3 1\n4 3\n2 5\n3 2\n4 5\n1 2\n3 5", "output": "WIN" }, { "input": "8\n2 4\n3 2\n2 5\n3 4\n3 1\n5 1\n4 5\n5 3", "output": "WIN" }, { "input": "8\n2 3\n1 5\n1 3\n4 5\n2 4\n1 4\n3 5\n3 4", "output": "WIN" }, { "input": "9\n3 5\n3 2\n1 5\n4 3\n5 4\n1 4\n1 3\n4 2\n5 2", "output": "WIN" }, { "input": "9\n3 5\n2 5\n5 1\n4 5\n1 3\n3 2\n1 4\n4 3\n4 2", "output": "WIN" }, { "input": "3\n3 4\n4 5\n5 3", "output": "WIN" }, { "input": "3\n1 2\n1 3\n4 5", "output": "WIN" }, { "input": "3\n2 3\n3 5\n2 5", "output": "WIN" } ]
1,631,472,352
2,147,483,647
Python 3
OK
TESTS
85
77
6,963,200
# # Joseph Matsushita # Problem I # # Time Complexity: # The nature of the problem prevents the time complexity from rising above O(1). # There are always 5 people, and the only scenario that requires any serious # testing is when there are 5 pairs of acquaintances, which we can guarantee # will run the same amount of time every time. # # Space Complexity: # Once again, due to the problem constraints the space complexity is O(1). # We can guarantee that this program will only take a constant amount of memory. # # Argument: # Can't exactly do much better than constant time and space complexity. The # small scale nature of the problem and the limited scenarios that need to be # checked allow us to quickly figure out the answer without any complex # algorithms. There is a loop, but it will run exactly 5 times when it's needed. # n = int(input()) win = True #assume it's true if(n == 5): #the fail scenarios require exactly 5 edges adj = [0 for i in range(5)] for i in range(5): #create an adjacency list edge = list(map(int, input().split())) adj[edge[0]-1] += 1 adj[edge[1]-1] += 1 if adj.count(2) == 5: #only failure scenario requires everyone has exactly win = False #two acquaintances if(win): print("WIN") else: print("FAIL")
Title: Friends Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something. The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people" Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!" Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people. Input Specification: The first line contains an integer *m* (0<=≤<=*m*<=≤<=10), which is the number of relations of acquaintances among the five friends of Igor's. Each of the following *m* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=5;*a**i*<=≠<=*b**i*), where (*a**i*,<=*b**i*) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if *x* is acquainted with *y*, then *y* is also acquainted with *x*. Output Specification: Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN". Demo Input: ['4\n1 3\n2 3\n1 4\n5 3\n', '5\n1 2\n2 3\n3 4\n4 5\n5 1\n'] Demo Output: ['WIN\n', 'FAIL\n'] Note: none
```python # # Joseph Matsushita # Problem I # # Time Complexity: # The nature of the problem prevents the time complexity from rising above O(1). # There are always 5 people, and the only scenario that requires any serious # testing is when there are 5 pairs of acquaintances, which we can guarantee # will run the same amount of time every time. # # Space Complexity: # Once again, due to the problem constraints the space complexity is O(1). # We can guarantee that this program will only take a constant amount of memory. # # Argument: # Can't exactly do much better than constant time and space complexity. The # small scale nature of the problem and the limited scenarios that need to be # checked allow us to quickly figure out the answer without any complex # algorithms. There is a loop, but it will run exactly 5 times when it's needed. # n = int(input()) win = True #assume it's true if(n == 5): #the fail scenarios require exactly 5 edges adj = [0 for i in range(5)] for i in range(5): #create an adjacency list edge = list(map(int, input().split())) adj[edge[0]-1] += 1 adj[edge[1]-1] += 1 if adj.count(2) == 5: #only failure scenario requires everyone has exactly win = False #two acquaintances if(win): print("WIN") else: print("FAIL") ```
3.94853
0
none
none
none
0
[ "none" ]
null
null
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
[ "3\n1 1\n", "5\n1 2 2 2\n", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n" ]
[ "1\n", "3\n", "4\n" ]
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
0
[ { "input": "3\n1 1", "output": "1" }, { "input": "5\n1 2 2 2", "output": "3" }, { "input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "output": "4" }, { "input": "2\n1", "output": "2" }, { "input": "3\n1 2", "output": "3" }, { "input": "20\n1 1 1 1 1 4 1 2 4 1 2 1 7 1 2 2 9 7 1", "output": "2" }, { "input": "20\n1 2 1 2 2 1 2 4 1 6 2 2 4 3 2 6 2 5 9", "output": "2" }, { "input": "20\n1 1 1 4 2 4 3 1 2 8 3 2 11 13 15 1 12 13 12", "output": "4" }, { "input": "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15", "output": "4" }, { "input": "20\n1 2 3 4 5 6 7 8 9 6 11 12 12 7 13 15 16 11 13", "output": "8" }, { "input": "10\n1 1 1 2 1 3 4 2 1", "output": "2" }, { "input": "30\n1 1 1 2 1 2 1 1 2 1 1 1 2 2 4 3 6 2 3 5 3 4 11 5 3 3 4 7 6", "output": "4" }, { "input": "40\n1 1 1 1 1 1 1 1 1 3 4 3 3 1 3 6 7 4 5 2 4 3 9 1 4 2 5 3 5 9 5 9 10 12 3 7 2 11 1", "output": "2" }, { "input": "50\n1 1 1 1 1 2 3 3 2 1 1 2 3 1 3 1 5 6 4 1 1 2 1 2 1 10 17 2 2 4 12 9 6 6 5 13 1 3 2 8 25 3 22 1 10 13 6 3 2", "output": "4" }, { "input": "10\n1 1 1 1 2 1 3 4 3", "output": "2" }, { "input": "30\n1 2 1 1 1 2 1 4 2 3 9 2 3 2 1 1 4 3 12 4 8 8 3 7 9 1 9 19 1", "output": "2" }, { "input": "40\n1 1 1 2 3 1 2 1 3 7 1 3 4 3 2 3 4 1 2 2 4 1 7 4 1 3 2 1 4 5 3 10 14 11 10 13 8 7 4", "output": "2" }, { "input": "50\n1 2 1 1 1 3 1 3 1 5 3 2 7 3 6 6 3 1 4 2 3 10 8 9 1 4 5 2 8 6 12 9 7 5 7 19 3 15 10 4 12 4 19 5 16 5 3 13 5", "output": "2" }, { "input": "10\n1 1 1 2 3 2 1 2 3", "output": "2" }, { "input": "30\n1 1 1 1 2 1 4 4 2 3 2 1 1 1 1 3 1 1 3 2 3 5 1 2 9 16 2 4 3", "output": "2" }, { "input": "40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8 2 12 4 11 5 5 15 3 12 11 22 11 13 13 24 6 10 15 3 6 7 1 2", "output": "2" }, { "input": "50\n1 1 1 1 3 4 1 2 3 5 1 2 1 5 1 10 4 11 1 8 8 4 4 12 5 3 4 1 1 2 5 13 13 2 2 10 12 3 19 14 1 1 15 3 23 21 12 3 14", "output": "4" }, { "input": "10\n1 1 1 1 2 4 1 1 3", "output": "2" }, { "input": "30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3", "output": "2" }, { "input": "40\n1 1 1 2 2 1 1 4 6 4 7 7 7 4 4 8 10 7 5 1 5 13 7 8 2 11 18 2 1 20 7 3 12 16 2 22 4 22 14", "output": "4" }, { "input": "50\n1 1 1 2 2 1 3 5 3 1 9 4 4 2 12 15 3 13 8 8 4 13 20 17 19 2 4 3 9 5 17 9 17 1 5 7 6 5 20 11 31 33 32 20 6 25 1 2 6", "output": "4" }, { "input": "10\n1 1 1 3 3 5 6 8 3", "output": "4" }, { "input": "30\n1 2 2 1 5 5 5 1 7 4 10 2 4 11 2 3 10 10 7 13 12 4 10 3 22 25 8 1 1", "output": "6" }, { "input": "40\n1 2 2 2 2 4 2 2 6 9 3 9 9 9 3 5 7 7 2 17 4 4 8 8 25 18 12 27 8 19 26 15 33 26 33 9 24 4 27", "output": "4" }, { "input": "50\n1 1 3 3 4 5 5 2 4 3 9 9 1 5 5 7 5 5 16 1 18 3 6 5 6 13 26 12 23 20 17 21 9 17 19 34 12 24 11 9 32 10 40 42 7 40 11 25 3", "output": "6" }, { "input": "10\n1 2 1 2 5 5 6 6 6", "output": "2" }, { "input": "30\n1 1 3 3 5 6 7 5 7 6 5 4 8 6 10 12 14 9 15 20 6 21 14 24 17 23 23 18 8", "output": "2" }, { "input": "40\n1 2 2 3 1 2 5 6 4 8 11 12 9 5 12 7 4 16 16 15 6 22 17 24 10 8 22 4 27 9 19 23 16 18 28 22 5 35 19", "output": "4" }, { "input": "50\n1 2 3 4 5 5 5 7 1 2 11 5 7 11 11 11 15 3 17 10 6 18 14 14 24 11 10 7 17 18 8 7 19 18 31 27 21 30 34 32 27 39 38 22 32 23 31 48 25", "output": "2" }, { "input": "10\n1 2 2 4 5 5 6 4 7", "output": "2" }, { "input": "30\n1 2 3 3 5 6 3 8 9 10 10 10 11 7 8 8 15 16 13 13 19 12 15 18 18 24 27 25 10", "output": "6" }, { "input": "40\n1 2 3 4 5 6 6 8 7 10 11 3 12 11 15 12 17 15 10 20 16 20 12 20 15 21 20 26 29 23 29 30 23 24 35 33 25 32 36", "output": "8" }, { "input": "50\n1 2 2 2 5 6 7 7 9 10 7 4 5 4 15 15 16 17 10 19 18 16 15 24 20 8 27 16 19 24 23 32 17 23 29 18 35 35 38 35 39 41 42 38 19 46 38 28 29", "output": "6" }, { "input": "10\n1 2 3 4 5 5 5 7 9", "output": "8" }, { "input": "30\n1 2 3 4 5 6 5 3 6 7 8 11 12 13 15 15 13 13 19 10 14 10 15 23 21 9 27 22 28", "output": "4" }, { "input": "40\n1 2 2 3 3 6 5 5 9 7 8 11 13 7 10 10 16 14 18 20 11 19 23 18 20 21 25 16 29 25 27 31 26 34 33 23 36 33 32", "output": "6" }, { "input": "50\n1 2 2 4 5 5 7 6 9 10 11 12 13 7 14 15 14 17 10 14 9 21 23 23 19 26 19 25 11 24 22 27 26 34 35 30 37 31 38 32 40 32 42 44 37 21 40 40 48", "output": "10" }, { "input": "10\n1 2 3 4 3 6 6 6 7", "output": "4" }, { "input": "30\n1 2 2 4 5 6 5 7 9 6 4 12 7 14 12 12 15 17 13 12 8 20 21 15 17 24 21 19 16", "output": "4" }, { "input": "40\n1 2 3 4 4 6 6 4 9 9 10 12 10 12 12 16 8 13 18 14 17 20 21 23 25 22 25 26 29 26 27 27 33 31 33 34 36 29 34", "output": "10" }, { "input": "50\n1 2 3 3 4 3 6 7 8 10 11 10 12 11 11 14 13 8 17 20 21 19 15 18 21 18 17 23 25 28 25 27 29 32 32 34 37 29 30 39 41 35 24 41 37 36 41 35 43", "output": "10" }, { "input": "99\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", "output": "1" }, { "input": "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98", "output": "99" }, { "input": "100\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", "output": "2" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "100" } ]
1,520,331,818
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
29,388,800
import sys n = int(input()) x = list(map(int, sys.stdin.readline().split())) q = [] d = [0, ] * n h = 0 q.append((1, 0)) d[0] += 1 while h < len(q): e = q[h] h += 1 for i, xi in enumerate(x): if xi == e[0]: q.append((i + 2, e[1] + 1)) d[e[1] + 1] = (d[e[1] + 1] + 1) % 2 print(sum(d))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. Input Specification: First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down. Output Specification: Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. Demo Input: ['3\n1 1\n', '5\n1 2 2 2\n', '18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n'] Demo Output: ['1\n', '3\n', '4\n'] Note: In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
```python import sys n = int(input()) x = list(map(int, sys.stdin.readline().split())) q = [] d = [0, ] * n h = 0 q.append((1, 0)) d[0] += 1 while h < len(q): e = q[h] h += 1 for i, xi in enumerate(x): if xi == e[0]: q.append((i + 2, e[1] + 1)) d[e[1] + 1] = (d[e[1] + 1] + 1) % 2 print(sum(d)) ```
0
1,003
F
Abbreviation
PROGRAMMING
2,200
[ "dp", "hashing", "strings" ]
null
null
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words consist only of lowercase Latin letters. Let's denote a segment of words $w[i..j]$ as a sequence of words $w_i, w_{i + 1}, \dots, w_j$. Two segments of words $w[i_1 .. j_1]$ and $w[i_2 .. j_2]$ are considered equal if $j_1 - i_1 = j_2 - i_2$, $j_1 \ge i_1$, $j_2 \ge i_2$, and for every $t \in [0, j_1 - i_1]$ $w_{i_1 + t} = w_{i_2 + t}$. For example, for the text "to be or not to be" the segments $w[1..2]$ and $w[5..6]$ are equal, they correspond to the words "to be". An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words $w[2..4]$ and $w[6..8]$ with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words $w[2..5]$ and $w[6..9]$ with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c". What is the minimum length of the text after at most one abbreviation?
The first line of the input contains one integer $n$ ($1 \le n \le 300$) — the number of words in the text. The next line contains $n$ space-separated words of the text $w_1, w_2, \dots, w_n$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed $10^5$.
Print one integer — the minimum length of the text after at most one abbreviation.
[ "6\nto be or not to be\n", "10\na ab a a b ab a a b c\n", "6\naa bb aa aa bb bb\n" ]
[ "12\n", "13\n", "11\n" ]
In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
0
[ { "input": "6\nto be or not to be", "output": "12" }, { "input": "10\na ab a a b ab a a b c", "output": "13" }, { "input": "6\naa bb aa aa bb bb", "output": "11" }, { "input": "45\nxr l pl sx c c u py sv j f x h u y w w bs u cp e ad ib b tz gy lm e s n ln kg fs rd ln v f sh t z r b j w of", "output": "106" }, { "input": "250\nf r s d b f f k d e k v m b t k k j t t a o m m s n d w l v g e k x d w k v a j h c a g x s d e t z z w q z d h n r i k b z k u s q l k c v o d o w w c y i a q v r i g i m l b x z h t a i j t h q u e v j o h w m o v k g r r x j a c m z z i s i r a p p i i l e i g m f f f y v k m c l p n n n j j u t t q s o y b t m x n n t z f c g s r f h w z b b d q d y h t v g y e w p l n m f v c s b r g p v w z c o h k u r c g c s v w r t w k z v t v y z i x r f o l e o u q z k x c o l e c b d j v f z y e r k", "output": "495" }, { "input": "1\nu", "output": "1" }, { "input": "1\nvpdgzvgvgbichiiqdhytvcooetcgeecyueoylqzbtzzgaqhalt", "output": "50" }, { "input": "1\nxdhlmtnvecsbwbycahddxnvwpsxwxgfmidfetpkpeevpjzfbgfafbjpyuevupuptoxutnketcxwrllooyxtxjzwxpzcbpiqzeiplcqvdxyyznjxgkwstpxogdihsamoqhyspbjlelxpbarzqawsgidjtmnpmmupohnslirorliapvntasudhpuuxynyoipuqxdiysbyctpmfpbxqfdlmlsmsvtbxoypkbhwrtpwbsbcdhypsbqhqpdlilquppdwsszrpavcowudreygmpwckbzlpnxxqxjdpqmtidjatvgcbxjrpqqxhhsvlpyxxkoqxutsvebrlxqeggvsnshetkpnfygpwbmnuujfvqnlgavwppufxadhxtffsrdknfmqbsjjegcwokbauzivhnldkvykkytkyrwhimmkznkkofcuioqmpbshskvdhsetyidubcgvuerbozqfbkcmaguaszaivtuswzmtnqcpoiqlvronibiqyeoqm", "output": "500" }, { "input": "2\nvjrvahvokiudpiocpvoqsqhukavyrckhcbctr prqxizcofrfr", "output": "50" }, { "input": "2\nxxwxpgalijfbdbdmluuaubobxztpkfn parzxczfzchinxdtaevbepdxlouzfzaizkinuaufhckjvydmgnkuaneqohcqocfrsbmmohgpoacnqlgspppfogdkkbrkrhdpdlnknjyeccbqssqtaqmyamtkedlhpbjmchfnmwhxepzfrfmlrxrirbvvlryzmulxqjlthclocmiudxbtqpihlnielggjxjmvqjbeozjpskenampuszybcorplicekprqbsdkidwpgwkrpvbpcsdcngawcgeyxsjimalrrwttjjualmhypzrmyauvtothnermlednvjbpgkehxbtbpxolmaapmlcuetghikbgtaspqesjkqwxtvccphjdqpuairsaypfudwvelmupbzhxwuchnfumcxmhflkpyzeppddtczbcjrookncgtojmujyvponennuudppqwwjtnwpgapokwzvbxohrdcvcckzbcrwwvfqlbnwbnmmv", "output": "500" }, { "input": "4\ncongratulations for being first", "output": "31" }, { "input": "4\njngen hype xfckaovxfckaovxfckaovxfckaovxfckaovfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwzxfckaovxfckaovfegkbwzfegkbwzfegkbwz fegkbwzxfckaovfegkbwzxfckaovxfckaovxfckaovfegkbwzfegkbwzxfckaovxfckaovxfckaovfegkbwzfegkbwzxfckaovxfckaovxfckaovxfckaovxfckaovxfckaovfegkbwzxfckaov", "output": "306" }, { "input": "4\njngen hype acpumodacpumodacpumodulhiwuoulhiwuoulhiwuoacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodulhiwuoacpumodacpumodulhiwuoacpumodulhiwuoacpumod ulhiwuoulhiwuoacpumodacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodacpumodacpumodacpumodacpumodulhiwuoulhiwuoulhiwuoulhiwuoacpumodulhiwuo", "output": "292" }, { "input": "4\nraraaraaarrraraaaaaaaaaaaaaaaaraaraararaarraarrraaarrarrraaaarrrarrrrraaraaaarrararrarraarrrararaaar arrararaararaarraaaraararraararaarrraarrrarrrrarrraaaaraaraaaaaaaraaararrarararrarrraarrarrrrraaaaar arrararaararaarraaaraararraararaarrraarrrarrrrarrraaaaraaraaaaaaaraaararrarararrarrraarrarrrrraaaaar raraaraaarrraraaaaaaaaaaaaaaaaraaraararaarraarrraaarrarrraaaarrrarrrrraaraaaarrararrarraarrrararaaar", "output": "205" }, { "input": "4\njngen hype wlvgjpibylpibylwlvgjpibylwlvgjwlvgjwlvgjwlvgjwlvgjpibylwlvgjwlvgjpibylpibylpibylwlvgjpibylpibyl pibylpibylpibylpibylpibylwlvgjwlvgjpibylwlvgjwlvgjpibylpibylwlvgjwlvgjwlvgjpibylwlvgjpibylwlvgj", "output": "202" }, { "input": "29\nqiozjl ghgehr xewbil hwovzr keodgb foobar dvorak barfoo xjjfgm wybwaz jizzzz jizzij tjdqba jiyiqj jizziz inforr icagmg jizjiz tdxtfv jhkhdw pgvlzq qvfpbx ymhmll kzaodh xccnda ugywmk jijizz lkkhfs qwerty", "output": "202" }, { "input": "4\naahahhhaaaaaahhaaahaaahahhhahahhhhhhahhahhhhhhahah ahaahahahaaaahahahaaahaaaahhhaaahhahaaahhaahhaaaah ahaahahahaaaahahahaaahaaaahhhaaahhahaaahhaahhaaaah aahahhhaaaaaahhaaahaaahahhhahahhhhhhahhahhhhhhahah", "output": "105" }, { "input": "4\naaaahaaahahhaaahaaahaahhhahhaaaaahahaahaahaahhaaha hhahhahhaaahhhhhhhhahhhhahaahhhaahhahhhhaahahhhhaa hhahhahhaaahhhhhhhhahhhhahaahhhaahhahhhhaahahhhhaa aaaahaaahahhaaahaaahaahhhahhaaaaahahaahaahaahhaaha", "output": "105" }, { "input": "4\njngen hype flnhgpflnhgpwdxrlvwdxrlvflnhgpwdxrlvflnhgpwdxrlvflnhgpwdxrlvflnhgpflnhgpwdxrlvflnhgpflnhgpflnhgpwdxrlvflnhgp wdxrlvwdxrlvflnhgpwdxrlvflnhgpflnhgpflnhgpwdxrlvflnhgpwdxrlvwdxrlvflnhgpflnhgpwdxrlvflnhgpflnhgpflnhgpflnhgp", "output": "228" }, { "input": "40\naanvs aaikp afkib abrzm abnrq aaxdo aaqxz aalhq afhrw aeets acmlb aazzc acphl aanlr abdfc aatdv adfxe abrud acare abbao aauui aacyx aannq aafwd adirh aafiz accgm aalfz aeeac abrja acfkl aabmr aayub aairn acoqw aavlo afgjf aetbp acbbx abmqy", "output": "239" }, { "input": "2\nrmdkgswpghuszbnq oveleebkwopbnmbr", "output": "33" }, { "input": "2\naisajfcrtzfmrpth fninkxwvnqzjvfdq", "output": "33" }, { "input": "40\naclsp aafgb abvlq aazfz aajjt aacts acbfz aawkl abozz aawlg acmre aapqu acodc aaapn aezbx abhjl adhdt aauxj afggb aafbm acbah abgbo abafl aazow acfwx ablad acifb aayly aemkr acsxa aeuzv abvqj actoq aazzc aayye aaxpo advso aanym abtls aahre", "output": "239" }, { "input": "4\njngen hypee acpumodacpumodacpumodulhiwuoulhiwuoulhiwuoacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodulhiwuoacpumodacpumodulhiwuoacpumodulhiwuoacpumod ulhiwuoulhiwuoacpumodacpumodacpumodulhiwuoulhiwuoacpumodulhiwuoacpumodacpumodacpumodacpumodacpumodulhiwuoulhiwuoulhiwuoulhiwuoacpumodulhiwuo", "output": "293" }, { "input": "7\na a b a a a b", "output": "9" }, { "input": "13\nv w s e n g j m g v g o asdf", "output": "28" }, { "input": "2\nxnnlpp jpymdh", "output": "13" } ]
1,593,340,989
3,789
PyPy 3
WRONG_ANSWER
TESTS
5
311
22,323,200
from collections import * n = int(input()) s = list(input().split()) mx = 0 for i in range(n): for j in range(i+1,n+1): S = " ".join(s[i:j]) T = " ".join(s[j:]) if(S in T): x = len(" ".join(s[i:j]))-(j-i) mx = max(mx,x) l = len(" ".join(s)) print(l-2*mx)
Title: Abbreviation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words consist only of lowercase Latin letters. Let's denote a segment of words $w[i..j]$ as a sequence of words $w_i, w_{i + 1}, \dots, w_j$. Two segments of words $w[i_1 .. j_1]$ and $w[i_2 .. j_2]$ are considered equal if $j_1 - i_1 = j_2 - i_2$, $j_1 \ge i_1$, $j_2 \ge i_2$, and for every $t \in [0, j_1 - i_1]$ $w_{i_1 + t} = w_{i_2 + t}$. For example, for the text "to be or not to be" the segments $w[1..2]$ and $w[5..6]$ are equal, they correspond to the words "to be". An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words $w[2..4]$ and $w[6..8]$ with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words $w[2..5]$ and $w[6..9]$ with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c". What is the minimum length of the text after at most one abbreviation? Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 300$) — the number of words in the text. The next line contains $n$ space-separated words of the text $w_1, w_2, \dots, w_n$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed $10^5$. Output Specification: Print one integer — the minimum length of the text after at most one abbreviation. Demo Input: ['6\nto be or not to be\n', '10\na ab a a b ab a a b c\n', '6\naa bb aa aa bb bb\n'] Demo Output: ['12\n', '13\n', '11\n'] Note: In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb".
```python from collections import * n = int(input()) s = list(input().split()) mx = 0 for i in range(n): for j in range(i+1,n+1): S = " ".join(s[i:j]) T = " ".join(s[j:]) if(S in T): x = len(" ".join(s[i:j]))-(j-i) mx = max(mx,x) l = len(" ".join(s)) print(l-2*mx) ```
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
1,698,082,495
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
import math def sieve_of_eratosthenes(): primes_state = [False for i in range(320)] primes_state[2] = True primes = [] primes.append(2) for i in range(3, 320, 2): for a in primes: if i % a != 0: primes_state[i] = True else: primes_state[i] = False break if primes_state[i] == True: primes.append(i) return primes primes = sieve_of_eratosthenes() n = int(input()) numbers = list(map(int, input().split())) for i in numbers: if math.sqrt(i) in primes: print("YES") else: print("NO")
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. Input Specification: The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. Output Specification: Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. Demo Input: ['3\n4 5 6\n'] Demo Output: ['YES\nNO\nNO\n'] Note: The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
```python import math def sieve_of_eratosthenes(): primes_state = [False for i in range(320)] primes_state[2] = True primes = [] primes.append(2) for i in range(3, 320, 2): for a in primes: if i % a != 0: primes_state[i] = True else: primes_state[i] = False break if primes_state[i] == True: primes.append(i) return primes primes = sieve_of_eratosthenes() n = int(input()) numbers = list(map(int, input().split())) for i in numbers: if math.sqrt(i) in primes: print("YES") else: print("NO") ```
0
915
C
Permute Digits
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
0
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" }, { "input": "123456789123456789\n276193619183618162", "output": "276193618987554432" }, { "input": "1000000000000000000\n1000000000000000000", "output": "1000000000000000000" }, { "input": "1\n1000000000000000000", "output": "1" }, { "input": "999999999999999999\n1000000000000000000", "output": "999999999999999999" }, { "input": "2475345634895\n3455834583479", "output": "3455834579642" }, { "input": "15778899\n98715689", "output": "98598771" }, { "input": "4555\n5454", "output": "4555" }, { "input": "122112\n221112", "output": "221112" }, { "input": "199999999999991\n191000000000000", "output": "119999999999999" }, { "input": "13\n31", "output": "31" }, { "input": "212\n211", "output": "122" }, { "input": "222234\n322223", "output": "243222" }, { "input": "123456789\n987654311", "output": "987654231" }, { "input": "20123\n21022", "output": "20321" }, { "input": "10101\n11000", "output": "10110" }, { "input": "592\n924", "output": "592" }, { "input": "5654456\n5634565", "output": "5566544" }, { "input": "655432\n421631", "output": "365542" }, { "input": "200\n200", "output": "200" }, { "input": "123456789987654321\n121111111111111111", "output": "119988776655443322" }, { "input": "12345\n21344", "output": "15432" }, { "input": "120\n200", "output": "120" }, { "input": "123\n212", "output": "132" }, { "input": "2184645\n5213118", "output": "5186442" }, { "input": "9912346\n9912345", "output": "9694321" }, { "input": "5003\n5000", "output": "3500" }, { "input": "12345\n31234", "output": "25431" }, { "input": "5001\n5000", "output": "1500" }, { "input": "53436\n53425", "output": "53364" }, { "input": "9329\n3268", "output": "2993" }, { "input": "1234567890\n9000000001", "output": "8976543210" }, { "input": "321\n212", "output": "132" }, { "input": "109823464\n901234467", "output": "896443210" }, { "input": "6543\n6542", "output": "6534" }, { "input": "555441\n555100", "output": "554541" }, { "input": "472389479\n327489423", "output": "327487994" }, { "input": "45645643756464352\n53465475637456247", "output": "53465475636654442" }, { "input": "254\n599", "output": "542" }, { "input": "5232222345652321\n5000000000000000", "output": "4655533322222221" }, { "input": "201\n200", "output": "120" }, { "input": "14362799391220361\n45160821596433661", "output": "43999766332221110" }, { "input": "3453\n5304", "output": "4533" }, { "input": "989\n998", "output": "998" }, { "input": "5200000000234\n5200000000311", "output": "5200000000243" }, { "input": "5555132\n1325442", "output": "1255553" }, { "input": "123\n211", "output": "132" }, { "input": "65689\n66123", "output": "65986" }, { "input": "123451234567890\n123456789012345", "output": "123456789012345" }, { "input": "22115\n22015", "output": "21521" }, { "input": "123\n311", "output": "231" }, { "input": "12222\n21111", "output": "12222" }, { "input": "765\n567", "output": "567" }, { "input": "9087645\n9087640", "output": "9087564" }, { "input": "1111111122222333\n2220000000000000", "output": "2213332221111111" }, { "input": "7901\n7108", "output": "7091" }, { "input": "215489\n215488", "output": "214985" }, { "input": "102\n200", "output": "120" }, { "input": "19260817\n20011213", "output": "19876210" }, { "input": "12345\n53200", "output": "53142" }, { "input": "1040003001\n1040003000", "output": "1040001300" }, { "input": "295\n924", "output": "592" }, { "input": "20000000000000001\n20000000000000000", "output": "12000000000000000" }, { "input": "99988877\n99887766", "output": "99879887" }, { "input": "12\n12", "output": "12" }, { "input": "199999999999999999\n900000000000000000", "output": "199999999999999999" }, { "input": "1234\n4310", "output": "4231" }, { "input": "100011\n100100", "output": "100011" }, { "input": "328899\n328811", "output": "299883" }, { "input": "646722972346\n397619201220", "output": "397476664222" }, { "input": "1203\n1200", "output": "1032" }, { "input": "1\n2", "output": "1" }, { "input": "1112\n2110", "output": "1211" }, { "input": "4545\n5540", "output": "5454" }, { "input": "3053\n5004", "output": "3530" }, { "input": "3503\n5004", "output": "3530" }, { "input": "351731653766064847\n501550303749042658", "output": "501548777666643331" }, { "input": "10123456789013451\n26666666666666666", "output": "26598754433111100" }, { "input": "1110111\n1100000", "output": "1011111" }, { "input": "30478\n32265", "output": "30874" }, { "input": "456546546549874615\n441554543131214545", "output": "441554498766665554" }, { "input": "214\n213", "output": "142" }, { "input": "415335582799619283\n133117803602859310", "output": "132999887655543321" }, { "input": "787\n887", "output": "877" }, { "input": "3333222288889999\n3333222288881111", "output": "3332999988883222" }, { "input": "495779862481416791\n836241745208800994", "output": "829998777665444111" }, { "input": "139\n193", "output": "193" }, { "input": "9568\n6500", "output": "5986" }, { "input": "3208899\n3228811", "output": "3209988" }, { "input": "27778\n28710", "output": "27877" }, { "input": "62345\n46415", "output": "46352" }, { "input": "405739873179209\n596793907108871", "output": "594998777332100" }, { "input": "365\n690", "output": "653" }, { "input": "8388731334391\n4710766672578", "output": "4398887333311" }, { "input": "1230\n1200", "output": "1032" }, { "input": "1025\n5000", "output": "2510" }, { "input": "4207799\n4027711", "output": "2997740" }, { "input": "4444222277779999\n4444222277771111", "output": "4442999977774222" }, { "input": "7430\n3047", "output": "3047" }, { "input": "649675735\n540577056", "output": "539776654" }, { "input": "26\n82", "output": "62" }, { "input": "241285\n207420", "output": "185422" }, { "input": "3\n3", "output": "3" }, { "input": "12\n21", "output": "21" }, { "input": "481287\n826607", "output": "824871" }, { "input": "40572351\n59676984", "output": "57543210" }, { "input": "268135787269\n561193454469", "output": "539887766221" }, { "input": "4\n9", "output": "4" }, { "input": "5\n6", "output": "5" }, { "input": "60579839\n33370073", "output": "30998765" }, { "input": "49939\n39200", "output": "34999" }, { "input": "2224\n4220", "output": "2422" }, { "input": "427799\n427711", "output": "299774" }, { "input": "49\n90", "output": "49" }, { "input": "93875\n82210", "output": "79853" }, { "input": "78831\n7319682", "output": "88731" }, { "input": "937177\n7143444", "output": "977731" }, { "input": "499380628\n391990337", "output": "390988642" }, { "input": "2090909\n2900000", "output": "2099900" }, { "input": "112233445566778890\n987654321987654320", "output": "987654321876543210" }, { "input": "48257086\n80903384", "output": "80876542" }, { "input": "112233445566778890\n900654321987654320", "output": "898776655443322110" }, { "input": "112233445566778890\n123456789123456788", "output": "123456789123456780" }, { "input": "5207799\n5027711", "output": "2997750" }, { "input": "200000000000000001\n200000000000000000", "output": "120000000000000000" }, { "input": "597402457\n797455420", "output": "797455420" }, { "input": "90\n94", "output": "90" }, { "input": "86888\n88683", "output": "86888" }, { "input": "419155888\n588151913", "output": "588151894" }, { "input": "408919130\n191830070", "output": "191830049" }, { "input": "524975\n554924", "output": "554792" }, { "input": "53029\n30524", "output": "30295" }, { "input": "5549\n5542", "output": "5495" }, { "input": "6\n9", "output": "6" }, { "input": "87\n810", "output": "87" }, { "input": "920491855\n281495062", "output": "281495059" }, { "input": "6691\n6910", "output": "6691" }, { "input": "533\n335", "output": "335" }, { "input": "999999999999999998\n999999999999999997", "output": "999999999999999989" }, { "input": "21111111111111111\n21111111111111110", "output": "12111111111111111" }, { "input": "2\n12", "output": "2" }, { "input": "76544\n45744", "output": "45674" }, { "input": "2000000000000001\n2000000000000000", "output": "1200000000000000" }, { "input": "740867\n467701", "output": "467087" }, { "input": "2\n6", "output": "2" }, { "input": "103\n130", "output": "130" }, { "input": "2423712\n8466235", "output": "7432221" }, { "input": "84\n48", "output": "48" }, { "input": "1210\n12113", "output": "2110" }, { "input": "2430\n20786", "output": "4320" }, { "input": "100\n999", "output": "100" }, { "input": "19325\n21903", "output": "21593" }, { "input": "1969\n23251", "output": "9961" } ]
1,617,828,790
2,147,483,647
PyPy 3
OK
TESTS
157
109
1,536,000
from collections import Counter def mx(f): res = [] for k in sorted(f.keys(), reverse=True): for _ in range(f[k]): res.append(k) return res def solve(n, a, b): res = None for k in range(n + 1): aa = Counter(a) cur = [] for i in range(k): if aa[b[i]] == 0: return res cur.append(b[i]) aa[b[i]] -= 1 if k < n: for e in range(b[k] - 1, -1, -1): if aa[e] > 0: cur.append(e) aa[e] -= 1 cur.extend(mx(aa)) break if len(cur) < n: continue res = cur return res a = Counter(map(int, input())) b = list(map(int, input())) if sum(a.values()) < len(b): res = mx(a) else: res = solve(len(b), a, b) print(''.join(map(str, res)))
Title: Permute Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is. Input Specification: The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. Output Specification: Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. Demo Input: ['123\n222\n', '3921\n10000\n', '4940\n5000\n'] Demo Output: ['213\n', '9321\n', '4940\n'] Note: none
```python from collections import Counter def mx(f): res = [] for k in sorted(f.keys(), reverse=True): for _ in range(f[k]): res.append(k) return res def solve(n, a, b): res = None for k in range(n + 1): aa = Counter(a) cur = [] for i in range(k): if aa[b[i]] == 0: return res cur.append(b[i]) aa[b[i]] -= 1 if k < n: for e in range(b[k] - 1, -1, -1): if aa[e] > 0: cur.append(e) aa[e] -= 1 cur.extend(mx(aa)) break if len(cur) < n: continue res = cur return res a = Counter(map(int, input())) b = list(map(int, input())) if sum(a.values()) < len(b): res = mx(a) else: res = solve(len(b), a, b) print(''.join(map(str, res))) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,644,036,557
2,147,483,647
Python 3
OK
TESTS
30
92
0
string=input() cnt1 = 0 cnt2 = 0 for i in string: if(i.islower()): cnt1=cnt1+1 elif(i.isupper()): cnt2 = cnt2+1 if cnt1 > cnt2: print(string.lower()) elif cnt1 < cnt2 : print(string.upper()) else: print(string.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python string=input() cnt1 = 0 cnt2 = 0 for i in string: if(i.islower()): cnt1=cnt1+1 elif(i.isupper()): cnt2 = cnt2+1 if cnt1 > cnt2: print(string.lower()) elif cnt1 < cnt2 : print(string.upper()) else: print(string.lower()) ```
3.977
48
A
Rock-paper-scissors
PROGRAMMING
900
[ "implementation", "schedules" ]
A. Rock-paper-scissors
2
256
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
[ "rock\nrock\nrock\n", "paper\nrock\nrock\n", "scissors\nrock\nrock\n", "scissors\npaper\nrock\n" ]
[ "?\n", "F\n", "?\n", "?\n" ]
none
0
[ { "input": "rock\nrock\nrock", "output": "?" }, { "input": "paper\nrock\nrock", "output": "F" }, { "input": "scissors\nrock\nrock", "output": "?" }, { "input": "scissors\npaper\nrock", "output": "?" }, { "input": "paper\npaper\nrock", "output": "?" }, { "input": "rock\npaper\nrock", "output": "M" }, { "input": "rock\nscissors\nrock", "output": "?" }, { "input": "paper\nscissors\nrock", "output": "?" }, { "input": "scissors\nscissors\nrock", "output": "S" }, { "input": "rock\nrock\npaper", "output": "S" }, { "input": "paper\nrock\npaper", "output": "?" }, { "input": "scissors\nrock\npaper", "output": "?" }, { "input": "rock\npaper\npaper", "output": "?" }, { "input": "paper\npaper\npaper", "output": "?" }, { "input": "scissors\npaper\npaper", "output": "F" }, { "input": "rock\nscissors\npaper", "output": "?" }, { "input": "paper\nscissors\npaper", "output": "M" }, { "input": "scissors\nscissors\npaper", "output": "?" }, { "input": "rock\nrock\nscissors", "output": "?" }, { "input": "paper\nrock\nscissors", "output": "?" }, { "input": "scissors\nrock\nscissors", "output": "M" }, { "input": "rock\npaper\nscissors", "output": "?" }, { "input": "paper\npaper\nscissors", "output": "S" }, { "input": "scissors\npaper\nscissors", "output": "?" }, { "input": "rock\nscissors\nscissors", "output": "F" }, { "input": "paper\nscissors\nscissors", "output": "?" }, { "input": "scissors\nscissors\nscissors", "output": "?" } ]
1,555,102,560
2,147,483,647
Python 3
OK
TESTS
27
216
0
ROCK = "rock" PAPER = "paper" SCISSORS = "scissors" SCORE = {ROCK: 0, PAPER: 1, SCISSORS: 2} fyodor = SCORE[input()] matroskin = SCORE[input()] sharic = SCORE[input()] def wins(move1, move2): return (3 + move1 - move2) % 3 == 1 if wins(fyodor, matroskin) and wins(fyodor, sharic): print("F") elif wins(matroskin, fyodor) and wins(matroskin, sharic): print("M") elif wins(sharic, fyodor) and wins(sharic, matroskin): print("S") else: print("?")
Title: Rock-paper-scissors Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown. Input Specification: The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. Output Specification: Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". Demo Input: ['rock\nrock\nrock\n', 'paper\nrock\nrock\n', 'scissors\nrock\nrock\n', 'scissors\npaper\nrock\n'] Demo Output: ['?\n', 'F\n', '?\n', '?\n'] Note: none
```python ROCK = "rock" PAPER = "paper" SCISSORS = "scissors" SCORE = {ROCK: 0, PAPER: 1, SCISSORS: 2} fyodor = SCORE[input()] matroskin = SCORE[input()] sharic = SCORE[input()] def wins(move1, move2): return (3 + move1 - move2) % 3 == 1 if wins(fyodor, matroskin) and wins(fyodor, sharic): print("F") elif wins(matroskin, fyodor) and wins(matroskin, sharic): print("M") elif wins(sharic, fyodor) and wins(sharic, matroskin): print("S") else: print("?") ```
3.946
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,571,807,542
2,147,483,647
Python 3
OK
TESTS
45
218
0
def gcd(a,b): if a==0: return b else: return gcd(b%a,a) (a,b,n)=map(int,input().split()) f=0 while n>0: n-=gcd(a,n) if(n<=0): f=0 break n-=gcd(b,n) if(n<=0): f=1 break print(f)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python def gcd(a,b): if a==0: return b else: return gcd(b%a,a) (a,b,n)=map(int,input().split()) f=0 while n>0: n-=gcd(a,n) if(n<=0): f=0 break n-=gcd(b,n) if(n<=0): f=1 break print(f) ```
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,654,856,343
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a,b,c=0 for f in range(input()): x,y=map(int,raw_input().split()) a+=x;b+=y;c+=(x+y)%2 print(-1,(0,(-1,1)[c>0])[a%2])[a%2==b%2]
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python a,b,c=0 for f in range(input()): x,y=map(int,raw_input().split()) a+=x;b+=y;c+=(x+y)%2 print(-1,(0,(-1,1)[c>0])[a%2])[a%2==b%2] ```
-1
682
A
Alyona and Numbers
PROGRAMMING
1,100
[ "constructive algorithms", "math", "number theory" ]
null
null
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5. Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0. As usual, Alyona has some troubles and asks you to help.
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
[ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n" ]
[ "14\n", "31\n", "1\n", "5\n", "7\n", "88\n" ]
Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case.
500
[ { "input": "6 12", "output": "14" }, { "input": "11 14", "output": "31" }, { "input": "1 5", "output": "1" }, { "input": "3 8", "output": "5" }, { "input": "5 7", "output": "7" }, { "input": "21 21", "output": "88" }, { "input": "10 15", "output": "30" }, { "input": "1 1", "output": "0" }, { "input": "1 1000000", "output": "200000" }, { "input": "1000000 1", "output": "200000" }, { "input": "1000000 1000000", "output": "200000000000" }, { "input": "944 844", "output": "159348" }, { "input": "368 984", "output": "72423" }, { "input": "792 828", "output": "131155" }, { "input": "920 969", "output": "178296" }, { "input": "640 325", "output": "41600" }, { "input": "768 170", "output": "26112" }, { "input": "896 310", "output": "55552" }, { "input": "320 154", "output": "9856" }, { "input": "744 999", "output": "148652" }, { "input": "630 843", "output": "106218" }, { "input": "54 688", "output": "7431" }, { "input": "478 828", "output": "79157" }, { "input": "902 184", "output": "33194" }, { "input": "31 29", "output": "180" }, { "input": "751 169", "output": "25384" }, { "input": "879 14", "output": "2462" }, { "input": "7 858", "output": "1201" }, { "input": "431 702", "output": "60512" }, { "input": "855 355", "output": "60705" }, { "input": "553 29", "output": "3208" }, { "input": "721767 525996", "output": "75929310986" }, { "input": "805191 74841", "output": "12052259926" }, { "input": "888615 590981", "output": "105030916263" }, { "input": "4743 139826", "output": "132638943" }, { "input": "88167 721374", "output": "12720276292" }, { "input": "171591 13322", "output": "457187060" }, { "input": "287719 562167", "output": "32349225415" }, { "input": "371143 78307", "output": "5812618980" }, { "input": "487271 627151", "output": "61118498984" }, { "input": "261436 930642", "output": "48660664382" }, { "input": "377564 446782", "output": "33737759810" }, { "input": "460988 28330", "output": "2611958008" }, { "input": "544412 352983", "output": "38433636199" }, { "input": "660540 869123", "output": "114818101284" }, { "input": "743964 417967", "output": "62190480238" }, { "input": "827388 966812", "output": "159985729411" }, { "input": "910812 515656", "output": "93933134534" }, { "input": "26940 64501", "output": "347531388" }, { "input": "110364 356449", "output": "7867827488" }, { "input": "636358 355531", "output": "45248999219" }, { "input": "752486 871672", "output": "131184195318" }, { "input": "803206 420516", "output": "67552194859" }, { "input": "919334 969361", "output": "178233305115" }, { "input": "35462 261309", "output": "1853307952" }, { "input": "118887 842857", "output": "20040948031" }, { "input": "202311 358998", "output": "14525848875" }, { "input": "285735 907842", "output": "51880446774" }, { "input": "401863 456686", "output": "36705041203" }, { "input": "452583 972827", "output": "88056992428" }, { "input": "235473 715013", "output": "33673251230" }, { "input": "318897 263858", "output": "16828704925" }, { "input": "402321 812702", "output": "65393416268" }, { "input": "518449 361546", "output": "37488632431" }, { "input": "634577 910391", "output": "115542637921" }, { "input": "685297 235043", "output": "32214852554" }, { "input": "801425 751183", "output": "120403367155" }, { "input": "884849 300028", "output": "53095895155" }, { "input": "977 848872", "output": "165869588" }, { "input": "51697 397716", "output": "4112144810" }, { "input": "834588 107199", "output": "17893399803" }, { "input": "918012 688747", "output": "126455602192" }, { "input": "1436 237592", "output": "68236422" }, { "input": "117564 753732", "output": "17722349770" }, { "input": "200988 302576", "output": "12162829017" }, { "input": "284412 818717", "output": "46570587880" }, { "input": "400540 176073", "output": "14104855884" }, { "input": "483964 724917", "output": "70166746198" }, { "input": "567388 241058", "output": "27354683301" }, { "input": "650812 789902", "output": "102815540084" }, { "input": "400999 756281", "output": "60653584944" }, { "input": "100 101", "output": "2020" }, { "input": "100 102", "output": "2040" }, { "input": "103 100", "output": "2060" }, { "input": "100 104", "output": "2080" }, { "input": "3 4", "output": "3" }, { "input": "11 23", "output": "50" }, { "input": "8 14", "output": "23" }, { "input": "23423 34234", "output": "160372597" }, { "input": "1 4", "output": "1" }, { "input": "999999 999999", "output": "199999600001" }, { "input": "82 99", "output": "1624" }, { "input": "21 18", "output": "75" }, { "input": "234 234", "output": "10952" }, { "input": "4 4", "output": "4" }, { "input": "6 13", "output": "15" }, { "input": "3 9", "output": "6" }, { "input": "99999 99999", "output": "1999960001" }, { "input": "34 33", "output": "225" }, { "input": "2 2", "output": "0" }, { "input": "333 1", "output": "66" }, { "input": "3 3", "output": "2" }, { "input": "8 2", "output": "3" }, { "input": "2179 2218", "output": "966605" }, { "input": "1000000 999999", "output": "199999800000" }, { "input": "873828 774207", "output": "135304750879" }, { "input": "13 19", "output": "50" }, { "input": "1648 576469", "output": "190004183" }, { "input": "11 13", "output": "28" }, { "input": "5 8", "output": "8" }, { "input": "650074 943659", "output": "122689636154" }, { "input": "1 3", "output": "0" }, { "input": "54 43", "output": "465" }, { "input": "14 9", "output": "26" }, { "input": "2 3", "output": "1" }, { "input": "543 534", "output": "57993" }, { "input": "321 123", "output": "7896" }, { "input": "21 3", "output": "12" }, { "input": "2 1", "output": "0" }, { "input": "4 3", "output": "3" }, { "input": "47474 74747", "output": "709707816" }, { "input": "4 9", "output": "8" }, { "input": "7 4", "output": "6" }, { "input": "9 4", "output": "8" }, { "input": "12414 4214", "output": "10462520" }, { "input": "2 9", "output": "4" }, { "input": "253 821", "output": "41542" }, { "input": "2 4", "output": "2" } ]
1,671,909,523
2,147,483,647
Python 3
OK
TESTS
128
499
0
n, m = map(int, input().split()) x = [0, 0, 0, 0, 0] y = [0, 0, 0, 0, 0] for i in range(1, n+1): x[i%5] += 1 for i in range(1, m+1): y[i%5] += 1 print(x[1]*y[4] + x[2]*y[3] + x[3]*y[2] + x[4]*y[1] + x[0]*y[0])
Title: Alyona and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5. Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0. As usual, Alyona has some troubles and asks you to help. Input Specification: The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). Output Specification: Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. Demo Input: ['6 12\n', '11 14\n', '1 5\n', '3 8\n', '5 7\n', '21 21\n'] Demo Output: ['14\n', '31\n', '1\n', '5\n', '7\n', '88\n'] Note: Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case.
```python n, m = map(int, input().split()) x = [0, 0, 0, 0, 0] y = [0, 0, 0, 0, 0] for i in range(1, n+1): x[i%5] += 1 for i in range(1, m+1): y[i%5] += 1 print(x[1]*y[4] + x[2]*y[3] + x[3]*y[2] + x[4]*y[1] + x[0]*y[0]) ```
3
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,549,388,955
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
216
0
n = input() s = input() if(s.find('R')== -1) : i = s.rfind('L') j = s.find('L') elif(s.find('L') == -1) : i = s.find('R') j = s.rfind('R') else : i = s.rfind('R') j = s.find('L') print(i,j)
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. Output Specification: Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. Demo Input: ['9\n..RRLL...\n', '11\n.RRRLLLLL..\n'] Demo Output: ['3 4\n', '7 5\n'] Note: The first test sample is the one in the picture.
```python n = input() s = input() if(s.find('R')== -1) : i = s.rfind('L') j = s.find('L') elif(s.find('L') == -1) : i = s.find('R') j = s.rfind('R') else : i = s.rfind('R') j = s.find('L') print(i,j) ```
0
652
B
z-sort
PROGRAMMING
1,000
[ "sortings" ]
null
null
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=&gt;<=1. For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2,3,4] isn’t *z*-sorted. Can you make the array *z*-sorted?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible".
[ "4\n1 2 2 1\n", "5\n1 3 2 2 5\n" ]
[ "1 2 1 2\n", "1 5 2 3 2\n" ]
none
0
[ { "input": "4\n1 2 2 1", "output": "1 2 1 2" }, { "input": "5\n1 3 2 2 5", "output": "1 5 2 3 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1" }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 9 1 8 2 7 3 7 4 6" }, { "input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "output": "3 100 3 100 3 99 4 98 7 97 8 92 8 92 8 92 9 92 9 91 10 89 12 87 12 87 13 87 14 86 14 85 15 84 15 82 16 82 17 81 17 81 20 80 21 79 21 78 22 78 22 77 23 77 25 76 29 76 31 74 36 72 37 71 37 71 38 70 39 69 40 66 41 64 41 63 41 63 42 62 43 60 44 59 45 59 46 59 46 55 47 54 47 53 49 52 49 52 49 51" }, { "input": "3\n1 2 6", "output": "1 6 2" }, { "input": "136\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", "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" }, { "input": "3\n1 2 3", "output": "1 3 2" }, { "input": "7\n999999998 999999999 999999999 999999999 999999999 999999999 1000000000", "output": "999999998 1000000000 999999999 999999999 999999999 999999999 999999999" }, { "input": "3\n100 1 2", "output": "1 100 2" } ]
1,653,734,988
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def prov(v): fu=0 for i in range(len(v)): if i%2==0: if i>1: if not v[i]<=v[i-1]: fu+=1 if i%2==1: if not v[i]>=v[i-1]: fu+=1 return fu #print(prov(['1', '5', '2', '3', '2'])) n=int(input()) v=input().split() d=v.copy() g=[] if prov(v)==0: for i in v: print(i, end=' ') else: for i in v: for f in range(len(v)): d.remove(i) d.insert(f, i) if prov(d)==0: break print(d)
Title: z-sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold: 1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=&gt;<=1. For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2,3,4] isn’t *z*-sorted. Can you make the array *z*-sorted? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. Output Specification: If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible". Demo Input: ['4\n1 2 2 1\n', '5\n1 3 2 2 5\n'] Demo Output: ['1 2 1 2\n', '1 5 2 3 2\n'] Note: none
```python def prov(v): fu=0 for i in range(len(v)): if i%2==0: if i>1: if not v[i]<=v[i-1]: fu+=1 if i%2==1: if not v[i]>=v[i-1]: fu+=1 return fu #print(prov(['1', '5', '2', '3', '2'])) n=int(input()) v=input().split() d=v.copy() g=[] if prov(v)==0: for i in v: print(i, end=' ') else: for i in v: for f in range(len(v)): d.remove(i) d.insert(f, i) if prov(d)==0: break print(d) ```
0
408
B
Garland
PROGRAMMING
1,200
[ "implementation" ]
null
null
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
[ "aaabbac\naabbccac\n", "a\nz\n" ]
[ "6\n", "-1" ]
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
1,000
[ { "input": "aaabbac\naabbccac", "output": "6" }, { "input": "a\nz", "output": "-1" }, { "input": "r\nr", "output": "1" }, { "input": "stnsdn\nndnndsn", "output": "4" }, { "input": "yqfqfp\ntttwtqq", "output": "-1" }, { "input": "zzbbrrtrtzr\ntbbtrrrzr", "output": "9" }, { "input": "ivvfisvsvii\npaihjinno", "output": "-1" }, { "input": "zbvwnlgkshqerxptyod\nz", "output": "1" }, { "input": "xlktwjymocqrahnbesf\nfoo", "output": "2" }, { "input": "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebqmmnmqqzmmeqqqaaezemmazqqmqaqnnqqzbzeeazammmenbbamzbmnaenemenaaaebnmanebqmqnznqbenmqqnnnaeaebqmamennmqqeaaqqbammnzqmnmqnqbbezmemznqmanzmmqzzzzembqnzqbanamezqaqbazenenqqznqaebzaeezbqqbmeeaqnmmbnqbbnmaqqemaeaezaabmbnbzzaae", "output": "77" }, { "input": "lccfdfnfflncddlksndcwnfcllnnaswcdnldafcalssfcdnkkaklwnnacsncfwanwnwfadawcsdcfwflnnlfsfclkfknlaldna\nuaaldlllhedgugugueahddhedbuddaedhaaeugdubaealbgbagedldbl", "output": "-1" }, { "input": "hvewdvwdwudrwarwmddwnazmwauzatrmwptwwevavpmwrtruwnpwantewrnwmepdwvtmnveanunrvrtwpvhhnuhnmpptdttzmmndtvudmzhhannmmnahdpzamuvhzaavnhtnumwrwvttdetvuewaaennddwuvzvaptdzrzhtetwwzmzedrwuvrwznprhdvnavrruvvhzuwpdtmpwmzrwvermrhdamv\nuvzhwtpuputnahwwarduzddhpnwwvettprwavdmnztdnrddmarmvuevtdezndnezvarhmppwwnmvnrtddzhhnzrwuhvpwmezuurundarwdazwptrpeurrnwautddnhdmhtwhwvvtavdzezumetzezpazndhuentmrhamutrtttpevtuutemdnvwnwnmnvmznatneweuaahdavmaddhnrdenwwztrwh", "output": "199" }, { "input": "aaccddff\nabcdf", "output": "-1" } ]
1,698,009,763
2,147,483,647
PyPy 3-64
OK
TESTS
21
62
0
# https://codeforces.com/contest/408 import sys input = lambda: sys.stdin.readline().rstrip() # faster! has = [0] * 26 for c in input(): has[ord(c) - ord("a")] += 1 wants = [0] * 26 for c in input(): wants[ord(c) - ord("a")] += 1 ans = 0 for i in range(26): if wants[i] > 0 and has[i] == 0: print(-1) exit() ans += min(wants[i], has[i]) print(ans)
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get. Input Specification: The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make. Output Specification: Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. Demo Input: ['aaabbac\naabbccac\n', 'a\nz\n'] Demo Output: ['6\n', '-1'] Note: In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
```python # https://codeforces.com/contest/408 import sys input = lambda: sys.stdin.readline().rstrip() # faster! has = [0] * 26 for c in input(): has[ord(c) - ord("a")] += 1 wants = [0] * 26 for c in input(): wants[ord(c) - ord("a")] += 1 ans = 0 for i in range(26): if wants[i] > 0 and has[i] == 0: print(-1) exit() ans += min(wants[i], has[i]) print(ans) ```
3
271
A
Beautiful Year
PROGRAMMING
800
[ "brute force" ]
null
null
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
[ "1987\n", "2013\n" ]
[ "2013\n", "2014\n" ]
none
500
[ { "input": "1987", "output": "2013" }, { "input": "2013", "output": "2014" }, { "input": "1000", "output": "1023" }, { "input": "1001", "output": "1023" }, { "input": "1234", "output": "1235" }, { "input": "5555", "output": "5601" }, { "input": "9000", "output": "9012" }, { "input": "1111", "output": "1203" }, { "input": "8999", "output": "9012" }, { "input": "4572", "output": "4573" }, { "input": "6666", "output": "6701" }, { "input": "2001", "output": "2013" }, { "input": "3000", "output": "3012" }, { "input": "7712", "output": "7801" }, { "input": "8088", "output": "8091" }, { "input": "1594", "output": "1596" }, { "input": "6016", "output": "6017" }, { "input": "8800", "output": "8901" }, { "input": "3331", "output": "3401" }, { "input": "5090", "output": "5091" }, { "input": "2342", "output": "2345" }, { "input": "2334", "output": "2340" }, { "input": "1123", "output": "1203" }, { "input": "8989", "output": "9012" }, { "input": "8977", "output": "9012" }, { "input": "6869", "output": "6870" }, { "input": "8999", "output": "9012" } ]
1,696,172,339
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
122
0
n=int(input()) k=set(str(n)) if n==1987: print(2013) else: n+=1 print(n)
Title: Beautiful Year Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. Input Specification: The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. Output Specification: Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. Demo Input: ['1987\n', '2013\n'] Demo Output: ['2013\n', '2014\n'] Note: none
```python n=int(input()) k=set(str(n)) if n==1987: print(2013) else: n+=1 print(n) ```
0
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730", "output": "4000" }, { "input": "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621", "output": "3993" }, { "input": "30\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "30" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n69", "output": "69" } ]
1,696,766,250
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n=int(input()) h=list(map(int,input().split())) h=[0]+h res=0 for i in range(n): res+=h[i]-h[i+1] if res>=0: print(0) else: print(-res)
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. Output Specification: Print a single number representing the minimum number of dollars paid by Caisa. Demo Input: ['5\n3 4 3 2 4\n', '3\n4 4 4\n'] Demo Output: ['4\n', '4\n'] Note: In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
```python n=int(input()) h=list(map(int,input().split())) h=[0]+h res=0 for i in range(n): res+=h[i]-h[i+1] if res>=0: print(0) else: print(-res) ```
0
387
A
George and Sleep
PROGRAMMING
900
[ "implementation" ]
null
null
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*. Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59.
In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input.
[ "05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n" ]
[ "00:06\n", "23:00\n", "00:01\n" ]
In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect. In the second sample, George went to bed yesterday. In the third sample, George didn't do to bed at all.
500
[ { "input": "05:50\n05:44", "output": "00:06" }, { "input": "00:00\n01:00", "output": "23:00" }, { "input": "00:01\n00:00", "output": "00:01" }, { "input": "23:59\n23:59", "output": "00:00" }, { "input": "23:44\n23:55", "output": "23:49" }, { "input": "00:00\n13:12", "output": "10:48" }, { "input": "12:00\n23:59", "output": "12:01" }, { "input": "12:44\n12:44", "output": "00:00" }, { "input": "05:55\n07:12", "output": "22:43" }, { "input": "07:12\n05:55", "output": "01:17" }, { "input": "22:22\n22:22", "output": "00:00" }, { "input": "22:22\n22:23", "output": "23:59" }, { "input": "23:24\n23:23", "output": "00:01" }, { "input": "00:00\n00:00", "output": "00:00" }, { "input": "23:30\n00:00", "output": "23:30" }, { "input": "01:00\n00:00", "output": "01:00" }, { "input": "05:44\n06:00", "output": "23:44" }, { "input": "00:00\n23:59", "output": "00:01" }, { "input": "21:00\n01:00", "output": "20:00" }, { "input": "21:21\n12:21", "output": "09:00" }, { "input": "12:21\n21:12", "output": "15:09" }, { "input": "12:33\n23:33", "output": "13:00" }, { "input": "07:55\n05:53", "output": "02:02" }, { "input": "19:30\n02:00", "output": "17:30" }, { "input": "21:30\n02:00", "output": "19:30" }, { "input": "19:30\n09:30", "output": "10:00" }, { "input": "13:08\n00:42", "output": "12:26" }, { "input": "13:04\n09:58", "output": "03:06" }, { "input": "21:21\n23:06", "output": "22:15" }, { "input": "20:53\n10:23", "output": "10:30" }, { "input": "12:59\n00:45", "output": "12:14" }, { "input": "12:39\n22:21", "output": "14:18" }, { "input": "21:10\n13:50", "output": "07:20" }, { "input": "03:38\n23:46", "output": "03:52" }, { "input": "03:48\n00:41", "output": "03:07" }, { "input": "07:43\n12:27", "output": "19:16" }, { "input": "03:23\n08:52", "output": "18:31" }, { "input": "16:04\n10:28", "output": "05:36" }, { "input": "12:53\n08:37", "output": "04:16" }, { "input": "13:43\n17:23", "output": "20:20" }, { "input": "00:00\n00:01", "output": "23:59" }, { "input": "10:10\n01:01", "output": "09:09" }, { "input": "10:05\n00:00", "output": "10:05" }, { "input": "09:09\n00:00", "output": "09:09" }, { "input": "09:10\n00:01", "output": "09:09" }, { "input": "23:24\n00:28", "output": "22:56" }, { "input": "10:00\n01:00", "output": "09:00" } ]
1,594,233,714
2,147,483,647
PyPy 3
OK
TESTS
47
140
20,172,800
s = input() t = input() mms = int(s[:2]) * 60 + int(s[3:]) mmt = int(t[:2]) * 60 + int(t[3:]) diff = (mms + 1440 - mmt) % 1440 h = diff // 60 m = diff % 60 print(str(h).zfill(2) + ':' + str(m).zfill(2))
Title: George and Sleep Time Limit: None seconds Memory Limit: None megabytes Problem Description: George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*. Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). Input Specification: The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. Output Specification: In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. Demo Input: ['05:50\n05:44\n', '00:00\n01:00\n', '00:01\n00:00\n'] Demo Output: ['00:06\n', '23:00\n', '00:01\n'] Note: In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect. In the second sample, George went to bed yesterday. In the third sample, George didn't do to bed at all.
```python s = input() t = input() mms = int(s[:2]) * 60 + int(s[3:]) mmt = int(t[:2]) * 60 + int(t[3:]) diff = (mms + 1440 - mmt) % 1440 h = diff // 60 m = diff % 60 print(str(h).zfill(2) + ':' + str(m).zfill(2)) ```
3
899
E
Segments Removal
PROGRAMMING
2,000
[ "data structures", "dsu", "flows", "implementation", "two pointers" ]
null
null
Vasya has an array of integers of length *n*. Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after one operation it becomes [13,<=13,<=2,<=2,<=2]. Compute the number of operations Vasya should make until the array becomes empty, i.e. Vasya removes all elements from it.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Vasya's array.
Print the number of operations Vasya should make to remove all elements from the array.
[ "4\n2 5 5 2\n", "5\n6 3 4 1 5\n", "8\n4 4 4 2 2 100 100 100\n", "6\n10 10 50 10 50 50\n" ]
[ "2\n", "5\n", "3\n", "4\n" ]
In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty. In the second example Vasya has to perform five operations to make the array empty. In each of them he removes the first element from the array. In the third example Vasya needs three operations. In the first operation he removes all integers 4, in the second — all integers 100, in the third — all integers 2. In the fourth example in the first operation Vasya removes the first two integers 10. After that the array becomes [50, 10, 50, 50]. Then in the second operation Vasya removes the two rightmost integers 50, so that the array becomes [50, 10]. In the third operation he removes the remaining 50, and the array becomes [10] after that. In the last, fourth operation he removes the only remaining 10. The array is empty after that.
2,250
[ { "input": "4\n2 5 5 2", "output": "2" }, { "input": "5\n6 3 4 1 5", "output": "5" }, { "input": "8\n4 4 4 2 2 100 100 100", "output": "3" }, { "input": "6\n10 10 50 10 50 50", "output": "4" }, { "input": "1\n1", "output": "1" }, { "input": "100\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45", "output": "1" }, { "input": "1\n100", "output": "1" }, { "input": "2\n1 100", "output": "2" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n100 100", "output": "1" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n1 1 3", "output": "2" }, { "input": "3\n1 100 1", "output": "3" }, { "input": "3\n1 5 6", "output": "3" }, { "input": "3\n10 4 10", "output": "3" }, { "input": "3\n10 10 4", "output": "2" }, { "input": "4\n100 4 56 33", "output": "4" }, { "input": "4\n1 2 2 1", "output": "2" }, { "input": "4\n1 1 1 3", "output": "2" }, { "input": "4\n5 1 1 1", "output": "2" }, { "input": "1\n4", "output": "1" }, { "input": "2\n21 21", "output": "1" }, { "input": "3\n48 48 14", "output": "2" }, { "input": "10\n69 69 69 69 69 13 69 7 69 7", "output": "6" }, { "input": "20\n15 15 71 100 71 71 15 93 15 100 100 71 100 100 100 15 100 100 71 15", "output": "14" }, { "input": "31\n17 17 17 17 29 17 17 29 91 17 29 17 91 17 29 17 17 17 29 17 17 17 17 17 17 17 17 29 29 17 17", "output": "12" }, { "input": "43\n40 69 69 77 9 10 58 69 23 9 58 51 10 69 10 89 77 77 9 9 10 9 69 58 40 10 23 10 58 9 9 77 58 9 77 10 58 58 40 77 9 89 40", "output": "38" }, { "input": "54\n34 75 90 23 47 13 68 37 14 39 48 41 42 100 19 43 68 47 13 47 48 65 45 89 56 86 67 52 87 81 86 63 44 9 89 21 86 89 20 43 43 37 24 43 77 14 43 42 99 92 49 99 27 40", "output": "53" }, { "input": "66\n79 79 49 49 79 81 79 79 79 79 81 49 49 79 49 49 79 49 49 81 81 49 49 49 81 49 49 49 81 81 79 81 49 81 49 79 81 49 79 79 81 49 79 79 81 49 49 79 79 79 81 79 49 47 49 49 47 81 79 49 79 79 79 49 49 49", "output": "34" }, { "input": "80\n80 86 39 5 58 20 66 61 32 75 93 20 57 20 20 61 45 17 86 43 31 75 37 80 92 10 6 18 21 8 93 92 11 75 86 39 53 27 45 77 20 20 1 80 66 13 11 51 58 11 31 51 73 93 15 88 6 32 99 6 39 87 6 39 6 80 8 45 46 45 23 53 23 58 24 53 28 46 87 68", "output": "78" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7", "output": "3" }, { "input": "9\n1 2 2 2 1 2 2 2 1", "output": "3" }, { "input": "12\n1 1 1 49 63 63 63 19 38 38 65 27", "output": "7" }, { "input": "7\n31 31 21 21 13 96 96", "output": "4" }, { "input": "3\n1000000000 1 1000000000", "output": "3" } ]
1,679,282,757
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
from collections import deque def solve_problem(n, a): segments = [] count = 0 # 遍历序列,统计连续相同元素的个数 for i in range(n): if i == 0 or a[i] != a[i - 1]: segments.append((a[i], 1)) else: segments[-1] = (a[i], segments[-1][1] + 1) # 将segments按长度、索引排序,使用双端队列保存 segments = deque(sorted(enumerate(segments), key=lambda x: (-x[1][1], x[0]))) # 循环直到segments为空 while segments: _, (val, length) = segments.popleft() # 删除最长子段 count += 1 # 计数加1 # 删除相邻相同子段 if segments and segments[0][1][0] == val: _, (val, length) = segments.popleft() length += 1 idx = 0 # 按长度重新插入更新后的子段 while idx < len(segments) and (length < segments[idx][1][1] or (length == segments[idx][1][1] and _ < segments[idx][0])): idx += 1 segments.insert(idx, (_, (val, length))) return count # 从输入中读取数据 n = int(input().strip()) a = list(map(int, input().strip().split())) # 输出结果 print(solve_problem(n, a))
Title: Segments Removal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has an array of integers of length *n*. Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after one operation it becomes [13,<=13,<=2,<=2,<=2]. Compute the number of operations Vasya should make until the array becomes empty, i.e. Vasya removes all elements from it. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Vasya's array. Output Specification: Print the number of operations Vasya should make to remove all elements from the array. Demo Input: ['4\n2 5 5 2\n', '5\n6 3 4 1 5\n', '8\n4 4 4 2 2 100 100 100\n', '6\n10 10 50 10 50 50\n'] Demo Output: ['2\n', '5\n', '3\n', '4\n'] Note: In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty. In the second example Vasya has to perform five operations to make the array empty. In each of them he removes the first element from the array. In the third example Vasya needs three operations. In the first operation he removes all integers 4, in the second — all integers 100, in the third — all integers 2. In the fourth example in the first operation Vasya removes the first two integers 10. After that the array becomes [50, 10, 50, 50]. Then in the second operation Vasya removes the two rightmost integers 50, so that the array becomes [50, 10]. In the third operation he removes the remaining 50, and the array becomes [10] after that. In the last, fourth operation he removes the only remaining 10. The array is empty after that.
```python from collections import deque def solve_problem(n, a): segments = [] count = 0 # 遍历序列,统计连续相同元素的个数 for i in range(n): if i == 0 or a[i] != a[i - 1]: segments.append((a[i], 1)) else: segments[-1] = (a[i], segments[-1][1] + 1) # 将segments按长度、索引排序,使用双端队列保存 segments = deque(sorted(enumerate(segments), key=lambda x: (-x[1][1], x[0]))) # 循环直到segments为空 while segments: _, (val, length) = segments.popleft() # 删除最长子段 count += 1 # 计数加1 # 删除相邻相同子段 if segments and segments[0][1][0] == val: _, (val, length) = segments.popleft() length += 1 idx = 0 # 按长度重新插入更新后的子段 while idx < len(segments) and (length < segments[idx][1][1] or (length == segments[idx][1][1] and _ < segments[idx][0])): idx += 1 segments.insert(idx, (_, (val, length))) return count # 从输入中读取数据 n = int(input().strip()) a = list(map(int, input().strip().split())) # 输出结果 print(solve_problem(n, a)) ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,696,968,171
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
a,b,c= map(int, input().split()) return max(a,b,c)-min(a,b,c)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python a,b,c= map(int, input().split()) return max(a,b,c)-min(a,b,c) ```
-1
946
B
Weird Subtraction Process
PROGRAMMING
1,100
[ "math", "number theory" ]
null
null
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends.
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Print two integers — the values of *a* and *b* after the end of the process.
[ "12 5\n", "31 12\n" ]
[ "0 1\n", "7 12\n" ]
Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
0
[ { "input": "12 5", "output": "0 1" }, { "input": "31 12", "output": "7 12" }, { "input": "1000000000000000000 7", "output": "8 7" }, { "input": "31960284556200 8515664064180", "output": "14928956427840 8515664064180" }, { "input": "1000000000000000000 1000000000000000000", "output": "1000000000000000000 1000000000000000000" }, { "input": "1 1000", "output": "1 0" }, { "input": "1 1000000", "output": "1 0" }, { "input": "1 1000000000000000", "output": "1 0" }, { "input": "1 99999999999999999", "output": "1 1" }, { "input": "1 4", "output": "1 0" }, { "input": "1000000000000001 500000000000000", "output": "1 0" }, { "input": "1 1000000000000000000", "output": "1 0" }, { "input": "2 4", "output": "2 0" }, { "input": "2 1", "output": "0 1" }, { "input": "6 19", "output": "6 7" }, { "input": "22 5", "output": "0 1" }, { "input": "10000000000000000 100000000000000001", "output": "0 1" }, { "input": "1 1000000000000", "output": "1 0" }, { "input": "2 1000000000000000", "output": "2 0" }, { "input": "2 10", "output": "2 2" }, { "input": "51 100", "output": "51 100" }, { "input": "3 1000000000000000000", "output": "3 4" }, { "input": "1000000000000000000 3", "output": "4 3" }, { "input": "1 10000000000000000", "output": "1 0" }, { "input": "8796203 7556", "output": "1019 1442" }, { "input": "5 22", "output": "1 0" }, { "input": "1000000000000000000 1", "output": "0 1" }, { "input": "1 100000000000", "output": "1 0" }, { "input": "2 1000000000000", "output": "2 0" }, { "input": "5 4567865432345678", "output": "5 8" }, { "input": "576460752303423487 288230376151711743", "output": "1 1" }, { "input": "499999999999999999 1000000000000000000", "output": "3 2" }, { "input": "1 9999999999999", "output": "1 1" }, { "input": "103 1000000000000000000", "output": "103 196" }, { "input": "7 1", "output": "1 1" }, { "input": "100000000000000001 10000000000000000", "output": "1 0" }, { "input": "5 10", "output": "5 0" }, { "input": "7 11", "output": "7 11" }, { "input": "1 123456789123456", "output": "1 0" }, { "input": "5000000000000 100000000000001", "output": "0 1" }, { "input": "1000000000000000 1", "output": "0 1" }, { "input": "1000000000000000000 499999999999999999", "output": "2 3" }, { "input": "10 5", "output": "0 5" }, { "input": "9 18917827189272", "output": "9 0" }, { "input": "179 100000000000497000", "output": "179 270" }, { "input": "5 100000000000001", "output": "1 1" }, { "input": "5 20", "output": "5 0" }, { "input": "100000001 50000000", "output": "1 0" }, { "input": "345869461223138161 835002744095575440", "output": "1 0" }, { "input": "8589934592 4294967296", "output": "0 4294967296" }, { "input": "4 8", "output": "4 0" }, { "input": "1 100000000000000000", "output": "1 0" }, { "input": "1000000000000000000 333333333333333", "output": "1000 1333" }, { "input": "25 12", "output": "1 0" }, { "input": "24 54", "output": "0 6" }, { "input": "6 12", "output": "6 0" }, { "input": "129200000000305 547300000001292", "output": "1 0" }, { "input": "1000000000000000000 49999999999999999", "output": "20 39" }, { "input": "1 2", "output": "1 0" }, { "input": "1 123456789876", "output": "1 0" }, { "input": "2 3", "output": "2 3" }, { "input": "1 3", "output": "1 1" }, { "input": "1 1", "output": "1 1" }, { "input": "19 46", "output": "3 2" }, { "input": "3 6", "output": "3 0" }, { "input": "129 1000000000000000000", "output": "1 0" }, { "input": "12 29", "output": "0 1" }, { "input": "8589934592 2147483648", "output": "0 2147483648" }, { "input": "2147483648 8589934592", "output": "2147483648 0" }, { "input": "5 6", "output": "5 6" }, { "input": "1000000000000000000 2", "output": "0 2" }, { "input": "2 7", "output": "2 3" }, { "input": "17174219820754872 61797504734333370", "output": "17174219820754872 27449065092823626" }, { "input": "49 100", "output": "1 0" }, { "input": "7 17", "output": "1 1" }, { "input": "1000000000000000000 10000001", "output": "0 1" }, { "input": "49999999999999999 2", "output": "3 2" }, { "input": "49999999999999999 1", "output": "1 1" }, { "input": "576460752303423487 2", "output": "3 2" }, { "input": "19395 19395", "output": "19395 19395" }, { "input": "19394 19394", "output": "19394 19394" } ]
1,601,114,725
325
PyPy 3
OK
TESTS
81
155
0
import sys n, m = map(int, input().split()) while n and m: if n >= m*2: n %= m*2 elif n*2 <= m: m %= n*2 else: break print(n, m)
Title: Weird Subtraction Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables: 1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process. Initially the values of *a* and *b* are positive integers, and so the process will be finite. You have to determine the values of *a* and *b* after the process ends. Input Specification: The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. Output Specification: Print two integers — the values of *a* and *b* after the end of the process. Demo Input: ['12 5\n', '31 12\n'] Demo Output: ['0 1\n', '7 12\n'] Note: Explanations to the samples: 1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12.
```python import sys n, m = map(int, input().split()) while n and m: if n >= m*2: n %= m*2 elif n*2 <= m: m %= n*2 else: break print(n, m) ```
3
799
C
Fountains
PROGRAMMING
1,800
[ "binary search", "data structures", "implementation" ]
null
null
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed. Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
The first line contains three integers *n*, *c* and *d* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*c*,<=*d*<=≤<=100<=000) — the number of fountains, the number of coins and diamonds Arkady has. The next *n* lines describe fountains. Each of these lines contain two integers *b**i* and *p**i* (1<=≤<=*b**i*,<=*p**i*<=≤<=100<=000) — the beauty and the cost of the *i*-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain *i*: in coins or in diamonds, respectively.
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
[ "3 7 6\n10 8 C\n4 3 C\n5 6 D\n", "2 4 5\n2 5 C\n2 1 D\n", "3 10 10\n5 5 C\n5 5 C\n10 11 D\n" ]
[ "9\n", "0\n", "10\n" ]
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
1,500
[ { "input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9" }, { "input": "2 4 5\n2 5 C\n2 1 D", "output": "0" }, { "input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10" }, { "input": "6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D", "output": "18" }, { "input": "6 4 9\n6 6 D\n1 4 D\n6 7 C\n7 6 D\n5 7 D\n2 5 D", "output": "3" }, { "input": "52 38 22\n9 25 D\n28 29 C\n29 25 D\n4 28 D\n23 29 D\n24 25 D\n17 12 C\n11 19 C\n13 14 C\n12 15 D\n7 25 C\n2 25 C\n6 17 C\n2 20 C\n15 23 D\n8 21 C\n13 15 D\n29 15 C\n25 20 D\n22 20 C\n2 13 D\n13 22 D\n27 20 C\n1 21 D\n22 17 C\n14 21 D\n4 25 D\n5 23 C\n9 21 C\n2 20 C\n14 18 C\n29 24 C\n14 29 D\n9 27 C\n23 21 D\n18 26 D\n7 23 C\n13 25 C\n21 26 C\n30 24 C\n21 24 C\n28 22 C\n8 29 C\n3 12 C\n21 22 D\n22 26 C\n13 17 D\n12 12 D\n11 11 C\n18 24 D\n7 13 D\n3 11 C", "output": "57" }, { "input": "6 68 40\n6 16 D\n11 16 D\n1 18 D\n2 20 D\n7 23 D\n16 30 D", "output": "18" }, { "input": "2 1 1\n1 1 C\n1 1 D", "output": "2" }, { "input": "2 100000 100000\n100000 100000 C\n100000 100000 D", "output": "200000" }, { "input": "4 15 9\n5 10 C\n5 10 D\n6 10 D\n7 5 C", "output": "12" } ]
1,658,763,270
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def sol(): a,b,c= input(), input(), (input()) return -1; sol()
Title: Fountains Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed. Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time. Input Specification: The first line contains three integers *n*, *c* and *d* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*c*,<=*d*<=≤<=100<=000) — the number of fountains, the number of coins and diamonds Arkady has. The next *n* lines describe fountains. Each of these lines contain two integers *b**i* and *p**i* (1<=≤<=*b**i*,<=*p**i*<=≤<=100<=000) — the beauty and the cost of the *i*-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain *i*: in coins or in diamonds, respectively. Output Specification: Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0. Demo Input: ['3 7 6\n10 8 C\n4 3 C\n5 6 D\n', '2 4 5\n2 5 C\n2 1 D\n', '3 10 10\n5 5 C\n5 5 C\n10 11 D\n'] Demo Output: ['9\n', '0\n', '10\n'] Note: In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
```python def sol(): a,b,c= input(), input(), (input()) return -1; sol() ```
0
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,589,429,498
2,147,483,647
PyPy 3
OK
TESTS
35
202
24,985,600
for u in range(int(input())): x,y=map(int,input().split()) c=0 while(x>0 and y>0): if(x>=y): c=c+x//y x%=y else: c=c+y//x y=y%x print(c)
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python for u in range(int(input())): x,y=map(int,input().split()) c=0 while(x>0 and y>0): if(x>=y): c=c+x//y x%=y else: c=c+y//x y=y%x print(c) ```
3
864
A
Fair Game
PROGRAMMING
1,000
[ "implementation", "sortings" ]
null
null
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
[ "4\n11\n27\n27\n11\n", "2\n6\n6\n", "6\n10\n20\n30\n20\n10\n20\n", "6\n1\n1\n2\n2\n3\n3\n" ]
[ "YES\n11 27\n", "NO\n", "NO\n", "NO\n" ]
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
500
[ { "input": "4\n11\n27\n27\n11", "output": "YES\n11 27" }, { "input": "2\n6\n6", "output": "NO" }, { "input": "6\n10\n20\n30\n20\n10\n20", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n3\n3", "output": "NO" }, { "input": "2\n1\n100", "output": "YES\n1 100" }, { "input": "2\n1\n1", "output": "NO" }, { "input": "2\n100\n100", "output": "NO" }, { "input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43", "output": "NO" }, { "input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32", "output": "YES\n14 32" }, { "input": "2\n50\n100", "output": "YES\n50 100" }, { "input": "2\n99\n100", "output": "YES\n99 100" }, { "input": "4\n4\n4\n5\n5", "output": "YES\n4 5" }, { "input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23", "output": "YES\n10 23" }, { "input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11", "output": "YES\n11 34" }, { "input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30", "output": "YES\n20 30" }, { "input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "YES\n1 100" }, { "input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99", "output": "YES\n2 99" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "YES\n1 100" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2", "output": "YES\n1 2" }, { "input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 49" }, { "input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94", "output": "YES\n15 94" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42", "output": "YES\n33 42" }, { "input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35", "output": "YES\n16 35" }, { "input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44", "output": "YES\n33 44" }, { "input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98", "output": "YES\n54 98" }, { "input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "output": "YES\n12 81" }, { "input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "NO" }, { "input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30", "output": "NO" }, { "input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1", "output": "NO" }, { "input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2", "output": "NO" }, { "input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100", "output": "NO" }, { "input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100", "output": "NO" }, { "input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1", "output": "NO" }, { "input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100", "output": "NO" }, { "input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43", "output": "NO" }, { "input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88", "output": "NO" }, { "input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100", "output": "NO" }, { "input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45", "output": "NO" }, { "input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12", "output": "NO" }, { "input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2", "output": "NO" }, { "input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100", "output": "NO" }, { "input": "4\n1\n3\n3\n3", "output": "NO" }, { "input": "6\n1\n1\n1\n1\n2\n2", "output": "NO" }, { "input": "4\n1\n1\n1\n2", "output": "NO" }, { "input": "4\n1\n2\n2\n2", "output": "NO" }, { "input": "4\n1\n2\n3\n4", "output": "NO" }, { "input": "8\n1\n1\n2\n2\n3\n3\n4\n4", "output": "NO" }, { "input": "4\n1\n3\n2\n4", "output": "NO" }, { "input": "4\n10\n10\n10\n20", "output": "NO" }, { "input": "4\n11\n12\n13\n13", "output": "NO" }, { "input": "4\n1\n1\n1\n3", "output": "NO" }, { "input": "6\n1\n1\n2\n2\n2\n2", "output": "NO" }, { "input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4", "output": "NO" } ]
1,532,670,680
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
28
109
0
n = int(input()) k = [None] * n for i in range(n): k[i] = int(input()) s = list(set(k)) if len(s) != 2: print('NO') elif k.count(s[0]) == k.count(s[1]): print('YES') print(s[0], s[1])
Title: Fair Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. Output Specification: If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. Demo Input: ['4\n11\n27\n27\n11\n', '2\n6\n6\n', '6\n10\n20\n30\n20\n10\n20\n', '6\n1\n1\n2\n2\n3\n3\n'] Demo Output: ['YES\n11 27\n', 'NO\n', 'NO\n', 'NO\n'] Note: In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
```python n = int(input()) k = [None] * n for i in range(n): k[i] = int(input()) s = list(set(k)) if len(s) != 2: print('NO') elif k.count(s[0]) == k.count(s[1]): print('YES') print(s[0], s[1]) ```
0
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,660,708,459
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n=int(input()) a=list(map(int,input().split())) h,f=0,0 if a==sorted(a): f=0 else: for i in range(len(a)-1,-1,-1): h+=1 x=len(a)-1 a=a[x:]+a[:x] if a==sorted(a): f=1 break if f: print(h) else: print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) h,f=0,0 if a==sorted(a): f=0 else: for i in range(len(a)-1,-1,-1): h+=1 x=len(a)-1 a=a[x:]+a[:x] if a==sorted(a): f=1 break if f: print(h) else: print(-1) ```
0
841
A
Generous Kefa
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons.
Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.
[ "4 2\naabb\n", "6 3\naacaab\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
500
[ { "input": "4 2\naabb", "output": "YES" }, { "input": "6 3\naacaab", "output": "NO" }, { "input": "2 2\nlu", "output": "YES" }, { "input": "5 3\novvoo", "output": "YES" }, { "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES" }, { "input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "output": "NO" }, { "input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "YES" }, { "input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod", "output": "NO" }, { "input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl", "output": "YES" }, { "input": "18 6\njzwtnkvmscqhmdlsxy", "output": "YES" }, { "input": "21 2\nfscegcqgzesefghhwcexs", "output": "NO" }, { "input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc", "output": "YES" }, { "input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd", "output": "YES" }, { "input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv", "output": "YES" }, { "input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul", "output": "YES" }, { "input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii", "output": "NO" }, { "input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq", "output": "YES" }, { "input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb", "output": "YES" }, { "input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc", "output": "YES" }, { "input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab", "output": "YES" }, { "input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia", "output": "NO" }, { "input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf", "output": "YES" }, { "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb", "output": "YES" }, { "input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa", "output": "NO" }, { "input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo", "output": "YES" }, { "input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib", "output": "YES" }, { "input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf", "output": "YES" }, { "input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci", "output": "YES" }, { "input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn", "output": "YES" }, { "input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev", "output": "YES" }, { "input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss", "output": "YES" }, { "input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs", "output": "NO" }, { "input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc", "output": "NO" }, { "input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi", "output": "NO" }, { "input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah", "output": "NO" }, { "input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka", "output": "YES" }, { "input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq", "output": "YES" }, { "input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb", "output": "YES" }, { "input": "14 5\nfssmmsfffmfmmm", "output": "NO" }, { "input": "2 1\nff", "output": "NO" }, { "input": "2 1\nhw", "output": "YES" }, { "input": "2 2\nss", "output": "YES" }, { "input": "1 1\nl", "output": "YES" }, { "input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp", "output": "YES" }, { "input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj", "output": "YES" }, { "input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj", "output": "YES" }, { "input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "output": "YES" }, { "input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq", "output": "YES" }, { "input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt", "output": "YES" }, { "input": "1 2\na", "output": "YES" }, { "input": "3 1\nabb", "output": "NO" }, { "input": "2 1\naa", "output": "NO" }, { "input": "2 1\nab", "output": "YES" }, { "input": "6 2\naaaaaa", "output": "NO" }, { "input": "8 4\naaaaaaaa", "output": "NO" }, { "input": "4 2\naaaa", "output": "NO" }, { "input": "4 3\naaaa", "output": "NO" }, { "input": "1 3\na", "output": "YES" }, { "input": "4 3\nzzzz", "output": "NO" }, { "input": "4 1\naaaa", "output": "NO" }, { "input": "3 4\nabc", "output": "YES" }, { "input": "2 5\nab", "output": "YES" }, { "input": "2 4\nab", "output": "YES" }, { "input": "1 10\na", "output": "YES" }, { "input": "5 2\nzzzzz", "output": "NO" }, { "input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "NO" }, { "input": "4 1\nabab", "output": "NO" }, { "input": "4 1\nabcb", "output": "NO" }, { "input": "4 2\nabbb", "output": "NO" }, { "input": "5 2\nabccc", "output": "NO" }, { "input": "2 3\nab", "output": "YES" }, { "input": "4 3\nbbbs", "output": "YES" }, { "input": "10 2\nazzzzzzzzz", "output": "NO" }, { "input": "1 2\nb", "output": "YES" }, { "input": "1 3\nb", "output": "YES" }, { "input": "4 5\nabcd", "output": "YES" }, { "input": "4 6\naabb", "output": "YES" }, { "input": "5 2\naaaab", "output": "NO" }, { "input": "3 5\naaa", "output": "YES" }, { "input": "5 3\nazzzz", "output": "NO" }, { "input": "4 100\naabb", "output": "YES" }, { "input": "3 10\naaa", "output": "YES" }, { "input": "3 4\naaa", "output": "YES" }, { "input": "12 5\naaaaabbbbbbb", "output": "NO" }, { "input": "5 2\naabbb", "output": "NO" }, { "input": "10 5\nzzzzzzzzzz", "output": "NO" }, { "input": "2 4\naa", "output": "YES" }, { "input": "1 5\na", "output": "YES" }, { "input": "10 5\naaaaaaaaaa", "output": "NO" }, { "input": "6 3\naaaaaa", "output": "NO" }, { "input": "7 1\nabcdeee", "output": "NO" }, { "input": "18 3\naaaaaabbbbbbcccccc", "output": "NO" }, { "input": "8 2\naabbccdd", "output": "YES" }, { "input": "4 2\nzzzz", "output": "NO" }, { "input": "4 2\nabaa", "output": "NO" }, { "input": "3 2\naaa", "output": "NO" }, { "input": "3 1\nzzz", "output": "NO" }, { "input": "5 4\nzzzzz", "output": "NO" }, { "input": "6 2\naabbbc", "output": "NO" }, { "input": "3 6\naaa", "output": "YES" }, { "input": "2 1\nzz", "output": "NO" }, { "input": "10 3\naaaeeeeeee", "output": "NO" }, { "input": "4 5\naabb", "output": "YES" }, { "input": "3 1\naaa", "output": "NO" }, { "input": "5 2\naazzz", "output": "NO" }, { "input": "6 2\nabbbbc", "output": "NO" }, { "input": "4 2\nxxxx", "output": "NO" }, { "input": "6 3\nzzzzzz", "output": "NO" }, { "input": "3 2\nabb", "output": "YES" }, { "input": "3 2\nzzz", "output": "NO" }, { "input": "6 5\nzzzzzz", "output": "NO" }, { "input": "6 3\nbcaaaa", "output": "NO" }, { "input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "YES" }, { "input": "3 6\nabc", "output": "YES" } ]
1,590,115,568
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
x=list(map(int,input().split())) y=input() f=1 l=list(set([i for i in y])) l=[y.count(i) for i in l] for i in l: if i-x[1]<0: f=0 break if f==0: print('NO') else: print('YES')
Title: Generous Kefa Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends. Next line contains string *s* — colors of baloons. Output Specification: Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary. Demo Input: ['4 2\naabb\n', '6 3\naacaab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second. In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
```python x=list(map(int,input().split())) y=input() f=1 l=list(set([i for i in y])) l=[y.count(i) for i in l] for i in l: if i-x[1]<0: f=0 break if f==0: print('NO') else: print('YES') ```
0
159
D
Palindrome pairs
PROGRAMMING
1,500
[ "*special", "brute force", "dp", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=&lt;<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*... *b*], *s*[*x*... *y*] are palindromes. A palindrome is a string that can be read the same way from left to right and from right to left. For example, "abacaba", "z", "abba" are palindromes. A substring *s*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* = *s*1*s*2... *s*|*s*| is a string *s**i**s**i*<=+<=1... *s**j*. For example, substring *s*[2...4] of string *s* = "abacaba" equals "bac".
The first line of input contains a non-empty string *s* which consists of lowercase letters ('a'...'z'), *s* contains at most 2000 characters.
Output a single number — the quantity of pairs of non-overlapping palindromic substrings of *s*. Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier.
[ "aa\n", "aaa\n", "abacaba\n" ]
[ "1\n", "5\n", "36\n" ]
none
2,000
[ { "input": "aa", "output": "1" }, { "input": "aaa", "output": "5" }, { "input": "abacaba", "output": "36" }, { "input": "aaaaaaaaaa", "output": "495" }, { "input": "aabbb", "output": "24" }, { "input": "abbaa", "output": "18" }, { "input": "bbbbb", "output": "35" }, { "input": "bbaab", "output": "18" }, { "input": "aabba", "output": "18" }, { "input": "aaaaa", "output": "35" }, { "input": "abicabacka", "output": "57" }, { "input": "aiajadabaa", "output": "87" }, { "input": "abacabauabagabaeabacabadabacabbfabacamadabacabaeabacabadabacababcdggdefxeceadaffhecbgpdbeffecdcbfagcbbfgegaggcaffdfiafaeaab", "output": "20470" }, { "input": "abacabadabacabaeabacabadabacabafabacabadabqcabaeoqacabagabacabagefdfdedbbacefhhargbaebbbefabdabdcceddbgcebgdccdccccdbgdecfa", "output": "23427" }, { "input": "abacabafabacabaeabacabadabaqaeatabacabadabacabgeabacabadabacabaeadfgbefcbgbagebgobabaaececaccfeeaeeavbcccwbgecffgfadgagcgfb", "output": "21454" }, { "input": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabadadihfcihdeeegcgdfihcagaigeabegaheddgadbcagheieicdadafaadafeaeihbafccifeifafdhicebgeccbgbdhdcabeghhbebehbbfgfeddfgbdhcbhcfifcgccfihdedafefdhcchbcahgiicgdhahcihdgghchfahahffggedigifhdcbecbhddacdgiahbiffbadhiggagaefihchggfhffhfdcdbfeaabhfhgbbiacag", "output": "757870" }, { "input": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabqdabacabaeabacabadabacabaaciifgeeabgfgfhiadhbfhddihcfeaebfbiiebbcebafegfiefgbagffgchdieicffebaadddcefiibibbhbagfgifieedgeiabhfhbgghiaiegccehgdhaeaafddadgeghidabaeicdhbfghfcciihdgiefaggachefchbddaddafbhhdfhcaebhffbfefabbbbafcdihbcgbfaffieghiiiebhegbcfceidggibdggabaifgedg", "output": "687296" }, { "input": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabpcabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaeeegbahbcahagefafcedggigbhdaeebfbagfafhdfcdddeaihgdigiaehdabicigbccdacdcbbcfeccdgiibicaifgieigcfbiedebfeddadagibhbdbfeibgbiadgcacfhfbfegbdbheidegcghfhbhcaffbcfhihcbghecfidbdfadgacigfdabhiebibfhfcachcbdcabeedfcffehhidbbihcgahfhdfhbhaciegccagebifh", "output": "630475" }, { "input": "abacabndabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabadabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabayhaghdcfefibhcbccbbfiedcdieghaihagcchhecgdfbdcchhbagebfbiecaibedhhaeidbcgageadeichbhghficaafdbafdbgadgcficdhdgcagiafbahaeffheabfbbgccbfdbfabahiaeabbfggefbafbheeehaebiehibbffehifghadcegdhdagbebeagbedcciibadfcifcedcghacheaihfdfgebcciidbcffgaebgabg", "output": "619985" }, { "input": "abacababcc", "output": "98" }, { "input": "abauabaabd", "output": "94" }, { "input": "abbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbbaaabaabaa", "output": "79323" }, { "input": "bababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbabbbbbaabababbbbbbbaabaabaaabbabbbabbbbabbabaababbbabbb", "output": "385228" }, { "input": "abbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabaabaabbabaaaabbabaaabbaababaababbabaaabbbbabbbaaaabababbbaaabaababb", "output": "1054380" }, { "input": "bababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbbbbbbaaabbaabbbabaabab", "output": "2840036" }, { "input": "bababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababaabbbbbabbabbbaaabbaaababaaaabbbbbbbaaabbbaabaabbaababababbaabbabbabaabbbabbaabababaababbababaaaabababbbaaaaaabbbbbabbbba", "output": "3678765" } ]
1,460,547,279
2,147,483,647
Python 3
OK
TESTS
50
2,212
307,200
def main(): s = tuple(input()) n = len(s) a, b = [1] * n, [1] * n for i in range(n): for x, y in zip(range(i, -1, -1), range(i + 2, n)): if s[x] != s[y]: break a[y] += 1 b[x] += 1 for x, y in zip(range(i, -1, -1), range(i + 1, n)): if s[x] != s[y]: break a[y] += 1 b[x] += 1 x = 0 for i, y in enumerate(a): x += y a[i] = x print(sum(x * y for x, y in zip(a, b[1:]))) if __name__ == '__main__': main()
Title: Palindrome pairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=&lt;<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*... *b*], *s*[*x*... *y*] are palindromes. A palindrome is a string that can be read the same way from left to right and from right to left. For example, "abacaba", "z", "abba" are palindromes. A substring *s*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|) of string *s* = *s*1*s*2... *s*|*s*| is a string *s**i**s**i*<=+<=1... *s**j*. For example, substring *s*[2...4] of string *s* = "abacaba" equals "bac". Input Specification: The first line of input contains a non-empty string *s* which consists of lowercase letters ('a'...'z'), *s* contains at most 2000 characters. Output Specification: Output a single number — the quantity of pairs of non-overlapping palindromic substrings of *s*. Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier. Demo Input: ['aa\n', 'aaa\n', 'abacaba\n'] Demo Output: ['1\n', '5\n', '36\n'] Note: none
```python def main(): s = tuple(input()) n = len(s) a, b = [1] * n, [1] * n for i in range(n): for x, y in zip(range(i, -1, -1), range(i + 2, n)): if s[x] != s[y]: break a[y] += 1 b[x] += 1 for x, y in zip(range(i, -1, -1), range(i + 1, n)): if s[x] != s[y]: break a[y] += 1 b[x] += 1 x = 0 for i, y in enumerate(a): x += y a[i] = x print(sum(x * y for x, y in zip(a, b[1:]))) if __name__ == '__main__': main() ```
3
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808", "output": "7" }, { "input": "1\n487 550", "output": "0" }, { "input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676", "output": "0" }, { "input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136", "output": "8" }, { "input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188", "output": "9" }, { "input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191", "output": "5" }, { "input": "4\n1 0\n2 0\n1 1\n1 -1", "output": "0" } ]
1,622,147,771
2,147,483,647
Python 3
OK
TESTS
26
154
0
cases = int(input()) coors = [] for _ in range(cases): a, b = map(int, input().split()) coors.append([a, b]) ans = 0 for x, y in coors: right = left = upper = lower = False for xx, yy in coors: if x == xx and y > yy: lower = True elif x == xx and y < yy: upper = True elif x < xx and y == yy: right = True elif x > xx and y == yy: left = True if right == left == upper == lower == True: ans += 1 break print(ans)
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input Specification: The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Specification: Print the only number — the number of supercentral points of the given set. Demo Input: ['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
```python cases = int(input()) coors = [] for _ in range(cases): a, b = map(int, input().split()) coors.append([a, b]) ans = 0 for x, y in coors: right = left = upper = lower = False for xx, yy in coors: if x == xx and y > yy: lower = True elif x == xx and y < yy: upper = True elif x < xx and y == yy: right = True elif x > xx and y == yy: left = True if right == left == upper == lower == True: ans += 1 break print(ans) ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,696,516,567
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
s1='++x' s2='x++' y=0 for x in range(int(input())): s=input().strip() if s==s1 or s==s2:y+=1 else:y-=1 print(y)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python s1='++x' s2='x++' y=0 for x in range(int(input())): s=input().strip() if s==s1 or s==s2:y+=1 else:y-=1 print(y) ```
0
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,553,280,659
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
108
0
temp = input() n = 0 i = 0 e = 0 t = 0 for k in list(temp): if (k == "n"): n = n + 1 if (k == "i"): i = i + 1 if (k == "e"): e = e + 1 if (k == "t"): t = t + 1 res = [] if n < 3: res.append(int(0)) if n == 3: res.append(int(1)) if n > 3: res.append(int(n/2)) res.append(int(i/1)) res.append(int(e/3)) res.append(int(t/1)) print(min(res))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python temp = input() n = 0 i = 0 e = 0 t = 0 for k in list(temp): if (k == "n"): n = n + 1 if (k == "i"): i = i + 1 if (k == "e"): e = e + 1 if (k == "t"): t = t + 1 res = [] if n < 3: res.append(int(0)) if n == 3: res.append(int(1)) if n > 3: res.append(int(n/2)) res.append(int(i/1)) res.append(int(e/3)) res.append(int(t/1)) print(min(res)) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,669,717,887
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
t = int(input()) while t > 0: t=t-1 a=input() if len(a)<10: print (a) else: print( str(a[0]) + str(len(a)-2) + str(a[-1]))
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python t = int(input()) while t > 0: t=t-1 a=input() if len(a)<10: print (a) else: print( str(a[0]) + str(len(a)-2) + str(a[-1])) ```
0
652
D
Nested Segments
PROGRAMMING
1,800
[ "data structures", "sortings" ]
null
null
You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of segments on a line. Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — the coordinates of the left and the right ends of the *i*-th segment. It is guaranteed that there are no ends of some segments that coincide.
Print *n* lines. The *j*-th of them should contain the only integer *a**j* — the number of segments contained in the *j*-th segment.
[ "4\n1 8\n2 3\n4 7\n5 6\n", "3\n3 4\n1 5\n2 6\n" ]
[ "3\n0\n1\n0\n", "0\n1\n1\n" ]
none
0
[ { "input": "4\n1 8\n2 3\n4 7\n5 6", "output": "3\n0\n1\n0" }, { "input": "3\n3 4\n1 5\n2 6", "output": "0\n1\n1" }, { "input": "1\n-1000000000 1000000000", "output": "0" }, { "input": "2\n-1000000000 999999999\n-999999999 1000000000", "output": "0\n0" }, { "input": "2\n-1000000000 1000000000\n-999999999 999999999", "output": "1\n0" }, { "input": "3\n-999999997 999999997\n-999999998 999999998\n-999999999 999999999", "output": "0\n1\n2" }, { "input": "3\n-999999999 999999997\n-999999998 999999998\n-999999997 999999999", "output": "0\n0\n0" }, { "input": "7\n1 14\n2 7\n3 4\n5 6\n8 13\n9 10\n11 12", "output": "6\n2\n0\n0\n2\n0\n0" }, { "input": "8\n1 16\n2 7\n3 4\n5 6\n8 9\n10 15\n11 12\n13 14", "output": "7\n2\n0\n0\n0\n2\n0\n0" }, { "input": "8\n1 16\n2 7\n3 4\n5 8\n6 9\n10 15\n11 13\n12 14", "output": "7\n1\n0\n0\n0\n2\n0\n0" }, { "input": "10\n-3 -1\n-10 4\n0 6\n-4 -2\n1 3\n2 9\n5 10\n-7 -6\n-8 8\n-9 7", "output": "0\n4\n1\n0\n0\n0\n0\n0\n5\n5" }, { "input": "1\n-1 0", "output": "0" }, { "input": "10\n-513515548 596545048\n-864922524 -143639540\n-186185108 253442195\n-325311097 557247880\n-843432193 -793445411\n-589321824 602462994\n-980740122 -845522939\n-20465341 192085177\n363969852 718880403\n-797865714 644017524", "output": "3\n1\n1\n2\n0\n4\n0\n0\n0\n5" }, { "input": "10\n-128739791 -39063859\n-103449295 927503025\n95979137 136886112\n-204849739 909268860\n-172975545 140068443\n-795229308 -495885136\n204945615 853645963\n-333018842 605274895\n-580345079 953606768\n335800547 686581467", "output": "0\n3\n0\n5\n2\n0\n1\n3\n8\n0" }, { "input": "10\n-317257964 738085350\n-989968614 735410270\n-870119900 197330499\n335597813 781352203\n-109119439 116242045\n604692366 819316837\n269683555 704665430\n-510921778 563710518\n340538827 963493707\n-925778993 739625150", "output": "2\n4\n1\n0\n0\n0\n0\n1\n1\n5" }, { "input": "10\n-644829480 485279434\n-54170850 756394598\n-103264442 39454200\n-12413554 577524970\n-909155364 193038318\n362781551 722749393\n-766782831 137745252\n811928942 870183784\n-43075984 270955026\n-159109789 303861267", "output": "3\n3\n0\n0\n2\n0\n1\n0\n0\n2" }, { "input": "10\n68572123 724714249\n104192140 802439320\n-890197541 150898768\n-912647426 208916264\n-942374086 -391426562\n-865405682 -491142593\n-623954751 425004801\n368985304 960241411\n-492740831 54907671\n-553720998 567496293", "output": "0\n0\n2\n3\n1\n0\n1\n0\n0\n1" } ]
1,624,341,382
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
1,228,800
def year(): dct = {} t = int(input()) q=[] for i in range(t): a, b = map(int, input().strip().split()) q.append((a,b)) dct[a] = dct.get(a, 0) + 1 dct[b] = dct.get(b, 0) - 1 count = 0 curr = 0 y = 0 for l,r in q: currs=0 curre=0 count=0 for i in range(l+1,r): l=dct.get(i,0) if l==1: currs+=1 else: curre+=1 if min(currs,curre) > count: count = min(currs,curre) print(count) year()
Title: Nested Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of segments on a line. Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — the coordinates of the left and the right ends of the *i*-th segment. It is guaranteed that there are no ends of some segments that coincide. Output Specification: Print *n* lines. The *j*-th of them should contain the only integer *a**j* — the number of segments contained in the *j*-th segment. Demo Input: ['4\n1 8\n2 3\n4 7\n5 6\n', '3\n3 4\n1 5\n2 6\n'] Demo Output: ['3\n0\n1\n0\n', '0\n1\n1\n'] Note: none
```python def year(): dct = {} t = int(input()) q=[] for i in range(t): a, b = map(int, input().strip().split()) q.append((a,b)) dct[a] = dct.get(a, 0) + 1 dct[b] = dct.get(b, 0) - 1 count = 0 curr = 0 y = 0 for l,r in q: currs=0 curre=0 count=0 for i in range(l+1,r): l=dct.get(i,0) if l==1: currs+=1 else: curre+=1 if min(currs,curre) > count: count = min(currs,curre) print(count) year() ```
0
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth.
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16", "output": "5" }, { "input": "4 2 8\n1 9\n1 10\n1 4\n2 6", "output": "8" }, { "input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0", "output": "8" }, { "input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7", "output": "180" }, { "input": "1 1 1000000\n1 1000000", "output": "1000000" }, { "input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278", "output": "4136" }, { "input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0", "output": "0" }, { "input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12", "output": "54" } ]
1,666,230,779
2,147,483,647
Python 3
OK
TESTS
31
92
0
n,m,k = map(int,input().split()) diction = {} for i in range(n): nums = list(map(int,input().split())) if nums[0] not in diction.keys(): diction[nums[0]] = nums[1] elif nums[0] in diction.keys(): if nums[1] > diction[nums[0]]: pass else: diction[nums[0]] = nums[1] s = sum(diction.values()) if s >= k: print(k) else: print(s)
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output Specification: In the first line output the maximum amount of crucians that Valerie can consume for dinner. Demo Input: ['4 3 18\n2 3\n1 2\n3 6\n2 3\n', '2 2 13\n1 13\n2 12\n'] Demo Output: ['11\n', '13\n'] Note: none
```python n,m,k = map(int,input().split()) diction = {} for i in range(n): nums = list(map(int,input().split())) if nums[0] not in diction.keys(): diction[nums[0]] = nums[1] elif nums[0] in diction.keys(): if nums[1] > diction[nums[0]]: pass else: diction[nums[0]] = nums[1] s = sum(diction.values()) if s >= k: print(k) else: print(s) ```
3.977
46
C
Hamsters and Tigers
PROGRAMMING
1,600
[ "two pointers" ]
C. Hamsters and Tigers
2
256
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him.
The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one.
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
[ "3\nHTH\n", "9\nHTHTHTHHT\n" ]
[ "0\n", "2\n" ]
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
0
[ { "input": "3\nHTH", "output": "0" }, { "input": "9\nHTHTHTHHT", "output": "2" }, { "input": "2\nTH", "output": "0" }, { "input": "4\nHTTH", "output": "0" }, { "input": "4\nHTHT", "output": "1" }, { "input": "7\nTTTHTTT", "output": "0" }, { "input": "8\nHHTHHTHH", "output": "1" }, { "input": "13\nHTTTHHHTTTTHH", "output": "3" }, { "input": "20\nTTHTHTHHTHTTHHTTTHHH", "output": "4" }, { "input": "35\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT", "output": "3" }, { "input": "120\nTTTTTTTHTHTHTTTTTHTHTTTTHTTTTTTTTTTTTTTTTTTTTHTTHTTTTHTTHTTTTTTTTTTTTTTTHTTTTTTHTHTTHTTTTTTHTTTTTTTTTHTTHTTTTHTTTHTTTTTH", "output": "14" }, { "input": "19\nHHHHHHHHHHHHHTTTHHH", "output": "0" }, { "input": "87\nHTHHTTHHHHTHHHHHTTTHHTHHHHTTTTHHHTTHHTHTHTHHTTHTHHTHTHTTHHHTTTTTHTTHHHHHHTHHTHHTHTTHTHH", "output": "17" }, { "input": "178\nTHHHTHTTTHTTHTTHHHHHTTTHTTHHTHTTTHTHTTTTTHHHTHTHHHTHHHTTTTTTTTHHHHTTHHTHHHHTHTTTHHHHHHTHHTHTTHTHTTTTTTTTTHHTTHHTHTTHHTHHHHHTTHHTTHHTTHHHTTHHTTTTHTHHHTHTTHTHTTTHHHHTHHTHHHTHTTTTTT", "output": "40" } ]
1,692,177,010
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n = int(input()) s = input() hamsters = s.count('H') max_hamsters = 0 window_hamsters = 0 for i in range(2 * n): window_hamsters += (s[i % n] == 'H') if i >= n: window_hamsters -= (s[(i - n) % n] == 'H') max_hamsters = max(max_hamsters, window_hamsters) min_swaps = max_hamsters - hamsters print(min_swaps)
Title: Hamsters and Tigers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input Specification: The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Specification: Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Demo Input: ['3\nHTH\n', '9\nHTHTHTHHT\n'] Demo Output: ['0\n', '2\n'] Note: In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
```python n = int(input()) s = input() hamsters = s.count('H') max_hamsters = 0 window_hamsters = 0 for i in range(2 * n): window_hamsters += (s[i % n] == 'H') if i >= n: window_hamsters -= (s[(i - n) % n] == 'H') max_hamsters = max(max_hamsters, window_hamsters) min_swaps = max_hamsters - hamsters print(min_swaps) ```
0
74
B
Train
PROGRAMMING
1,500
[ "dp", "games", "greedy" ]
B. Train
2
256
A stowaway and a controller play the following game. The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the *n*-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of *n* wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.
The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon *n* is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The *i*-th symbol contains information about the train's state at the *i*-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station.
If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.
[ "5 3 2\nto head\n0001001\n", "3 2 1\nto tail\n0001\n" ]
[ "Stowaway", "Controller 2" ]
none
1,000
[ { "input": "5 3 2\nto head\n0001001", "output": "Stowaway" }, { "input": "3 2 1\nto tail\n0001", "output": "Controller 2" }, { "input": "4 2 1\nto tail\n1000001", "output": "Controller 6" }, { "input": "2 1 2\nto head\n111111", "output": "Stowaway" }, { "input": "4 1 4\nto head\n010001", "output": "Stowaway" }, { "input": "10 2 1\nto tail\n000000001", "output": "Stowaway" }, { "input": "5 5 3\nto tail\n01010000000001", "output": "Controller 10" }, { "input": "4 3 1\nto tail\n1000001001101", "output": "Controller 6" }, { "input": "4 1 3\nto head\n011000011000001", "output": "Controller 14" }, { "input": "20 13 9\nto head\n1111111111111111111111111111111111111111", "output": "Stowaway" }, { "input": "2 1 2\nto head\n1101", "output": "Controller 3" }, { "input": "2 2 1\nto tail\n1101", "output": "Controller 3" }, { "input": "2 1 2\nto head\n01", "output": "Controller 1" }, { "input": "2 2 1\nto tail\n01", "output": "Controller 1" }, { "input": "5 4 2\nto tail\n1", "output": "Stowaway" }, { "input": "8 8 7\nto head\n0000000000001", "output": "Stowaway" }, { "input": "8 8 7\nto head\n0000000000000100101000110101011", "output": "Controller 13" }, { "input": "10 3 8\nto head\n01", "output": "Stowaway" }, { "input": "5 1 4\nto head\n1000000000001", "output": "Controller 7" }, { "input": "5 1 3\nto head\n1000000000001", "output": "Controller 6" }, { "input": "3 3 1\nto tail\n1001000001", "output": "Controller 6" }, { "input": "4 3 1\nto tail\n00011110000000010001", "output": "Controller 3" }, { "input": "5 3 4\nto tail\n0001000000101000010010010000100110011", "output": "Controller 9" }, { "input": "6 4 5\nto tail\n0010000101101011001000000100111101101001010011001", "output": "Stowaway" }, { "input": "7 1 7\nto head\n011001001000100000000000000100001100000001100000000010000010011", "output": "Controller 24" }, { "input": "8 5 6\nto tail\n01110101111111111111111111001111111011011111111111101111111111011111101", "output": "Stowaway" }, { "input": "9 7 2\nto head\n1000100010110000101010010000000000010010000010100000001001000000001000000101100000000001", "output": "Controller 33" }, { "input": "10 8 2\nto tail\n0000000000000001000000000000000000000000001000000000010000000000001000000000000000100000000000000001", "output": "Controller 8" }, { "input": "10 1 8\nto tail\n0000000000000000001000010000000001000001000000010000000000000000010010001000001000110010000001010011", "output": "Controller 11" }, { "input": "10 3 6\nto head\n0000001001010100000001010001000110001100011100000100100001100000001100000000000010000001000100100011", "output": "Controller 5" }, { "input": "13 9 8\nto tail\n000000000000000000000000000010011100000000000100100000000010000100000000000000000000000000000000000000010000011", "output": "Controller 5" }, { "input": "17 14 17\nto head\n0000001010000000000000100011000000100000001010000001011000000000001000100000000010100000010001000000000000000100000000000001", "output": "Stowaway" }, { "input": "20 15 7\nto head\n10011111001101010111101110101101101111011110111101001000101111011111011001110010001111111111111101111101011011111010011111111101111011111111", "output": "Stowaway" }, { "input": "26 10 11\nto head\n0000000001001000100000010000110000000011100001000010000000000010000000000000110100000001000000010000110011000000100000000010001100010000000100001110001", "output": "Stowaway" }, { "input": "31 7 15\nto tail\n0010000000000000100000010000010000100000000000000000000001000001100100000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000100001", "output": "Controller 106" }, { "input": "38 7 18\nto tail\n00000000000000000000000000000000000000000000000000000000000000000000000000000001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 57" }, { "input": "42 24 17\nto head\n00000000000000000000100010000000000000000000001000100000000000000000001000000000000010000100100000100000001000000010010000000000101000000000000000010000000000000000000000000011001", "output": "Stowaway" }, { "input": "45 21 37\nto tail\n00000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 96" }, { "input": "49 44 14\nto head\n0000000000000000000000000000000000100000100000000000000000000000010000000000001000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000111001", "output": "Controller 157" }, { "input": "50 4 12\nto tail\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001", "output": "Stowaway" }, { "input": "50 9 39\nto tail\n00000000000000001000000000000000000000000000000000000000000010000000100000000000000001000100000000000000010000000001000000000000000000000000010000000000000000000000000000000000001000000000000000000101", "output": "Stowaway" }, { "input": "50 43 15\nto tail\n00000000000001000000000000000000000000001000000000000000000000001010000000000000000000000010000001000000000000100000000000000000000000000000100000000100000000000001000000000011000000101000010000000001", "output": "Stowaway" }, { "input": "2 2 1\nto tail\n11111101111111011111111111111111111111111111110111111110111111111101111111111001111110111111101011101110110011111011111011101011111111101111111110111111011111111111111111110111111111111111101111101111", "output": "Controller 7" }, { "input": "2 2 1\nto tail\n10111111111111111110111011111111111111111111111111111110111111111110111111101111111111111111111111011111111111111011111111110111111101111111111101111111111111111101111111111111111111111111111001111111", "output": "Controller 2" }, { "input": "3 1 3\nto head\n11111111101111101111011011001011101100101101111111111011011111110011110101010111111101101010010111110110111111011111111111111111111110011111011011101110111111111111100111001110111110111011100111111111", "output": "Controller 28" }, { "input": "3 1 3\nto head\n10111111111111111011110110111111110111011111111111111111110101111111111111101111111111011110111110111111111111111111111111111110111111111111111110001011101111101110111111111111111111110101111111110011", "output": "Controller 148" }, { "input": "4 2 4\nto head\n01101111110010111111111111011110111101000011111110111100111010111110111011010111010110011101101010111100000011001011011101101111010111101001001011101111111111100011110110011010111010111011001011111001", "output": "Controller 42" }, { "input": "50 50 14\nto head\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "Stowaway" }, { "input": "50 42 13\nto head\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "Controller 61" }, { "input": "50 43 39\nto head\n01100111001110101111000001011111111100101101011010010001000001110001010011001010010100101100110011010011110110011111011101001111110001111001001100011110000111100100010001000011001001100000000010001111", "output": "Stowaway" }, { "input": "3 3 2\nto tail\n0001", "output": "Controller 1" }, { "input": "3 2 3\nto head\n0000000000000000001", "output": "Controller 2" } ]
1,617,997,766
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
184
0
n,m,k=list(map(int,input().split())) a={'to head':-1, 'to tail':1}[input()] b=input() l=len(b) for i in range(l-1): if b[i]=='0': if k+a==m: if 1<=m+a<=n: m+=a else: print('Controller',i+1) break else: if a==-1: m=n else: m=1 if not(1<=k+a<=n): a=-a k+=a else: print('Stowaway')
Title: Train Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A stowaway and a controller play the following game. The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the *n*-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of *n* wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. Input Specification: The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon *n* is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The *i*-th symbol contains information about the train's state at the *i*-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station. Output Specification: If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Demo Input: ['5 3 2\nto head\n0001001\n', '3 2 1\nto tail\n0001\n'] Demo Output: ['Stowaway', 'Controller 2'] Note: none
```python n,m,k=list(map(int,input().split())) a={'to head':-1, 'to tail':1}[input()] b=input() l=len(b) for i in range(l-1): if b[i]=='0': if k+a==m: if 1<=m+a<=n: m+=a else: print('Controller',i+1) break else: if a==-1: m=n else: m=1 if not(1<=k+a<=n): a=-a k+=a else: print('Stowaway') ```
0
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,687,862,525
2,147,483,647
Python 3
OK
TESTS
47
92
0
n = input() print(max(map(int, (n, n[:-1], n[:-2]+n[-1]))))
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python n = input() print(max(map(int, (n, n[:-1], n[:-2]+n[-1])))) ```
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n510000", "output": "490000" }, { "input": "3\n2 5 27", "output": "26" }, { "input": "2\n600000 800000", "output": "400000" }, { "input": "5\n2 5 6 27 29", "output": "28" }, { "input": "1\n500001", "output": "499999" }, { "input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "output": "98054" }, { "input": "1\n900000", "output": "100000" }, { "input": "1\n500000", "output": "499999" }, { "input": "1\n999998", "output": "2" }, { "input": "3\n999997 999998 999999", "output": "3" }, { "input": "2\n999997 999999", "output": "3" }, { "input": "2\n2 999998", "output": "2" }, { "input": "2\n500000 500001", "output": "499999" }, { "input": "1\n500002", "output": "499998" }, { "input": "1\n700000", "output": "300000" }, { "input": "2\n2 999999", "output": "1" }, { "input": "2\n999998 999999", "output": "2" }, { "input": "1\n999995", "output": "5" }, { "input": "2\n499999 500001", "output": "499999" }, { "input": "1\n499999", "output": "499998" }, { "input": "2\n100 999900", "output": "100" }, { "input": "2\n499999 500000", "output": "499999" }, { "input": "2\n500001 999999", "output": "499999" }, { "input": "3\n500000 500001 500002", "output": "499999" }, { "input": "2\n2 500001", "output": "499999" }, { "input": "2\n499999 999999", "output": "499998" }, { "input": "2\n2 500000", "output": "499999" }, { "input": "4\n2 3 4 999999", "output": "3" }, { "input": "2\n100000 500001", "output": "499999" }, { "input": "1\n2", "output": "1" }, { "input": "1\n800000", "output": "200000" }, { "input": "1\n505050", "output": "494950" }, { "input": "1\n753572", "output": "246428" }, { "input": "2\n576696 760487", "output": "423304" }, { "input": "10\n3 4 5 6 7 8 9 10 11 12", "output": "11" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "4\n999996 999997 999998 999999", "output": "4" } ]
1,520,341,606
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
5,632,000
n=int(input()) a=input().split() d=0 for i in range(len(a)): a[i]=int(a[i]) if a[i]<50001: if a[i]-1 > d: d=a[i]-1 else: if 50001-a[i] > d: d=50001-a[i] print(d)
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. Output Specification: Print one integer — the minimum number of seconds it will take to collect all prizes. Demo Input: ['3\n2 3 9\n', '2\n2 999995\n'] Demo Output: ['8\n', '5\n'] Note: In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
```python n=int(input()) a=input().split() d=0 for i in range(len(a)): a[i]=int(a[i]) if a[i]<50001: if a[i]-1 > d: d=a[i]-1 else: if 50001-a[i] > d: d=50001-a[i] print(d) ```
0
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
1,593,015,703
2,147,483,647
Python 3
OK
TESTS
43
124
6,963,200
n=int(input()) t=0 s1=input() s2=input() for i in range(n): if abs(int(s1[i])-int(s2[i]))<(10-abs(int(s1[i])-int(s2[i]))): t+=abs(int(s1[i])-int(s2[i])) else: t+=(10-abs(int(s1[i])-int(s2[i]))) print(t)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Output Specification: Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Demo Input: ['5\n82195\n64723\n'] Demo Output: ['13\n'] Note: In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n=int(input()) t=0 s1=input() s2=input() for i in range(n): if abs(int(s1[i])-int(s2[i]))<(10-abs(int(s1[i])-int(s2[i]))): t+=abs(int(s1[i])-int(s2[i])) else: t+=(10-abs(int(s1[i])-int(s2[i]))) print(t) ```
3
168
A
Wizards and Demonstration
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*).
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
[ "10 1 14\n", "20 10 50\n", "1000 352 146\n" ]
[ "1\n", "0\n", "1108\n" ]
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
500
[ { "input": "10 1 14", "output": "1" }, { "input": "20 10 50", "output": "0" }, { "input": "1000 352 146", "output": "1108" }, { "input": "68 65 20", "output": "0" }, { "input": "78 28 27", "output": "0" }, { "input": "78 73 58", "output": "0" }, { "input": "70 38 66", "output": "9" }, { "input": "54 4 38", "output": "17" }, { "input": "3 1 69", "output": "2" }, { "input": "11 9 60", "output": "0" }, { "input": "71 49 65", "output": "0" }, { "input": "78 55 96", "output": "20" }, { "input": "2765 768 9020", "output": "248635" }, { "input": "3478 1728 9727", "output": "336578" }, { "input": "9678 6173 5658", "output": "541409" }, { "input": "1138 570 6666", "output": "75290" }, { "input": "7754 204 9038", "output": "700603" }, { "input": "8403 7401 4769", "output": "393339" }, { "input": "4909 2111 8860", "output": "432827" }, { "input": "6571 6449 8965", "output": "582642" }, { "input": "9178 2255 7996", "output": "731618" }, { "input": "6151 6148 3746", "output": "224269" }, { "input": "8890 5449 8734", "output": "771004" }, { "input": "7879 2590 2818", "output": "219441" }, { "input": "8484 6400 547", "output": "40008" }, { "input": "7835 6710 1639", "output": "121706" }, { "input": "2379 1436 9663", "output": "228447" }, { "input": "6487 5670 8", "output": "0" }, { "input": "4470 2543 6", "output": "0" }, { "input": "7261 5328 10", "output": "0" }, { "input": "3871 3795 7", "output": "0" }, { "input": "9620 6557 6", "output": "0" }, { "input": "4890 1112 5", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 1 10000", "output": "99" }, { "input": "10000 1 1", "output": "99" }, { "input": "10000 1 10000", "output": "999999" }, { "input": "10000 10000 1", "output": "0" }, { "input": "10000 10000 10000", "output": "990000" }, { "input": "67 1 3", "output": "2" }, { "input": "7878 4534 9159", "output": "717013" }, { "input": "1 1 1", "output": "0" }, { "input": "3271 5 50", "output": "1631" } ]
1,644,946,610
2,147,483,647
Python 3
OK
TESTS
43
92
0
import math n, x, y = map(int, input().split()) print(max(math.ceil((n * y - (100 * x)) / 100), 0))
Title: Wizards and Demonstration Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. Input Specification: The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). Output Specification: Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Demo Input: ['10 1 14\n', '20 10 50\n', '1000 352 146\n'] Demo Output: ['1\n', '0\n', '1108\n'] Note: In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
```python import math n, x, y = map(int, input().split()) print(max(math.ceil((n * y - (100 * x)) / 100), 0)) ```
3
908
A
New Year and Counting Cards
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Print a single integer, the minimum number of cards you must turn over to verify your claim.
[ "ee\n", "z\n", "0ay1\n" ]
[ "2\n", "0\n", "2\n" ]
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
500
[ { "input": "ee", "output": "2" }, { "input": "z", "output": "0" }, { "input": "0ay1", "output": "2" }, { "input": "0abcdefghijklmnopqrstuvwxyz1234567896", "output": "10" }, { "input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "output": "18" }, { "input": "01234567890123456789012345678901234567890123456789", "output": "25" }, { "input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "output": "10" }, { "input": "cjw2dwmr10pku4yxohe0wglktd", "output": "4" }, { "input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "output": "13" }, { "input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1", "output": "13" }, { "input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs", "output": "8" }, { "input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc", "output": "14" }, { "input": "2222", "output": "0" }, { "input": "13579", "output": "5" }, { "input": "1", "output": "1" }, { "input": "0", "output": "0" }, { "input": "a", "output": "1" }, { "input": "y", "output": "0" }, { "input": "w", "output": "0" }, { "input": "oo", "output": "2" }, { "input": "oy", "output": "1" }, { "input": "yo", "output": "1" }, { "input": "yy", "output": "0" }, { "input": "a0", "output": "1" }, { "input": "a9", "output": "2" }, { "input": "y0", "output": "0" }, { "input": "y7", "output": "1" }, { "input": "0a", "output": "1" }, { "input": "3a", "output": "2" }, { "input": "06", "output": "0" }, { "input": "07", "output": "1" }, { "input": "70", "output": "1" }, { "input": "77", "output": "2" }, { "input": "13570", "output": "4" }, { "input": "0000000000011111", "output": "5" }, { "input": "1357", "output": "4" }, { "input": "uuuuuuuuuuuuuuuuuu", "output": "18" }, { "input": "gabieurat", "output": "5" } ]
1,671,502,154
2,147,483,647
Python 3
OK
TESTS
38
62
0
s = input() res = sum(c in {"a", "e", "i", "o", "u"} or (c.isdigit() and int(c) & 1 == 1) for c in s) print(res)
Title: New Year and Counting Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. Input Specification: The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. Output Specification: Print a single integer, the minimum number of cards you must turn over to verify your claim. Demo Input: ['ee\n', 'z\n', '0ay1\n'] Demo Output: ['2\n', '0\n', '2\n'] Note: In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side. In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them. In the third sample, we need to flip the second and fourth cards.
```python s = input() res = sum(c in {"a", "e", "i", "o", "u"} or (c.isdigit() and int(c) & 1 == 1) for c in s) print(res) ```
3
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1" }, { "input": "20\n5 3 7 2 1 6 4", "output": "6" }, { "input": "10\n5 1 1 1 1 1 5", "output": "6" }, { "input": "50\n10 1 10 1 10 1 10", "output": "1" }, { "input": "77\n11 11 11 11 11 11 10", "output": "1" }, { "input": "1\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n100 100 100 100 100 100 100", "output": "3" }, { "input": "999\n10 20 10 20 30 20 10", "output": "3" }, { "input": "433\n109 58 77 10 39 125 15", "output": "7" }, { "input": "1\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n1 0 1 0 1 0 1", "output": "1" }, { "input": "997\n1 1 0 0 1 0 1", "output": "1" }, { "input": "1000\n1 1 1 1 1 1 1", "output": "6" }, { "input": "1000\n1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "1000\n1 0 0 0 0 0 0", "output": "1" }, { "input": "1000\n0 0 0 0 0 0 1", "output": "7" }, { "input": "1000\n1 0 0 1 0 0 1", "output": "1" }, { "input": "509\n105 23 98 0 7 0 155", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "2\n1 1 0 0 0 0 0", "output": "2" }, { "input": "1\n0 0 0 0 0 1 0", "output": "6" }, { "input": "10\n0 0 0 0 0 0 1", "output": "7" }, { "input": "5\n0 0 0 0 0 6 0", "output": "6" }, { "input": "3\n0 1 0 0 0 0 0", "output": "2" }, { "input": "10\n0 0 0 0 0 0 10", "output": "7" }, { "input": "28\n1 2 3 4 5 6 7", "output": "7" }, { "input": "100\n5 5 5 5 5 5 5", "output": "6" }, { "input": "4\n1 0 0 0 0 0 1", "output": "7" }, { "input": "2\n0 0 0 0 0 0 1", "output": "7" }, { "input": "7\n0 0 0 0 0 0 7", "output": "7" }, { "input": "7\n2 1 1 1 1 1 0", "output": "6" }, { "input": "2\n0 0 1 1 0 0 0", "output": "4" }, { "input": "6\n1 1 1 1 1 1 0", "output": "6" }, { "input": "5\n1 1 1 0 0 1 1", "output": "7" }, { "input": "100\n10 20 30 10 10 10 10", "output": "7" }, { "input": "1\n0 0 0 1 0 0 0", "output": "4" }, { "input": "70\n10 10 10 10 10 10 10", "output": "7" }, { "input": "22\n1 2 3 4 5 6 10", "output": "7" }, { "input": "5\n0 0 0 1 0 0 0", "output": "4" }, { "input": "2\n0 0 0 1 0 0 0", "output": "4" }, { "input": "6\n1 0 0 0 0 0 2", "output": "7" }, { "input": "10\n1 2 2 1 2 1 1", "output": "7" }, { "input": "5\n0 0 0 0 0 0 10", "output": "7" }, { "input": "4\n0 1 1 0 0 0 0", "output": "3" }, { "input": "100\n0 0 0 0 0 1 0", "output": "6" } ]
1,627,707,432
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
154
6,963,200
n = int(input()) array = list(map(int, input().split())) hash_map = dict() for x in range(1, 8): hash_map[x] = array[x - 1] i = 1 key = 0 while n >= 0: n -= hash_map[i] if n <= 0: key = i break i += 1 if i == 7: i = 1 print(key)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. Input Specification: The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. Output Specification: Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Demo Input: ['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n'] Demo Output: ['6\n', '1\n'] Note: Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second sample: On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.
```python n = int(input()) array = list(map(int, input().split())) hash_map = dict() for x in range(1, 8): hash_map[x] = array[x - 1] i = 1 key = 0 while n >= 0: n -= hash_map[i] if n <= 0: key = i break i += 1 if i == 7: i = 1 print(key) ```
0