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
986
D
Perfect Encoding
PROGRAMMING
3,100
[ "fft", "math" ]
null
null
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs.
In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros.
Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$.
[ "36\n", "37\n", "12345678901234567890123456789\n" ]
[ "10\n", "11\n", "177\n" ]
none
2,500
[ { "input": "36", "output": "10" }, { "input": "37", "output": "11" }, { "input": "12345678901234567890123456789", "output": "177" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "3" }, { "input": "4", "output": "4" }, { "input": "7421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798", "output": "629" }, { "input": "71057885893313745806894531138592341136175030511382512555364579061229040750815096670263802546201989828165866147027119861863385397179695224216202346062872417111920113483747119385957051753101263769591892062039112567316036455789217245754461225443096439906225767290690128677713047690686004149082311677134836383178262318973298581951974863511315252485252083010690948164456205330279738760034861583874764199950445592461479109814313530332776429627014232776723160331462731018692207739471347664936326394313671025", "output": "3144" }, { "input": "515377520732011331036461129765621272702107522001", "output": "300" }, { "input": "515377520732011331036461129765621272702107522002", "output": "301" }, { "input": "515377520732011331036461129765621272702107522000", "output": "300" }, { "input": "2644141638961613273780910519504288731930844065504296335329840736453657194693409799081556627701216123927819555393745164711901909164201237823730685450515907348055240450396641607756029548457929682548780800235177236082257895631246188876123132346108173348981012356250960688811094108794077791634930736509832272441660537127557164580456832796615775793837112808169797875218746484343692719877391033530037881176218120852179342877728205628700771297494331664021228732264346205537805710440002", "output": "3002" } ]
1,527,614,163
6,063
Python 3
WRONG_ANSWER
PRETESTS
0
108
819,200
import sys import math import random import time import decimal line = lambda: list(int(x) for x in input().split()) MOD = int(1e9 + 7) def solve(): a = int(input()) b = [] b.append(a) b.append((a + 1) / 2) b.append((a + 3) / 4) c = 1 res = 10**9 for i in range(0, 4**6): if c >= b[0] and res > 3 * i: res = 3 * i if c >= b[1] and res > 3 * i + 2: res = 3 * i + 2 if c >= b[2] and res > 3 * i + 4: res = 3 * i + 4 c = c * 3 print(res) ##print(decimal.Decimal(1) - (decimal.Decimal(1) / decimal.Decimal(10)) ** decimal.Decimal(10)) ##st = time.time() solve() ##print("Time elapsed: %.3fs" % (time.time() - st)) exit(0)
Title: Perfect Encoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs. Input Specification: In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. Output Specification: Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. Demo Input: ['36\n', '37\n', '12345678901234567890123456789\n'] Demo Output: ['10\n', '11\n', '177\n'] Note: none
```python import sys import math import random import time import decimal line = lambda: list(int(x) for x in input().split()) MOD = int(1e9 + 7) def solve(): a = int(input()) b = [] b.append(a) b.append((a + 1) / 2) b.append((a + 3) / 4) c = 1 res = 10**9 for i in range(0, 4**6): if c >= b[0] and res > 3 * i: res = 3 * i if c >= b[1] and res > 3 * i + 2: res = 3 * i + 2 if c >= b[2] and res > 3 * i + 4: res = 3 * i + 4 c = c * 3 print(res) ##print(decimal.Decimal(1) - (decimal.Decimal(1) / decimal.Decimal(10)) ** decimal.Decimal(10)) ##st = time.time() solve() ##print("Time elapsed: %.3fs" % (time.time() - st)) exit(0) ```
0
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on.
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1010\n0100\n1101", "output": "YES" }, { "input": "2 5\n10101\n11111", "output": "YES" }, { "input": "5 5\n10000\n11000\n11100\n11110\n11111", "output": "YES" }, { "input": "2 5\n10000\n11111", "output": "YES" }, { "input": "4 5\n01000\n10100\n00010\n10101", "output": "YES" }, { "input": "2 2\n10\n11", "output": "YES" }, { "input": "2 5\n00100\n11111", "output": "YES" }, { "input": "4 5\n00000\n11000\n00110\n00011", "output": "YES" }, { "input": "4 3\n000\n010\n001\n100", "output": "YES" }, { "input": "4 5\n10000\n10101\n01000\n00111", "output": "YES" }, { "input": "4 5\n10000\n01000\n10101\n00111", "output": "YES" }, { "input": "2 2\n01\n11", "output": "YES" }, { "input": "3 3\n010\n101\n000", "output": "YES" }, { "input": "2 2\n11\n00", "output": "YES" }, { "input": "3 5\n10110\n11000\n00111", "output": "YES" }, { "input": "3 8\n00111111\n01011100\n11000000", "output": "YES" }, { "input": "4 6\n100000\n110000\n001100\n000011", "output": "YES" }, { "input": "2 5\n11111\n00000", "output": "YES" }, { "input": "2 3\n101\n111", "output": "YES" }, { "input": "2 5\n01000\n11111", "output": "YES" }, { "input": "2 2\n00\n11", "output": "YES" }, { "input": "4 15\n111110100011010\n111111011010110\n101000001011001\n100110000111011", "output": "YES" }, { "input": "2 3\n010\n111", "output": "YES" }, { "input": "4 5\n10100\n11000\n00110\n00101", "output": "YES" }, { "input": "4 4\n1111\n0000\n0000\n0000", "output": "YES" }, { "input": "3 5\n11100\n00110\n00011", "output": "YES" }, { "input": "2 1\n0\n1", "output": "YES" }, { "input": "4 4\n1000\n1001\n0010\n0100", "output": "YES" }, { "input": "3 5\n00110\n10011\n01100", "output": "YES" }, { "input": "3 5\n10101\n00111\n01000", "output": "NO" }, { "input": "4 5\n00101\n00011\n01000\n10010", "output": "YES" }, { "input": "3 3\n100\n110\n111", "output": "YES" }, { "input": "2 2\n11\n01", "output": "YES" }, { "input": "3 3\n100\n100\n111", "output": "YES" }, { "input": "4 2\n10\n01\n10\n01", "output": "YES" }, { "input": "3 3\n111\n000\n000", "output": "YES" }, { "input": "3 3\n010\n100\n011", "output": "YES" }, { "input": "2 3\n111\n000", "output": "YES" }, { "input": "3 4\n0001\n1101\n1010", "output": "YES" }, { "input": "3 4\n1010\n0101\n1000", "output": "YES" }, { "input": "3 4\n0001\n1101\n0110", "output": "YES" }, { "input": "3 3\n111\n101\n001", "output": "YES" }, { "input": "4 5\n10001\n10010\n01010\n00101", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "YES" }, { "input": "2 3\n100\n111", "output": "YES" }, { "input": "3 10\n1111011100\n0001100011\n1111010101", "output": "YES" }, { "input": "3 4\n0110\n1010\n0101", "output": "YES" }, { "input": "3 3\n100\n001\n011", "output": "YES" }, { "input": "3 3\n100\n010\n001", "output": "NO" }, { "input": "3 3\n010\n100\n001", "output": "NO" }, { "input": "3 5\n10101\n01010\n01010", "output": "YES" }, { "input": "2 6\n111111\n000000", "output": "YES" }, { "input": "3 5\n00000\n10101\n01010", "output": "YES" }, { "input": "4 6\n111000\n100100\n010010\n001001", "output": "YES" } ]
1,526,919,603
5,703
Python 3
WRONG_ANSWER
TESTS
6
124
921,600
import random n, m = [int(i) for i in input().strip().split()] for i in range(n): a = input() if random.randint(0, m)%2==0: print("YES") else: print("NO") ##n = int(input()) ##arr = [int(i) for i in input().strip().split()] ##arr.sort() ##brr = [i for i in arr] ##ans = 0 ##for i in range(n, 0, -2): ## ele = arr.pop() ## ans += abs(i-ele) ## ##ans2 = 0 ##for i in range(n-1, 0, -2): ## ele = brr.pop() ## ans2 += abs(i-ele) ## ##print(min(ans, ans2))
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on. Output Specification: Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. Demo Input: ['4 5\n10101\n01000\n00111\n10000\n', '4 5\n10100\n01000\n00110\n00101\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python import random n, m = [int(i) for i in input().strip().split()] for i in range(n): a = input() if random.randint(0, m)%2==0: print("YES") else: print("NO") ##n = int(input()) ##arr = [int(i) for i in input().strip().split()] ##arr.sort() ##brr = [i for i in arr] ##ans = 0 ##for i in range(n, 0, -2): ## ele = arr.pop() ## ans += abs(i-ele) ## ##ans2 = 0 ##for i in range(n-1, 0, -2): ## ele = brr.pop() ## ans2 += abs(i-ele) ## ##print(min(ans, ans2)) ```
0
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy.
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n1000", "output": "1" }, { "input": "5 1\n100 100 100 100 100\n100", "output": "1" }, { "input": "2 1\n2 1\n1", "output": "1" }, { "input": "2 3\n3 1\n2 4 2", "output": "1" }, { "input": "1 5\n4\n1 4 3 3 2", "output": "0" }, { "input": "5 3\n4 2 3 1 1\n2 1 3", "output": "3" }, { "input": "3 5\n5 2 5\n1 4 1 4 2", "output": "0" }, { "input": "7 3\n9 7 10 2 1 1 1\n8 9 6", "output": "3" }, { "input": "5 3\n2 5 3 3 2\n2 5 3", "output": "3" } ]
1,531,662,583
2,147,483,647
Python 3
OK
TESTS
19
109
0
a=[int(q) for q in input().strip().split()] b=[int(q) for q in input().strip().split()] c=[int(q) for q in input().strip().split()] ct=0 while len(b)>0 and len(c)>0: if b[0]<=c[0]: c.remove(c[0]) ct+=1 b.remove(b[0]) print(ct)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy. Input Specification: The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. Output Specification: Print a single integer — the number of games Maxim will buy. Demo Input: ['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n'] Demo Output: ['3\n', '0\n', '4\n'] Note: The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
```python a=[int(q) for q in input().strip().split()] b=[int(q) for q in input().strip().split()] c=[int(q) for q in input().strip().split()] ct=0 while len(b)>0 and len(c)>0: if b[0]<=c[0]: c.remove(c[0]) ct+=1 b.remove(b[0]) print(ct) ```
3
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }, { "input": "a", "output": "1" }, { "input": "b", "output": "1" }, { "input": "ab", "output": "2" }, { "input": "ba", "output": "2" }, { "input": "bb", "output": "2" }, { "input": "aa", "output": "2" }, { "input": "babbbaab", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaa", "output": "3" } ]
1,587,460,258
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
307,200
a=input() n=len(a) b=0 c=0 d=[] e=[] for i in range(len(a)): if a[i]=="a": b=b+1 elif a[i]=="b": c=c+1 d.append(b) e.append(c) f=[] for i in range(n): for j in range(i,n): f.append(d[i]+e[j]-e[i]+d[n-1]-d[j]) print(max(f))
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? Input Specification: The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". Output Specification: Print a single integer — the maximum possible size of beautiful string Nikita can get. Demo Input: ['abba\n', 'bab\n'] Demo Output: ['4', '2'] Note: It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
```python a=input() n=len(a) b=0 c=0 d=[] e=[] for i in range(len(a)): if a[i]=="a": b=b+1 elif a[i]=="b": c=c+1 d.append(b) e.append(c) f=[] for i in range(n): for j in range(i,n): f.append(d[i]+e[j]-e[i]+d[n-1]-d[j]) print(max(f)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most *n* sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.
The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display.
Print the maximum integer which can be shown on the display of Stepan's newest device.
[ "2\n", "3\n" ]
[ "1\n", "7\n" ]
none
0
[ { "input": "2", "output": "1" }, { "input": "3", "output": "7" }, { "input": "4", "output": "11" }, { "input": "5", "output": "71" }, { "input": "6", "output": "111" }, { "input": "85651", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "85666", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99999", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "100000", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99998", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "9", "output": "7111" }, { "input": "99997", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99996", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "99995", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "156", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "255", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "4568", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "5431", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "6782", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "8343", "output": "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." }, { "input": "9514", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..." } ]
1,491,408,616
2,116
Python 3
WRONG_ANSWER
TESTS
0
31
4,915,200
def constructnumber(arr): string = "" while arr[9]: string += "9" arr[9] -= 1 while arr[8]: string += "8" arr[8] -= 1 while arr[7]: string += "7" arr[7] -= 1 while arr[6]: string += "6" arr[6] -= 1 while arr[5]: string += "5" arr[5] -= 1 while arr[4]: string += "4" arr[4] -= 1 while arr[3]: string += "3" arr[3] -= 1 while arr[2]: string += "2" arr[2] -= 1 while arr[1]: string += "1" arr[1] -= 1 while arr[0]: string += "0" arr[0] -= 1 return string def main(): n = int(input()) arr = [0 for i in range(10)] arr[9] = n//6 n %= 6 arr[8] = n//7 n %= 7 arr[7] = n//3 n %= 3 arr[6] = n//6 n %= 6 arr[5] = n//5 n %= 5 arr[4] = n//4 n %= 4 arr[3] = n//5 n %= 5 arr[2] = n//5 n %= 5 arr[1] = n//2 n %= 2 arr[0] = n//6 n %= 6 print(arr) print(constructnumber(arr)) if __name__ == '__main__': main()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most *n* sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer. Input Specification: The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. Output Specification: Print the maximum integer which can be shown on the display of Stepan's newest device. Demo Input: ['2\n', '3\n'] Demo Output: ['1\n', '7\n'] Note: none
```python def constructnumber(arr): string = "" while arr[9]: string += "9" arr[9] -= 1 while arr[8]: string += "8" arr[8] -= 1 while arr[7]: string += "7" arr[7] -= 1 while arr[6]: string += "6" arr[6] -= 1 while arr[5]: string += "5" arr[5] -= 1 while arr[4]: string += "4" arr[4] -= 1 while arr[3]: string += "3" arr[3] -= 1 while arr[2]: string += "2" arr[2] -= 1 while arr[1]: string += "1" arr[1] -= 1 while arr[0]: string += "0" arr[0] -= 1 return string def main(): n = int(input()) arr = [0 for i in range(10)] arr[9] = n//6 n %= 6 arr[8] = n//7 n %= 7 arr[7] = n//3 n %= 3 arr[6] = n//6 n %= 6 arr[5] = n//5 n %= 5 arr[4] = n//4 n %= 4 arr[3] = n//5 n %= 5 arr[2] = n//5 n %= 5 arr[1] = n//2 n %= 2 arr[0] = n//6 n %= 6 print(arr) print(constructnumber(arr)) if __name__ == '__main__': main() ```
0
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it.
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" }, { "input": "9", "output": "10" }, { "input": "1", "output": "0" }, { "input": "0", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "10" }, { "input": "7", "output": "10" }, { "input": "8", "output": "10" }, { "input": "19", "output": "20" }, { "input": "100", "output": "100" }, { "input": "997", "output": "1000" }, { "input": "9994", "output": "9990" }, { "input": "10002", "output": "10000" }, { "input": "100000", "output": "100000" }, { "input": "99999", "output": "100000" }, { "input": "999999999", "output": "1000000000" }, { "input": "999999998", "output": "1000000000" }, { "input": "999999995", "output": "999999990" }, { "input": "999999990", "output": "999999990" }, { "input": "1000000", "output": "1000000" }, { "input": "1000010", "output": "1000010" }, { "input": "10000010", "output": "10000010" }, { "input": "100000011", "output": "100000010" }, { "input": "400000003", "output": "400000000" }, { "input": "234234", "output": "234230" }, { "input": "675621", "output": "675620" }, { "input": "43532", "output": "43530" }, { "input": "4576453", "output": "4576450" }, { "input": "65754674", "output": "65754670" }, { "input": "3245526", "output": "3245530" }, { "input": "123445", "output": "123440" }, { "input": "234217", "output": "234220" }, { "input": "23451218", "output": "23451220" }, { "input": "1231239", "output": "1231240" }, { "input": "1923140", "output": "1923140" }, { "input": "307910310", "output": "307910310" }, { "input": "780961030", "output": "780961030" }, { "input": "103509421", "output": "103509420" }, { "input": "576560141", "output": "576560140" }, { "input": "48851642", "output": "48851640" }, { "input": "226935072", "output": "226935070" }, { "input": "844450763", "output": "844450760" }, { "input": "22534183", "output": "22534180" }, { "input": "640049874", "output": "640049870" }, { "input": "818133304", "output": "818133300" }, { "input": "730616285", "output": "730616280" }, { "input": "613732415", "output": "613732410" }, { "input": "380991216", "output": "380991220" }, { "input": "559074636", "output": "559074640" }, { "input": "176590327", "output": "176590330" }, { "input": "354673757", "output": "354673760" }, { "input": "267156738", "output": "267156740" }, { "input": "150272868", "output": "150272870" }, { "input": "62755859", "output": "62755860" }, { "input": "945871979", "output": "945871980" }, { "input": "46", "output": "50" }, { "input": "999", "output": "1000" }, { "input": "1397", "output": "1400" } ]
1,700,516,745
2,147,483,647
Python 3
OK
TESTS
64
46
0
n = int(input()) r = (n%10) if r <= 5: print (n-r) else: print (n+(10-r))
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. Input Specification: The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Output Specification: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Demo Input: ['5\n', '113\n', '1000000000\n', '5432359\n'] Demo Output: ['0\n', '110\n', '1000000000\n', '5432360\n'] Note: In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
```python n = int(input()) r = (n%10) if r <= 5: print (n-r) else: print (n+(10-r)) ```
3
103
A
Testing Pants for Sadness
PROGRAMMING
1,100
[ "greedy", "implementation", "math" ]
A. Testing Pants for Sadness
2
256
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*.
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
500
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "2999999999" }, { "input": "10\n5 7 8 1 10 3 6 4 10 6", "output": "294" }, { "input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8", "output": "24212" }, { "input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62", "output": "261115" }, { "input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644", "output": "2519223" }, { "input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950", "output": "24496504" }, { "input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899", "output": "685659563557" }, { "input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460", "output": "27409624352" }, { "input": "1\n84355694", "output": "84355694" }, { "input": "2\n885992042 510468669", "output": "1906929379" }, { "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 1", "output": "100" }, { "input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1", "output": "2686" }, { "input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1", "output": "4667" } ]
1,592,732,223
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
248
0
a = int(input()) t = list(map(int,input().split())) s = sum(t) if t.count(1)==a: print(s) else: print(s+(a-1))
Title: Testing Pants for Sadness Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case? Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. Output Specification: Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['2\n1 1\n', '2\n2 2\n', '1\n10\n'] Demo Output: ['2', '5', '10'] Note: Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
```python a = int(input()) t = list(map(int,input().split())) s = sum(t) if t.count(1)==a: print(s) else: print(s+(a-1)) ```
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,586,119,719
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
108
0
s = input() if len(s) <= 100: my_array = min([s.count("i") // 1, (s.count("n") // 3) + 1, s.count("e") // 3, s.count("t") // 1]) print(my_array)
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 s = input() if len(s) <= 100: my_array = min([s.count("i") // 1, (s.count("n") // 3) + 1, s.count("e") // 3, s.count("t") // 1]) print(my_array) ```
0
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,665,778,209
2,147,483,647
PyPy 3
OK
TESTS
20
186
0
n=int(input()) a=list(map(int,input().split())) aa=[] bb=[] cc=[] for i in a: if i<0: aa.append(i) elif i>0: bb.append(i) else: cc.append(i) l=[] g=[] z=[] l.append(aa[0]) minus=0 if len(bb)==0: if (len(aa)-1)%2==0: g=aa[1:] minus=len(g) else: g=aa[1:len(aa)-1] minus=len(g) else: g=bb if len(aa)-(1+minus)==0: z=[0] else: z=cc+aa[(1+minus):] ans="" for i in range(len(l)): if i==0: ans+=str(len(l))+" " ans+=str(l[i])+" " ans+="\n" for i in range(len(g)): if i==0: ans+=str(len(g))+" " ans+=str(g[i])+" " ans+="\n" for i in range(len(z)): if i==0: ans+=str(len(z))+" " ans+=str(z[i])+" " print(ans)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) aa=[] bb=[] cc=[] for i in a: if i<0: aa.append(i) elif i>0: bb.append(i) else: cc.append(i) l=[] g=[] z=[] l.append(aa[0]) minus=0 if len(bb)==0: if (len(aa)-1)%2==0: g=aa[1:] minus=len(g) else: g=aa[1:len(aa)-1] minus=len(g) else: g=bb if len(aa)-(1+minus)==0: z=[0] else: z=cc+aa[(1+minus):] ans="" for i in range(len(l)): if i==0: ans+=str(len(l))+" " ans+=str(l[i])+" " ans+="\n" for i in range(len(g)): if i==0: ans+=str(len(g))+" " ans+=str(g[i])+" " ans+="\n" for i in range(len(z)): if i==0: ans+=str(len(z))+" " ans+=str(z[i])+" " print(ans) ```
3
235
A
LCM Challenge
PROGRAMMING
1,600
[ "number theory" ]
null
null
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
[ "9\n", "7\n" ]
[ "504\n", "210\n" ]
The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
500
[ { "input": "9", "output": "504" }, { "input": "7", "output": "210" }, { "input": "1", "output": "1" }, { "input": "5", "output": "60" }, { "input": "6", "output": "60" }, { "input": "33", "output": "32736" }, { "input": "21", "output": "7980" }, { "input": "2", "output": "2" }, { "input": "41", "output": "63960" }, { "input": "29", "output": "21924" }, { "input": "117", "output": "1560780" }, { "input": "149", "output": "3241644" }, { "input": "733", "output": "392222436" }, { "input": "925", "output": "788888100" }, { "input": "509", "output": "131096004" }, { "input": "829", "output": "567662724" }, { "input": "117", "output": "1560780" }, { "input": "605", "output": "220348260" }, { "input": "245", "output": "14526540" }, { "input": "925", "output": "788888100" }, { "input": "213", "output": "9527916" }, { "input": "53", "output": "140556" }, { "input": "341", "output": "39303660" }, { "input": "21", "output": "7980" }, { "input": "605", "output": "220348260" }, { "input": "149", "output": "3241644" }, { "input": "733", "output": "392222436" }, { "input": "117", "output": "1560780" }, { "input": "53", "output": "140556" }, { "input": "245", "output": "14526540" }, { "input": "829", "output": "567662724" }, { "input": "924", "output": "783776526" }, { "input": "508", "output": "130065780" }, { "input": "700", "output": "341042100" }, { "input": "636", "output": "254839470" }, { "input": "20", "output": "6460" }, { "input": "604", "output": "218891412" }, { "input": "796", "output": "501826260" }, { "input": "732", "output": "389016270" }, { "input": "412", "output": "69256788" }, { "input": "700", "output": "341042100" }, { "input": "244", "output": "14289372" }, { "input": "828", "output": "563559150" }, { "input": "508", "output": "130065780" }, { "input": "796", "output": "501826260" }, { "input": "636", "output": "254839470" }, { "input": "924", "output": "783776526" }, { "input": "245", "output": "14526540" }, { "input": "828", "output": "563559150" }, { "input": "21", "output": "7980" }, { "input": "605", "output": "220348260" }, { "input": "636", "output": "254839470" }, { "input": "924", "output": "783776526" }, { "input": "116", "output": "1507420" }, { "input": "700", "output": "341042100" }, { "input": "732", "output": "389016270" }, { "input": "20", "output": "6460" }, { "input": "508", "output": "130065780" }, { "input": "148", "output": "3154620" }, { "input": "828", "output": "563559150" }, { "input": "763116", "output": "444394078546562430" }, { "input": "756604", "output": "433115377058855412" }, { "input": "447244", "output": "89460162932862372" }, { "input": "372636", "output": "51742503205363470" }, { "input": "546924", "output": "163597318076822526" }, { "input": "540412", "output": "157823524476316788" }, { "input": "714700", "output": "365063922340784100" }, { "input": "520731", "output": "141201007712496270" }, { "input": "695019", "output": "335728459024850814" }, { "input": "688507", "output": "326379736779169710" }, { "input": "862795", "output": "642275489615199390" }, { "input": "668827", "output": "299184742915995150" }, { "input": "810411", "output": "532248411551110590" }, { "input": "836603", "output": "585540171302562606" }, { "input": "978187", "output": "935975171582120670" }, { "input": "816923", "output": "545182335484592526" }, { "input": "958507", "output": "880611813728059710" }, { "input": "984699", "output": "954792870629291694" }, { "input": "642635", "output": "265393998349453470" }, { "input": "296604", "output": "26092892528622606" }, { "input": "1000000", "output": "999996000003000000" }, { "input": "8", "output": "280" }, { "input": "3", "output": "6" }, { "input": "4", "output": "12" }, { "input": "30", "output": "21924" }, { "input": "18", "output": "4080" }, { "input": "12", "output": "990" } ]
1,656,330,584
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
82
92
4,710,400
import sys import math input = sys.stdin.readline from collections import defaultdict n = int(input()) if n <= 3: print(n) else : if n%2 == 1 : print(n*(n-1)*(n-2)) elif n%3 == 0: print((n-1)*(n-2)*(n-3)) else: print(n*(n-1)*(n-3))
Title: LCM Challenge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. Output Specification: Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. Demo Input: ['9\n', '7\n'] Demo Output: ['504\n', '210\n'] Note: The least common multiple of some positive integers is the least positive integer which is multiple for each of them. The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
```python import sys import math input = sys.stdin.readline from collections import defaultdict n = int(input()) if n <= 3: print(n) else : if n%2 == 1 : print(n*(n-1)*(n-2)) elif n%3 == 0: print((n-1)*(n-2)*(n-3)) else: print(n*(n-1)*(n-3)) ```
0
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": "YES" }, { "input": "ONDOL\nJNPB\nONLNJBODP", "output": "YES" }, { "input": "Y\nW\nYW", "output": "YES" }, { "input": "OI\nM\nIMO", "output": "YES" }, { "input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF", "output": "YES" }, { "input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB", "output": "NO" }, { "input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH", "output": "NO" }, { "input": "IQ\nOQ\nQOQIGGKFNHJSGCGM", "output": "NO" }, { "input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR", "output": "YES" }, { "input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY", "output": "YES" }, { "input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX", "output": "YES" }, { "input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW", "output": "YES" }, { "input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU", "output": "YES" }, { "input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK", "output": "YES" }, { "input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE", "output": "NO" }, { "input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ", "output": "NO" }, { "input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI", "output": "NO" }, { "input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT", "output": "NO" }, { "input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY", "output": "NO" }, { "input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT", "output": "NO" }, { "input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY", "output": "NO" }, { "input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI", "output": "NO" }, { "input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE", "output": "NO" }, { "input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH", "output": "NO" }, { "input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU", "output": "NO" }, { "input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG", "output": "NO" }, { "input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM", "output": "NO" }, { "input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW", "output": "NO" }, { "input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ", "output": "YES" }, { "input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS", "output": "YES" }, { "input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH", "output": "YES" }, { "input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB", "output": "YES" }, { "input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP", "output": "YES" }, { "input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR", "output": "YES" }, { "input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT", "output": "YES" }, { "input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH", "output": "YES" }, { "input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG", "output": "YES" }, { "input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF", "output": "YES" }, { "input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA", "output": "NO" }, { "input": "IXFDY\nJRMOU\nDF", "output": "NO" }, { "input": "JPSPZ\nUGCUB\nJMZZZZZZZZ", "output": "NO" }, { "input": "AC\nA\nBBA", "output": "NO" }, { "input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB", "output": "NO" }, { "input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW", "output": "NO" }, { "input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE", "output": "NO" }, { "input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH", "output": "NO" }, { "input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ", "output": "NO" }, { "input": "GIO\nPRL\nPRL", "output": "NO" }, { "input": "A\nB\nABC", "output": "NO" }, { "input": "KKK\nKKK\nZZZZZ", "output": "NO" }, { "input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA", "output": "NO" } ]
1,688,806,194
2,147,483,647
Python 3
OK
TESTS
54
92
0
h=input() u=input() i=input() funny=h+u slojna=sorted(funny) legko=sorted(i) if slojna==legko: print("YES") else: print("NO") # Sat Jul 08 2023 11:49:53 GMT+0300 (Moscow Standard Time)
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door. The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters. Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. Input Specification: The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. Output Specification: Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. Demo Input: ['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
```python h=input() u=input() i=input() funny=h+u slojna=sorted(funny) legko=sorted(i) if slojna==legko: print("YES") else: print("NO") # Sat Jul 08 2023 11:49:53 GMT+0300 (Moscow Standard Time) ```
3
608
A
Saitama Destroys Hotel
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
[ "3 7\n2 1\n3 8\n5 2\n", "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n" ]
[ "11\n", "79\n" ]
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: takes 1 second. 7. Pick up passenger 1. 8. Go to floor 0: takes 2 seconds. This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
500
[ { "input": "3 7\n2 1\n3 8\n5 2", "output": "11" }, { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64", "output": "79" }, { "input": "1 1000\n1000 1000", "output": "2000" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 1000\n1 1", "output": "1000" }, { "input": "1 1000\n1 1000", "output": "1001" }, { "input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "2" }, { "input": "2 7\n6 3\n1 5", "output": "9" }, { "input": "2 100\n99 2\n1 10", "output": "101" }, { "input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1", "output": "6" }, { "input": "3 7\n1 6\n5 5\n6 1", "output": "10" }, { "input": "2 100\n4 100\n7 99", "output": "106" }, { "input": "2 10\n9 3\n1 4", "output": "12" }, { "input": "2 5\n4 4\n5 4", "output": "9" }, { "input": "2 10\n9 10\n6 11", "output": "19" }, { "input": "2 100\n99 9\n1 10", "output": "108" }, { "input": "2 7\n3 5\n7 4", "output": "11" }, { "input": "4 4\n4 6\n4 8\n1 7\n2 9", "output": "12" }, { "input": "2 1000\n1 2\n1000 1", "output": "1001" }, { "input": "2 20\n1 1\n2 2", "output": "20" }, { "input": "2 20\n10 10\n19 9", "output": "28" } ]
1,681,539,065
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
N=input().split() n=int(N[0]) s=int(N[1]) t=0 p=[0]*(s+1) for i in range(0,n): P=input().split() p[int(P[0])]+=int(P[1]) for i in range(s-1,0,-1): t+=1 if t<p[i]: t=p[i] print(t+1)
Title: Saitama Destroys Hotel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. Input Specification: The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. Output Specification: Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. Demo Input: ['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n'] Demo Output: ['11\n', '79\n'] Note: In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done: 1. Move to floor 5: takes 2 seconds. 2. Pick up passenger 3. 3. Move to floor 3: takes 2 seconds. 4. Wait for passenger 2 to arrive: takes 4 seconds. 5. Pick up passenger 2. 6. Go to floor 2: takes 1 second. 7. Pick up passenger 1. 8. Go to floor 0: takes 2 seconds. This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
```python N=input().split() n=int(N[0]) s=int(N[1]) t=0 p=[0]*(s+1) for i in range(0,n): P=input().split() p[int(P[0])]+=int(P[1]) for i in range(s-1,0,-1): t+=1 if t<p[i]: t=p[i] print(t+1) ```
0
224
B
Array
PROGRAMMING
1,500
[ "bitmasks", "implementation", "two pointers" ]
null
null
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
[ "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "7 4\n4 7 7 4 7 4 7\n" ]
[ "1 2\n", "2 5\n", "-1 -1\n" ]
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
1,000
[ { "input": "4 2\n1 2 2 3", "output": "1 2" }, { "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5" }, { "input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1" }, { "input": "5 1\n1 7 2 3 2", "output": "1 1" }, { "input": "1 2\n666", "output": "-1 -1" }, { "input": "1 1\n5", "output": "1 1" }, { "input": "10 4\n1 1 2 2 3 3 4 4 4 4", "output": "2 7" }, { "input": "4 2\n3 3 4 3", "output": "2 3" }, { "input": "4 3\n4 4 4 2", "output": "-1 -1" }, { "input": "10 5\n15 17 2 13 3 16 4 5 9 12", "output": "1 5" }, { "input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148", "output": "1 13" }, { "input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796", "output": "-1 -1" }, { "input": "8 5\n1 2 1 1 2 3 4 5", "output": "4 8" }, { "input": "7 3\n2 1 2 2 1 2 3", "output": "5 7" }, { "input": "6 3\n1 3 1 1 4 5", "output": "2 5" }, { "input": "5 3\n1 2 1 1 3", "output": "2 5" }, { "input": "9 3\n1 2 1 2 1 2 2 3 1", "output": "5 8" }, { "input": "4 3\n1 2 1 3", "output": "2 4" }, { "input": "5 3\n1 3 1 3 4", "output": "3 5" }, { "input": "6 3\n1 3 3 1 4 4", "output": "3 5" }, { "input": "5 3\n1 2 1 2 3", "output": "3 5" }, { "input": "8 4\n1 2 3 2 1 2 3 4", "output": "5 8" }, { "input": "10 4\n1 2 3 1 2 3 4 3 2 1", "output": "4 7" }, { "input": "10 3\n1 1 1 2 1 2 3 3 3 4", "output": "5 7" }, { "input": "10 3\n1 1 2 1 2 2 3 4 5 6", "output": "4 7" } ]
1,634,350,106
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
0
# 8 3 # 1 1 2 2 3 3 4 5 N, K = list(map(int, input().split())) a = list(map(int, input().split())) # a = [1, 6, 6, 6, 4, 2, 3, 3, 4, 5] # N, K = len(a), 3 l = 0 r = 0 unique_set = set() while len(unique_set) < K and r < N: # O(1) * n unique_set.add(a[r]) r += 1 unique_set = set() l = r while len(unique_set) < K and l >= 0 and l < N: unique_set.add(a[l]) l -= 1 if len(unique_set) == K: print(l + 2, r) else: print(-1, -1)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. Input Specification: The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. Demo Input: ['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n'] Demo Output: ['1 2\n', '2 5\n', '-1 -1\n'] Note: In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
```python # 8 3 # 1 1 2 2 3 3 4 5 N, K = list(map(int, input().split())) a = list(map(int, input().split())) # a = [1, 6, 6, 6, 4, 2, 3, 3, 4, 5] # N, K = len(a), 3 l = 0 r = 0 unique_set = set() while len(unique_set) < K and r < N: # O(1) * n unique_set.add(a[r]) r += 1 unique_set = set() l = r while len(unique_set) < K and l >= 0 and l < N: unique_set.add(a[l]) l -= 1 if len(unique_set) == K: print(l + 2, r) else: print(-1, -1) ```
0
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5", "output": "6" }, { "input": "2\n3 5\n1 9", "output": "0" }, { "input": "10\n43 80\n39 75\n26 71\n4 17\n11 57\n31 42\n1 62\n9 19\n27 76\n34 53", "output": "4" }, { "input": "50\n33 35\n98 99\n1 2\n4 6\n17 18\n63 66\n29 30\n35 37\n44 45\n73 75\n4 5\n39 40\n92 93\n96 97\n23 27\n49 50\n2 3\n60 61\n43 44\n69 70\n7 8\n45 46\n21 22\n85 86\n48 49\n41 43\n70 71\n10 11\n27 28\n71 72\n6 7\n15 16\n46 47\n89 91\n54 55\n19 21\n86 87\n37 38\n77 82\n84 85\n54 55\n93 94\n45 46\n37 38\n75 76\n22 23\n50 52\n38 39\n1 2\n66 67", "output": "2" }, { "input": "2\n1 5\n7 9", "output": "4" }, { "input": "2\n1 5\n3 5", "output": "2" }, { "input": "2\n1 5\n1 2", "output": "3" }, { "input": "5\n5 10\n5 10\n5 10\n5 10\n5 10", "output": "0" }, { "input": "6\n1 99\n33 94\n68 69\n3 35\n93 94\n5 98", "output": "3" }, { "input": "11\n2 98\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "2" }, { "input": "10\n95 96\n19 20\n72 73\n1 2\n25 26\n48 49\n90 91\n22 23\n16 17\n16 17", "output": "1" }, { "input": "11\n1 100\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "4" }, { "input": "21\n0 100\n81 90\n11 68\n18 23\n75 78\n45 86\n37 58\n15 21\n40 98\n53 100\n10 70\n14 75\n1 92\n23 81\n13 66\n93 100\n6 34\n22 87\n27 84\n15 63\n54 91", "output": "1" }, { "input": "10\n60 66\n5 14\n1 3\n55 56\n70 87\n34 35\n16 21\n23 24\n30 31\n25 27", "output": "6" }, { "input": "40\n29 31\n22 23\n59 60\n70 71\n42 43\n13 15\n11 12\n64 65\n1 2\n62 63\n54 56\n8 9\n2 3\n53 54\n27 28\n48 49\n72 73\n17 18\n46 47\n18 19\n43 44\n39 40\n83 84\n63 64\n52 53\n33 34\n3 4\n24 25\n74 75\n0 1\n61 62\n68 69\n80 81\n5 6\n36 37\n81 82\n50 51\n66 67\n69 70\n20 21", "output": "2" }, { "input": "15\n22 31\n0 4\n31 40\n77 80\n81 83\n11 13\n59 61\n53 59\n51 53\n87 88\n14 22\n43 45\n8 10\n45 47\n68 71", "output": "9" }, { "input": "31\n0 100\n2 97\n8 94\n9 94\n14 94\n15 93\n15 90\n17 88\n19 88\n19 87\n20 86\n25 86\n30 85\n32 85\n35 82\n35 81\n36 80\n37 78\n38 74\n38 74\n39 71\n40 69\n40 68\n41 65\n43 62\n44 62\n45 61\n45 59\n46 57\n49 54\n50 52", "output": "5" }, { "input": "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n26 28\n47 88\n30 40\n26 34\n2 12\n9 10\n4 19\n35 36\n41 92\n1 16\n41 78\n56 81\n23 35\n40 68", "output": "7" }, { "input": "27\n0 97\n7 9\n6 9\n12 33\n12 26\n15 27\n10 46\n33 50\n31 47\n15 38\n12 44\n21 35\n24 37\n51 52\n65 67\n58 63\n53 60\n63 68\n57 63\n60 68\n55 58\n74 80\n70 75\n89 90\n81 85\n93 99\n93 98", "output": "19" }, { "input": "20\n23 24\n22 23\n84 86\n6 10\n40 45\n11 13\n24 27\n81 82\n53 58\n87 90\n14 15\n49 50\n70 75\n75 78\n98 100\n66 68\n18 21\n1 2\n92 93\n34 37", "output": "1" }, { "input": "11\n2 100\n34 65\n4 50\n63 97\n82 99\n43 54\n23 52\n4 33\n15 84\n23 31\n12 34", "output": "3" }, { "input": "60\n73 75\n6 7\n69 70\n15 16\n54 55\n66 67\n7 8\n39 40\n38 39\n37 38\n1 2\n46 47\n7 8\n21 22\n23 27\n15 16\n45 46\n37 38\n60 61\n4 6\n63 66\n10 11\n33 35\n43 44\n2 3\n4 6\n10 11\n93 94\n45 46\n7 8\n44 45\n41 43\n35 37\n17 18\n48 49\n89 91\n27 28\n46 47\n71 72\n1 2\n75 76\n49 50\n84 85\n17 18\n98 99\n54 55\n46 47\n19 21\n77 82\n29 30\n4 5\n70 71\n85 86\n96 97\n86 87\n92 93\n22 23\n50 52\n44 45\n63 66", "output": "2" }, { "input": "40\n47 48\n42 44\n92 94\n15 17\n20 22\n11 13\n37 39\n6 8\n39 40\n35 37\n21 22\n41 42\n77 78\n76 78\n69 71\n17 19\n18 19\n17 18\n84 85\n9 10\n11 12\n51 52\n99 100\n7 8\n97 99\n22 23\n60 62\n7 8\n67 69\n20 22\n13 14\n89 91\n15 17\n12 13\n56 57\n37 39\n29 30\n24 26\n37 38\n25 27", "output": "1" }, { "input": "10\n28 36\n18 26\n28 35\n95 100\n68 72\n41 42\n76 84\n99 100\n6 8\n58 60", "output": "1" }, { "input": "20\n69 72\n88 92\n77 80\n64 69\n66 67\n79 81\n91 96\n78 83\n81 86\n11 12\n48 53\n22 23\n81 84\n89 92\n56 60\n1 4\n1 5\n60 62\n20 23\n63 66", "output": "3" }, { "input": "71\n1 99\n11 69\n86 92\n7 49\n31 70\n42 53\n48 81\n86 96\n36 91\n19 38\n39 91\n41 64\n87 93\n83 97\n40 41\n3 32\n15 18\n58 65\n22 32\n1 71\n58 86\n64 77\n15 69\n4 34\n42 89\n9 66\n15 18\n58 65\n59 96\n39 89\n19 38\n6 63\n26 73\n29 47\n55 88\n5 78\n41 74\n48 81\n20 71\n59 96\n42 49\n4 69\n41 74\n87 93\n0 65\n2 34\n15 18\n10 56\n55 88\n33 56\n42 89\n86 92\n42 81\n65 82\n5 78\n13 52\n32 85\n7 65\n59 96\n4 65\n46 69\n10 56\n42 89\n4 69\n0 65\n32 35\n5 78\n32 75\n42 53\n55 59\n64 77", "output": "2" }, { "input": "1\n1 2", "output": "1" } ]
1,583,057,505
2,147,483,647
Python 3
OK
TESTS
37
109
512,000
n = int(input()) segments = [] for _ in range(n): segments.append(list(map(int, input().split()))) l = segments[0][0] r = segments[0][1] list_of_tuples = [] for i in range(l,r): list_of_tuples.append((i,i+1)) i=1 while i<n: for j in range(segments[i][0],segments[i][1]): if (j,j+1) in list_of_tuples: list_of_tuples.remove((j,j+1)) i += 1 print(len(list_of_tuples))
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. Output Specification: On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. Demo Input: ['3\n0 5\n2 8\n1 6\n', '3\n0 10\n1 5\n7 15\n'] Demo Output: ['1\n', '3\n'] Note: Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
```python n = int(input()) segments = [] for _ in range(n): segments.append(list(map(int, input().split()))) l = segments[0][0] r = segments[0][1] list_of_tuples = [] for i in range(l,r): list_of_tuples.append((i,i+1)) i=1 while i<n: for j in range(segments[i][0],segments[i][1]): if (j,j+1) in list_of_tuples: list_of_tuples.remove((j,j+1)) i += 1 print(len(list_of_tuples)) ```
3
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "1 0 7" }, { "input": "8 1 1 8", "output": "2 1 7" }, { "input": "7 7 6 6", "output": "2 1 1" }, { "input": "8 1 8 8", "output": "1 0 7" }, { "input": "1 8 1 1", "output": "1 0 7" }, { "input": "1 8 8 1", "output": "2 1 7" }, { "input": "1 8 8 8", "output": "1 0 7" }, { "input": "8 8 1 1", "output": "2 1 7" }, { "input": "8 8 1 8", "output": "1 0 7" }, { "input": "8 8 8 1", "output": "1 0 7" }, { "input": "1 3 1 6", "output": "1 0 3" }, { "input": "1 3 1 4", "output": "1 0 1" }, { "input": "1 3 1 5", "output": "1 2 2" }, { "input": "3 3 2 4", "output": "2 1 1" }, { "input": "3 3 1 5", "output": "2 1 2" }, { "input": "1 6 2 1", "output": "2 2 5" }, { "input": "1 5 6 4", "output": "2 2 5" }, { "input": "1 3 3 7", "output": "2 2 4" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 7 5 4", "output": "2 0 4" }, { "input": "1 5 2 7", "output": "2 0 2" }, { "input": "1 4 6 2", "output": "2 0 5" }, { "input": "1 2 3 5", "output": "2 0 3" }, { "input": "1 8 8 7", "output": "2 2 7" }, { "input": "6 5 6 2", "output": "1 0 3" }, { "input": "6 3 3 5", "output": "2 0 3" }, { "input": "6 1 7 8", "output": "2 2 7" }, { "input": "1 2 3 2", "output": "1 2 2" }, { "input": "3 8 7 2", "output": "2 2 6" }, { "input": "4 2 6 4", "output": "2 1 2" }, { "input": "1 1 1 3", "output": "1 2 2" }, { "input": "6 8 8 6", "output": "2 1 2" }, { "input": "6 7 4 1", "output": "2 2 6" }, { "input": "6 5 1 4", "output": "2 2 5" }, { "input": "3 2 7 6", "output": "2 1 4" }, { "input": "3 8 4 1", "output": "2 2 7" }, { "input": "3 6 1 4", "output": "2 1 2" } ]
1,643,793,819
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
32
46
0
# inp = lambda :list(map(int, input().split())) c = list(map(int, input().split())) def tower(r1, c1, r2, c2): if r1 - r2 == 0 or c1 - c2 == 0: return 1 return 2 def eleph(r1, c1, r2, c2): if abs(r1-c1)%2 != abs(r2-c2)%2: return 0 if abs(r1-c1) == abs(r2-c2) or r1+c1 == r2 + c2: return 1 return 2 def king(r1, c1, r2, c2): return max(abs(r1-r2), abs(c1-c2)) print(' '.join(str(i) for i in (tower(*c), eleph(*c), king(*c))))
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input Specification: The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Specification: Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Demo Input: ['4 3 1 6\n', '5 5 5 6\n'] Demo Output: ['2 1 3\n', '1 0 1\n'] Note: none
```python # inp = lambda :list(map(int, input().split())) c = list(map(int, input().split())) def tower(r1, c1, r2, c2): if r1 - r2 == 0 or c1 - c2 == 0: return 1 return 2 def eleph(r1, c1, r2, c2): if abs(r1-c1)%2 != abs(r2-c2)%2: return 0 if abs(r1-c1) == abs(r2-c2) or r1+c1 == r2 + c2: return 1 return 2 def king(r1, c1, r2, c2): return max(abs(r1-r2), abs(c1-c2)) print(' '.join(str(i) for i in (tower(*c), eleph(*c), king(*c)))) ```
0
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712", "output": "NO" }, { "input": "190492", "output": "YES" }, { "input": "5722367", "output": "NO" }, { "input": "816761542", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "NO" }, { "input": "9", "output": "YES" }, { "input": "10", "output": "NO" }, { "input": "12", "output": "YES" }, { "input": "13", "output": "YES" }, { "input": "14", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "16", "output": "YES" }, { "input": "17", "output": "NO" }, { "input": "18", "output": "YES" }, { "input": "19", "output": "NO" }, { "input": "20", "output": "YES" }, { "input": "41", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "69", "output": "YES" }, { "input": "82", "output": "NO" }, { "input": "85", "output": "NO" }, { "input": "736", "output": "NO" }, { "input": "895", "output": "YES" }, { "input": "934", "output": "YES" }, { "input": "6213", "output": "YES" }, { "input": "7405", "output": "NO" }, { "input": "9919", "output": "NO" }, { "input": "40942", "output": "YES" }, { "input": "41992", "output": "NO" }, { "input": "68535", "output": "NO" }, { "input": "405718", "output": "NO" }, { "input": "1046146", "output": "YES" }, { "input": "3761248", "output": "YES" }, { "input": "6195181", "output": "YES" }, { "input": "35354345", "output": "NO" }, { "input": "81282830", "output": "NO" }, { "input": "187719774", "output": "NO" }, { "input": "296798673", "output": "NO" }, { "input": "938938476", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "999887464", "output": "YES" }, { "input": "999111944", "output": "NO" }, { "input": "999966520", "output": "YES" }, { "input": "999912080", "output": "NO" }, { "input": "999992017", "output": "YES" }, { "input": "999990474", "output": "NO" }, { "input": "999999190", "output": "YES" }, { "input": "999999125", "output": "NO" }, { "input": "999999940", "output": "YES" }, { "input": "999999995", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "999999999", "output": "YES" }, { "input": "83495494", "output": "NO" }, { "input": "968022000", "output": "YES" }, { "input": "399980000", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "999999998", "output": "NO" } ]
1,626,525,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
124
6,963,200
import math funk = [] n = int(input()) for i in range(int(math.sqrt(n))+1): funk.append(i*(i+1)// 2) i = 0 j = len(funk) - 1 while j >= i: if funk[i] + funk[j] > n: j -= 1 elif funk[i] + funk[j] < n: i += 1 else: print("YES") exit() print("NO")
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! Input Specification: The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Demo Input: ['256\n', '512\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
```python import math funk = [] n = int(input()) for i in range(int(math.sqrt(n))+1): funk.append(i*(i+1)// 2) i = 0 j = len(funk) - 1 while j >= i: if funk[i] + funk[j] > n: j -= 1 elif funk[i] + funk[j] < n: i += 1 else: print("YES") exit() print("NO") ```
0
911
C
Three Garlands
PROGRAMMING
1,400
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this!
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
0
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" }, { "input": "3 3 3", "output": "YES" }, { "input": "2 3 6", "output": "NO" }, { "input": "2 3 3", "output": "NO" }, { "input": "4 4 2", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "2 11 2", "output": "YES" }, { "input": "4 4 4", "output": "NO" }, { "input": "4 4 5", "output": "NO" }, { "input": "3 3 2", "output": "NO" }, { "input": "3 6 6", "output": "NO" }, { "input": "2 3 2", "output": "YES" }, { "input": "1 1 3", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "2 4 4", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "2 10 10", "output": "NO" }, { "input": "3 4 4", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "2 4 5", "output": "NO" }, { "input": "228 2 2", "output": "YES" }, { "input": "2 998 1000", "output": "NO" }, { "input": "2 6 6", "output": "NO" }, { "input": "6 4 7", "output": "NO" }, { "input": "2 5 2", "output": "YES" }, { "input": "2 100 100", "output": "NO" }, { "input": "7 7 2", "output": "NO" }, { "input": "3 3 6", "output": "NO" }, { "input": "82 3 82", "output": "NO" }, { "input": "2 3 5", "output": "NO" }, { "input": "1 218 924", "output": "YES" }, { "input": "4 4 123", "output": "NO" }, { "input": "4 4 3", "output": "NO" }, { "input": "3 4 2", "output": "NO" }, { "input": "2 2 5", "output": "YES" }, { "input": "2 10 2", "output": "YES" }, { "input": "5 2 2", "output": "YES" }, { "input": "3 3 9", "output": "NO" }, { "input": "1 5 5", "output": "YES" }, { "input": "2 4 6", "output": "NO" }, { "input": "15 3 3", "output": "NO" }, { "input": "1 5 10", "output": "YES" }, { "input": "2 3 14", "output": "NO" }, { "input": "1265 2 593", "output": "NO" }, { "input": "2 2 567", "output": "YES" }, { "input": "1 6 5", "output": "YES" }, { "input": "2 2 7", "output": "YES" }, { "input": "2 2 1500", "output": "YES" }, { "input": "3 6 9", "output": "NO" }, { "input": "1 46 79", "output": "YES" }, { "input": "4 3 3", "output": "NO" }, { "input": "2 4 8", "output": "NO" }, { "input": "1493 1489 1487", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "1 2 5", "output": "YES" }, { "input": "1 2 8", "output": "YES" }, { "input": "3 4 5", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "3 2 3", "output": "NO" }, { "input": "7 2 2", "output": "YES" }, { "input": "3 2 2", "output": "YES" }, { "input": "6 7 4", "output": "NO" } ]
1,590,648,209
2,609
PyPy 3
OK
TESTS
67
1,933
8,089,600
import sys #import math #import random #sys.setrecursionlimit(100000000) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ k1,k2,k3=invr() for x1 in range(1,1200): for x2 in range(1,1200): ache=[0]*105 now=x1 while now<105: ache[now]=1 now+=k1 now=x2 while now<105: ache[now]=1 now+=k2 baki=[] for i in range(1,105): if ache[i]==0: baki.append(i) if len(baki)<2: #print(str(x1)+" "+str(x2),end=" ") print("YES") exit(0) else: flag=True for i in range(1,len(baki)): flag&=((baki[i]-baki[i-1])%k3==0) if not flag: break if flag: print("YES") exit(0) print("NO")
Title: Three Garlands Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this! Input Specification: The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. Output Specification: If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO. Demo Input: ['2 2 3\n', '4 2 3\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
```python import sys #import math #import random #sys.setrecursionlimit(100000000) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ k1,k2,k3=invr() for x1 in range(1,1200): for x2 in range(1,1200): ache=[0]*105 now=x1 while now<105: ache[now]=1 now+=k1 now=x2 while now<105: ache[now]=1 now+=k2 baki=[] for i in range(1,105): if ache[i]==0: baki.append(i) if len(baki)<2: #print(str(x1)+" "+str(x2),end=" ") print("YES") exit(0) else: flag=True for i in range(1,len(baki)): flag&=((baki[i]-baki[i-1])%k3==0) if not flag: break if flag: print("YES") exit(0) print("NO") ```
3
792
A
New Bus Route
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
[ "4\n6 -3 0 4\n", "3\n-2 0 2\n" ]
[ "2 1\n", "2 2\n" ]
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
0
[ { "input": "4\n6 -3 0 4", "output": "2 1" }, { "input": "3\n-2 0 2", "output": "2 2" }, { "input": "2\n1 2", "output": "1 1" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000 1" }, { "input": "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "output": "1 4" }, { "input": "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "output": "1 2" }, { "input": "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 553280622 553280633 553280621 553280630 553280619", "output": "1 19" }, { "input": "20\n105619866 106083760 106090730 105809555 106115212 105155938 105979518 106075627 106145216 105637844 105925719 105498536 105927000 106155938 106134226 106125969 106130588 105464813 106145509 106114971", "output": "241 1" }, { "input": "10\n570685866 570685854 570685858 570685850 570685856 570685864 570685860 570685852 570685862 570685868", "output": "2 9" }, { "input": "2\n1 1000000000", "output": "999999999 1" }, { "input": "6\n1 2 3 4 5 6", "output": "1 5" }, { "input": "3\n7 10 12", "output": "2 1" }, { "input": "5\n-7 -5 -4 -3 -1", "output": "1 2" }, { "input": "4\n-6 -4 -2 1", "output": "2 2" }, { "input": "4\n3 5 7 8", "output": "1 1" }, { "input": "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1", "output": "1 8" }, { "input": "2\n15 13", "output": "2 1" }, { "input": "2\n14 13", "output": "1 1" }, { "input": "2\n12 13", "output": "1 1" }, { "input": "2\n-1000000000 13265920", "output": "1013265920 1" }, { "input": "2\n8 10", "output": "2 1" } ]
1,637,303,192
92
PyPy 3-64
OK
TESTS
45
249
22,323,200
import sys input = sys.stdin.readline n = int(input()) l = sorted([int(i) for i in input().split()]) res = 10**18 ans = 0 for i in range(n-1): t = l[i+1]-l[i] if t == res: ans += 1 elif t < res: res = t ans = 1 print(res, ans)
Title: New Bus Route Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates. It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance. Input Specification: The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. Output Specification: Print two integer numbers — the minimal distance and the quantity of pairs with this distance. Demo Input: ['4\n6 -3 0 4\n', '3\n-2 0 2\n'] Demo Output: ['2 1\n', '2 2\n'] Note: In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
```python import sys input = sys.stdin.readline n = int(input()) l = sorted([int(i) for i in input().split()]) res = 10**18 ans = 0 for i in range(n-1): t = l[i+1]-l[i] if t == res: ans += 1 elif t < res: res = t ans = 1 print(res, ans) ```
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,678,334,038
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
1,331,200
k,r=map(int,input().split()) x=1 while (k*x)%10!=r: x+=1 print(x)
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 k,r=map(int,input().split()) x=1 while (k*x)%10!=r: x+=1 print(x) ```
0
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol.
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "output": "1" }, { "input": "4\nSAKE\nSAKE\n13\n2", "output": "4" }, { "input": "2\n0\n17", "output": "2" }, { "input": "1\n0", "output": "1" } ]
1,580,374,511
2,147,483,647
Python 3
OK
TESTS
28
218
0
lis = ["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] n = int(input()) k = 0 for i in range(n): s = input() if s.isnumeric(): s = int(s) if s < 18: k = k + 1 else: if s in lis: k = k + 1 print(k)
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol. Output Specification: Print a single number which is the number of people Vasya should check to guarantee the law enforcement. Demo Input: ['5\n18\nVODKA\nCOKE\n19\n17\n'] Demo Output: ['2\n'] Note: In the sample test the second and fifth clients should be checked.
```python lis = ["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] n = int(input()) k = 0 for i in range(n): s = input() if s.isnumeric(): s = int(s) if s < 18: k = k + 1 else: if s in lis: k = k + 1 print(k) ```
3.9455
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,691,446,160
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
number = input('what is your input?') numberInt = int(number) minValue=1 maxValue=100 if minValue<=numberInt<= maxValue: if numberInt % 2 == 0: print('YES') else: print('NO') else: print('Number range in 1 to 100')
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python number = input('what is your input?') numberInt = int(number) minValue=1 maxValue=100 if minValue<=numberInt<= maxValue: if numberInt % 2 == 0: print('YES') else: print('NO') else: print('Number range in 1 to 100') ```
0
382
A
Ksenia and Pan Scales
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.
[ "AC|T\nL\n", "|ABC\nXYZ\n", "W|T\nF\n", "ABC|\nD\n" ]
[ "AC|TL\n", "XYZ|ABC\n", "Impossible\n", "Impossible\n" ]
none
500
[ { "input": "AC|T\nL", "output": "AC|TL" }, { "input": "|ABC\nXYZ", "output": "XYZ|ABC" }, { "input": "W|T\nF", "output": "Impossible" }, { "input": "ABC|\nD", "output": "Impossible" }, { "input": "A|BC\nDEF", "output": "ADF|BCE" }, { "input": "|\nABC", "output": "Impossible" }, { "input": "|\nZXCVBANMIO", "output": "XVAMO|ZCBNI" }, { "input": "|C\nA", "output": "A|C" }, { "input": "|\nAB", "output": "B|A" }, { "input": "A|XYZ\nUIOPL", "output": "Impossible" }, { "input": "K|B\nY", "output": "Impossible" }, { "input": "EQJWDOHKZRBISPLXUYVCMNFGT|\nA", "output": "Impossible" }, { "input": "|MACKERIGZPVHNDYXJBUFLWSO\nQT", "output": "Impossible" }, { "input": "ERACGIZOVPT|WXUYMDLJNQS\nKB", "output": "ERACGIZOVPTB|WXUYMDLJNQSK" }, { "input": "CKQHRUZMISGE|FBVWPXDLTJYN\nOA", "output": "CKQHRUZMISGEA|FBVWPXDLTJYNO" }, { "input": "V|CMOEUTAXBFWSK\nDLRZJGIYNQHP", "output": "VDLRZJGIYNQHP|CMOEUTAXBFWSK" }, { "input": "QWHNMALDGKTJ|\nPBRYVXZUESCOIF", "output": "QWHNMALDGKTJF|PBRYVXZUESCOI" }, { "input": "|\nFXCVMUEWZAHNDOSITPRLKQJYBG", "output": "XVUWANOIPLQYG|FCMEZHDSTRKJB" }, { "input": "IB|PCGHZ\nFXWTJQNEKAUM", "output": "Impossible" }, { "input": "EC|IWAXQ\nJUHSRKGZTOMYN", "output": "ECJUHRGTMN|IWAXQSKZOY" }, { "input": "VDINYMA|UQKWBCLRHZJ\nXEGOF", "output": "Impossible" }, { "input": "ZLTPSIQUBAR|XFDEMYC\nHNOJWG", "output": "ZLTPSIQUBARG|XFDEMYCHNOJW" }, { "input": "R|FLZOTJNU\nGIYHKVX", "output": "RGIYHKVX|FLZOTJNU" }, { "input": "W|TL\nQROFSADYPKHEJNMXBZVUCIG", "output": "WQOSDPHJMBVCG|TLRFAYKENXZUI" }, { "input": "NRDFQSEKLAYMOT|ZH\nGUXIBJCVPW", "output": "Impossible" }, { "input": "FGRT|\nAC", "output": "Impossible" }, { "input": "|FGRT\nAC", "output": "Impossible" }, { "input": "A|\nB", "output": "A|B" }, { "input": "|A\nB", "output": "B|A" }, { "input": "|\nA", "output": "Impossible" }, { "input": "|\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "WRYIPSFHKZCBM|QETUOADGJLXVN" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN|\nM", "output": "Impossible" }, { "input": "QWERTY|VBN\nUIOPASDFGHJKLZXC", "output": "Impossible" }, { "input": "ABC|D\nKSL", "output": "Impossible" }, { "input": "A|BCDEF\nGH", "output": "Impossible" }, { "input": "|ABC\nD", "output": "Impossible" }, { "input": "A|BC\nDE", "output": "Impossible" }, { "input": "|ASD\nX", "output": "Impossible" }, { "input": "AB|CDEF\nXYZRT", "output": "Impossible" } ]
1,566,667,078
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
109
0
x=list(input()) z=input() h=x.index("|") min1=min(h,len(x)-(h+1)) max1=max(h,len(x)-(h+1)) f=len(x)-1+len(z) if(f%2!=0 or min1+len(z)<max1): print("Impossible") else: if(f/2>max1): if(max1==len(x)-(h+1)): x[-1]+=z[0:int(((f/2)-max1))] else: x[h-1]+=z[0:int(((f/2)-max1))] N=(f/2)-max1 if(min1==h): if(h==0): x[min1]=z[int(N):]+"|" else: x[min1-1]+=z[int(N):] else: x[-1]+=z[int(N):] z=0 while(z<len(x)): print(x[z],end='') z+=1
Title: Ksenia and Pan Scales Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan. Input Specification: The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters. Output Specification: If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them. Demo Input: ['AC|T\nL\n', '|ABC\nXYZ\n', 'W|T\nF\n', 'ABC|\nD\n'] Demo Output: ['AC|TL\n', 'XYZ|ABC\n', 'Impossible\n', 'Impossible\n'] Note: none
```python x=list(input()) z=input() h=x.index("|") min1=min(h,len(x)-(h+1)) max1=max(h,len(x)-(h+1)) f=len(x)-1+len(z) if(f%2!=0 or min1+len(z)<max1): print("Impossible") else: if(f/2>max1): if(max1==len(x)-(h+1)): x[-1]+=z[0:int(((f/2)-max1))] else: x[h-1]+=z[0:int(((f/2)-max1))] N=(f/2)-max1 if(min1==h): if(h==0): x[min1]=z[int(N):]+"|" else: x[min1-1]+=z[int(N):] else: x[-1]+=z[int(N):] z=0 while(z<len(x)): print(x[z],end='') z+=1 ```
0
631
B
Print Check
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing. Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0. Your program has to support two operations: 1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*. If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*. Your program has to print the resulting table after *k* operation.
The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively. Each of the next *k* lines contains the description of exactly one query: - 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*.
Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
[ "3 3 3\n1 1 3\n2 2 1\n1 2 2\n", "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n" ]
[ "3 1 3 \n2 2 2 \n0 1 0 \n", "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n" ]
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
1,000
[ { "input": "3 3 3\n1 1 3\n2 2 1\n1 2 2", "output": "3 1 3 \n2 2 2 \n0 1 0 " }, { "input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1", "output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 " }, { "input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1", "output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 " }, { "input": "4 6 8\n1 2 1\n2 2 2\n2 5 2\n1 1 1\n1 4 1\n1 3 2\n2 1 1\n2 6 1", "output": "1 1 1 1 1 1 \n1 2 1 1 2 1 \n1 2 2 2 2 1 \n1 1 1 1 1 1 " }, { "input": "2 2 3\n1 1 1\n1 2 1\n2 1 2", "output": "2 1 \n2 1 " }, { "input": "1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 1 4", "output": "4 4 " }, { "input": "2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7", "output": "77 \n7 " }, { "input": "2 1 1\n1 2 1000000000", "output": "0 \n1000000000 " }, { "input": "1 2 1\n2 2 1000000000", "output": "0 1000000000 " }, { "input": "160 600 1\n1 132 589472344", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "600 160 1\n1 124 542622711", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "10 1 1\n2 1 1000000000", "output": "1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 " }, { "input": "1 10 1\n1 1 1000000000", "output": "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 " }, { "input": "5000 20 15\n2 13 447246914\n2 10 89345638\n2 6 393683717\n2 1 62225152\n2 12 990340161\n2 4 227462932\n1 4011 327145900\n1 1915 981331082\n1 802 437883065\n2 11 205232924\n2 15 303578182\n1 2667 835309719\n2 3 550440583\n1 3852 766318960\n2 5 204700467", "output": "62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 ..." }, { "input": "20 5000 15\n1 14 94104058\n1 3 170575572\n1 12 613859505\n2 4797 363375206\n1 10 554079405\n2 4481 223609505\n2 4974 385117513\n1 7 363246561\n2 2503 128936152\n1 2 152944073\n1 14 25797327\n1 20 258831369\n1 10 453164078\n2 2159 753235825\n2 1823 827844660", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "1 1 1\n1 1 1", "output": "1 " }, { "input": "1 1 1\n1 1 1000000000", "output": "1000000000 " }, { "input": "1 1 2\n1 1 123\n1 1 321", "output": "321 " }, { "input": "1 1 2\n1 1 321\n1 1 123", "output": "123 " } ]
1,457,025,112
2,212
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
10
1,000
1,536,000
mx = [] ops = [] nx=list(map(int,input().split())) n=nx[0] m=nx[1] k=nx[2] for i in range (0,n): mx.append([0]*m) for i in range (0,k): ops.append(list(map(int,input().split()))) if ops[i][0]==1: for j in range (0,m): mx[ops[i][1]-1][j]=ops[i][2] else: for j in range (0,n): mx[j][ops[i][1]-1]=ops[i][2] for i in range (0,n): for j in range (0,m): print (mx[i][j],end=' ') print()
Title: Print Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing. Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0. Your program has to support two operations: 1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*. If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*. Your program has to print the resulting table after *k* operation. Input Specification: The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively. Each of the next *k* lines contains the description of exactly one query: - 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*. Output Specification: Print *n* lines containing *m* integers each — the resulting table after all operations are applied. Demo Input: ['3 3 3\n1 1 3\n2 2 1\n1 2 2\n', '5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n'] Demo Output: ['3 1 3 \n2 2 2 \n0 1 0 \n', '1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n'] Note: The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
```python mx = [] ops = [] nx=list(map(int,input().split())) n=nx[0] m=nx[1] k=nx[2] for i in range (0,n): mx.append([0]*m) for i in range (0,k): ops.append(list(map(int,input().split()))) if ops[i][0]==1: for j in range (0,m): mx[ops[i][1]-1][j]=ops[i][2] else: for j in range (0,n): mx[j][ops[i][1]-1]=ops[i][2] for i in range (0,n): for j in range (0,m): print (mx[i][j],end=' ') print() ```
0
676
A
Nicholas and Permutation
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
[ "5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n" ]
[ "3\n", "6\n", "5\n" ]
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
500
[ { "input": "5\n4 5 1 3 2", "output": "3" }, { "input": "7\n1 6 5 3 4 7 2", "output": "6" }, { "input": "6\n6 5 4 3 2 1", "output": "5" }, { "input": "2\n1 2", "output": "1" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "5\n1 4 5 2 3", "output": "4" }, { "input": "6\n4 6 3 5 2 1", "output": "5" }, { "input": "7\n1 5 3 6 2 4 7", "output": "6" }, { "input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75", "output": "94" }, { "input": "8\n4 5 3 8 6 7 1 2", "output": "6" }, { "input": "9\n6 8 5 3 4 7 9 2 1", "output": "8" }, { "input": "10\n8 7 10 1 2 3 4 6 5 9", "output": "7" }, { "input": "11\n5 4 6 9 10 11 7 3 1 2 8", "output": "8" }, { "input": "12\n3 6 7 8 9 10 12 5 4 2 11 1", "output": "11" }, { "input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6", "output": "10" }, { "input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8", "output": "8" }, { "input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9", "output": "9" }, { "input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16", "output": "15" }, { "input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17", "output": "16" }, { "input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10", "output": "11" }, { "input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1", "output": "18" }, { "input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1", "output": "19" }, { "input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21", "output": "20" }, { "input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1", "output": "21" }, { "input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6", "output": "22" }, { "input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4", "output": "16" }, { "input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25", "output": "24" }, { "input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3", "output": "21" }, { "input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1", "output": "26" }, { "input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2", "output": "27" }, { "input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26", "output": "22" }, { "input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7", "output": "26" }, { "input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7", "output": "18" }, { "input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28", "output": "30" }, { "input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3", "output": "29" }, { "input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12", "output": "33" }, { "input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7", "output": "21" }, { "input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8", "output": "35" }, { "input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28", "output": "35" }, { "input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29", "output": "34" }, { "input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1", "output": "38" }, { "input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1", "output": "39" }, { "input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6", "output": "34" }, { "input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35", "output": "41" }, { "input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1", "output": "42" }, { "input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28", "output": "37" }, { "input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1", "output": "44" }, { "input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30", "output": "34" }, { "input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2", "output": "41" }, { "input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7", "output": "38" }, { "input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31", "output": "40" }, { "input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40", "output": "38" }, { "input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32", "output": "43" }, { "input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39", "output": "48" }, { "input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49", "output": "52" }, { "input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53", "output": "41" }, { "input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52", "output": "48" }, { "input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15", "output": "46" }, { "input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57", "output": "56" }, { "input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50", "output": "57" }, { "input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20", "output": "58" }, { "input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1", "output": "59" }, { "input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21", "output": "60" }, { "input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62", "output": "61" }, { "input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17", "output": "46" }, { "input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47", "output": "55" }, { "input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64", "output": "62" }, { "input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29", "output": "65" }, { "input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32", "output": "45" }, { "input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3", "output": "64" }, { "input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63", "output": "45" }, { "input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35", "output": "64" }, { "input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21", "output": "50" }, { "input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56", "output": "57" }, { "input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21", "output": "45" }, { "input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58", "output": "63" }, { "input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58", "output": "74" }, { "input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68", "output": "75" }, { "input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34", "output": "62" }, { "input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72", "output": "70" }, { "input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58", "output": "77" }, { "input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78", "output": "52" }, { "input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55", "output": "69" }, { "input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52", "output": "53" }, { "input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69", "output": "66" }, { "input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38", "output": "80" }, { "input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78", "output": "84" }, { "input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3", "output": "70" }, { "input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85", "output": "58" }, { "input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67", "output": "87" }, { "input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89", "output": "88" }, { "input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25", "output": "60" }, { "input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1", "output": "90" }, { "input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72", "output": "67" }, { "input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34", "output": "85" }, { "input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68", "output": "69" }, { "input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1", "output": "94" }, { "input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56", "output": "86" }, { "input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90", "output": "95" }, { "input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1", "output": "97" }, { "input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71", "output": "87" }, { "input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37", "output": "89" }, { "input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1", "output": "99" }, { "input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42", "output": "65" }, { "input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93", "output": "87" }, { "input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11", "output": "81" }, { "input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75", "output": "99" }, { "input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67", "output": "96" }, { "input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56", "output": "62" }, { "input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100", "output": "99" }, { "input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64", "output": "97" }, { "input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57", "output": "98" }, { "input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69", "output": "98" }, { "input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14", "output": "98" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "3\n1 3 2", "output": "2" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 3 1", "output": "2" }, { "input": "3\n3 1 2", "output": "2" }, { "input": "3\n3 2 1", "output": "2" }, { "input": "4\n1 2 3 4", "output": "3" }, { "input": "4\n1 2 4 3", "output": "3" }, { "input": "4\n1 3 2 4", "output": "3" }, { "input": "4\n1 3 4 2", "output": "3" }, { "input": "4\n1 4 2 3", "output": "3" }, { "input": "4\n1 4 3 2", "output": "3" }, { "input": "4\n2 1 3 4", "output": "3" }, { "input": "4\n2 1 4 3", "output": "2" }, { "input": "4\n2 4 1 3", "output": "2" }, { "input": "4\n2 4 3 1", "output": "3" }, { "input": "4\n3 1 2 4", "output": "3" }, { "input": "4\n3 1 4 2", "output": "2" }, { "input": "4\n3 2 1 4", "output": "3" }, { "input": "4\n3 2 4 1", "output": "3" }, { "input": "4\n3 4 1 2", "output": "2" }, { "input": "4\n3 4 2 1", "output": "3" }, { "input": "4\n4 1 2 3", "output": "3" }, { "input": "4\n4 1 3 2", "output": "3" }, { "input": "4\n4 2 1 3", "output": "3" }, { "input": "4\n4 2 3 1", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "4\n4 3 2 1", "output": "3" }, { "input": "8\n2 5 6 4 8 3 1 7", "output": "6" }, { "input": "5\n2 3 1 5 4", "output": "3" }, { "input": "6\n2 5 3 6 4 1", "output": "5" }, { "input": "6\n5 4 2 6 1 3", "output": "4" }, { "input": "6\n4 2 3 1 6 5", "output": "4" }, { "input": "6\n5 4 2 1 6 3", "output": "4" }, { "input": "9\n7 2 3 4 5 6 1 9 8", "output": "7" }, { "input": "6\n3 2 1 4 6 5", "output": "4" }, { "input": "6\n2 3 4 1 6 5", "output": "4" }, { "input": "10\n5 2 3 4 1 6 7 8 10 9", "output": "8" }, { "input": "6\n5 2 3 1 6 4", "output": "4" }, { "input": "10\n2 9 3 4 1 10 5 6 7 8", "output": "5" }, { "input": "10\n2 3 4 5 6 7 1 8 10 9", "output": "8" }, { "input": "8\n2 3 4 5 1 6 8 7", "output": "6" }, { "input": "6\n2 1 3 4 5 6", "output": "5" } ]
1,685,950,052
2,147,483,647
PyPy 3-64
OK
TESTS
159
62
0
n = int(input()) x = [int(x) for x in input().split()] minpos = x.index(min(x)) maxpos = x.index(max(x)) if(minpos>maxpos): d1 = (n-1)-(minpos) d2 = maxpos-0 print((minpos-maxpos)+max(d1,d2)) else: d1 = (n-1)-(maxpos) d2 = minpos-0 print((maxpos-minpos)+max(d1,d2))
Title: Nicholas and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*. Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. Input Specification: The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation. The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. Output Specification: Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. Demo Input: ['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n'] Demo Output: ['3\n', '6\n', '5\n'] Note: In the first sample, one may obtain the optimal answer by swapping elements 1 and 2. In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2. In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
```python n = int(input()) x = [int(x) for x in input().split()] minpos = x.index(min(x)) maxpos = x.index(max(x)) if(minpos>maxpos): d1 = (n-1)-(minpos) d2 = maxpos-0 print((minpos-maxpos)+max(d1,d2)) else: d1 = (n-1)-(maxpos) d2 = minpos-0 print((maxpos-minpos)+max(d1,d2)) ```
3
550
B
Preparing Olympiad
PROGRAMMING
1,400
[ "bitmasks", "brute force" ]
null
null
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least *l* and at most *r*. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least *x*. Find the number of ways to choose a problemset for the contest.
The first line contains four integers *n*, *l*, *r*, *x* (1<=≤<=*n*<=≤<=15, 1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — the difficulty of each problem.
Print the number of ways to choose a suitable problemset for the contest.
[ "3 5 6 1\n1 2 3\n", "4 40 50 10\n10 20 30 25\n", "5 25 35 10\n10 10 20 10 20\n" ]
[ "2\n", "2\n", "6\n" ]
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems. In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30. In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.
750
[ { "input": "3 5 6 1\n1 2 3", "output": "2" }, { "input": "4 40 50 10\n10 20 30 25", "output": "2" }, { "input": "5 25 35 10\n10 10 20 10 20", "output": "6" }, { "input": "4 15 60 10\n10 20 30 25", "output": "6" }, { "input": "1 10 20 1\n15", "output": "0" }, { "input": "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "output": "914" }, { "input": "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 392011 318488 857649 30681 740872 115749", "output": "31485" }, { "input": "7 1000 2000 1\n10 20 30 40 50 60 70", "output": "0" }, { "input": "4 10 20 1\n4 6 4 6", "output": "9" }, { "input": "4 10 20 1\n5 15 13 7", "output": "4" }, { "input": "2 10 20 5\n5 10", "output": "1" }, { "input": "5 1098816 3969849 167639\n85627 615007 794045 530104 7091", "output": "15" }, { "input": "13 700147 8713522 390093\n996812 94040 954140 545670 369698 423872 365802 784830 700267 960664 949252 84637 257447", "output": "8026" }, { "input": "15 4531977 20754263 137419\n637830 85299 755530 64382 896833 879525 331501 148182 741013 192101 112217 52165 702790 988594 587499", "output": "6759" }, { "input": "15 2572491 5084070 823435\n570344 78552 775918 501843 844935 71141 331498 636557 435494 715447 992666 831188 28969 171046 989614", "output": "15078" }, { "input": "15 4789415 23152928 233992\n502422 273992 449428 947379 700461 681985 857134 243310 478052 77769 936151 642380 464695 281772 964693", "output": "10875" }, { "input": "3 390224 390224 1\n264237 125987 288891", "output": "1" }, { "input": "7 1652707 1652707 1\n492387 684636 235422 332532 924898 499872 192988", "output": "1" }, { "input": "10 501107 501107 1\n843967 30518 196518 619138 204862 690754 274071 550121 173607 359971", "output": "1" }, { "input": "15 6627289 6627289 1\n683844 183950 184972 764255 211665 842336 790234 815301 914823 513046 93547 713159 554415 200951 388028", "output": "1" }, { "input": "15 5083470 5083470 1\n978510 643688 591921 723137 573784 346171 920030 352119 528857 365128 627302 308557 716247 263519 654230", "output": "1" }, { "input": "15 6558665 6558665 1\n572491 435494 916457 775918 823435 78552 501843 331498 71141 844935 636557 992666 570344 831188 715447", "output": "1" }, { "input": "10 159699 10967276 3542\n998862 999751 995306 992648 992661 991407 997503 998809 999740 997669", "output": "942" }, { "input": "5 2815840 8479687 4082\n991137 992161 997887 998891 994990", "output": "14" }, { "input": "15 2898377 6694755 721\n992733 999159 990076 996808 990975 993338 993234 994757 997873 993303 994409 993801 998027 990495 999287", "output": "9819" }, { "input": "6 20 70 1\n10 10 20 20 30 30", "output": "35" }, { "input": "6 20 70 1\n10 10 10 10 10 10", "output": "0" }, { "input": "15 1 1000000000 1\n10 20 30 40 50 60 70 80 90 100 110 120 130 140 150", "output": "32752" }, { "input": "6 30 40 1\n19 20 21 14 15 16", "output": "13" }, { "input": "4 5 234 2\n10 9 12 11", "output": "8" } ]
1,692,088,409
2,147,483,647
Python 3
OK
TESTS
30
233
0
n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 #find all subsets using bitmasking and find values and compare with restrictions for i in range(1 << n): mx = -1 mn = 1000000 sum_val = 0 for j in range(n): if i & (1 << j): sum_val += a[j] mx = max(mx, a[j]) mn = min(mn, a[j]) if l <= sum_val <= r and (mx - mn) >= x: ans += 1 print(ans)
Title: Preparing Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least *l* and at most *r*. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least *x*. Find the number of ways to choose a problemset for the contest. Input Specification: The first line contains four integers *n*, *l*, *r*, *x* (1<=≤<=*n*<=≤<=15, 1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — the difficulty of each problem. Output Specification: Print the number of ways to choose a suitable problemset for the contest. Demo Input: ['3 5 6 1\n1 2 3\n', '4 40 50 10\n10 20 30 25\n', '5 25 35 10\n10 10 20 10 20\n'] Demo Output: ['2\n', '2\n', '6\n'] Note: In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems. In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30. In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.
```python n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 #find all subsets using bitmasking and find values and compare with restrictions for i in range(1 << n): mx = -1 mn = 1000000 sum_val = 0 for j in range(n): if i & (1 << j): sum_val += a[j] mx = max(mx, a[j]) mn = min(mn, a[j]) if l <= sum_val <= r and (mx - mn) >= x: ans += 1 print(ans) ```
3
0
none
none
none
0
[ "none" ]
null
null
Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero. A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0. Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose?
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=300<=000) — the number of columns in the grid. The next two lines contain numbers in the grid. The *i*-th of those two lines contains *n* integers *t**i*,<=1,<=*t**i*,<=2,<=...,<=*t**i*,<=*n* (<=-<=109<=≤<=*t**i*,<=*j*<=≤<=109).
Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles.
[ "6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15\n", "4\n0 -1 0 0\n0 0 1 0\n", "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998\n" ]
[ "3\n", "6\n", "1\n" ]
In the first sample, there are four nice rectangles: Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings. In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number 0. In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is 0. Clearly, Limak can choose at most one nice rectangle, so the answer is 1.
0
[ { "input": "6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15", "output": "3" }, { "input": "4\n0 -1 0 0\n0 0 1 0", "output": "6" }, { "input": "3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998", "output": "1" }, { "input": "1\n0\n0", "output": "2" }, { "input": "1\n20\n-20", "output": "1" }, { "input": "2\n-1 0\n0 0", "output": "3" }, { "input": "3\n-2 -1 1\n0 1 0", "output": "3" }, { "input": "5\n-1 -2 2 0 -2\n-1 2 -2 2 2", "output": "4" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "10\n2 1 -2 -1 2 2 -2 0 2 -2\n1 -2 -1 0 1 -2 -1 -1 -2 1", "output": "5" }, { "input": "50\n0 -1 -1 -1 -1 -1 0 -1 1 1 0 0 1 1 -1 0 1 1 -1 -1 1 -1 0 0 -1 -1 0 1 -1 1 1 1 -1 0 0 0 1 1 -1 1 1 0 -1 0 0 0 -1 0 -1 0\n0 -1 1 1 0 -1 0 1 -1 1 0 0 0 1 -1 -1 -1 1 1 -1 0 1 1 -1 0 -1 -1 0 0 1 1 -1 -1 1 1 1 -1 -1 -1 -1 0 -1 0 -1 1 1 -1 1 -1 -1", "output": "51" }, { "input": "50\n1 -1 2 -2 0 -2 0 2 -2 1 0 0 0 -1 0 -1 -1 -1 -2 0 1 -2 2 -2 0 -2 -2 -2 1 -2 -2 1 1 -1 1 -2 -2 2 0 0 0 -1 -2 -2 1 1 1 -1 -1 -1\n0 0 -1 2 1 -2 -2 0 -2 0 -1 -2 -2 -1 -2 -2 -1 0 1 -2 0 -1 2 -1 -2 -1 -1 0 0 -2 -1 -1 1 -1 -2 -1 -1 -2 2 2 1 -1 0 1 0 1 -2 -1 -1 0", "output": "36" }, { "input": "100\n-1 3 3 0 -3 2 3 -3 1 0 -2 2 1 3 -1 -2 -2 -2 -3 -3 2 3 -1 -2 0 3 -1 2 2 -1 1 1 2 3 0 -3 -1 2 0 0 -2 -2 2 3 2 -1 -2 -1 -2 -2 -3 0 3 -2 2 -1 -2 3 0 -2 1 0 1 3 0 -2 2 -1 2 1 3 1 -3 1 0 0 2 3 -3 -2 -1 0 -3 0 3 2 1 1 0 -3 -3 -3 2 -3 -1 3 1 3 3 -3\n-2 -2 2 -1 -2 -2 3 2 2 -1 3 2 -3 2 -2 2 -3 3 -3 0 2 0 1 1 -2 3 -1 0 3 -1 3 0 1 2 2 -3 3 -3 -1 2 0 0 0 2 1 2 0 1 -2 2 -3 1 3 -1 3 -3 -3 -3 3 0 3 0 1 1 -2 -3 3 -1 -3 -1 -1 -2 -2 1 2 0 -3 -3 2 0 2 -3 1 -3 1 -1 1 3 -2 0 -3 -2 -1 -2 1 -2 -3 2 -1 3", "output": "57" }, { "input": "1\n-5\n-5", "output": "0" }, { "input": "1\n0\n17", "output": "1" }, { "input": "2\n1 1\n-1 -1", "output": "2" }, { "input": "3\n1 -1 1\n1 0 -1", "output": "3" }, { "input": "4\n-1 1 -1 0\n1 1 -1 0", "output": "5" } ]
1,689,647,186
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
print("_RANDOM_GUESS_1689647186.5794013")# 1689647186.5794203
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak has a grid that consists of 2 rows and *n* columns. The *j*-th cell in the *i*-th row contains an integer *t**i*,<=*j* which can be positive, negative or zero. A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 0. Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose? Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=300<=000) — the number of columns in the grid. The next two lines contain numbers in the grid. The *i*-th of those two lines contains *n* integers *t**i*,<=1,<=*t**i*,<=2,<=...,<=*t**i*,<=*n* (<=-<=109<=≤<=*t**i*,<=*j*<=≤<=109). Output Specification: Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles. Demo Input: ['6\n70 70 70 70 70 -15\n90 -60 -30 30 -30 15\n', '4\n0 -1 0 0\n0 0 1 0\n', '3\n1000000000 999999999 -1000000000\n999999999 -1000000000 -999999998\n'] Demo Output: ['3\n', '6\n', '1\n'] Note: In the first sample, there are four nice rectangles: Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings. In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number 0. In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is 0. Clearly, Limak can choose at most one nice rectangle, so the answer is 1.
```python print("_RANDOM_GUESS_1689647186.5794013")# 1689647186.5794203 ```
0
1,007
A
Reorder the Array
PROGRAMMING
1,300
[ "combinatorics", "data structures", "math", "sortings", "two pointers" ]
null
null
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
[ "7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n" ]
[ "4\n", "0\n" ]
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
500
[ { "input": "7\n10 1 1 1 5 5 3", "output": "4" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "1\n1", "output": "0" }, { "input": "7\n3 5 2 2 5 2 4", "output": "4" }, { "input": "5\n1 5 4 2 3", "output": "4" } ]
1,654,396,633
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) l = a[::-1] a.sort() c = 0 for i in range(n): if(l[i] == a[i]): c += 1 print(n - c)
Title: Reorder the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. Output Specification: Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. Demo Input: ['7\n10 1 1 1 5 5 3\n', '5\n1 1 1 1 1\n'] Demo Output: ['4\n', '0\n'] Note: In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4. In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) l = a[::-1] a.sort() c = 0 for i in range(n): if(l[i] == a[i]): c += 1 print(n - c) ```
0
701
B
Cells Not Under Attack
PROGRAMMING
1,200
[ "data structures", "math" ]
null
null
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack. You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks. Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.
Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put.
[ "3 3\n1 1\n3 1\n2 2\n", "5 2\n1 5\n5 1\n", "100000 1\n300 400\n" ]
[ "4 2 0 \n", "16 9 \n", "9999800001 \n" ]
On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.
750
[ { "input": "3 3\n1 1\n3 1\n2 2", "output": "4 2 0 " }, { "input": "5 2\n1 5\n5 1", "output": "16 9 " }, { "input": "100000 1\n300 400", "output": "9999800001 " }, { "input": "10 4\n2 8\n1 8\n9 8\n6 9", "output": "81 72 63 48 " }, { "input": "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14", "output": "841 784 729 702 650 600 600 552 506 484 441 400 380 380 361 342 324 289 272 272 255 240 225 225 210 196 182 182 168 143 " }, { "input": "70 31\n22 39\n33 43\n50 27\n70 9\n20 67\n61 24\n60 4\n60 28\n4 25\n30 29\n46 47\n51 48\n37 5\n14 29\n45 44\n68 35\n52 21\n7 37\n18 43\n44 22\n26 12\n39 37\n51 55\n50 23\n51 16\n16 49\n22 62\n35 45\n56 2\n20 51\n3 37", "output": "4761 4624 4489 4356 4225 4096 3969 3906 3782 3660 3540 3422 3306 3249 3136 3025 2916 2809 2756 2652 2550 2499 2450 2401 2352 2256 2208 2115 2024 1978 1935 " }, { "input": "330 17\n259 262\n146 20\n235 69\n84 74\n131 267\n153 101\n32 232\n214 212\n239 157\n121 156\n10 45\n266 78\n52 258\n109 279\n193 276\n239 142\n321 89", "output": "108241 107584 106929 106276 105625 104976 104329 103684 103041 102400 101761 101124 100489 99856 99225 98910 98282 " }, { "input": "500 43\n176 85\n460 171\n233 260\n73 397\n474 35\n290 422\n309 318\n280 415\n485 169\n106 22\n355 129\n180 301\n205 347\n197 93\n263 318\n336 382\n314 350\n476 214\n367 277\n333 166\n500 376\n236 17\n94 73\n116 204\n166 50\n168 218\n144 369\n340 91\n274 360\n171 360\n41 251\n262 478\n27 163\n151 491\n208 415\n448 386\n293 486\n371 479\n330 435\n220 374\n163 316\n155 158\n26 126", "output": "249001 248004 247009 246016 245025 244036 243049 242064 241081 240100 239121 238144 237169 236196 235710 234740 233772 232806 231842 230880 229920 228962 228006 227052 226100 225150 224202 223256 222312 221840 220899 219960 219023 218088 217620 216688 215758 214830 213904 212980 212058 211138 210220 " }, { "input": "99999 1\n54016 16192", "output": "9999600004 " }, { "input": "99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281", "output": "9998000100 9997800121 9997600144 9997400169 9997200196 9997000225 9996800256 9996600289 9996400324 " }, { "input": "1 1\n1 1", "output": "0 " } ]
1,589,790,356
2,147,483,647
PyPy 3
OK
TESTS
40
1,543
30,208,000
m,n=map(int,input().split()) s,q=m,m row=[0]*(m+1) co=[0]*(m+1) for i in range(n): a,b=map(int,input().split()) if row[a]==0: row[a]=1 s=s-1 if co[b]==0: co[b]=1 q=q-1 if i!=n-1: print(s*q,end=" ") else: print(s*q)
Title: Cells Not Under Attack Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another. The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack. You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks. Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. Output Specification: Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. Demo Input: ['3 3\n1 1\n3 1\n2 2\n', '5 2\n1 5\n5 1\n', '100000 1\n300 400\n'] Demo Output: ['4 2 0 \n', '16 9 \n', '9999800001 \n'] Note: On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.
```python m,n=map(int,input().split()) s,q=m,m row=[0]*(m+1) co=[0]*(m+1) for i in range(n): a,b=map(int,input().split()) if row[a]==0: row[a]=1 s=s-1 if co[b]==0: co[b]=1 q=q-1 if i!=n-1: print(s*q,end=" ") else: print(s*q) ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,694,182,579
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
122
0
n=int(input()) proportion=input().split() orange_volume=0 for i in range(0,n): orange_volume+=int(proportion[i]) print(orange_volume/3)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python n=int(input()) proportion=input().split() orange_volume=0 for i in range(0,n): orange_volume+=int(proportion[i]) print(orange_volume/3) ```
0
369
C
Valera and Elections
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "trees" ]
null
null
The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree.
In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them.
[ "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n", "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n", "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n" ]
[ "1\n5 \n", "1\n3 \n", "4\n5 4 3 2 \n" ]
none
1,500
[ { "input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2", "output": "1\n5 " }, { "input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1", "output": "1\n3 " }, { "input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2", "output": "4\n5 4 3 2 " }, { "input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2", "output": "1\n2 " }, { "input": "2\n1 2 1", "output": "0" }, { "input": "10\n7 5 1\n2 1 2\n8 7 2\n2 4 1\n4 5 2\n9 5 1\n3 2 2\n2 10 1\n6 5 2", "output": "3\n8 6 3 " }, { "input": "2\n2 1 1", "output": "0" }, { "input": "2\n1 2 2", "output": "1\n2 " }, { "input": "5\n3 1 1\n4 5 1\n1 4 1\n1 2 1", "output": "0" }, { "input": "5\n1 3 2\n5 4 2\n2 1 2\n4 3 2", "output": "2\n5 2 " }, { "input": "10\n1 9 1\n3 2 2\n1 2 2\n4 7 2\n3 5 2\n4 3 2\n10 3 2\n7 8 2\n3 6 1", "output": "3\n8 10 5 " }, { "input": "10\n7 9 2\n2 6 2\n7 4 1\n5 4 2\n3 2 1\n8 5 2\n4 3 2\n7 10 1\n1 2 2", "output": "3\n9 8 6 " }, { "input": "10\n3 9 1\n2 10 2\n1 7 1\n3 4 1\n7 8 2\n1 2 1\n5 3 1\n5 6 2\n2 3 2", "output": "3\n6 10 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 1\n7 5 1\n6 4 1\n5 3 1\n4 2 1", "output": "2\n7 8 " }, { "input": "10\n1 10 2\n10 9 2\n10 8 2\n9 7 2\n8 6 2\n7 5 2\n6 4 2\n5 3 2\n4 2 2", "output": "2\n3 2 " }, { "input": "4\n1 2 2\n2 3 1\n2 4 2", "output": "1\n4 " } ]
1,580,853,166
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
14,336,000
def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations n=I() white=[0]*n con=[0]*n for i in range(n): con[i]=[] for i in range(n-1): x,y,t=R() con[x-1].append(y-1) con[y-1].append(x-1) if t==2: white[x-1]=1 white[y-1]=1 d=[0]*n def dfs(x,prev): ans=0 if white[x]: ans+=1 for i in con[x]: if i==prev: continue ans+=dfs(i,x) d[x]=ans return ans dfs(0,0) cnt=sum(d[x]==1 for x in range(n)) print(cnt) for i in range(n): if d[i]==1: print(i+1,end=' ')
Title: Valera and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The city Valera lives in is going to hold elections to the city Parliament. The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, for each road the residents decided if it is the problem road or not. A problem road is a road that needs to be repaired. There are *n* candidates running the elections. Let's enumerate all candidates in some way by integers from 1 to *n*, inclusive. If the candidate number *i* will be elected in the city Parliament, he will perform exactly one promise — to repair all problem roads on the way from the *i*-th district to the district 1, where the city Parliament is located. Help Valera and determine the subset of candidates such that if all candidates from the subset will be elected to the city Parliament, all problem roads in the city will be repaired. If there are several such subsets, you should choose the subset consisting of the minimum number of candidates. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city. Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *i*-th bidirectional road and the road type. If *t**i* equals to one, then the *i*-th road isn't the problem road; if *t**i* equals to two, then the *i*-th road is the problem road. It's guaranteed that the graph structure of the city is a tree. Output Specification: In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print any of them. Demo Input: ['5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n', '5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n', '5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n'] Demo Output: ['1\n5 \n', '1\n3 \n', '4\n5 4 3 2 \n'] Note: none
```python def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys from itertools import permutations n=I() white=[0]*n con=[0]*n for i in range(n): con[i]=[] for i in range(n-1): x,y,t=R() con[x-1].append(y-1) con[y-1].append(x-1) if t==2: white[x-1]=1 white[y-1]=1 d=[0]*n def dfs(x,prev): ans=0 if white[x]: ans+=1 for i in con[x]: if i==prev: continue ans+=dfs(i,x) d[x]=ans return ans dfs(0,0) cnt=sum(d[x]==1 for x in range(n)) print(cnt) for i in range(n): if d[i]==1: print(i+1,end=' ') ```
0
676
E
The Last Fight Between Human and AI
PROGRAMMING
2,400
[ "math" ]
null
null
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynomial Polynomial *P*(*x*) is said to be divisible by polynomial *Q*(*x*) if there exists a representation *P*(*x*)<==<=*B*(*x*)*Q*(*x*), where *B*(*x*) is also some polynomial. Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=|*k*|<=≤<=10<=000) — the size of the polynomial and the integer *k*. The *i*-th of the following *n*<=+<=1 lines contain character '?' if the coefficient near *x**i*<=-<=1 is yet undefined or the integer value *a**i*, if the coefficient is already known (<=-<=10<=000<=≤<=*a**i*<=≤<=10<=000). Each of integers *a**i* (and even *a**n*) may be equal to 0. Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
[ "1 2\n-1\n?\n", "2 100\n-10000\n0\n1\n", "4 5\n?\n1\n?\n1\n?\n" ]
[ "Yes\n", "Yes", "No" ]
In the first sample, computer set *a*<sub class="lower-index">0</sub> to  - 1 on the first move, so if human can set coefficient *a*<sub class="lower-index">1</sub> to 0.5 and win. In the second sample, all coefficients are already set and the resulting polynomial is divisible by *x* - 100, so the human has won.
2,250
[ { "input": "1 2\n-1\n?", "output": "Yes" }, { "input": "2 100\n-10000\n0\n1", "output": "Yes" }, { "input": "4 5\n?\n1\n?\n1\n?", "output": "No" }, { "input": "68 -9959\n-3666\n-3501\n9169\n5724\n1478\n-643\n-3039\n-5537\n-4295\n-1856\n-6720\n6827\n-39\n-9509\n-7005\n1942\n-5173\n-4564\n2390\n4604\n-6098\n-9847\n-9708\n2382\n7421\n8716\n9718\n9895\n-4553\n-8275\n4771\n1538\n-8131\n9912\n-4334\n-3702\n7035\n-106\n-1298\n-6190\n1321\n332\n7673\n-5336\n5141\n-2289\n-1748\n-3132\n-4454\n-2357\n2661\n2756\n-9964\n2859\n-1277\n-259\n-2472\n-9222\n2316\n-6965\n-7811\n-8158\n-9712\n105\n-960\n-1058\n9264\n-7353\n-2555", "output": "No" }, { "input": "5 10\n5400\n-900\n-1014\n325\n-32\n1", "output": "Yes" }, { "input": "5 -6\n-5400\n-2700\n414\n151\n-26\n1", "output": "No" }, { "input": "10 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n?", "output": "No" }, { "input": "9 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n?", "output": "Yes" }, { "input": "4 0\n0\n-10000\n10000\n-10000\n10000", "output": "Yes" }, { "input": "5 3\n?\n?\n?\n?\n?\n?", "output": "Yes" }, { "input": "4 4\n?\n?\n?\n?\n?", "output": "No" }, { "input": "5 6\n-5400\n-2700\n414\n151\n-26\n1", "output": "Yes" }, { "input": "5 10\n30\n27\n-53\n5\n-10\n1", "output": "Yes" }, { "input": "64 4\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "3 0\n5\n3\n?\n13", "output": "No" }, { "input": "4 0\n?\n10000\n-10000\n15\n?", "output": "Yes" }, { "input": "4 0\n0\n3\n?\n13\n?", "output": "Yes" }, { "input": "5 0\n?\n-123\n534\n?\n?\n?", "output": "No" }, { "input": "1 10000\n?\n?", "output": "Yes" }, { "input": "1 10000\n0\n0", "output": "Yes" }, { "input": "1 10000\n?\n0", "output": "Yes" }, { "input": "7 10000\n0\n0\n0\n0\n0\n0\n0\n10000", "output": "No" }, { "input": "32 2\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "64 2\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "100 100\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "No" }, { "input": "1 0\n1\n?", "output": "No" }, { "input": "2 0\n0\n?\n?", "output": "Yes" }, { "input": "18 10\n3\n2\n4\n0\n0\n0\n0\n0\n0\n6\n5\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "17 10\n3\n6\n0\n0\n0\n0\n0\n0\n7\n9\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "3 0\n1\n?\n?\n?", "output": "No" }, { "input": "2 0\n?\n?\n1", "output": "Yes" }, { "input": "1 0\n-1\n?", "output": "No" }, { "input": "17 10\n1\n1\n2\n4\n2\n0\n3\n6\n8\n3\n7\n1\n9\n8\n2\n3\n2\n1", "output": "No" }, { "input": "18 16\n13\n0\n7\n3\n5\n12\n11\n3\n15\n2\n13\n12\n12\n1\n3\n2\n13\n2\n1", "output": "No" }, { "input": "1 0\n?\n?", "output": "No" }, { "input": "102 31\n-1\n4\n-6\n3\n2\n-1\n-4\n7\n-4\n-1\n-1\n3\n4\n2\n1\n-7\n7\n2\n-4\n4\n5\n-4\n-4\n3\n1\n7\n-2\n9\n-6\n-12\n-9\n-1\n6\n3\n-6\n-1\n-7\n0\n-3\n0\n0\n-1\n4\n-4\n2\n-5\n4\n-6\n3\n-2\n-7\n-1\n7\n5\n1\n2\n-8\n1\n-1\n0\n-5\n-7\n1\n6\n7\n4\n5\n-4\n-3\n-3\n1\n-2\n-2\n1\n-5\n-1\n0\n4\n-1\n0\n0\n-1\n-1\n-5\n-6\n0\n-3\n0\n5\n4\n10\n-4\n-2\n6\n-6\n7\n3\n0\n8\n-4\n1\n4\n5", "output": "No" }, { "input": "26 10\n8\n2\n7\n7\n7\n7\n7\n0\n2\n6\n8\n5\n7\n9\n1\n1\n0\n3\n5\n5\n3\n2\n1\n0\n0\n0\n1", "output": "No" }, { "input": "53 10\n1\n1\n5\n8\n3\n2\n9\n9\n6\n2\n8\n7\n0\n3\n1\n2\n3\n1\n4\n3\n9\n5\n8\n4\n2\n0\n9\n0\n8\n5\n4\n5\n3\n2\n4\n2\n9\n8\n4\n9\n3\n1\n2\n9\n2\n3\n0\n2\n0\n9\n2\n4\n7\n1", "output": "No" }, { "input": "84 10\n9\n9\n1\n5\n7\n1\n9\n0\n9\n0\n2\n1\n4\n2\n8\n7\n5\n2\n4\n6\n1\n4\n2\n2\n1\n7\n6\n9\n0\n6\n4\n0\n3\n8\n9\n8\n3\n4\n0\n0\n4\n5\n2\n5\n7\n1\n9\n2\n1\n0\n0\n0\n2\n3\n6\n7\n1\n3\n1\n4\n6\n9\n5\n4\n8\n9\n2\n6\n8\n6\n4\n2\n0\n7\n3\n7\n9\n8\n3\n9\n1\n4\n7\n0\n1", "output": "No" }, { "input": "44 10\n9\n5\n1\n4\n5\n0\n9\n7\n8\n7\n1\n5\n2\n9\n1\n6\n9\n6\n0\n6\n3\n6\n7\n8\n7\n4\n2\n2\n9\n5\n4\n4\n5\n2\n3\n7\n7\n2\n4\n0\n3\n1\n8\n9\n5", "output": "No" }, { "input": "18 10\n3\n6\n0\n0\n0\n0\n0\n0\n0\n6\n1\n0\n0\n0\n0\n0\n0\n0\n1", "output": "No" }, { "input": "100 10000\n427\n5059\n4746\n3792\n2421\n1434\n4381\n9757\n9891\n45\n7135\n933\n8193\n805\n5369\n8487\n5065\n4881\n4459\n4228\n8920\n5272\n7420\n5685\n4612\n2641\n6890\n2826\n2318\n6590\n4634\n5534\n9709\n3951\n3604\n8736\n1303\n9939\n5769\n3690\n6163\n2136\n5933\n4906\n9187\n808\n7153\n5830\n2599\n6141\n5544\n7001\n7919\n205\n4770\n1869\n2840\n6\n100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "No" }, { "input": "19 10\n-6\n-1\n-6\n-1\n-5\n-5\n-9\n0\n-7\n-3\n-7\n0\n-4\n-4\n-7\n-6\n-4\n-4\n-8\n-1", "output": "No" }, { "input": "100 10000\n9137\n5648\n7125\n5337\n4138\n5127\n3419\n7396\n9781\n6103\n3941\n9511\n9183\n4193\n7945\n52\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "No" }, { "input": "2 0\n?\n1\n?", "output": "Yes" }, { "input": "30 1000\n564\n146\n187\n621\n589\n852\n981\n874\n602\n667\n263\n721\n246\n93\n992\n868\n168\n521\n618\n471\n511\n876\n742\n810\n899\n258\n172\n177\n523\n417\n68", "output": "No" }, { "input": "30 1000\n832\n350\n169\n416\n972\n507\n385\n86\n581\n80\n59\n281\n635\n507\n86\n639\n257\n738\n325\n285\n688\n20\n263\n763\n443\n467\n952\n928\n590\n876\n13", "output": "No" }, { "input": "1 0\n?\n1", "output": "Yes" }, { "input": "100 2\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n-1", "output": "No" }, { "input": "6 1000\n63\n0\n0\n16\n0\n0\n1", "output": "No" } ]
1,678,985,400
6,000
PyPy 3
WRONG_ANSWER
TESTS
8
93
0
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = [input().rstrip().decode() for _ in range(n + 1)] inf = pow(10, 9) + 1 b = [inf if i == "?" else int(i) for i in a] c = 0 for i in b: if i ^ inf: c += 1 if not k: ans = "No" if b[0] ^ inf or not c % 2 else "Yes" elif c == n + 1: for _ in range(n): u = b.pop() b[-1] += u * k ans = "Yes" if not b[0] else "No" else: ans = "Yes" if n % 2 else "No" print(ans)
Title: The Last Fight Between Human and AI Time Limit: None seconds Memory Limit: None megabytes Problem Description: 100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynomial Polynomial *P*(*x*) is said to be divisible by polynomial *Q*(*x*) if there exists a representation *P*(*x*)<==<=*B*(*x*)*Q*(*x*), where *B*(*x*) is also some polynomial. Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally? Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=|*k*|<=≤<=10<=000) — the size of the polynomial and the integer *k*. The *i*-th of the following *n*<=+<=1 lines contain character '?' if the coefficient near *x**i*<=-<=1 is yet undefined or the integer value *a**i*, if the coefficient is already known (<=-<=10<=000<=≤<=*a**i*<=≤<=10<=000). Each of integers *a**i* (and even *a**n*) may be equal to 0. Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move. Output Specification: Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise. Demo Input: ['1 2\n-1\n?\n', '2 100\n-10000\n0\n1\n', '4 5\n?\n1\n?\n1\n?\n'] Demo Output: ['Yes\n', 'Yes', 'No'] Note: In the first sample, computer set *a*<sub class="lower-index">0</sub> to  - 1 on the first move, so if human can set coefficient *a*<sub class="lower-index">1</sub> to 0.5 and win. In the second sample, all coefficients are already set and the resulting polynomial is divisible by *x* - 100, so the human has won.
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = [input().rstrip().decode() for _ in range(n + 1)] inf = pow(10, 9) + 1 b = [inf if i == "?" else int(i) for i in a] c = 0 for i in b: if i ^ inf: c += 1 if not k: ans = "No" if b[0] ^ inf or not c % 2 else "Yes" elif c == n + 1: for _ in range(n): u = b.pop() b[-1] += u * k ans = "Yes" if not b[0] else "No" else: ans = "Yes" if n % 2 else "No" print(ans) ```
0
399
B
Red and Blue Balls
PROGRAMMING
0
[]
null
null
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside. If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue.
Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\nRBR\n", "4\nRBBR\n", "5\nRBBRR\n" ]
[ "2\n", "6\n", "6\n" ]
The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2. The second example is depicted below. The blue arrow denotes a single operation.
1,000
[ { "input": "3\nRBR", "output": "2" }, { "input": "4\nRBBR", "output": "6" }, { "input": "5\nRBBRR", "output": "6" }, { "input": "5\nRBRBR", "output": "10" }, { "input": "10\nRRBRRBBRRR", "output": "100" }, { "input": "10\nBRBRRRRRRR", "output": "5" }, { "input": "10\nBRRRRRRRRR", "output": "1" }, { "input": "20\nBRBRRRRRRRRRRRRRRRRR", "output": "5" }, { "input": "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1073741820" }, { "input": "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1125899906842609" }, { "input": "20\nRRRBRBBBBBRRRRRRRRRR", "output": "1000" }, { "input": "20\nRRBRBBBBBRRRRRRRRRRR", "output": "500" }, { "input": "1\nR", "output": "0" }, { "input": "1\nB", "output": "1" }, { "input": "2\nRR", "output": "0" }, { "input": "2\nBR", "output": "1" }, { "input": "50\nRRRRRRRRRRBBBBBBRRBBRRRBRRBBBRRRRRRRRRRRRRRRRRRRRR", "output": "479001600" }, { "input": "50\nRBRRRRRBRBRRBBBBBBRRRBRRRRRBBBRRBRRRRRBBBRRRRRRRRR", "output": "1929382195842" }, { "input": "48\nRBRBRRRRBRBRRBRRRRRRRBBBRRBRBRRRBBRRRRRRRRRRRRRR", "output": "13235135754" }, { "input": "30\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "0" }, { "input": "50\nRRBBBBBBBBBBBBBBBBRBRRBBBRBBRBBBRRBRBBBBBRBBRBBRBR", "output": "402373705727996" }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1125899906842623" }, { "input": "19\nRRRRRBRRBRRRRBRBBBB", "output": "500000" }, { "input": "32\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBR", "output": "2147483647" }, { "input": "3\nBBB", "output": "7" }, { "input": "3\nBBR", "output": "3" }, { "input": "3\nBRB", "output": "5" }, { "input": "3\nBRR", "output": "1" }, { "input": "3\nRBB", "output": "6" }, { "input": "3\nRBR", "output": "2" }, { "input": "3\nRRB", "output": "4" }, { "input": "3\nRRR", "output": "0" }, { "input": "2\nRB", "output": "2" }, { "input": "2\nBB", "output": "3" } ]
1,501,423,535
2,147,483,647
Python 3
OK
TESTS
34
62
4,608,000
n = int(input()) s = input() ans = 0 for i in range(len(s)): ch = s[i] if ch == 'B': ans |= 1 << i print(ans)
Title: Red and Blue Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside. If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue. Output Specification: Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\nRBR\n', '4\nRBBR\n', '5\nRBBRR\n'] Demo Output: ['2\n', '6\n', '6\n'] Note: The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2. The second example is depicted below. The blue arrow denotes a single operation.
```python n = int(input()) s = input() ans = 0 for i in range(len(s)): ch = s[i] if ch == 'B': ans |= 1 << i print(ans) ```
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,607,768,021
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
0
n=input() s=0 t=0 for i in n: if i.isupper(): s+=1 elif i.islower(): t+=1 if s>=t: print(n.upper()) else: print(n.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 n=input() s=0 t=0 for i in n: if i.isupper(): s+=1 elif i.islower(): t+=1 if s>=t: print(n.upper()) else: print(n.lower()) ```
0
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,664,179,477
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
t = int(input()) for i in range(t): a = 0 angle = int(input()) for j in range(3, 30): if (angle == (180*(j-2))/j): print("YES") a = 1 break if (a == 0): print("NO")
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python t = int(input()) for i in range(t): a = 0 angle = int(input()) for j in range(3, 30): if (angle == (180*(j-2))/j): print("YES") a = 1 break if (a == 0): print("NO") ```
0
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" }, { "input": "3\nb\nb\nb", "output": "OK\nb1\nb2" }, { "input": "2\nc\ncn", "output": "OK\nOK" }, { "input": "3\nvhn\nvhn\nh", "output": "OK\nvhn1\nOK" }, { "input": "4\nd\nhd\nd\nh", "output": "OK\nOK\nd1\nOK" }, { "input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp", "output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9" }, { "input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh", "output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7" }, { "input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj", "output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4" }, { "input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4" }, { "input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz", "output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3" } ]
1,690,048,851
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
62
0
n = int(input()) Name = [] f = 0 for a in range(n - 1): name = input() if f == 0: Name += [name] name = input() f += 1 lengthName = len(name) c = 0 b = 0 while b != len(Name): if name == Name[c] and len(name) == lengthName: name += "1" elif name == Name[c] and len(name) > lengthName: name = name[0:lengthName] + str(int(name[lengthName:len(name)]) + 1) c += 1 b += 1 Name += [name] c = 0 for e in range(n): name = Name[c] if name[-1] == "0" or name[-1] == "1" or name[-1] == "2" or name[-1] == "3" or name[-1] == "4" or name[-1] == "5" or name[-1] == "6" or name[-1] == "7" or name[-1] == "8" or name[-1] == "9": print(name) else: print("OK") c += 1 exit()
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. Output Specification: Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. Demo Input: ['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n'] Demo Output: ['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n'] Note: none
```python n = int(input()) Name = [] f = 0 for a in range(n - 1): name = input() if f == 0: Name += [name] name = input() f += 1 lengthName = len(name) c = 0 b = 0 while b != len(Name): if name == Name[c] and len(name) == lengthName: name += "1" elif name == Name[c] and len(name) > lengthName: name = name[0:lengthName] + str(int(name[lengthName:len(name)]) + 1) c += 1 b += 1 Name += [name] c = 0 for e in range(n): name = Name[c] if name[-1] == "0" or name[-1] == "1" or name[-1] == "2" or name[-1] == "3" or name[-1] == "4" or name[-1] == "5" or name[-1] == "6" or name[-1] == "7" or name[-1] == "8" or name[-1] == "9": print(name) else: print("OK") c += 1 exit() ```
-1
774
D
Lie or Truth
PROGRAMMING
1,500
[ "*special", "constructive algorithms", "implementation", "sortings" ]
null
null
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to *b*1,<=*b*2,<=...,<=*b**n*. Stepan said that he swapped only cubes which where on the positions between *l* and *r*, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions *l* and *r*, inclusive, in some way). Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
[ "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n", "3 1 2\n1 2 3\n3 1 2\n", "4 2 4\n1 1 1 1\n1 1 1 1\n" ]
[ "TRUTH\n", "LIE\n", "TRUTH\n" ]
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]). In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother. In the third example for any values *l* and *r* there is a situation when Stepan said the truth.
0
[ { "input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH" }, { "input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE" }, { "input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH" }, { "input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "output": "TRUTH" }, { "input": "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4", "output": "TRUTH" }, { "input": "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6", "output": "TRUTH" }, { "input": "1 1 1\n1\n1", "output": "TRUTH" }, { "input": "4 3 4\n1 2 3 4\n2 1 3 4", "output": "LIE" }, { "input": "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7", "output": "LIE" }, { "input": "5 1 2\n1 2 3 4 5\n1 2 3 5 4", "output": "LIE" }, { "input": "8 3 6\n5 3 1 1 1 1 3 5\n3 3 1 1 1 1 5 5", "output": "LIE" }, { "input": "4 2 2\n2 1 2 2\n1 2 2 2", "output": "LIE" } ]
1,491,409,368
2,868
Python 3
OK
TESTS
52
140
14,950,400
n, l, r = map(int, input().split()) l -= 1 r -= 1 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if (b[i] != a[i]) and (i < l or i > r): print("LIE") break else: print("TRUTH")
Title: Lie or Truth Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*. While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to *b*1,<=*b*2,<=...,<=*b**n*. Stepan said that he swapped only cubes which where on the positions between *l* and *r*, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions *l* and *r*, inclusive, in some way). Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother. Input Specification: The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes. Output Specification: Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes). Demo Input: ['5 2 4\n3 4 2 3 1\n3 2 3 4 1\n', '3 1 2\n1 2 3\n3 1 2\n', '4 2 4\n1 1 1 1\n1 1 1 1\n'] Demo Output: ['TRUTH\n', 'LIE\n', 'TRUTH\n'] Note: In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]). In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother. In the third example for any values *l* and *r* there is a situation when Stepan said the truth.
```python n, l, r = map(int, input().split()) l -= 1 r -= 1 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if (b[i] != a[i]) and (i < l or i > r): print("LIE") break else: print("TRUTH") ```
3
172
C
Bus
PROGRAMMING
1,500
[ "*special", "implementation", "sortings" ]
null
null
There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct). We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, that is, towards the positive direction of the coordinate axis, and back. The *i*-th student needs to get to the point with coordinate *x**i* (*x**i*<=&gt;<=0). The bus moves by the following algorithm. Initially it is at point 0. The students consistently come to the stop and get on it. The bus has a seating capacity which is equal to *m* passengers. At the moment when *m* students get on the bus, it starts moving in the positive direction of the coordinate axis. Also it starts moving when the last (*n*-th) student gets on the bus. The bus is moving at a speed of 1 unit of distance per 1 unit of time, i.e. it covers distance *y* in time *y*. Every time the bus passes the point at which at least one student needs to get off, it stops and these students get off the bus. The students need 1<=+<=[*k*<=/<=2] units of time to get off the bus, where *k* is the number of students who leave at this point. Expression [*k*<=/<=2] denotes rounded down *k*<=/<=2. As soon as the last student leaves the bus, the bus turns around and goes back to the point *x*<==<=0. It doesn't make any stops until it reaches the point. At the given point the bus fills with students once more, and everything is repeated. If students come to the stop when there's no bus, they form a line (queue) and get on the bus in the order in which they came. Any number of students get on the bus in negligible time, you should assume that it doesn't take any time. Any other actions also take no time. The bus has no other passengers apart from the students. Write a program that will determine for each student the time when he got off the bus. The moment a student got off the bus is the moment the bus stopped at the student's destination stop (despite the fact that the group of students need some time to get off).
The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of students and the number of passengers the bus can transport, correspondingly. Next *n* lines contain descriptions of the students, one per line. Each line contains a pair of integers *t**i*,<=*x**i* (1<=≤<=*t**i*<=≤<=105,<=1<=≤<=*x**i*<=≤<=104). The lines are given in the order of strict increasing of *t**i*. Values of *x**i* can coincide.
Print *n* numbers *w*1,<=*w*2,<=...,<=*w**n*, *w**i* — the moment of time when the *i*-th student got off the bus. Print the numbers on one line and separate them with single spaces.
[ "1 10\n3 5\n", "2 1\n3 5\n4 5\n", "5 4\n3 5\n4 5\n5 5\n6 5\n7 1\n", "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2\n" ]
[ "8\n", "8 19\n", "11 11 11 11 20\n", "51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195\n" ]
In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8. In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This student is the same as the student from the first sample. So the bus arrives to his destination at the moment of time 8, spends 1 + [1 / 2] = 1 units of time on getting him off, and returns back to 0 in additional 5 units of time. That is, the bus returns to the bus stop at the moment of time 14. By this moment the second student has already came to the bus stop. So he immediately gets in the bus, and is driven to his destination in additional 5 units of time. He gets there at the moment 14 + 5 = 19. In the third sample the bus waits for the fourth student for 6 units of time, then drives for 5 units of time, then gets the passengers off for 1 + [4 / 2] = 3 units of time, then returns for 5 units of time, and then drives the fifth student for 1 unit of time.
1,500
[ { "input": "1 10\n3 5", "output": "8" }, { "input": "2 1\n3 5\n4 5", "output": "8 19" }, { "input": "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "output": "11 11 11 11 20" }, { "input": "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2", "output": "51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195" }, { "input": "1 1\n109 15", "output": "124" }, { "input": "2 1\n43 5\n102 1", "output": "48 103" }, { "input": "4 2\n7 1\n12 14\n90 15\n176 1", "output": "13 27 192 177" }, { "input": "8 8\n48 14\n74 12\n94 4\n127 14\n151 11\n173 4\n190 14\n191 9", "output": "210 207 195 210 205 195 210 202" }, { "input": "16 1\n29 10\n48 13\n53 10\n54 5\n59 6\n67 9\n68 10\n95 13\n132 5\n148 6\n150 6\n154 6\n169 10\n171 10\n185 6\n198 6", "output": "39 63 87 103 115 131 151 175 194 206 219 232 249 270 287 300" }, { "input": "32 3\n9 2\n12 4\n13 7\n14 7\n15 4\n19 10\n20 10\n29 2\n38 7\n58 4\n59 1\n61 4\n73 4\n90 1\n92 4\n95 7\n103 4\n107 7\n119 4\n121 4\n122 10\n123 10\n127 2\n134 10\n142 7\n144 7\n151 10\n160 7\n165 10\n191 1\n197 1\n199 7", "output": "15 18 22 38 34 42 65 55 61 81 77 81 97 93 97 115 111 115 128 128 136 158 149 158 177 177 182 201 205 194 217 224" }, { "input": "32 4\n4 6\n7 5\n13 6\n27 6\n39 5\n48 5\n57 11\n62 13\n64 11\n68 11\n84 9\n86 5\n89 6\n91 6\n107 13\n108 13\n113 11\n120 13\n126 5\n130 6\n134 9\n136 6\n137 5\n139 9\n143 5\n154 9\n155 5\n157 13\n171 11\n179 11\n185 13\n190 5", "output": "34 32 34 34 67 67 75 78 105 105 102 97 124 124 133 133 161 164 153 155 189 185 183 189 205 211 205 216 242 242 246 235" }, { "input": "32 5\n12 11\n17 14\n21 2\n24 2\n35 7\n41 15\n51 11\n52 2\n53 2\n61 14\n62 14\n75 2\n89 15\n90 14\n95 7\n102 7\n104 2\n105 14\n106 14\n109 2\n133 2\n135 2\n143 14\n151 11\n155 14\n168 15\n169 15\n179 14\n180 7\n181 15\n186 7\n198 14", "output": "49 53 37 37 44 87 81 70 70 85 119 105 122 119 111 147 140 155 155 140 173 173 188 184 188 221 221 219 211 221 245 253" }, { "input": "32 6\n15 12\n24 6\n30 13\n35 6\n38 6\n46 6\n47 12\n60 6\n66 9\n71 15\n74 6\n76 15\n104 6\n105 6\n110 15\n124 12\n126 12\n129 9\n131 12\n134 15\n135 15\n141 12\n154 13\n167 9\n171 9\n179 15\n181 15\n185 12\n189 12\n191 6\n192 6\n196 12", "output": "61 52 63 52 52 52 92 83 88 96 83 96 135 135 149 144 144 140 180 186 186 180 183 176 213 222 222 217 217 209 245 252" }, { "input": "32 7\n4 14\n6 14\n17 4\n22 3\n29 4\n32 4\n39 10\n40 11\n44 11\n51 11\n57 10\n76 4\n82 4\n87 14\n88 10\n118 10\n121 10\n136 14\n141 3\n143 4\n159 10\n162 10\n163 11\n165 10\n171 4\n172 10\n175 4\n176 3\n179 10\n196 10\n197 3\n198 10", "output": "57 57 44 42 44 44 52 101 101 101 99 91 91 106 171 171 171 178 162 164 171 206 209 206 198 206 198 196 232 232 224 232" }, { "input": "32 8\n12 9\n26 8\n27 8\n29 9\n43 11\n44 9\n45 5\n48 5\n50 8\n53 8\n57 9\n69 8\n76 11\n86 1\n88 9\n103 5\n116 9\n131 8\n139 8\n142 5\n148 1\n152 8\n154 8\n167 1\n170 5\n172 5\n173 5\n181 8\n183 1\n185 1\n190 1\n200 5", "output": "61 58 58 61 65 61 53 53 113 113 116 113 120 104 116 109 182 178 178 174 168 178 178 168 207 207 207 213 201 201 201 207" } ]
1,651,327,818
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
7,987,200
def solution_task3(): data = input().split(" ") n = int(data[0]) m = int(data[1]) students = dict() for i in range(n): data = input().split(" ") students[int(data[0])] = int(data[1]) current_passengers = 0 total_time = 0 students_per_time = [ti for ti in students.keys()] students_per_time.sort() current_passengers_info = list() students_out_info = dict() i = 0 while i < len(students) or current_passengers != 0: if total_time >= students_per_time[i]: current_passengers += 1 current_passengers_info.append((students_per_time[i], students[students_per_time[i]])) i += 1 else: total_time += 1 if current_passengers == m or i == n: x = 0 while current_passengers > 0: x += 1 total_time += 1 out_count = 0 for j in range(len(current_passengers_info)): if current_passengers_info[j][1] == x: out_count += 1 students_out_info[current_passengers_info[j][0]] = total_time current_passengers -= 1 if out_count != 0: total_time = total_time + 1 + (out_count // 2) current_passengers_info = [] total_time += x result = [] for key in students.keys(): result.append(students_out_info[key]) return " ".join(str(el) for el in result) result = solution_task3() print(result)
Title: Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a bus stop near the university. The lessons are over, and *n* students come to the stop. The *i*-th student will appear at the bus stop at time *t**i* (all *t**i*'s are distinct). We shall assume that the stop is located on the coordinate axis *Ox*, at point *x*<==<=0, and the bus goes along the ray *Ox*, that is, towards the positive direction of the coordinate axis, and back. The *i*-th student needs to get to the point with coordinate *x**i* (*x**i*<=&gt;<=0). The bus moves by the following algorithm. Initially it is at point 0. The students consistently come to the stop and get on it. The bus has a seating capacity which is equal to *m* passengers. At the moment when *m* students get on the bus, it starts moving in the positive direction of the coordinate axis. Also it starts moving when the last (*n*-th) student gets on the bus. The bus is moving at a speed of 1 unit of distance per 1 unit of time, i.e. it covers distance *y* in time *y*. Every time the bus passes the point at which at least one student needs to get off, it stops and these students get off the bus. The students need 1<=+<=[*k*<=/<=2] units of time to get off the bus, where *k* is the number of students who leave at this point. Expression [*k*<=/<=2] denotes rounded down *k*<=/<=2. As soon as the last student leaves the bus, the bus turns around and goes back to the point *x*<==<=0. It doesn't make any stops until it reaches the point. At the given point the bus fills with students once more, and everything is repeated. If students come to the stop when there's no bus, they form a line (queue) and get on the bus in the order in which they came. Any number of students get on the bus in negligible time, you should assume that it doesn't take any time. Any other actions also take no time. The bus has no other passengers apart from the students. Write a program that will determine for each student the time when he got off the bus. The moment a student got off the bus is the moment the bus stopped at the student's destination stop (despite the fact that the group of students need some time to get off). Input Specification: The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of students and the number of passengers the bus can transport, correspondingly. Next *n* lines contain descriptions of the students, one per line. Each line contains a pair of integers *t**i*,<=*x**i* (1<=≤<=*t**i*<=≤<=105,<=1<=≤<=*x**i*<=≤<=104). The lines are given in the order of strict increasing of *t**i*. Values of *x**i* can coincide. Output Specification: Print *n* numbers *w*1,<=*w*2,<=...,<=*w**n*, *w**i* — the moment of time when the *i*-th student got off the bus. Print the numbers on one line and separate them with single spaces. Demo Input: ['1 10\n3 5\n', '2 1\n3 5\n4 5\n', '5 4\n3 5\n4 5\n5 5\n6 5\n7 1\n', '20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2\n'] Demo Output: ['8\n', '8 19\n', '11 11 11 11 20\n', '51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195\n'] Note: In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8. In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This student is the same as the student from the first sample. So the bus arrives to his destination at the moment of time 8, spends 1 + [1 / 2] = 1 units of time on getting him off, and returns back to 0 in additional 5 units of time. That is, the bus returns to the bus stop at the moment of time 14. By this moment the second student has already came to the bus stop. So he immediately gets in the bus, and is driven to his destination in additional 5 units of time. He gets there at the moment 14 + 5 = 19. In the third sample the bus waits for the fourth student for 6 units of time, then drives for 5 units of time, then gets the passengers off for 1 + [4 / 2] = 3 units of time, then returns for 5 units of time, and then drives the fifth student for 1 unit of time.
```python def solution_task3(): data = input().split(" ") n = int(data[0]) m = int(data[1]) students = dict() for i in range(n): data = input().split(" ") students[int(data[0])] = int(data[1]) current_passengers = 0 total_time = 0 students_per_time = [ti for ti in students.keys()] students_per_time.sort() current_passengers_info = list() students_out_info = dict() i = 0 while i < len(students) or current_passengers != 0: if total_time >= students_per_time[i]: current_passengers += 1 current_passengers_info.append((students_per_time[i], students[students_per_time[i]])) i += 1 else: total_time += 1 if current_passengers == m or i == n: x = 0 while current_passengers > 0: x += 1 total_time += 1 out_count = 0 for j in range(len(current_passengers_info)): if current_passengers_info[j][1] == x: out_count += 1 students_out_info[current_passengers_info[j][0]] = total_time current_passengers -= 1 if out_count != 0: total_time = total_time + 1 + (out_count // 2) current_passengers_info = [] total_time += x result = [] for key in students.keys(): result.append(students_out_info[key]) return " ".join(str(el) for el in result) result = solution_task3() print(result) ```
0
352
A
Jeff and Digits
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
[ "4\n5 0 5 0\n", "11\n5 5 5 5 5 5 5 5 0 5 5\n" ]
[ "0\n", "5555555550\n" ]
In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
500
[ { "input": "4\n5 0 5 0", "output": "0" }, { "input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550" }, { "input": "7\n5 5 5 5 5 5 5", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "11\n5 0 5 5 5 0 0 5 5 5 5", "output": "0" }, { "input": "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "9\n5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n5 5 5 5 5 0 0 5 0 5", "output": "0" }, { "input": "3\n5 5 0", "output": "0" }, { "input": "5\n5 5 0 5 5", "output": "0" }, { "input": "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5", "output": "0" }, { "input": "3\n5 5 5", "output": "-1" }, { "input": "3\n0 5 5", "output": "0" }, { "input": "13\n0 0 5 0 5 0 5 5 0 0 0 0 0", "output": "0" }, { "input": "9\n5 5 0 5 5 5 5 5 5", "output": "0" }, { "input": "8\n0 0 0 0 0 0 0 0", "output": "0" }, { "input": "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0", "output": "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0", "output": "555555555000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n5 0 0", "output": "0" }, { "input": "4\n5 5 5 5", "output": "-1" }, { "input": "2\n0 5", "output": "0" }, { "input": "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "10\n5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" } ]
1,685,865,880
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n = int(input()) a = 0 b = 0 s = input().split() for i in s: if i == "5": a += 1 if i == "0": b += 1 if a >= 9 : if b > 0: print("5"*9,"0"*b,sep="") else: print(-1) else: if b > 0: print(0) else: print(-1)
Title: Jeff and Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. Output Specification: In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. Demo Input: ['4\n5 0 5 0\n', '11\n5 5 5 5 5 5 5 5 0 5 5\n'] Demo Output: ['0\n', '5555555550\n'] Note: In the first test you can make only one number that is a multiple of 90 — 0. In the second test you can make number 5555555550, it is a multiple of 90.
```python n = int(input()) a = 0 b = 0 s = input().split() for i in s: if i == "5": a += 1 if i == "0": b += 1 if a >= 9 : if b > 0: print("5"*9,"0"*b,sep="") else: print(-1) else: if b > 0: print(0) else: print(-1) ```
0
0
none
none
none
0
[ "none" ]
null
null
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*.
The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*.
In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them.
[ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ]
[ "4 3 6 2", "42 ", "1 1 " ]
none
0
[ { "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 " }, { "input": "1\n42", "output": "42 " }, { "input": "2\n1 1 1 1", "output": "1 1 " }, { "input": "2\n54748096 1 641009859 1", "output": "54748096 641009859 " }, { "input": "3\n1 7 923264237 374288891 7 524125987 1 1 1", "output": "374288891 524125987 923264237 " }, { "input": "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "output": "496813081 561219907 673102149 702209411 " }, { "input": "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "output": "291882089 365329221 412106895 564718673 585325539 " }, { "input": "5\n1 161 1 534447872 161 233427865 1 7 7 73701396 1 401939237 4 1 1 1 1 1 7 115704211 1 4 1 7 1", "output": "73701396 115704211 233427865 401939237 534447872 " }, { "input": "5\n2 11 1 1 2 4 2 1 181951 4 345484316 2 4 4 4 2 1 140772746 1 634524 4 521302304 1 2 11", "output": "181951 634524 140772746 345484316 521302304 " }, { "input": "5\n27 675 1 1 347621274 5 2 13 189 738040275 5 1 189 13 1 959752125 770516962 769220855 5 5 2 675 1 1 27", "output": "347621274 738040275 769220855 770516962 959752125 " }, { "input": "5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2029 165353355 4058 2029 731472761 739767313 2029 2029 2029 585281282", "output": "165353355 527243766 585281282 731472761 739767313 " }, { "input": "5\n537163 537163 537163 537163 537163 537163 1074326 537163 537163 537163 515139317 1074326 537163 537163 537163 539311652 321760637 170817834 537163 537163 537163 537163 537163 537163 392666153", "output": "170817834 321760637 392666153 515139317 539311652 " }, { "input": "4\n1 188110 607844 2 1 1 695147 1 1 1 143380513 1 1 1 1 2", "output": "188110 607844 695147 143380513 " }, { "input": "4\n3 1 96256522 120 360284388 3 3 2 2 2 3 12 12 2 1 198192381", "output": "120 96256522 198192381 360284388 " }, { "input": "4\n67025 13405 1915 1915 1915 1915 5745 676469920 53620 5745 660330300 67025 53620 380098775 533084295 13405", "output": "380098775 533084295 660330300 676469920 " }, { "input": "4\n700521 233507 759364764 467014 468181535 233507 233507 890362191 233507 700521 467014 233507 946637378 233507 233507 233507", "output": "468181535 759364764 890362191 946637378 " }, { "input": "3\n484799 1 1 744137 1 1 909312183 1 1", "output": "484799 744137 909312183 " }, { "input": "3\n1 716963379 1 1 205 1 1 964 1", "output": "205 964 716963379 " }, { "input": "3\n5993 781145599 54740062 5993 5993 267030101 5993 5993 5993", "output": "54740062 267030101 781145599 " }, { "input": "3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339", "output": "55451923 435485671 531222142 " }, { "input": "5\n4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1", "output": "1 2 4 4 4 " }, { "input": "4\n1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3", "output": "1 1 3 3 " }, { "input": "6\n1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6", "output": "1 3 3 6 6 6 " } ]
1,464,898,753
3,373
Python 3
OK
TESTS
54
811
23,859,200
import fractions import collections n = int(input()) l = sorted(map(int, input().split(" ")), reverse = True) aux = [] cont = collections.Counter(l) r = [] for i in l: if not cont[i]: continue r.append(i) cont[i] -= 1 for j in aux: '''print(str(i) + " " + str(j))''' cont[fractions.gcd(i, j)] -= 2 aux.append(i) print(' '.join(map(str, r)))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*. Output Specification: In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. Demo Input: ['4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n', '1\n42\n', '2\n1 1 1 1\n'] Demo Output: ['4 3 6 2', '42 ', '1 1 '] Note: none
```python import fractions import collections n = int(input()) l = sorted(map(int, input().split(" ")), reverse = True) aux = [] cont = collections.Counter(l) r = [] for i in l: if not cont[i]: continue r.append(i) cont[i] -= 1 for j in aux: '''print(str(i) + " " + str(j))''' cont[fractions.gcd(i, j)] -= 2 aux.append(i) print(' '.join(map(str, r))) ```
3
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. 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. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "output": "8" }, { "input": "774", "output": "13" }, { "input": "4", "output": "1" }, { "input": "4447747", "output": "140" }, { "input": "7747474", "output": "233" }, { "input": "4444", "output": "15" }, { "input": "4447", "output": "16" }, { "input": "7", "output": "2" }, { "input": "4", "output": "1" }, { "input": "4447744", "output": "139" }, { "input": "77474", "output": "57" }, { "input": "7747", "output": "28" }, { "input": "444", "output": "7" }, { "input": "7", "output": "2" }, { "input": "7774477", "output": "242" }, { "input": "4477774", "output": "157" }, { "input": "7444", "output": "23" }, { "input": "7474747", "output": "212" }, { "input": "77", "output": "6" }, { "input": "774477", "output": "114" }, { "input": "7", "output": "2" }, { "input": "47", "output": "4" }, { "input": "747777", "output": "110" }, { "input": "444444444", "output": "511" }, { "input": "777777777", "output": "1022" }, { "input": "477477447", "output": "728" }, { "input": "777744747", "output": "996" } ]
1,610,286,670
2,147,483,647
PyPy 3
OK
TESTS
33
108
0
a = int(input()) b = str(a) h = 0 t = len(b) for x in range(t): if b[x] == "4": h += (2**(t-1-x))*1 else: h += (2**(t-1-x))*2 print(h)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. 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. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. Input Specification: The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the index of *n* among all lucky numbers. Demo Input: ['4\n', '7\n', '77\n'] Demo Output: ['1\n', '2\n', '6\n'] Note: none
```python a = int(input()) b = str(a) h = 0 t = len(b) for x in range(t): if b[x] == "4": h += (2**(t-1-x))*1 else: h += (2**(t-1-x))*2 print(h) ```
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,686,847,217
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def abbreviate_words(text): words = text.split() abbreviated_text = [] for word in words: if len(word) > 10: abbreviation = word[0] + str(len(word) - 2) + word[-1] abbreviated_text.append(abbreviation) else: abbreviated_text.append(word) return ' '.join(abbreviated_text) # Example usage input_text = "Sometimes some words like localization or internationalization are so long that writing them many times in one text is quite tiresome." abbreviated_text = abbreviate_words(input_text) print(abbreviated_text)
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 def abbreviate_words(text): words = text.split() abbreviated_text = [] for word in words: if len(word) > 10: abbreviation = word[0] + str(len(word) - 2) + word[-1] abbreviated_text.append(abbreviation) else: abbreviated_text.append(word) return ' '.join(abbreviated_text) # Example usage input_text = "Sometimes some words like localization or internationalization are so long that writing them many times in one text is quite tiresome." abbreviated_text = abbreviate_words(input_text) print(abbreviated_text) ```
0
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "input": "xulsyfkuizjauadjjopu", "output": "526" }, { "input": "e", "output": "51" }, { "input": "zv", "output": "76" }, { "input": "jgv", "output": "101" }, { "input": "zsfo", "output": "126" }, { "input": "jselr", "output": "151" }, { "input": "dwemig", "output": "176" }, { "input": "mddoxsf", "output": "201" }, { "input": "jgirkrmi", "output": "226" }, { "input": "spkxurcum", "output": "251" }, { "input": "fykkiubdkt", "output": "276" }, { "input": "fznbcxsxygs", "output": "301" }, { "input": "qcrvrdqcbtou", "output": "326" }, { "input": "qktrbjzrqgmlr", "output": "351" }, { "input": "foamodbvptlxxg", "output": "376" }, { "input": "ydzpjhsidipricw", "output": "401" }, { "input": "lpfpndmjfvqejdgf", "output": "426" }, { "input": "ofkvparuvjtggnmab", "output": "451" }, { "input": "xxncfutrtxcwdzwbgs", "output": "476" }, { "input": "zovhffccflkgqncsdte", "output": "501" }, { "input": "cskgsxywlvfeicoueglr", "output": "526" }, { "input": "gggggggggggggggggggg", "output": "526" }, { "input": "qdqdddqddqqddqddqdqd", "output": "526" }, { "input": "takttttaakaaktakttkt", "output": "526" }, { "input": "coccoooogogcgocccmcg", "output": "526" }, { "input": "kskkskkkssksssk", "output": "401" }, { "input": "lllllllllllllll", "output": "401" } ]
1,669,886,266
2,147,483,647
Python 3
OK
TESTS
33
46
0
s = (input()) print((len(s)+1)*25+1)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. Output Specification: Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Demo Input: ['a\n', 'hi\n'] Demo Output: ['51\n', '76\n'] Note: In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
```python s = (input()) print((len(s)+1)*25+1) ```
3
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "input": "eihdi", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "edhii", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto", "output": "YES" }, { "input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm", "output": "YES" }, { "input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv", "output": "YES" }, { "input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs", "output": "YES" }, { "input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji", "output": "YES" }, { "input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn", "output": "YES" }, { "input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx", "output": "YES" }, { "input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy", "output": "YES" }, { "input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc", "output": "YES" }, { "input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef", "output": "NO" }, { "input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa", "output": "YES" }, { "input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg", "output": "YES" }, { "input": "oagjghsidigeh", "output": "NO" }, { "input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz", "output": "YES" }, { "input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi", "output": "YES" }, { "input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx", "output": "YES" }, { "input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq", "output": "YES" } ]
1,660,525,382
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
s = input() if s.count('h') >= 1 and s.count('e') >= 1 and s.count('i') >= 2 and s.count('d') >= 1: h_index = [] e_index = [] i_index = [] d_index = [] for i in range(len(s)): if s[i] == 'h': h_index.append(i) elif s[i] == 'e': e_index.append(i) elif s[i] == 'i': i_index.append(i) elif s[i] == 'd': d_index.append(i) heidi = 0 for h in h_index: for e in e_index: for first_i in i_index: for d in d_index: for second_i in i_index: if h < e < first_i < d < second_i: heidi += 1 break if heidi > 0: print('YES') else: print('NO') else: print('NO')
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... Input Specification: The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). Output Specification: Output YES if the string *s* contains heidi as a subsequence and NO otherwise. Demo Input: ['abcheaibcdi\n', 'hiedi\n'] Demo Output: ['YES', 'NO'] Note: A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
```python s = input() if s.count('h') >= 1 and s.count('e') >= 1 and s.count('i') >= 2 and s.count('d') >= 1: h_index = [] e_index = [] i_index = [] d_index = [] for i in range(len(s)): if s[i] == 'h': h_index.append(i) elif s[i] == 'e': e_index.append(i) elif s[i] == 'i': i_index.append(i) elif s[i] == 'd': d_index.append(i) heidi = 0 for h in h_index: for e in e_index: for first_i in i_index: for d in d_index: for second_i in i_index: if h < e < first_i < d < second_i: heidi += 1 break if heidi > 0: print('YES') else: print('NO') else: print('NO') ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,645,697,927
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) d = 0 ; e = 0; f = 0 for i in range(n): a,b,c = map(int,input().split()) d += a ; e += b ; f += c if d == 0 and e == 0 and f == 0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) d = 0 ; e = 0; f = 0 for i in range(n): a,b,c = map(int,input().split()) d += a ; e += b ; f += c if d == 0 and e == 0 and f == 0: print("YES") else: print("NO") ```
3.977
899
C
Dividing the numbers
PROGRAMMING
1,300
[ "constructive algorithms", "graphs", "math" ]
null
null
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
[ "4\n", "2\n" ]
[ "0\n2 1 4 \n", "1\n1 1 \n" ]
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
1,500
[ { "input": "4", "output": "0\n2 1 4 " }, { "input": "2", "output": "1\n1 1 " }, { "input": "3", "output": "0\n1\n3 " }, { "input": "5", "output": "1\n3\n1 2 5 " }, { "input": "59998", "output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "60000", "output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59991", "output": "0\n29995\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 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 1..." }, { "input": "59989", "output": "1\n29995\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 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 1..." }, { "input": "6", "output": "1\n3 1 4 5 " }, { "input": "7", "output": "0\n3\n1 6 7 " }, { "input": "8", "output": "0\n4 1 4 5 8 " }, { "input": "9", "output": "1\n5\n1 2 3 8 9 " }, { "input": "10", "output": "1\n5 1 4 5 8 9 " }, { "input": "11", "output": "0\n5\n1 2 9 10 11 " }, { "input": "12", "output": "0\n6 1 4 5 8 9 12 " }, { "input": "13", "output": "1\n7\n1 2 3 4 11 12 13 " }, { "input": "14", "output": "1\n7 1 4 5 8 9 12 13 " }, { "input": "15", "output": "0\n7\n1 2 3 12 13 14 15 " }, { "input": "16", "output": "0\n8 1 4 5 8 9 12 13 16 " }, { "input": "17", "output": "1\n9\n1 2 3 4 5 14 15 16 17 " }, { "input": "18", "output": "1\n9 1 4 5 8 9 12 13 16 17 " }, { "input": "19", "output": "0\n9\n1 2 3 4 15 16 17 18 19 " }, { "input": "20", "output": "0\n10 1 4 5 8 9 12 13 16 17 20 " }, { "input": "21", "output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 " }, { "input": "22", "output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 " }, { "input": "23", "output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 " }, { "input": "24", "output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 " }, { "input": "59999", "output": "0\n29999\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 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 1..." }, { "input": "59997", "output": "1\n29999\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 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 1..." }, { "input": "59996", "output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59995", "output": "0\n29997\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 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 1..." }, { "input": "59994", "output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59993", "output": "1\n29997\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 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 1..." }, { "input": "59992", "output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59990", "output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "100", "output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 " }, { "input": "1000", "output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "10001", "output": "1\n5001\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 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 15..." }, { "input": "103", "output": "0\n51\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 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 " }, { "input": "1002", "output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "31724", "output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "2032", "output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "42620", "output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "18076", "output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "53520", "output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "37193", "output": "1\n18597\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 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 1..." }, { "input": "12645", "output": "1\n6323\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 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 15..." }, { "input": "53237", "output": "1\n26619\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 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 1..." }, { "input": "28693", "output": "1\n14347\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 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 1..." }, { "input": "4145", "output": "1\n2073\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 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 15..." }, { "input": "36042", "output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "16646", "output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "57238", "output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "27542", "output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "8146", "output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "46659", "output": "0\n23329\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 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 1..." }, { "input": "27259", "output": "0\n13629\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 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 1..." }, { "input": "2715", "output": "0\n1357\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 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 15..." }, { "input": "38159", "output": "0\n19079\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 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 1..." }, { "input": "18759", "output": "0\n9379\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 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 15..." } ]
1,679,597,585
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) sigma = int(n*(n+1)/2) dif = sigma%2 grupo1 = [] grupo2 = [] i = n sum = 0 while sum < sigma//2 and i > 0: print(sum, " ", sigma//2) if (sum + i <= sigma//2): sum += i grupo2.append(i) print(1) else: grupo1.append(i) print(2) i -= 1 print(len(grupo2), end = " ") for i in grupo2: print(i, end = " ")
Title: Dividing the numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. Output Specification: Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. Demo Input: ['4\n', '2\n'] Demo Output: ['0\n2 1 4 \n', '1\n1 1 \n'] Note: In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
```python n = int(input()) sigma = int(n*(n+1)/2) dif = sigma%2 grupo1 = [] grupo2 = [] i = n sum = 0 while sum < sigma//2 and i > 0: print(sum, " ", sigma//2) if (sum + i <= sigma//2): sum += i grupo2.append(i) print(1) else: grupo1.append(i) print(2) i -= 1 print(len(grupo2), end = " ") for i in grupo2: print(i, end = " ") ```
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,447,608,143
2,843
Python 3
WRONG_ANSWER
PRETESTS
2
46
0
n=int(input()) r=[int(j) for j in input().split()] q=0 t=True for j in range(1,n): if t==True: if r[j]>r[j-1]: q=q+1 else: if r[j]<r[j-1]: q=q+1 t=False else: if r[j]<r[j-1]: q=q+1 else: if r[j]>r[j-1]: q=q+1 t=True if q==0: print(n) else: print(q+1)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python n=int(input()) r=[int(j) for j in input().split()] q=0 t=True for j in range(1,n): if t==True: if r[j]>r[j-1]: q=q+1 else: if r[j]<r[j-1]: q=q+1 t=False else: if r[j]<r[j-1]: q=q+1 else: if r[j]>r[j-1]: q=q+1 t=True if q==0: print(n) else: print(q+1) ```
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,662,443,013
2,147,483,647
Python 3
OK
TESTS
102
61
0
n=str(input()) m=str(input()) o=' ' for i in range(len(m)): if n[i]==m[i]: o+='0' else: o+='1' print(o)
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 n=str(input()) m=str(input()) o=' ' for i in range(len(m)): if n[i]==m[i]: o+='0' else: o+='1' print(o) ```
3.98475
8
A
Train and Peter
PROGRAMMING
1,200
[ "strings" ]
A. Train and Peter
1
64
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
[ "atob\na\nb\n", "aaacaaa\naca\naa\n" ]
[ "forward\n", "both\n" ]
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
0
[ { "input": "atob\na\nb", "output": "forward" }, { "input": "aaacaaa\naca\naa", "output": "both" }, { "input": "aaa\naa\naa", "output": "fantasy" }, { "input": "astalavista\nastla\nlavista", "output": "fantasy" }, { "input": "abacabadabacaba\nabacaba\nabacaba", "output": "both" }, { "input": "a\na\na", "output": "fantasy" }, { "input": "ab\nb\na", "output": "backward" }, { "input": "aaa\naaaa\naaaa", "output": "fantasy" }, { "input": "bbabbbbababbaabaabaa\nabb\nbaab", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa", "output": "backward" }, { "input": "aaaa\naaa\naa", "output": "fantasy" }, { "input": "zzzz\nzz\nzzz", "output": "fantasy" }, { "input": "zzzz\nzzzz\nzzzz", "output": "fantasy" }, { "input": "zzzz\nzz\nzz", "output": "both" }, { "input": "aabaa\naab\nbaa", "output": "fantasy" }, { "input": "aabaab\naba\nab", "output": "forward" }, { "input": "aab\nb\naa", "output": "backward" }, { "input": "abacaba\naca\nba", "output": "both" } ]
1,546,247,101
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
218
0
str = input() a = input() b = input() flag = 0 if a in str and b in str: flag += 1 if a in str[:-1] and b in str[:-1]: flag += 2 if flag == 0: print('fantasy') elif flag == 1: print('forward') elif flag == 2: print('backward') else: print('both')
Title: Train and Peter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. Input Specification: The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. Output Specification: Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. Demo Input: ['atob\na\nb\n', 'aaacaaa\naca\naa\n'] Demo Output: ['forward\n', 'both\n'] Note: It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
```python str = input() a = input() b = input() flag = 0 if a in str and b in str: flag += 1 if a in str[:-1] and b in str[:-1]: flag += 2 if flag == 0: print('fantasy') elif flag == 1: print('forward') elif flag == 2: print('backward') else: print('both') ```
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,676,667,309
2,147,483,647
Python 3
OK
TESTS
23
342
11,059,200
print(int(input()) - max((map(input().split().count, map(str, range(1, 4))))))
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 print(int(input()) - max((map(input().split().count, map(str, range(1, 4)))))) ```
3.893901
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\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": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "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": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,696,317,778
2,147,483,647
Python 3
OK
TESTS
71
92
0
stops = int(input()) capacity = 0 inside = 0 for i in range(stops): a, b = map(int, input().split(" ")) inside = inside - a + b capacity = max(capacity, inside) print(capacity)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python stops = int(input()) capacity = 0 inside = 0 for i in range(stops): a, b = map(int, input().split(" ")) inside = inside - a + b capacity = max(capacity, inside) print(capacity) ```
3
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together.
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
1,541,314,046
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
a,b,c,d,e=map(int,raw_input().split()) a=max(a,c) b=min(b,d) print max(0,b-a+1)
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together. Input Specification: The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Specification: Print one integer — the number of minutes Sonya and Filya will be able to spend together. Demo Input: ['1 10 9 20 1\n', '1 100 50 200 75\n'] Demo Output: ['2\n', '50\n'] Note: In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
```python a,b,c,d,e=map(int,raw_input().split()) a=max(a,c) b=min(b,d) print max(0,b-a+1) ```
-1
8
B
Obsession with Robots
PROGRAMMING
1,400
[ "constructive algorithms", "graphs", "implementation" ]
B. Obsession with Robots
2
64
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
[ "LLUUUR\n", "RRUULLDD\n" ]
[ "OK\n", "BUG\n" ]
none
0
[ { "input": "LLUUUR", "output": "OK" }, { "input": "RRUULLDD", "output": "BUG" }, { "input": "L", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "RR", "output": "OK" }, { "input": "DL", "output": "OK" }, { "input": "LD", "output": "OK" }, { "input": "RUL", "output": "BUG" }, { "input": "ULD", "output": "BUG" }, { "input": "DDR", "output": "OK" }, { "input": "RRDD", "output": "OK" }, { "input": "RRLR", "output": "BUG" }, { "input": "RRDL", "output": "BUG" }, { "input": "LRUD", "output": "BUG" }, { "input": "RDRLL", "output": "BUG" }, { "input": "DRDRD", "output": "OK" }, { "input": "ULURL", "output": "BUG" }, { "input": "LUUDU", "output": "BUG" }, { "input": "RDLUR", "output": "BUG" }, { "input": "DLDLDDRR", "output": "OK" }, { "input": "RDRDDD", "output": "OK" }, { "input": "UULLDLUR", "output": "BUG" }, { "input": "LULU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "UL", "output": "OK" }, { "input": "UDR", "output": "BUG" }, { "input": "DDDR", "output": "OK" }, { "input": "UUUDU", "output": "BUG" }, { "input": "LULULL", "output": "OK" }, { "input": "DLURUUU", "output": "BUG" }, { "input": "UURUURRUUU", "output": "OK" }, { "input": "DDDDRDDLDDDDDDDRDDLD", "output": "OK" }, { "input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU", "output": "BUG" }, { "input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR", "output": "BUG" }, { "input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR", "output": "BUG" }, { "input": "DDUL", "output": "BUG" }, { "input": "UUULLLLRDD", "output": "BUG" }, { "input": "LLLLLLLLRRRRDDDDDDDUUUUUU", "output": "BUG" }, { "input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL", "output": "BUG" }, { "input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU", "output": "BUG" }, { "input": "DLUR", "output": "BUG" }, { "input": "UUUURDLLLL", "output": "BUG" }, { "input": "RRRRRRRRRRRURLLLLLLLLLLLL", "output": "BUG" }, { "input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "BUG" }, { "input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BUG" }, { "input": "DDLDRRR", "output": "BUG" }, { "input": "RRUULLD", "output": "BUG" }, { "input": "LUUUULLLLDDDDRRRD", "output": "BUG" }, { "input": "DDDDLLLDDDRRRUURRRR", "output": "BUG" }, { "input": "DDDDDDDLLDDRRURRRRRRR", "output": "BUG" }, { "input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR", "output": "BUG" }, { "input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR", "output": "BUG" }, { "input": "RRRUUULLLDD", "output": "BUG" }, { "input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BUG" }, { "input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU", "output": "BUG" } ]
1,625,754,754
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
squares=[[0,0]] x=y=0 check=True def readInput(direction,x,y): if direction=='R': return [x+1,y] elif direction=='L': return [x-1,y] elif direction=='U': return [x,y+1] elif direction=='D': return [x,y-1] path=input() for d in path: x,y=direction(d,x,y) if [x,y] in squares: print('BUG') check=False break squares.append([x,y]) if check: print('OK')
Title: Obsession with Robots Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input Specification: The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output Specification: In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Demo Input: ['LLUUUR\n', 'RRUULLDD\n'] Demo Output: ['OK\n', 'BUG\n'] Note: none
```python squares=[[0,0]] x=y=0 check=True def readInput(direction,x,y): if direction=='R': return [x+1,y] elif direction=='L': return [x-1,y] elif direction=='U': return [x,y+1] elif direction=='D': return [x,y-1] path=input() for d in path: x,y=direction(d,x,y) if [x,y] in squares: print('BUG') check=False break squares.append([x,y]) if check: print('OK') ```
-1
0
none
none
none
0
[ "none" ]
null
null
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different.
Print a single number — the number of vertexes in the maximum clique of the given graph.
[ "4\n2 3\n3 1\n6 1\n0 2\n" ]
[ "3\n" ]
If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
0
[ { "input": "4\n2 3\n3 1\n6 1\n0 2", "output": "3" }, { "input": "1\n42 23", "output": "1" }, { "input": "2\n1 5\n2 6", "output": "1" }, { "input": "2\n1 5\n12 6", "output": "2" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "2\n4 4\n12 5", "output": "1" }, { "input": "2\n4 4\n12 4", "output": "2" }, { "input": "2\n4 4\n12 3", "output": "2" }, { "input": "3\n0 1\n2 1\n4 1", "output": "3" }, { "input": "3\n0 1\n2 2\n4 1", "output": "2" }, { "input": "2\n0 1\n1000000000 1", "output": "2" }, { "input": "2\n0 1000000000\n1000000000 1000000000", "output": "1" }, { "input": "1\n76438 10", "output": "1" }, { "input": "10\n6 15\n4 5\n1 4\n2 4\n0 6\n9 5\n8 14\n5 4\n7 20\n10 20", "output": "1" }, { "input": "10\n0 3\n30 3\n54 3\n6 3\n36 3\n12 3\n42 3\n24 3\n48 3\n18 3", "output": "10" }, { "input": "10\n48 4\n54 4\n12 4\n6 4\n30 4\n36 4\n24 4\n0 4\n42 4\n18 4", "output": "5" }, { "input": "11\n0 4\n54 4\n48 4\n18 4\n24 4\n42 4\n6 4\n36 4\n12 4\n30 4\n60 4", "output": "6" }, { "input": "12\n66 4\n12 4\n60 4\n24 4\n48 4\n0 4\n36 4\n30 4\n6 4\n54 4\n42 4\n18 4", "output": "6" }, { "input": "1\n0 1000000000", "output": "1" } ]
1,577,926,663
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
561
16,384,000
def solve(): from sys import stdin f_i = stdin n = int(f_i.readline()) points = [] for i in range(n): x, w = map(int, f_i.readline().split()) points.append((x - w, x + w)) points.sort() ans = 0 t = points[0][0] for start, end in points: if t <= start: ans += 1 t = end print(ans) solve()
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different. Output Specification: Print a single number — the number of vertexes in the maximum clique of the given graph. Demo Input: ['4\n2 3\n3 1\n6 1\n0 2\n'] Demo Output: ['3\n'] Note: If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
```python def solve(): from sys import stdin f_i = stdin n = int(f_i.readline()) points = [] for i in range(n): x, w = map(int, f_i.readline().split()) points.append((x - w, x + w)) points.sort() ans = 0 t = points[0][0] for start, end in points: if t <= start: ans += 1 t = end print(ans) solve() ```
0
219
D
Choosing Capital for Treeland
PROGRAMMING
1,700
[ "dfs and similar", "dp", "graphs", "trees" ]
null
null
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed. Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
[ "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n" ]
[ "0\n2 \n", "2\n1 2 3 \n" ]
none
2,000
[ { "input": "3\n2 1\n2 3", "output": "0\n2 " }, { "input": "4\n1 4\n2 4\n3 4", "output": "2\n1 2 3 " }, { "input": "2\n1 2", "output": "0\n1 " }, { "input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7", "output": "3\n4 6 8 " }, { "input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "output": "3\n9 " }, { "input": "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1", "output": "4\n6 " }, { "input": "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9", "output": "2\n7 " }, { "input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3", "output": "3\n9 " }, { "input": "11\n3 10\n4 7\n11 7\n8 2\n6 9\n9 3\n5 9\n1 3\n3 8\n7 3", "output": "5\n4 5 6 11 " }, { "input": "12\n10 7\n6 10\n8 10\n4 12\n10 4\n3 12\n1 2\n2 7\n4 5\n11 5\n11 9", "output": "5\n1 6 8 " }, { "input": "13\n7 13\n5 4\n5 1\n11 12\n8 3\n13 4\n10 7\n11 5\n8 13\n2 8\n10 6\n4 9", "output": "4\n2 10 " }, { "input": "14\n13 10\n5 14\n9 4\n8 12\n10 1\n5 2\n3 6\n11 2\n13 2\n13 7\n8 2\n4 5\n1 3", "output": "3\n9 " }, { "input": "15\n15 6\n2 15\n14 15\n15 12\n1 2\n10 15\n7 4\n13 7\n11 2\n5 2\n7 2\n3 2\n7 8\n9 15", "output": "7\n13 " } ]
1,628,502,946
2,147,483,647
PyPy 3
OK
TESTS
34
2,182
104,857,600
from collections import deque, defaultdict import sys from types import GeneratorType input = sys.stdin.readline def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def compute_adj_list(edges): adj_list = defaultdict(list) # 0 correct direction, 1 not correct direction for src, dst in edges: adj_list[src].append((dst, 0)) adj_list[dst].append((src, 1)) return adj_list @bootstrap def dfs(current, parent, adj_list, num_reversed_roads): for child, cost in adj_list[current]: if child != parent: yield dfs(child, current, adj_list, num_reversed_roads) num_reversed_roads[current] += num_reversed_roads[child] + cost yield None def solution(edges, n): adj_list = compute_adj_list(edges) num_reversed_roads = [0] * n root = 0 # Fill num_reversed_roads in subtree dfs(root, -1, adj_list, num_reversed_roads) visited = [False] * n queue = deque() queue.append(root) visited[root] = True while queue: parent = queue.popleft() for child, cost in adj_list[parent]: reversed_cost = 1 if cost == 0 else -1 if not visited[child]: visited[child] = True num_reversed_roads[child] = num_reversed_roads[parent] + reversed_cost queue.append(child) min_reversed_roads = min(num_reversed_roads) capitals = [str(i+1) for i, num_roads in enumerate(num_reversed_roads) if num_roads == min_reversed_roads] print(min_reversed_roads) sys.stdout.write(' '.join(capitals) + '\n') if __name__ == "__main__": n = [int(val) for val in input().split()][0] edges = [] for _ in range(n-1): src, dst = [int(val)-1 for val in input().split()] edges.append([src, dst]) solution(edges, n)
Title: Choosing Capital for Treeland Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one. The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed. Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country. Input Specification: The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*. Output Specification: In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order. Demo Input: ['3\n2 1\n2 3\n', '4\n1 4\n2 4\n3 4\n'] Demo Output: ['0\n2 \n', '2\n1 2 3 \n'] Note: none
```python from collections import deque, defaultdict import sys from types import GeneratorType input = sys.stdin.readline def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def compute_adj_list(edges): adj_list = defaultdict(list) # 0 correct direction, 1 not correct direction for src, dst in edges: adj_list[src].append((dst, 0)) adj_list[dst].append((src, 1)) return adj_list @bootstrap def dfs(current, parent, adj_list, num_reversed_roads): for child, cost in adj_list[current]: if child != parent: yield dfs(child, current, adj_list, num_reversed_roads) num_reversed_roads[current] += num_reversed_roads[child] + cost yield None def solution(edges, n): adj_list = compute_adj_list(edges) num_reversed_roads = [0] * n root = 0 # Fill num_reversed_roads in subtree dfs(root, -1, adj_list, num_reversed_roads) visited = [False] * n queue = deque() queue.append(root) visited[root] = True while queue: parent = queue.popleft() for child, cost in adj_list[parent]: reversed_cost = 1 if cost == 0 else -1 if not visited[child]: visited[child] = True num_reversed_roads[child] = num_reversed_roads[parent] + reversed_cost queue.append(child) min_reversed_roads = min(num_reversed_roads) capitals = [str(i+1) for i, num_roads in enumerate(num_reversed_roads) if num_roads == min_reversed_roads] print(min_reversed_roads) sys.stdout.write(' '.join(capitals) + '\n') if __name__ == "__main__": n = [int(val) for val in input().split()][0] edges = [] for _ in range(n-1): src, dst = [int(val)-1 for val in input().split()] edges.append([src, dst]) solution(edges, n) ```
3
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it. Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on. The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest? Take a look at the notes if you think you haven't understood the problem completely.
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n1000000000", "output": "1000000000" }, { "input": "2 0\n0 0", "output": "0" }, { "input": "2 0\n1000000000 0", "output": "1000000000" }, { "input": "2 0\n0 1000000000", "output": "1000000000" }, { "input": "2 0\n1000000000 1000000000", "output": "2000000000" }, { "input": "2 1\n0 0\n1 2", "output": "0" } ]
1,599,853,624
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n, m = map(int,input().split()) ans = 0 b = [] for i in range(n): b.append(i) a = list(map(int,input().split())) if m == 0: print(sum(a)) quit() for i in range(m): x, y = map(int,input().split()) ans += min(x, y) print(ans)
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it. Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on. The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest? Take a look at the notes if you think you haven't understood the problem completely. Input Specification: The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. Output Specification: Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. Demo Input: ['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n'] Demo Output: ['10\n', '55\n', '15\n'] Note: In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
```python n, m = map(int,input().split()) ans = 0 b = [] for i in range(n): b.append(i) a = list(map(int,input().split())) if m == 0: print(sum(a)) quit() for i in range(m): x, y = map(int,input().split()) ans += min(x, y) print(ans) ```
-1
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", "output": "Yes" }, { "input": "+", "output": "No" }, { "input": "-+", "output": "No" }, { "input": "--", "output": "Yes" }, { "input": "+++", "output": "No" }, { "input": "--+", "output": "No" }, { "input": "++--++", "output": "Yes" }, { "input": "+-++-+", "output": "Yes" }, { "input": "+-+--+", "output": "No" }, { "input": "--++-+", "output": "No" }, { "input": "-+-+--", "output": "No" }, { "input": "+-+++-", "output": "No" }, { "input": "-+-+-+", "output": "No" }, { "input": "-++-+--++--+-++-", "output": "Yes" }, { "input": "+-----+-++---+------+++-++++", "output": "No" }, { "input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "output": "No" }, { "input": "-+-----++++--++-+-++", "output": "Yes" }, { "input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "output": "Yes" }, { "input": "-+-+-++-+-+-", "output": "Yes" }, { "input": "-+-++-+-", "output": "Yes" }, { "input": "-+-++-+-+-", "output": "No" }, { "input": "++-+-+-+-+--+", "output": "No" }, { "input": "+++---", "output": "No" }, { "input": "+-+-+-+-+--+-+-+-+-++--++--+", "output": "Yes" }, { "input": "+-+-++", "output": "No" }, { "input": "-++--+--+++-+-+-+-+-", "output": "No" }, { "input": "+---+-+-", "output": "No" }, { "input": "+-+--+-+", "output": "Yes" }, { "input": "+++---+++---", "output": "No" }, { "input": "-+++++", "output": "No" }, { "input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "output": "Yes" }, { "input": "-+++--", "output": "No" }, { "input": "+---+", "output": "No" }, { "input": "-++", "output": "No" }, { "input": "-+--+-", "output": "Yes" }, { "input": "+---++--++", "output": "No" }, { "input": "+++-", "output": "No" }, { "input": "--+++", "output": "No" }, { "input": "++-+", "output": "No" } ]
1,676,687,569
2,147,483,647
PyPy 3-64
OK
TESTS
62
996
10,444,800
signals = input() def wires(strg): transformed_signals = "" for i in range(len(signals)): if i % 2 == 0: if signals[i] == "+": transformed_signals += "A" else: transformed_signals += "B" else: if signals[i] == "+": transformed_signals += "B" else: transformed_signals += "A" count_a = transformed_signals.count("A") count_b = transformed_signals.count("B") if count_a == count_b: print("Yes") else: print("No") wires(signals)
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python signals = input() def wires(strg): transformed_signals = "" for i in range(len(signals)): if i % 2 == 0: if signals[i] == "+": transformed_signals += "A" else: transformed_signals += "B" else: if signals[i] == "+": transformed_signals += "B" else: transformed_signals += "A" count_a = transformed_signals.count("A") count_b = transformed_signals.count("B") if count_a == count_b: print("Yes") else: print("No") wires(signals) ```
3
397
A
On Segment's Own Points
PROGRAMMING
0
[ "implementation" ]
null
null
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student.
On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.
[ "3\n0 5\n2 8\n1 6\n", "3\n0 10\n1 5\n7 15\n" ]
[ "1\n", "3\n" ]
Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
500
[ { "input": "3\n0 5\n2 8\n1 6", "output": "1" }, { "input": "3\n0 10\n1 5\n7 15", "output": "3" }, { "input": "1\n0 100", "output": "100" }, { "input": "2\n1 9\n1 9", "output": "0" }, { "input": "2\n1 9\n5 10", "output": "4" }, { "input": "2\n1 9\n3 5", "output": "6" }, { "input": "2\n3 5\n1 9", "output": "0" }, { "input": "10\n43 80\n39 75\n26 71\n4 17\n11 57\n31 42\n1 62\n9 19\n27 76\n34 53", "output": "4" }, { "input": "50\n33 35\n98 99\n1 2\n4 6\n17 18\n63 66\n29 30\n35 37\n44 45\n73 75\n4 5\n39 40\n92 93\n96 97\n23 27\n49 50\n2 3\n60 61\n43 44\n69 70\n7 8\n45 46\n21 22\n85 86\n48 49\n41 43\n70 71\n10 11\n27 28\n71 72\n6 7\n15 16\n46 47\n89 91\n54 55\n19 21\n86 87\n37 38\n77 82\n84 85\n54 55\n93 94\n45 46\n37 38\n75 76\n22 23\n50 52\n38 39\n1 2\n66 67", "output": "2" }, { "input": "2\n1 5\n7 9", "output": "4" }, { "input": "2\n1 5\n3 5", "output": "2" }, { "input": "2\n1 5\n1 2", "output": "3" }, { "input": "5\n5 10\n5 10\n5 10\n5 10\n5 10", "output": "0" }, { "input": "6\n1 99\n33 94\n68 69\n3 35\n93 94\n5 98", "output": "3" }, { "input": "11\n2 98\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "2" }, { "input": "10\n95 96\n19 20\n72 73\n1 2\n25 26\n48 49\n90 91\n22 23\n16 17\n16 17", "output": "1" }, { "input": "11\n1 100\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "output": "4" }, { "input": "21\n0 100\n81 90\n11 68\n18 23\n75 78\n45 86\n37 58\n15 21\n40 98\n53 100\n10 70\n14 75\n1 92\n23 81\n13 66\n93 100\n6 34\n22 87\n27 84\n15 63\n54 91", "output": "1" }, { "input": "10\n60 66\n5 14\n1 3\n55 56\n70 87\n34 35\n16 21\n23 24\n30 31\n25 27", "output": "6" }, { "input": "40\n29 31\n22 23\n59 60\n70 71\n42 43\n13 15\n11 12\n64 65\n1 2\n62 63\n54 56\n8 9\n2 3\n53 54\n27 28\n48 49\n72 73\n17 18\n46 47\n18 19\n43 44\n39 40\n83 84\n63 64\n52 53\n33 34\n3 4\n24 25\n74 75\n0 1\n61 62\n68 69\n80 81\n5 6\n36 37\n81 82\n50 51\n66 67\n69 70\n20 21", "output": "2" }, { "input": "15\n22 31\n0 4\n31 40\n77 80\n81 83\n11 13\n59 61\n53 59\n51 53\n87 88\n14 22\n43 45\n8 10\n45 47\n68 71", "output": "9" }, { "input": "31\n0 100\n2 97\n8 94\n9 94\n14 94\n15 93\n15 90\n17 88\n19 88\n19 87\n20 86\n25 86\n30 85\n32 85\n35 82\n35 81\n36 80\n37 78\n38 74\n38 74\n39 71\n40 69\n40 68\n41 65\n43 62\n44 62\n45 61\n45 59\n46 57\n49 54\n50 52", "output": "5" }, { "input": "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n26 28\n47 88\n30 40\n26 34\n2 12\n9 10\n4 19\n35 36\n41 92\n1 16\n41 78\n56 81\n23 35\n40 68", "output": "7" }, { "input": "27\n0 97\n7 9\n6 9\n12 33\n12 26\n15 27\n10 46\n33 50\n31 47\n15 38\n12 44\n21 35\n24 37\n51 52\n65 67\n58 63\n53 60\n63 68\n57 63\n60 68\n55 58\n74 80\n70 75\n89 90\n81 85\n93 99\n93 98", "output": "19" }, { "input": "20\n23 24\n22 23\n84 86\n6 10\n40 45\n11 13\n24 27\n81 82\n53 58\n87 90\n14 15\n49 50\n70 75\n75 78\n98 100\n66 68\n18 21\n1 2\n92 93\n34 37", "output": "1" }, { "input": "11\n2 100\n34 65\n4 50\n63 97\n82 99\n43 54\n23 52\n4 33\n15 84\n23 31\n12 34", "output": "3" }, { "input": "60\n73 75\n6 7\n69 70\n15 16\n54 55\n66 67\n7 8\n39 40\n38 39\n37 38\n1 2\n46 47\n7 8\n21 22\n23 27\n15 16\n45 46\n37 38\n60 61\n4 6\n63 66\n10 11\n33 35\n43 44\n2 3\n4 6\n10 11\n93 94\n45 46\n7 8\n44 45\n41 43\n35 37\n17 18\n48 49\n89 91\n27 28\n46 47\n71 72\n1 2\n75 76\n49 50\n84 85\n17 18\n98 99\n54 55\n46 47\n19 21\n77 82\n29 30\n4 5\n70 71\n85 86\n96 97\n86 87\n92 93\n22 23\n50 52\n44 45\n63 66", "output": "2" }, { "input": "40\n47 48\n42 44\n92 94\n15 17\n20 22\n11 13\n37 39\n6 8\n39 40\n35 37\n21 22\n41 42\n77 78\n76 78\n69 71\n17 19\n18 19\n17 18\n84 85\n9 10\n11 12\n51 52\n99 100\n7 8\n97 99\n22 23\n60 62\n7 8\n67 69\n20 22\n13 14\n89 91\n15 17\n12 13\n56 57\n37 39\n29 30\n24 26\n37 38\n25 27", "output": "1" }, { "input": "10\n28 36\n18 26\n28 35\n95 100\n68 72\n41 42\n76 84\n99 100\n6 8\n58 60", "output": "1" }, { "input": "20\n69 72\n88 92\n77 80\n64 69\n66 67\n79 81\n91 96\n78 83\n81 86\n11 12\n48 53\n22 23\n81 84\n89 92\n56 60\n1 4\n1 5\n60 62\n20 23\n63 66", "output": "3" }, { "input": "71\n1 99\n11 69\n86 92\n7 49\n31 70\n42 53\n48 81\n86 96\n36 91\n19 38\n39 91\n41 64\n87 93\n83 97\n40 41\n3 32\n15 18\n58 65\n22 32\n1 71\n58 86\n64 77\n15 69\n4 34\n42 89\n9 66\n15 18\n58 65\n59 96\n39 89\n19 38\n6 63\n26 73\n29 47\n55 88\n5 78\n41 74\n48 81\n20 71\n59 96\n42 49\n4 69\n41 74\n87 93\n0 65\n2 34\n15 18\n10 56\n55 88\n33 56\n42 89\n86 92\n42 81\n65 82\n5 78\n13 52\n32 85\n7 65\n59 96\n4 65\n46 69\n10 56\n42 89\n4 69\n0 65\n32 35\n5 78\n32 75\n42 53\n55 59\n64 77", "output": "2" }, { "input": "1\n1 2", "output": "1" } ]
1,580,820,078
2,147,483,647
Python 3
OK
TESTS
37
109
307,200
num_of_student = int(input()) sush = list() for i in range(0, num_of_student): inp = input() inp_spl = inp.split(" ") sush.append(int(inp_spl[0])) sush.append(int(inp_spl[1])) one_range = [0 for i in range(0, max(sush)+1)] for i in range(0, num_of_student*2, 2): for j in range(sush[i], sush[i+1]): one_range[j] = i+1 count = 0 for i in one_range: if i == 1: count += 1 print(count)
Title: On Segment's Own Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. Output Specification: On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. Demo Input: ['3\n0 5\n2 8\n1 6\n', '3\n0 10\n1 5\n7 15\n'] Demo Output: ['1\n', '3\n'] Note: Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.
```python num_of_student = int(input()) sush = list() for i in range(0, num_of_student): inp = input() inp_spl = inp.split(" ") sush.append(int(inp_spl[0])) sush.append(int(inp_spl[1])) one_range = [0 for i in range(0, max(sush)+1)] for i in range(0, num_of_student*2, 2): for j in range(sush[i], sush[i+1]): one_range[j] = i+1 count = 0 for i in one_range: if i == 1: count += 1 print(count) ```
3
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { "input": "100 1000000000 20", "output": "10000034" }, { "input": "1000 1000 994", "output": "1" }, { "input": "100000000 200000000 54345", "output": "10001" }, { "input": "1000000000 1000000000 1", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 500000000", "output": "1" }, { "input": "1000 1000 3", "output": "1" }, { "input": "100000000 200020000 54345", "output": "10001" }, { "input": "100 108037 18", "output": "1115" }, { "input": "100000000 200020001 54345", "output": "10002" }, { "input": "200 6585 2", "output": "112" }, { "input": "30000 30593 5980", "output": "25" }, { "input": "40000 42107 10555", "output": "46" }, { "input": "50003 50921 192", "output": "31" }, { "input": "100000 113611 24910", "output": "117" }, { "input": "1000000 483447163 83104", "output": "21965" }, { "input": "10000000 10021505 600076", "output": "147" }, { "input": "100000000 102144805 2091145", "output": "1465" }, { "input": "1000000000 1000000000 481982093", "output": "1" }, { "input": "100 999973325 5", "output": "9999778" }, { "input": "200 999999109 61", "output": "5000053" }, { "input": "30000 999999384 5488", "output": "43849" }, { "input": "40000 999997662 8976", "output": "38038" }, { "input": "50003 999999649 405", "output": "44320" }, { "input": "100000 999899822 30885", "output": "31624" }, { "input": "1000000 914032367 528790", "output": "30217" }, { "input": "10000000 999617465 673112", "output": "31459" }, { "input": "100000000 993180275 362942", "output": "29887" }, { "input": "1000000000 1000000000 331431458", "output": "1" }, { "input": "100 10466 89", "output": "144" }, { "input": "200 5701 172", "output": "84" }, { "input": "30000 36932 29126", "output": "84" }, { "input": "40000 40771 22564", "output": "28" }, { "input": "50003 51705 49898", "output": "42" }, { "input": "100000 149408 74707", "output": "223" }, { "input": "1000000 194818222 998601", "output": "18389" }, { "input": "10000000 10748901 8882081", "output": "866" }, { "input": "100000000 106296029 98572386", "output": "2510" }, { "input": "1000000000 1000000000 193988157", "output": "1" }, { "input": "100 999981057 92", "output": "9999852" }, { "input": "200 999989691 199", "output": "5000046" }, { "input": "30000 999995411 24509", "output": "43846" }, { "input": "40000 999998466 30827", "output": "37930" }, { "input": "50003 999997857 48387", "output": "43163" }, { "input": "100000 999731886 98615", "output": "43371" }, { "input": "1000000 523220797 654341", "output": "22853" }, { "input": "10000000 999922591 8157724", "output": "31464" }, { "input": "100000000 999834114 93836827", "output": "29998" }, { "input": "1000000000 1000000000 912549504", "output": "1" }, { "input": "1000 97654978 234", "output": "97976" }, { "input": "1000 97654977 234", "output": "97975" }, { "input": "1000234 97653889 1", "output": "13903" }, { "input": "1000234 97653890 1", "output": "13904" }, { "input": "3450234 97656670 3000000", "output": "9707" }, { "input": "3450234 97656669 3000000", "output": "9706" }, { "input": "3 1000000000 2", "output": "333333334" }, { "input": "2 1000000000 1", "output": "500000000" }, { "input": "2 1000000000 2", "output": "500000000" }, { "input": "3 1000000000 1", "output": "333333334" }, { "input": "3 1000000000 3", "output": "333333334" }, { "input": "2 999999999 1", "output": "500000000" }, { "input": "2 999999999 2", "output": "500000000" }, { "input": "1 999999999 1", "output": "999999999" } ]
1,506,533,902
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
# x is the number of pillows Frodo wants def is_ok(x, y): if y > (x - 1): val = (((x-1) * x) >> 1) + y - (x - 1) else: val = (y * (x - 1 + x - y)) >> 1 return val hobbits, pillows, k = [int(x) for x in input().split()] l = 1 r = pillows while l <= r: m = (l + r) >> 1 valor = is_ok(m, k) + is_ok(m, hobbits - k) + m # print(valor, m, l, r) if valor < pillows: l = m + 1 else: r = m - 1 print(l)
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt? Input Specification: The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. Output Specification: Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. Demo Input: ['4 6 2\n', '3 10 3\n', '3 6 1\n'] Demo Output: ['2\n', '4\n', '3\n'] Note: In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
```python # x is the number of pillows Frodo wants def is_ok(x, y): if y > (x - 1): val = (((x-1) * x) >> 1) + y - (x - 1) else: val = (y * (x - 1 + x - y)) >> 1 return val hobbits, pillows, k = [int(x) for x in input().split()] l = 1 r = pillows while l <= r: m = (l + r) >> 1 valor = is_ok(m, k) + is_ok(m, hobbits - k) + m # print(valor, m, l, r) if valor < pillows: l = m + 1 else: r = m - 1 print(l) ```
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,601,048,700
2,147,483,647
PyPy 3
OK
TESTS
21
186
0
n = input() m = input() total_c = 0 for i in m: n_count = n.count(i) if n_count==0: total_c = 0 break total_c+=min(n_count,m.count(i)) m = m.replace(i,'') if total_c==0: total_c-=1 print(total_c)
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 n = input() m = input() total_c = 0 for i in m: n_count = n.count(i) if n_count==0: total_c = 0 break total_c+=min(n_count,m.count(i)) m = m.replace(i,'') if total_c==0: total_c-=1 print(total_c) ```
3
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,644,348,019
2,147,483,647
PyPy 3-64
OK
TESTS
32
154
0
n = int(input()) s = input().split() even_counter=0 temp, temp2 = 0, 0 for i in range(n): if int(s[i])%2 == 0: even_counter+=1 temp = i+1 else: temp2 = i+1 if even_counter>len(s)//2: print(temp2) else: print(temp)
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()) s = input().split() even_counter=0 temp, temp2 = 0, 0 for i in range(n): if int(s[i])%2 == 0: even_counter+=1 temp = i+1 else: temp2 = i+1 if even_counter>len(s)//2: print(temp2) else: print(temp) ```
3.9615
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
1,598,252,090
2,147,483,647
Python 3
OK
TESTS
10
93
6,656,000
def fact(n): sums = 1 for i in range(2, n + 1): sums *= i return sums n = 2 * (int(input()) - 1) print(fact(n) // fact(n // 2) // fact(n - n // 2))
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. Input Specification: The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. Output Specification: Print a single line containing a positive integer *m* — the maximum value in the table. Demo Input: ['1\n', '5\n'] Demo Output: ['1', '70'] Note: In the second test the rows of the table look as follows:
```python def fact(n): sums = 1 for i in range(2, n + 1): sums *= i return sums n = 2 * (int(input()) - 1) print(fact(n) // fact(n // 2) // fact(n - n // 2)) ```
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,621,622,658
2,147,483,647
Python 3
OK
TESTS
30
124
0
# author : Leandro # problem : A. Word # platform : Codeforces # date : 2021-05-21 line = input() lower = 0 for c in line: lower += int(c.islower()) solution = line.upper() if lower < len(line) - lower else line.lower() print(solution)
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 # author : Leandro # problem : A. Word # platform : Codeforces # date : 2021-05-21 line = input() lower = 0 for c in line: lower += int(c.islower()) solution = line.upper() if lower < len(line) - lower else line.lower() print(solution) ```
3.969
821
C
Okabe and Boxes
PROGRAMMING
1,500
[ "data structures", "greedy", "trees" ]
null
null
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack. That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it. Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack. It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
[ "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n" ]
[ "1\n", "2\n" ]
In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
1,500
[ { "input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "output": "1" }, { "input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "output": "2" }, { "input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove", "output": "2" }, { "input": "2\nadd 1\nremove\nadd 2\nremove", "output": "0" }, { "input": "1\nadd 1\nremove", "output": "0" }, { "input": "15\nadd 12\nadd 7\nadd 10\nadd 11\nadd 5\nadd 2\nadd 1\nadd 6\nadd 8\nremove\nremove\nadd 15\nadd 4\nadd 13\nadd 9\nadd 3\nadd 14\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "2" }, { "input": "14\nadd 7\nadd 2\nadd 13\nadd 5\nadd 12\nadd 6\nadd 4\nadd 1\nadd 14\nremove\nadd 10\nremove\nadd 9\nadd 8\nadd 11\nadd 3\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "3" }, { "input": "11\nadd 10\nadd 9\nadd 11\nadd 1\nadd 5\nadd 6\nremove\nadd 3\nadd 8\nadd 2\nadd 4\nremove\nremove\nremove\nremove\nremove\nadd 7\nremove\nremove\nremove\nremove\nremove", "output": "2" }, { "input": "3\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove", "output": "0" }, { "input": "4\nadd 1\nadd 3\nadd 4\nremove\nadd 2\nremove\nremove\nremove", "output": "1" }, { "input": "6\nadd 3\nadd 4\nadd 5\nadd 1\nadd 6\nremove\nadd 2\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "16\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "2\nadd 2\nadd 1\nremove\nremove", "output": "0" }, { "input": "17\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "18\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "4\nadd 1\nadd 2\nremove\nremove\nadd 4\nadd 3\nremove\nremove", "output": "1" }, { "input": "19\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nadd 19\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "5\nadd 4\nadd 3\nadd 1\nremove\nadd 2\nremove\nremove\nadd 5\nremove\nremove", "output": "1" }, { "input": "7\nadd 4\nadd 6\nadd 1\nadd 5\nadd 7\nremove\nadd 2\nremove\nadd 3\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "8\nadd 1\nadd 2\nadd 3\nadd 7\nadd 8\nremove\nremove\nremove\nadd 6\nadd 5\nadd 4\nremove\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "4\nadd 1\nadd 4\nremove\nadd 3\nadd 2\nremove\nremove\nremove", "output": "1" }, { "input": "7\nadd 1\nadd 2\nadd 3\nadd 5\nadd 7\nremove\nremove\nremove\nadd 4\nremove\nremove\nadd 6\nremove\nremove", "output": "1" }, { "input": "4\nadd 4\nadd 1\nadd 2\nremove\nremove\nadd 3\nremove\nremove", "output": "1" }, { "input": "5\nadd 1\nadd 3\nadd 4\nadd 5\nremove\nadd 2\nremove\nremove\nremove\nremove", "output": "1" }, { "input": "5\nadd 2\nadd 1\nremove\nremove\nadd 5\nadd 3\nremove\nadd 4\nremove\nremove", "output": "0" }, { "input": "9\nadd 3\nadd 2\nadd 1\nadd 4\nadd 6\nadd 9\nremove\nremove\nremove\nremove\nadd 5\nremove\nremove\nadd 8\nadd 7\nremove\nremove\nremove", "output": "1" }, { "input": "10\nadd 9\nadd 10\nadd 4\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove\nremove\nadd 8\nadd 7\nadd 5\nadd 6\nremove\nremove\nremove\nremove\nremove\nremove", "output": "1" } ]
1,541,157,905
2,345
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
3,000
52,736,000
import sys def main(input): n = int(next(input)) result = 0 last_rebuild = -1 required_box = 1 boxes = set() add_time = [0] * 2 * n for i in range(2 * n): query = next(input).split() if query[0] == 'add': id = int(query[1]) add_time[id] = i boxes.add((i, id)) else: last_box = max(boxes) if last_box[1] != required_box and last_rebuild < last_box[0]: result += 1 last_rebuild = i boxes.remove((add_time[required_box], required_box)) required_box += 1 print(result) if __name__ == '__main__': main(iter(sys.stdin.readlines()))
Title: Okabe and Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack. That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it. Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. Input Specification: The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack. It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. Output Specification: Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. Demo Input: ['3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n', '7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n'] Demo Output: ['1\n', '2\n'] Note: In the first sample, Daru should reorder the boxes after adding box 3 to the stack. In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
```python import sys def main(input): n = int(next(input)) result = 0 last_rebuild = -1 required_box = 1 boxes = set() add_time = [0] * 2 * n for i in range(2 * n): query = next(input).split() if query[0] == 'add': id = int(query[1]) add_time[id] = i boxes.add((i, id)) else: last_box = max(boxes) if last_box[1] != required_box and last_rebuild < last_box[0]: result += 1 last_rebuild = i boxes.remove((add_time[required_box], required_box)) required_box += 1 print(result) if __name__ == '__main__': main(iter(sys.stdin.readlines())) ```
0
416
C
Booking System
PROGRAMMING
1,600
[ "binary search", "dp", "greedy", "implementation" ]
null
null
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table.
In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly. Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them.
[ "3\n10 50\n2 100\n5 30\n3\n4 6 9\n" ]
[ "2 130\n2 1\n3 2\n" ]
none
1,500
[ { "input": "3\n10 50\n2 100\n5 30\n3\n4 6 9", "output": "2 130\n2 1\n3 2" }, { "input": "1\n1 1\n1\n1", "output": "1 1\n1 1" }, { "input": "1\n2 1\n1\n1", "output": "0 0" }, { "input": "2\n10 10\n5 5\n1\n5", "output": "1 5\n2 1" }, { "input": "2\n10 10\n5 5\n1\n10", "output": "1 10\n1 1" }, { "input": "2\n2 100\n10 10\n1\n10", "output": "1 100\n1 1" }, { "input": "2\n10 100\n5 90\n2\n15 20", "output": "2 190\n1 1\n2 2" }, { "input": "3\n10 10\n3 5\n5 8\n3\n3 4 10", "output": "2 15\n1 3\n2 1" }, { "input": "10\n739 307\n523 658\n700 143\n373 577\n120 433\n353 833\n665 516\n988 101\n817 604\n800 551\n10\n431 425 227 147 153 170 954 757 222 759", "output": "6 3621\n6 2\n2 8\n9 7\n4 1\n7 10\n5 4" }, { "input": "9\n216 860\n299 720\n688 831\n555 733\n863 873\n594 923\n583 839\n738 824\n57 327\n10\n492 578 452 808 492 163 670 31 267 627", "output": "7 5233\n6 10\n1 9\n7 7\n3 4\n4 2\n2 3\n9 6" }, { "input": "3\n694 606\n76 973\n676 110\n5\n592 737 313 903 13", "output": "3 1689\n2 3\n1 2\n3 4" }, { "input": "7\n172 864\n853 523\n368 989\n920 452\n351 456\n269 104\n313 677\n9\n165 47 259 51 693 941 471 871 206", "output": "5 3509\n3 7\n1 9\n7 5\n2 8\n5 6" }, { "input": "1\n545 609\n4\n584 822 973 652", "output": "1 609\n1 1" }, { "input": "9\n23 163\n895 838\n344 444\n284 763\n942 39\n431 92\n147 515\n59 505\n940 999\n8\n382 497 297 125 624 212 851 859", "output": "6 2482\n4 3\n7 6\n8 4\n3 1\n1 2\n6 5" }, { "input": "3\n500 613\n671 899\n628 131\n10\n622 467 479 982 886 968 326 64 228 321", "output": "3 1643\n2 5\n1 1\n3 6" }, { "input": "7\n682 870\n640 857\n616 306\n649 777\n725 215\n402 977\n981 353\n1\n846", "output": "1 977\n6 1" }, { "input": "1\n160 616\n5\n406 713 290 308 741", "output": "1 616\n1 3" }, { "input": "6\n397 946\n871 126\n800 290\n505 429\n239 43\n320 292\n9\n387 925 9 440 395 320 58 707 994", "output": "6 2126\n1 4\n4 8\n6 6\n3 2\n2 9\n5 1" }, { "input": "1\n3 20\n4\n3 2 1 4", "output": "1 20\n1 1" }, { "input": "2\n2 100\n1 1000\n1\n2", "output": "1 1000\n2 1" } ]
1,397,402,485
2,485
Python 3
WRONG_ANSWER
TESTS
4
61
0
n=int(input()) P=[] for i in range(n): x,y=map(int,input().split()) P.append((y,x,i)) k=int(input()) L=list(map(int,input().split())) for i in range(k): L[i]=(L[i],i) L.sort() P.sort() ans=0 Taken=[False]*k r=0 Ans=[-1]*n for i in range(n): for j in range(k): if(L[j][0]>=P[i][1] and Taken[j]==False): Taken[j]=True ans+=P[i][0] r+=1 Ans[P[i][2]]=L[j][1] break print(r,ans) for i in range(n): if(Ans[i]==-1): continue print(i+1,Ans[i]+1)
Title: Booking System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly. We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment. Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing. Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table. Output Specification: In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly. Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them. Demo Input: ['3\n10 50\n2 100\n5 30\n3\n4 6 9\n'] Demo Output: ['2 130\n2 1\n3 2\n'] Note: none
```python n=int(input()) P=[] for i in range(n): x,y=map(int,input().split()) P.append((y,x,i)) k=int(input()) L=list(map(int,input().split())) for i in range(k): L[i]=(L[i],i) L.sort() P.sort() ans=0 Taken=[False]*k r=0 Ans=[-1]*n for i in range(n): for j in range(k): if(L[j][0]>=P[i][1] and Taken[j]==False): Taken[j]=True ans+=P[i][0] r+=1 Ans[P[i][2]]=L[j][1] break print(r,ans) for i in range(n): if(Ans[i]==-1): continue print(i+1,Ans[i]+1) ```
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,672,156,757
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n=int(input()) if 1<=n<=100: for i in range(0, n): w=str(input()) if len(w)>10 and w.isalpha()==True and w.isupper()==False and 1<=len(w)<=100: print(w[0]+str(len(w))+w[-1]) elif len(w)<10 and w.isupper()==False and w.isalpha()==True and 1<=len(w)<=100: print(w)
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 n=int(input()) if 1<=n<=100: for i in range(0, n): w=str(input()) if len(w)>10 and w.isalpha()==True and w.isupper()==False and 1<=len(w)<=100: print(w[0]+str(len(w))+w[-1]) elif len(w)<10 and w.isupper()==False and w.isalpha()==True and 1<=len(w)<=100: print(w) ```
0
991
E
Bus Number
PROGRAMMING
1,800
[ "brute force", "combinatorics", "math" ]
null
null
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given $n$, determine the total number of possible bus number variants.
The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$.
Output a single integer — the amount of possible variants of the real bus number.
[ "97\n", "2028\n" ]
[ "2\n", "13\n" ]
In the first sample, only variants $97$ and $79$ are possible. In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$.
2,000
[ { "input": "97", "output": "2" }, { "input": "2028", "output": "13" }, { "input": "1", "output": "1" }, { "input": "10", "output": "1" }, { "input": "168", "output": "6" }, { "input": "999999", "output": "6" }, { "input": "987654320023456789", "output": "29340299842560" }, { "input": "1000000000000000000", "output": "18" }, { "input": "74774", "output": "28" }, { "input": "2", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "6", "output": "1" }, { "input": "7", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "101010101", "output": "246" }, { "input": "1010101010", "output": "456" }, { "input": "707070707070707070", "output": "92368" }, { "input": "19293", "output": "84" }, { "input": "987650", "output": "600" }, { "input": "123456", "output": "720" }, { "input": "900008", "output": "28" }, { "input": "1000000", "output": "6" }, { "input": "9900111", "output": "404" }, { "input": "11112222", "output": "242" }, { "input": "88888880", "output": "28" }, { "input": "100000009", "output": "70" }, { "input": "203456799", "output": "196560" }, { "input": "890009800", "output": "1120" }, { "input": "900000000", "output": "8" }, { "input": "987654321", "output": "362880" }, { "input": "999999999", "output": "9" }, { "input": "1000000000", "output": "9" }, { "input": "999999999999999999", "output": "18" }, { "input": "987654321123456789", "output": "33007837322880" }, { "input": "987654321123456780", "output": "55657759288320" }, { "input": "888888888888888888", "output": "18" }, { "input": "888884444444448888", "output": "184736" }, { "input": "880000000008888888", "output": "92368" }, { "input": "122661170586643693", "output": "4205605773600" }, { "input": "166187867387753706", "output": "224244425700" }, { "input": "54405428089931205", "output": "417074011200" }, { "input": "96517150587709082", "output": "417074011200" }, { "input": "234906817379759421", "output": "22773236965920" }, { "input": "470038695054731020", "output": "5099960335680" }, { "input": "888413836884649324", "output": "76835760120" }, { "input": "978691308972024154", "output": "33638772575520" }, { "input": "484211136976275613", "output": "6471643862880" }, { "input": "824250067279351651", "output": "21519859273920" }, { "input": "269041787841325833", "output": "22773236965920" }, { "input": "462534182594129378", "output": "13498126800480" }, { "input": "79318880250640214", "output": "2075276790720" }, { "input": "58577142509378476", "output": "1126629393120" }, { "input": "973088698775609061", "output": "1646603038080" }, { "input": "529916324588161451", "output": "3614537707200" }, { "input": "406105326393716536", "output": "2760291011520" }, { "input": "490977896148785607", "output": "2054415328560" }, { "input": "547694365350162078", "output": "21519859273920" }, { "input": "868572419889505545", "output": "1124978369760" } ]
1,657,784,381
2,147,483,647
Python 3
OK
TESTS
61
46
102,400
from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i-1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n+1)) for k, n in ds.items()]): possib = list(possib) non_zero_sum = sum(v for k, v in possib if k != '0') total = sum(v for _, v in possib) value = non_zero_sum * fac[total-1] for _, v in possib: value //= fac[v] res += value print(res)
Title: Bus Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given $n$, determine the total number of possible bus number variants. Input Specification: The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$. Output Specification: Output a single integer — the amount of possible variants of the real bus number. Demo Input: ['97\n', '2028\n'] Demo Output: ['2\n', '13\n'] Note: In the first sample, only variants $97$ and $79$ are possible. In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$.
```python from collections import Counter from itertools import product s = input() ds = Counter(s) fac = [1 for i in range(100)] for i in range(1, 100): fac[i] = fac[i-1] * i res = 0 for possib in product(*[zip([k] * n, range(1, n+1)) for k, n in ds.items()]): possib = list(possib) non_zero_sum = sum(v for k, v in possib if k != '0') total = sum(v for _, v in possib) value = non_zero_sum * fac[total-1] for _, v in possib: value //= fac[v] res += value print(res) ```
3
416
B
Art Union
PROGRAMMING
1,300
[ "brute force", "dp", "implementation" ]
null
null
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these *n* colors. Adding the *j*-th color to the *i*-th picture takes the *j*-th painter *t**ij* units of time. Order is important everywhere, so the painters' work is ordered by the following rules: - Each picture is first painted by the first painter, then by the second one, and so on. That is, after the *j*-th painter finishes working on the picture, it must go to the (*j*<=+<=1)-th painter (if *j*<=&lt;<=*n*); - each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on; - each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest; - as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter. Given that the painters start working at time 0, find for each picture the time when it is ready for sale.
The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture.
Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
[ "5 1\n1\n2\n3\n4\n5\n", "4 2\n2 5\n3 1\n5 3\n10 1\n" ]
[ "1 3 6 10 15 ", "7 8 13 21 " ]
none
1,000
[ { "input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15 " }, { "input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21 " }, { "input": "1 1\n66", "output": "66 " }, { "input": "2 2\n1 1\n1 1", "output": "2 3 " }, { "input": "2 2\n10 1\n10 1", "output": "11 21 " }, { "input": "1 5\n1 95 44 14 35", "output": "189 " }, { "input": "7 1\n80\n92\n24\n88\n40\n45\n7", "output": "80 172 196 284 324 369 376 " }, { "input": "1 2\n51 44", "output": "95 " }, { "input": "2 1\n19\n4", "output": "19 23 " }, { "input": "2 2\n1 10\n1 1", "output": "11 12 " }, { "input": "3 3\n3 9 4\n5 10 8\n4 4 7", "output": "16 30 37 " }, { "input": "10 3\n6 10 3\n2 7 9\n10 4 7\n6 3 4\n6 2 6\n8 4 4\n5 9 8\n6 9 7\n2 7 10\n2 6 2", "output": "19 32 39 43 49 53 61 68 78 80 " } ]
1,560,295,834
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
num = map(int, raw_input().split()) m = num[0] n = num[1] matriz=[] for i in range(m): lista=[] matriz.append(lista) for i in range(m): valor = map(int, raw_input().split()) for j in range(n): matriz[i].append(valor[j]) for i in range(m): for j in range(n): if ((i == 0 and j == 0)== False): if(i == 0 and j != 0): matriz[i][j]=(matriz[i][j]+matriz[i][j-1]) else: if (i != 0 and j == 0): matriz[i][j]=(matriz[i][j] + matriz[i-1][j]) else: maximo = max(matriz[i-1][j] , matriz[i][j-1]) matriz[i][j]=(matriz[i][j] + maximo) resp = "" for i in range(m): resp = resp+str(matriz[i][n-1])+" " print(resp)
Title: Art Union Time Limit: None seconds Memory Limit: None megabytes Problem Description: A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these *n* colors. Adding the *j*-th color to the *i*-th picture takes the *j*-th painter *t**ij* units of time. Order is important everywhere, so the painters' work is ordered by the following rules: - Each picture is first painted by the first painter, then by the second one, and so on. That is, after the *j*-th painter finishes working on the picture, it must go to the (*j*<=+<=1)-th painter (if *j*<=&lt;<=*n*); - each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on; - each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest; - as soon as the *j*-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter. Given that the painters start working at time 0, find for each picture the time when it is ready for sale. Input Specification: The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), where *t**ij* is the time the *j*-th painter needs to work on the *i*-th picture. Output Specification: Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture. Demo Input: ['5 1\n1\n2\n3\n4\n5\n', '4 2\n2 5\n3 1\n5 3\n10 1\n'] Demo Output: ['1 3 6 10 15 ', '7 8 13 21 '] Note: none
```python num = map(int, raw_input().split()) m = num[0] n = num[1] matriz=[] for i in range(m): lista=[] matriz.append(lista) for i in range(m): valor = map(int, raw_input().split()) for j in range(n): matriz[i].append(valor[j]) for i in range(m): for j in range(n): if ((i == 0 and j == 0)== False): if(i == 0 and j != 0): matriz[i][j]=(matriz[i][j]+matriz[i][j-1]) else: if (i != 0 and j == 0): matriz[i][j]=(matriz[i][j] + matriz[i-1][j]) else: maximo = max(matriz[i-1][j] , matriz[i][j-1]) matriz[i][j]=(matriz[i][j] + maximo) resp = "" for i in range(m): resp = resp+str(matriz[i][n-1])+" " print(resp) ```
-1
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,656,686,338
2,147,483,647
Python 3
OK
TESTS
79
46
0
(left_handers, right_handers, ambidexters) = map(int, input().split(' ')) if left_handers > right_handers: if left_handers >= right_handers + ambidexters: print((right_handers + ambidexters) * 2) else: print(left_handers * 2 + (right_handers + ambidexters - left_handers)// 2 * 2) elif right_handers > left_handers: if right_handers >= left_handers + ambidexters: print((left_handers + ambidexters) * 2) else: print(right_handers * 2 + (left_handers + ambidexters - right_handers)// 2 * 2) elif right_handers == left_handers: print(right_handers * 2 + ambidexters // 2 * 2)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python (left_handers, right_handers, ambidexters) = map(int, input().split(' ')) if left_handers > right_handers: if left_handers >= right_handers + ambidexters: print((right_handers + ambidexters) * 2) else: print(left_handers * 2 + (right_handers + ambidexters - left_handers)// 2 * 2) elif right_handers > left_handers: if right_handers >= left_handers + ambidexters: print((left_handers + ambidexters) * 2) else: print(right_handers * 2 + (left_handers + ambidexters - right_handers)// 2 * 2) elif right_handers == left_handers: print(right_handers * 2 + ambidexters // 2 * 2) ```
3
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "output": "80" }, { "input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR", "output": "84" }, { "input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD", "output": "76" }, { "input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR", "output": "86" }, { "input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR", "output": "84" }, { "input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL", "output": "86" }, { "input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU", "output": "86" }, { "input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL", "output": "84" }, { "input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR", "output": "82" }, { "input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD", "output": "92" }, { "input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD", "output": "86" }, { "input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL", "output": "88" }, { "input": "1\nU", "output": "0" }, { "input": "5\nUUULD", "output": "2" }, { "input": "1\nD", "output": "0" }, { "input": "5\nURLUL", "output": "2" }, { "input": "5\nDDDRU", "output": "2" }, { "input": "2\nLR", "output": "2" }, { "input": "8\nDDRDLDUR", "output": "4" }, { "input": "6\nLLLLUD", "output": "2" }, { "input": "13\nRRRLLLLLLLLLL", "output": "6" } ]
1,623,835,260
2,147,483,647
PyPy 3
OK
TESTS
25
109
0
n = int(input()) daf = input() cu = daf.count('U') cd = daf.count('D') cl = daf.count('L') cr = daf.count('R') print((min(cu, cd) + min(cl, cr)) * 2)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! Input Specification: The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. Output Specification: Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. Demo Input: ['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n'] Demo Output: ['4\n', '0\n', '4\n'] Note: none
```python n = int(input()) daf = input() cu = daf.count('U') cd = daf.count('D') cl = daf.count('L') cr = daf.count('R') print((min(cu, cd) + min(cl, cr)) * 2) ```
3
699
A
Launch of Collider
PROGRAMMING
1,000
[ "implementation" ]
null
null
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
[ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n" ]
[ "1\n", "-1\n" ]
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
500
[ { "input": "4\nRLRL\n2 4 6 10", "output": "1" }, { "input": "3\nLLR\n40 50 60", "output": "-1" }, { "input": "4\nRLLR\n46 230 264 470", "output": "92" }, { "input": "6\nLLRLLL\n446 492 650 844 930 970", "output": "97" }, { "input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922", "output": "17" }, { "input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000", "output": "3" }, { "input": "2\nRL\n0 1000000000", "output": "500000000" }, { "input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082", "output": "108" }, { "input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418", "output": "88" }, { "input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668", "output": "123" }, { "input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808", "output": "10" }, { "input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970", "output": "252" }, { "input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830", "output": "48" }, { "input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720", "output": "27" }, { "input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402", "output": "59" }, { "input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626", "output": "10" }, { "input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794", "output": "7" }, { "input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18", "output": "-1" }, { "input": "5\nLLLLL\n0 10 20 30 40", "output": "-1" }, { "input": "6\nRRRRRR\n40 50 60 70 80 100", "output": "-1" }, { "input": "1\nR\n0", "output": "-1" }, { "input": "2\nRL\n2 1000000000", "output": "499999999" }, { "input": "2\nRL\n0 400000", "output": "200000" }, { "input": "2\nRL\n0 200002", "output": "100001" }, { "input": "2\nRL\n2 20000000", "output": "9999999" }, { "input": "4\nLLRL\n2 4 10 100", "output": "45" }, { "input": "4\nRLRL\n2 10 12 14", "output": "1" }, { "input": "2\nRL\n0 100000000", "output": "50000000" }, { "input": "2\nRL\n2 600002", "output": "300000" }, { "input": "1\nL\n0", "output": "-1" }, { "input": "2\nRL\n0 600000", "output": "300000" }, { "input": "5\nRRRRR\n0 2 4 6 8", "output": "-1" }, { "input": "2\nRL\n2 200000000", "output": "99999999" }, { "input": "2\nRL\n0 267382766", "output": "133691383" }, { "input": "3\nRRL\n4 8 999999998", "output": "499999995" }, { "input": "2\nRL\n0 2", "output": "1" }, { "input": "2\nRL\n2 400002", "output": "200000" }, { "input": "2\nLL\n2 4", "output": "-1" }, { "input": "2\nLL\n0 2", "output": "-1" }, { "input": "2\nRL\n0 100000", "output": "50000" }, { "input": "2\nRL\n2 200000020", "output": "100000009" }, { "input": "2\nRL\n2000000 4000000", "output": "1000000" }, { "input": "2\nRL\n0 199998", "output": "99999" }, { "input": "3\nLRR\n40 50 60", "output": "-1" }, { "input": "2\nRL\n200 400400", "output": "200100" }, { "input": "2\nRL\n2 400004", "output": "200001" }, { "input": "2\nRL\n0 200000000", "output": "100000000" } ]
1,595,528,273
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
46
2,000
38,297,600
n = int(input()) s = input() arr = list(map(int, input().split())) mn = float('inf') for i in range(n): if s[i] == 'R': for j in range(i+1, n): if s[j] == 'L': mn = min(mn, arr[j] - arr[i]) break if mn == float('inf'): print(-1) else: print(mn // 2)
Title: Launch of Collider Time Limit: None seconds Memory Limit: None megabytes Problem Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. Input Specification: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. Output Specification: In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. Demo Input: ['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n'] Demo Output: ['1\n', '-1\n'] Note: In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
```python n = int(input()) s = input() arr = list(map(int, input().split())) mn = float('inf') for i in range(n): if s[i] == 'R': for j in range(i+1, n): if s[j] == 'L': mn = min(mn, arr[j] - arr[i]) break if mn == float('inf'): print(-1) else: print(mn // 2) ```
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,683,114,991
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
# 输入数字 print("请输入数字:") n = input() number = int(n) if len(n) == 1: print(n) else: if 0 <= number <= 10 ** 100000 and n[0] != '0': while len(n) > 1: numsum = sum(int(num) for num in n) n = str(numsum) print(n) else: print("请输入在0到10的十万次方且不包含任何前导零的数字") n = input()
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 # 输入数字 print("请输入数字:") n = input() number = int(n) if len(n) == 1: print(n) else: if 0 <= number <= 10 ** 100000 and n[0] != '0': while len(n) > 1: numsum = sum(int(num) for num in n) n = str(numsum) print(n) else: print("请输入在0到10的十万次方且不包含任何前导零的数字") n = input() ```
-1
877
B
Nikita and string
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
[ "abba\n", "bab\n" ]
[ "4", "2" ]
It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
1,000
[ { "input": "abba", "output": "4" }, { "input": "bab", "output": "2" }, { "input": "bbabbbaabbbb", "output": "9" }, { "input": "bbabbbbbaaba", "output": "10" }, { "input": "bbabbbababaa", "output": "9" }, { "input": "aabbaababbab", "output": "8" }, { "input": "a", "output": "1" }, { "input": "b", "output": "1" }, { "input": "ab", "output": "2" }, { "input": "ba", "output": "2" }, { "input": "bb", "output": "2" }, { "input": "aa", "output": "2" }, { "input": "babbbaab", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaa", "output": "3" } ]
1,644,242,372
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
s=input() p=[[0,0]] o=0 ans=-float("inf") u=0 for ch in s: p.append(p[-1][:]) if ch=="a": p[-1][0]+=1 o+=1 else : p[-1][1]+=1 u+=1 for i in range(len(s)-1): for j in range(i+1,len(s)+1): a=p[i+1][0] b=p[j][1]-p[i+1][1] c=o-p[j][0] ans=max(ans,a+b+c) print(ans)
Title: Nikita and string Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? Input Specification: The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". Output Specification: Print a single integer — the maximum possible size of beautiful string Nikita can get. Demo Input: ['abba\n', 'bab\n'] Demo Output: ['4', '2'] Note: It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
```python s=input() p=[[0,0]] o=0 ans=-float("inf") u=0 for ch in s: p.append(p[-1][:]) if ch=="a": p[-1][0]+=1 o+=1 else : p[-1][1]+=1 u+=1 for i in range(len(s)-1): for j in range(i+1,len(s)+1): a=p[i+1][0] b=p[j][1]-p[i+1][1] c=o-p[j][0] ans=max(ans,a+b+c) print(ans) ```
0
620
B
Grandfather Dovlet’s calculator
PROGRAMMING
1,000
[ "implementation" ]
null
null
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator. For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Print the only integer *a* — the total number of printed segments.
[ "1 3\n", "10 15\n" ]
[ "12\n", "39\n" ]
none
0
[ { "input": "1 3", "output": "12" }, { "input": "10 15", "output": "39" }, { "input": "1 100", "output": "928" }, { "input": "100 10000", "output": "188446" }, { "input": "213 221442", "output": "5645356" }, { "input": "1 1000000", "output": "28733372" }, { "input": "1000000 1000000", "output": "38" }, { "input": "222145 353252", "output": "3860750" }, { "input": "2 1000000", "output": "28733370" }, { "input": "1 999999", "output": "28733334" }, { "input": "192 200", "output": "122" } ]
1,561,094,947
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
0
A={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6} count = 0 a,b=list(map(int,input().split())) for val in range(a,b+1): Str=str(val) for v in Str: count += A[v] print(count)
Title: Grandfather Dovlet’s calculator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator. For example if *a*<==<=1 and *b*<==<=3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12. Input Specification: The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. Output Specification: Print the only integer *a* — the total number of printed segments. Demo Input: ['1 3\n', '10 15\n'] Demo Output: ['12\n', '39\n'] Note: none
```python A={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6} count = 0 a,b=list(map(int,input().split())) for val in range(a,b+1): Str=str(val) for v in Str: count += A[v] print(count) ```
0
8
A
Train and Peter
PROGRAMMING
1,200
[ "strings" ]
A. Train and Peter
1
64
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
[ "atob\na\nb\n", "aaacaaa\naca\naa\n" ]
[ "forward\n", "both\n" ]
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
0
[ { "input": "atob\na\nb", "output": "forward" }, { "input": "aaacaaa\naca\naa", "output": "both" }, { "input": "aaa\naa\naa", "output": "fantasy" }, { "input": "astalavista\nastla\nlavista", "output": "fantasy" }, { "input": "abacabadabacaba\nabacaba\nabacaba", "output": "both" }, { "input": "a\na\na", "output": "fantasy" }, { "input": "ab\nb\na", "output": "backward" }, { "input": "aaa\naaaa\naaaa", "output": "fantasy" }, { "input": "bbabbbbababbaabaabaa\nabb\nbaab", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa", "output": "backward" }, { "input": "aaaa\naaa\naa", "output": "fantasy" }, { "input": "zzzz\nzz\nzzz", "output": "fantasy" }, { "input": "zzzz\nzzzz\nzzzz", "output": "fantasy" }, { "input": "zzzz\nzz\nzz", "output": "both" }, { "input": "aabaa\naab\nbaa", "output": "fantasy" }, { "input": "aabaab\naba\nab", "output": "forward" }, { "input": "aab\nb\naa", "output": "backward" }, { "input": "abacaba\naca\nba", "output": "both" } ]
1,659,247,949
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
t1=input() s1=input() s2=input() t1=t1[::-1] ans=0 k1=t1.find() if k1!=-1: k2=t1.find(s2,k1+len(t1)) if k2!=0:ans+=1 if ans==1:print('forward') elif ans==2:print('backward') elif ans==3:print('both') else:print('fantasy')
Title: Train and Peter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. Input Specification: The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. Output Specification: Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. Demo Input: ['atob\na\nb\n', 'aaacaaa\naca\naa\n'] Demo Output: ['forward\n', 'both\n'] Note: It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
```python t1=input() s1=input() s2=input() t1=t1[::-1] ans=0 k1=t1.find() if k1!=-1: k2=t1.find(s2,k1+len(t1)) if k2!=0:ans+=1 if ans==1:print('forward') elif ans==2:print('backward') elif ans==3:print('both') else:print('fantasy') ```
-1
926
C
Is This a Zebra?
PROGRAMMING
1,700
[ "implementation" ]
null
null
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of *n* zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black. You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,<=0,<=0,<=1,<=1,<=1,<=0,<=0,<=0] can be a photo of zebra, while the photo [0,<=0,<=0,<=1,<=1,<=1,<=1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the width of the photo. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=1) — the description of the photo. If *a**i* is zero, the *i*-th column is all black. If *a**i* is one, then the *i*-th column is all white.
If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower).
[ "9\n0 0 0 1 1 1 0 0 0\n", "7\n0 0 0 1 1 1 1\n", "5\n1 1 1 1 1\n", "8\n1 1 1 0 0 0 1 1\n", "9\n1 1 0 1 1 0 1 1 0\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n" ]
The first two examples are described in the statements. In the third example all pixels are white, so the photo can be a photo of zebra. In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.
0
[ { "input": "9\n0 0 0 1 1 1 0 0 0", "output": "YES" }, { "input": "7\n0 0 0 1 1 1 1", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "YES" }, { "input": "8\n1 1 1 0 0 0 1 1", "output": "NO" }, { "input": "9\n1 1 0 1 1 0 1 1 0", "output": "NO" }, { "input": "1\n0", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "2\n0 0", "output": "YES" }, { "input": "2\n0 1", "output": "YES" }, { "input": "2\n1 0", "output": "YES" }, { "input": "2\n1 1", "output": "YES" }, { "input": "3\n1 1 0", "output": "NO" }, { "input": "7\n0 0 0 1 1 1 0", "output": "NO" }, { "input": "3\n0 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "6\n0 0 1 0 1 0", "output": "NO" }, { "input": "4\n0 1 1 0", "output": "NO" }, { "input": "5\n0 1 1 0 0", "output": "NO" }, { "input": "4\n0 1 0 0", "output": "NO" }, { "input": "5\n1 1 1 0 0", "output": "NO" }, { "input": "10\n0 0 1 1 0 0 0 1 1 1", "output": "NO" }, { "input": "5\n0 0 0 0 1", "output": "NO" }, { "input": "14\n0 0 0 1 1 1 1 0 0 0 0 1 1 1", "output": "NO" }, { "input": "4\n1 0 1 0", "output": "YES" }, { "input": "5\n1 0 0 0 1", "output": "NO" }, { "input": "6\n1 1 1 0 1 1", "output": "NO" }, { "input": "7\n1 1 1 1 1 0 1", "output": "NO" }, { "input": "8\n1 1 0 0 1 1 0 0", "output": "YES" }, { "input": "9\n0 1 1 0 0 0 1 1 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 1 1 1 1 1", "output": "YES" }, { "input": "11\n0 1 0 1 0 1 0 0 0 1 0", "output": "NO" }, { "input": "20\n1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0", "output": "YES" }, { "input": "50\n0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1", "output": "NO" }, { "input": "100\n1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1", "output": "YES" }, { "input": "3\n0 0 0", "output": "YES" }, { "input": "3\n0 1 0", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 1 1", "output": "YES" } ]
1,521,359,278
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
7,065,600
n = input() b = map(eval, raw_input().split(" ")) c = [1] for i in range(1, n): if (b[i] == b[i-1]): c[-1] += 1 else : c.append(1) for i in range(1, len(c)) : if (c[i] != c[i-1]) : print("NO") exit() print("YES")
Title: Is This a Zebra? Time Limit: None seconds Memory Limit: None megabytes Problem Description: A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of *n* pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of *n* zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black. You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0,<=0,<=0,<=1,<=1,<=1,<=0,<=0,<=0] can be a photo of zebra, while the photo [0,<=0,<=0,<=1,<=1,<=1,<=1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the width of the photo. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=1) — the description of the photo. If *a**i* is zero, the *i*-th column is all black. If *a**i* is one, then the *i*-th column is all white. Output Specification: If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO". You can print each letter in any case (upper or lower). Demo Input: ['9\n0 0 0 1 1 1 0 0 0\n', '7\n0 0 0 1 1 1 1\n', '5\n1 1 1 1 1\n', '8\n1 1 1 0 0 0 1 1\n', '9\n1 1 0 1 1 0 1 1 0\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n', 'NO\n'] Note: The first two examples are described in the statements. In the third example all pixels are white, so the photo can be a photo of zebra. In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.
```python n = input() b = map(eval, raw_input().split(" ")) c = [1] for i in range(1, n): if (b[i] == b[i-1]): c[-1] += 1 else : c.append(1) for i in range(1, len(c)) : if (c[i] != c[i-1]) : print("NO") exit() print("YES") ```
-1
868
A
Bark to Unlock
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
250
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { "input": "ba\n4\ncd\nad\ncc\ncb", "output": "YES" }, { "input": "pg\n4\nzl\nxs\ndi\nxn", "output": "NO" }, { "input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu", "output": "YES" }, { "input": "bb\n1\naa", "output": "NO" }, { "input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "NO" }, { "input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "bb\n1\nbb", "output": "YES" }, { "input": "ba\n1\ncc", "output": "NO" }, { "input": "ha\n1\nha", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "ez\n1\njl", "output": "NO" }, { "input": "aa\n2\nab\nba", "output": "YES" }, { "input": "aa\n2\nca\ncc", "output": "NO" }, { "input": "dd\n2\nac\ndc", "output": "NO" }, { "input": "qc\n2\nyc\nkr", "output": "NO" }, { "input": "aa\n3\nba\nbb\nab", "output": "YES" }, { "input": "ca\n3\naa\nbb\nab", "output": "NO" }, { "input": "ca\n3\nbc\nbd\nca", "output": "YES" }, { "input": "dd\n3\nmt\nrg\nxl", "output": "NO" }, { "input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb", "output": "YES" }, { "input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef", "output": "YES" }, { "input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca", "output": "YES" }, { "input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb", "output": "YES" }, { "input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc", "output": "YES" }, { "input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb", "output": "YES" }, { "input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha", "output": "YES" }, { "input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd", "output": "YES" }, { "input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi", "output": "YES" }, { "input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi", "output": "YES" }, { "input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj", "output": "YES" }, { "input": "ab\n1\nab", "output": "YES" }, { "input": "ya\n1\nya", "output": "YES" }, { "input": "ay\n1\nyb", "output": "NO" }, { "input": "ax\n2\nii\nxa", "output": "YES" }, { "input": "hi\n1\nhi", "output": "YES" }, { "input": "ag\n1\nag", "output": "YES" }, { "input": "th\n1\nth", "output": "YES" }, { "input": "sb\n1\nsb", "output": "YES" }, { "input": "hp\n1\nhp", "output": "YES" }, { "input": "ah\n1\nah", "output": "YES" }, { "input": "ta\n1\nta", "output": "YES" }, { "input": "tb\n1\ntb", "output": "YES" }, { "input": "ab\n5\nca\nda\nea\nfa\nka", "output": "NO" }, { "input": "ac\n1\nac", "output": "YES" }, { "input": "ha\n2\nha\nzz", "output": "YES" }, { "input": "ok\n1\nok", "output": "YES" }, { "input": "bc\n1\nbc", "output": "YES" }, { "input": "az\n1\nzz", "output": "NO" }, { "input": "ab\n2\nba\ntt", "output": "YES" }, { "input": "ah\n2\nap\nhp", "output": "NO" }, { "input": "sh\n1\nsh", "output": "YES" }, { "input": "az\n1\nby", "output": "NO" }, { "input": "as\n1\nas", "output": "YES" }, { "input": "ab\n2\nab\ncd", "output": "YES" }, { "input": "ab\n2\nxa\nza", "output": "NO" }, { "input": "ab\n2\net\nab", "output": "YES" }, { "input": "ab\n1\naa", "output": "NO" }, { "input": "ab\n2\nab\nde", "output": "YES" }, { "input": "ah\n2\nba\nha", "output": "YES" }, { "input": "ha\n3\ndd\ncc\nha", "output": "YES" }, { "input": "oo\n1\nox", "output": "NO" }, { "input": "ab\n2\nax\nbx", "output": "NO" }, { "input": "ww\n4\nuw\now\npo\nko", "output": "NO" }, { "input": "ay\n1\nay", "output": "YES" }, { "input": "yo\n1\nyo", "output": "YES" }, { "input": "ba\n1\nba", "output": "YES" }, { "input": "qw\n1\nqw", "output": "YES" }, { "input": "la\n1\nla", "output": "YES" }, { "input": "ab\n2\nbb\nbc", "output": "NO" }, { "input": "aa\n2\nab\nac", "output": "NO" }, { "input": "ah\n2\nbb\nha", "output": "YES" }, { "input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek", "output": "NO" }, { "input": "ab\n3\nab\nxx\nyy", "output": "YES" }, { "input": "ab\n2\nab\ncc", "output": "YES" }, { "input": "sa\n2\nxx\nas", "output": "YES" }, { "input": "ma\n1\nma", "output": "YES" }, { "input": "ba\n1\nbb", "output": "NO" }, { "input": "bc\n1\nab", "output": "NO" }, { "input": "fa\n1\nfa", "output": "YES" }, { "input": "ap\n1\nap", "output": "YES" }, { "input": "ab\n1\nbb", "output": "NO" }, { "input": "bk\n1\nbk", "output": "YES" }, { "input": "xy\n2\nxy\naa", "output": "YES" }, { "input": "ab\n2\nza\nbz", "output": "YES" } ]
1,601,374,805
2,147,483,647
PyPy 3
OK
TESTS
90
156
0
s = input() n = int(input()) words = [input() for word in range(n)] ans = 'NO' if s in words: ans = 'YES' start, end = False, False for word in words: if word[0] == s[1]: start = True if word[1] == s[0]: end = True if start and end: break if start and end: ans = 'YES' print(ans)
Title: Bark to Unlock Time Limit: None seconds Memory Limit: None megabytes Problem Description: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not. Input Specification: The first line contains two lowercase English letters — the password on the phone. The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct. Output Specification: Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['ya\n4\nah\noy\nto\nha\n', 'hp\n2\nht\ntp\n', 'ah\n1\nha\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
```python s = input() n = int(input()) words = [input() for word in range(n)] ans = 'NO' if s in words: ans = 'YES' start, end = False, False for word in words: if word[0] == s[1]: start = True if word[1] == s[0]: end = True if start and end: break if start and end: ans = 'YES' print(ans) ```
3
616
D
Longest k-Good Segment
PROGRAMMING
1,600
[ "binary search", "data structures", "two pointers" ]
null
null
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
[ "5 5\n1 2 3 4 5\n", "9 3\n6 5 1 2 3 2 1 4 5\n", "3 1\n1 2 3\n" ]
[ "1 5\n", "3 7\n", "1 1\n" ]
none
0
[ { "input": "5 5\n1 2 3 4 5", "output": "1 5" }, { "input": "9 3\n6 5 1 2 3 2 1 4 5", "output": "3 7" }, { "input": "3 1\n1 2 3", "output": "1 1" }, { "input": "1 1\n747391", "output": "1 1" }, { "input": "5 2\n171230 171230 171230 171230 171230", "output": "1 5" }, { "input": "10 3\n512008 512008 452221 512008 314256 123232 314256 512008 314256 123232", "output": "4 10" }, { "input": "6 1\n1 1 2 1 1 1", "output": "4 6" }, { "input": "5 4\n1 2 3 4 0", "output": "1 4" }, { "input": "5 4\n2 3 4 5 0", "output": "1 4" }, { "input": "2 2\n0 1", "output": "1 2" }, { "input": "2 2\n0 0", "output": "1 2" }, { "input": "5 4\n1 2 3 45 0", "output": "1 4" } ]
1,654,234,478
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
35,737,600
n,k = map(int, input().split()) A = list(map(int, input().split())) from collections import Counter j = 0 S = set() C = Counter() ans = 0 l, r = -1, -1 for i in range(n): while j < n and len(S|{A[j]}) <= k: S.add(A[j]) C[A[j]] += 1 j += 1 if j-i > ans: ans = j-i l = i+1 r = j if i == j: j += 1 else: if C[A[i]] == 1: S.remove(A[i]) C[A[i]] -= 1 print(l, r)
Title: Longest k-Good Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Output Specification: Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right. Demo Input: ['5 5\n1 2 3 4 5\n', '9 3\n6 5 1 2 3 2 1 4 5\n', '3 1\n1 2 3\n'] Demo Output: ['1 5\n', '3 7\n', '1 1\n'] Note: none
```python n,k = map(int, input().split()) A = list(map(int, input().split())) from collections import Counter j = 0 S = set() C = Counter() ans = 0 l, r = -1, -1 for i in range(n): while j < n and len(S|{A[j]}) <= k: S.add(A[j]) C[A[j]] += 1 j += 1 if j-i > ans: ans = j-i l = i+1 r = j if i == j: j += 1 else: if C[A[i]] == 1: S.remove(A[i]) C[A[i]] -= 1 print(l, r) ```
0
465
B
Inbox (100500)
PROGRAMMING
1,000
[ "implementation" ]
null
null
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
[ "5\n0 1 0 1 0\n", "5\n1 1 0 0 1\n", "2\n0 0\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
1,000
[ { "input": "5\n0 1 0 1 0", "output": "3" }, { "input": "5\n1 1 0 0 1", "output": "4" }, { "input": "2\n0 0", "output": "0" }, { "input": "9\n1 0 1 0 1 0 1 0 1", "output": "9" }, { "input": "5\n1 1 1 1 1", "output": "5" }, { "input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "output": "11" }, { "input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "output": "23" }, { "input": "27\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0", "output": "25" }, { "input": "10\n1 0 0 0 0 1 0 0 0 1", "output": "5" }, { "input": "10\n1 0 0 1 0 0 1 1 0 1", "output": "8" }, { "input": "27\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", "output": "0" }, { "input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "39" }, { "input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1", "output": "39" }, { "input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0", "output": "59" }, { "input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "99" }, { "input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1", "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 1", "output": "100" }, { "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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99" }, { "input": "193\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "1" }, { "input": "213\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "5" }, { "input": "2\n1 0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n0 0 0 0 1", "output": "1" }, { "input": "12\n0 1 1 0 1 1 0 1 1 0 0 0", "output": "8" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "5\n0 0 1 0 0", "output": "1" }, { "input": "3\n0 1 0", "output": "1" }, { "input": "6\n1 1 0 0 0 0", "output": "2" }, { "input": "4\n0 1 0 0", "output": "1" }, { "input": "5\n1 1 1 0 0", "output": "3" }, { "input": "4\n1 0 0 0", "output": "1" }, { "input": "6\n1 1 1 1 0 0", "output": "4" } ]
1,642,587,581
2,147,483,647
PyPy 3-64
OK
TESTS
44
109
0
n = int(input()) mails = input() if mails.count('1') == 0: print(0) else: res = 0 mails = [x for x in mails.split('0') if x.count('1') >= 1] for i in mails: res += i.count('1') print(res + len(mails) - 1)
Title: Inbox (100500) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. Output Specification: Print a single number — the minimum number of operations needed to make all the letters read. Demo Input: ['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n'] Demo Output: ['3\n', '4\n', '0\n'] Note: In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
```python n = int(input()) mails = input() if mails.count('1') == 0: print(0) else: res = 0 mails = [x for x in mails.split('0') if x.count('1') >= 1] for i in mails: res += i.count('1') print(res + len(mails) - 1) ```
3
936
A
Save Energy!
PROGRAMMING
1,700
[ "binary search", "implementation", "math" ]
null
null
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018).
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if .
[ "3 2 6\n", "4 2 20\n" ]
[ "6.5\n", "20.0\n" ]
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
500
[ { "input": "3 2 6", "output": "6.5" }, { "input": "4 2 20", "output": "20.0" }, { "input": "8 10 9", "output": "10.0" }, { "input": "43 50 140", "output": "150.5" }, { "input": "251 79 76", "output": "76.0" }, { "input": "892 67 1000", "output": "1023.0" }, { "input": "1000 1000 1000", "output": "1000.0" }, { "input": "87 4 1000", "output": "1005.5" }, { "input": "1 629 384378949109878497", "output": "767537647587662141" }, { "input": "2124 6621 12695", "output": "19018" }, { "input": "27548 68747 111", "output": "111.0" }, { "input": "74974 46016 1000000000", "output": "1102134775.0" }, { "input": "223 844 704", "output": "1014.5" }, { "input": "1 558 743", "output": "1483" }, { "input": "43 387 402", "output": "718" }, { "input": "972 2 763", "output": "763.0" }, { "input": "330 167 15", "output": "15.0" }, { "input": "387 43 650", "output": "650.0" }, { "input": "1 314 824", "output": "1642" }, { "input": "2 4 18", "output": "24.0" }, { "input": "3 5 127", "output": "158.0" }, { "input": "3260 4439 6837", "output": "7426.5" }, { "input": "3950 7386 195", "output": "195.0" }, { "input": "18036 47899 1000000000", "output": "1452914012" }, { "input": "29 46 1000000000", "output": "1226666661.0" }, { "input": "403 957 1000000000000000000", "output": "1407352941176470446" }, { "input": "999999999999999999 1000000000000000000 1000000000000000000", "output": "1000000000000000000.5" }, { "input": "9 1000000000000000000 1000000000000000000", "output": "1999999999999999982" }, { "input": "1 2 1000000000000000000", "output": "1333333333333333333.0" }, { "input": "2 5 1000000000000000000", "output": "1428571428571428571.0" }, { "input": "81413279254461199 310548139128293806 1000000000000000000", "output": "1572837149684581517.5" }, { "input": "6 3 417701740543616353", "output": "417701740543616353.0" }, { "input": "17 68 4913", "output": "7854" }, { "input": "68 17 4913", "output": "4913.0" }, { "input": "121 395 621154158314692955", "output": "950991831528308936" }, { "input": "897 443 134730567336441375", "output": "160877739434079591.0" }, { "input": "200 10 979220166595737684", "output": "979220166595737684.0" }, { "input": "740 251 930540301905511549", "output": "938642796161889076.5" }, { "input": "4 232 801899894850800409", "output": "1576616742418522838" }, { "input": "472 499 166288453006087540", "output": "170912333779686266.5" }, { "input": "42 9 1000000000000000000", "output": "1034482758620689654.0" }, { "input": "312 93 1000000000000000000", "output": "1087719298245614020.0" }, { "input": "1000 1000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "6000 1000 1000000000", "output": "1000000000.0" }, { "input": "9999999999 33333 1000000000", "output": "1000000000.0" }, { "input": "33333 9999999999 1000000000", "output": "1999966667" }, { "input": "25441360464 2658201820 1000000000", "output": "1000000000.0" }, { "input": "20958318104 46685 253251869", "output": "253251869.0" }, { "input": "963276084 698548036 1000000000", "output": "1036723916" }, { "input": "574520976350867177 413897686591532160 1000000000000000000", "output": "1126637198416098571.5" }, { "input": "575556838390916379 15 1000000000000000000", "output": "1000000000000000003.0" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "1 1000000000000000000 1000000000000000000", "output": "1999999999999999998" }, { "input": "8 1000000000000000000 1000000000000000000", "output": "1999999999999999984" }, { "input": "1 976958144546785462 1000000000000000000", "output": "1999999999999999997" }, { "input": "3 10 1000000000000000000", "output": "1538461538461538461.0" }, { "input": "312200625484460654 543737694709247394 1000000000000000000", "output": "1231537069224786740.0" }, { "input": "2 99 53", "output": "102" }, { "input": "900000000000000000 1 1234", "output": "1234.0" } ]
1,555,775,928
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
a,b,c=map(int,input().split()) ans=0 r=a%b+a ws=a%b*1.5+a aa=c//r ans+=ws*aa c-=aa*r yhn=min(c,a) ans+=yhn c-=yhn yhn=min(c,a%b) c=0 ans+=yhn print(ans)
Title: Save Energy! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input Specification: The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018). Output Specification: Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if . Demo Input: ['3 2 6\n', '4 2 20\n'] Demo Output: ['6.5\n', '20.0\n'] Note: In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
```python a,b,c=map(int,input().split()) ans=0 r=a%b+a ws=a%b*1.5+a aa=c//r ans+=ws*aa c-=aa*r yhn=min(c,a) ans+=yhn c-=yhn yhn=min(c,a%b) c=0 ans+=yhn print(ans) ```
0
888
C
K-Dominant Character
PROGRAMMING
1,400
[ "binary search", "implementation", "two pointers" ]
null
null
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character.
The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000).
Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character.
[ "abacaba\n", "zzzzz\n", "abcde\n" ]
[ "2\n", "1\n", "3\n" ]
none
0
[ { "input": "abacaba", "output": "2" }, { "input": "zzzzz", "output": "1" }, { "input": "abcde", "output": "3" }, { "input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab", "output": "8" }, { "input": "daabcdabbabbacacbaacabacbcaabaacac", "output": "4" }, { "input": "abghim", "output": "4" }, { "input": "gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech", "output": "17" }, { "input": "a", "output": "1" }, { "input": "aaabbb", "output": "4" }, { "input": "ab", "output": "2" }, { "input": "abbb", "output": "2" }, { "input": "ob", "output": "2" }, { "input": "abccba", "output": "3" }, { "input": "saaaaaaaas", "output": "2" }, { "input": "axxx", "output": "2" }, { "input": "abcba", "output": "2" }, { "input": "abb", "output": "2" }, { "input": "abcdea", "output": "4" }, { "input": "axcbb", "output": "3" }, { "input": "tmivvdcbbfrfogjviirrximhttoskopwrcmkcborcxvr", "output": "13" }, { "input": "dlchmmuateksgldkckljrovmeuniobjrelqjpnjljlvhpqrjsfklliqpufplgaelevmlcnodbllquubobecem", "output": "15" }, { "input": "zx", "output": "2" }, { "input": "zxz", "output": "2" }, { "input": "bbhdgaefbhf", "output": "6" }, { "input": "xx", "output": "1" }, { "input": "zxx", "output": "2" }, { "input": "cbcada", "output": "4" }, { "input": "z", "output": "1" }, { "input": "aab", "output": "2" }, { "input": "jficc", "output": "3" }, { "input": "cceeaabfba", "output": "5" }, { "input": "jk", "output": "2" }, { "input": "lzeznbwu", "output": "5" }, { "input": "rr", "output": "1" } ]
1,610,218,569
2,147,483,647
PyPy 3
OK
TESTS
51
170
3,276,800
import string from collections import defaultdict s=input() window=defaultdict(list) character_set=string.ascii_lowercase n,ans=len(s),len(s) for idx,char in enumerate(character_set): prev=-1 consider=-10**9-7 for jdx,x in enumerate(s): if x==char: consider=max(consider,jdx-prev) prev=jdx consider=max(consider,n-prev) if prev!=-1: ans=min(ans,consider) print(ans)
Title: K-Dominant Character Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character. Input Specification: The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). Output Specification: Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. Demo Input: ['abacaba\n', 'zzzzz\n', 'abcde\n'] Demo Output: ['2\n', '1\n', '3\n'] Note: none
```python import string from collections import defaultdict s=input() window=defaultdict(list) character_set=string.ascii_lowercase n,ans=len(s),len(s) for idx,char in enumerate(character_set): prev=-1 consider=-10**9-7 for jdx,x in enumerate(s): if x==char: consider=max(consider,jdx-prev) prev=jdx consider=max(consider,n-prev) if prev!=-1: ans=min(ans,consider) print(ans) ```
3
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,696,585,910
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
26,521,600
import math from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin n = int(stream.readline()) n_arr = [int(i) for i in stream.readline().split()] def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) minn = min(n_arr) maxn = max(n_arr) comb = (n_arr.count(minn) * n_arr.count(maxn)) if minn != maxn else ncr(n_arr.count(minn), 2) print(maxn - minn, comb)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python import math from sys import stdin stream = None try: stream = open('file.txt', 'r') except: stream = stdin n = int(stream.readline()) n_arr = [int(i) for i in stream.readline().split()] def ncr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) minn = min(n_arr) maxn = max(n_arr) comb = (n_arr.count(minn) * n_arr.count(maxn)) if minn != maxn else ncr(n_arr.count(minn), 2) print(maxn - minn, comb) ```
0
710
B
Optimal Point on a Line
PROGRAMMING
1,400
[ "brute force", "sortings" ]
null
null
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
[ "4\n1 2 3 4\n" ]
[ "2\n" ]
none
0
[ { "input": "4\n1 2 3 4", "output": "2" }, { "input": "5\n-1 -10 2 6 7", "output": "2" }, { "input": "10\n-68 10 87 22 30 89 82 -97 -52 25", "output": "22" }, { "input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424", "output": "64" }, { "input": "2\n-1 0", "output": "-1" }, { "input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981", "output": "15" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "4\n-1 -1 0 1", "output": "-1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 1000000000", "output": "0" }, { "input": "2\n1 -1", "output": "-1" }, { "input": "2\n100 50", "output": "50" }, { "input": "2\n1 2", "output": "1" }, { "input": "1\n10", "output": "10" }, { "input": "3\n606194955 -856471310 117647402", "output": "117647402" }, { "input": "2\n615002717 -843553590", "output": "-843553590" }, { "input": "2\n-1 2", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "1\n2", "output": "2" }, { "input": "5\n-638512131 348325781 -550537933 -618161835 -567935532", "output": "-567935532" }, { "input": "1\n120", "output": "120" }, { "input": "2\n-1000000000 1000000000", "output": "-1000000000" }, { "input": "1\n618309368", "output": "618309368" } ]
1,621,150,310
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll n;cin>>n; double x,total=0; for(ll i=0;i<n;i++){ cin>>x;total+=x; } double y = (double)total/n; ll z = total/n; //cout<<y-z<<endl; if(y>0){ if(y-z<=0.5){ cout<<z<<endl; }else{ cout<<z+1<<endl; } }else{ if(y-z>=-0.5){ cout<<z-1<<endl; }else{ cout<<z<<endl; } } //cout<<total/n<<endl; return 0; }
Title: Optimal Point on a Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line. The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. Output Specification: Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. Demo Input: ['4\n1 2 3 4\n'] Demo Output: ['2\n'] Note: none
```python #include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll n;cin>>n; double x,total=0; for(ll i=0;i<n;i++){ cin>>x;total+=x; } double y = (double)total/n; ll z = total/n; //cout<<y-z<<endl; if(y>0){ if(y-z<=0.5){ cout<<z<<endl; }else{ cout<<z+1<<endl; } }else{ if(y-z>=-0.5){ cout<<z-1<<endl; }else{ cout<<z<<endl; } } //cout<<total/n<<endl; return 0; } ```
-1
921
05
Labyrinth-5
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
83.362
[]
1,517,503,936
3,136
Python 3
PARTIAL
TESTS
1
46
5,529,600
ans = """ for-350 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-left move-down move-left move-up end move-down move-down end """ print(ans)
Title: Labyrinth-5 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python ans = """ for-350 for-351 move-down move-right move-up move-right end move-down move-down for-351 move-left move-down move-left move-up end move-down move-down end """ print(ans) ```
2
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,675,411,633
2,147,483,647
Python 3
OK
TESTS
48
46
0
z = list(map(int, input().split())) print( max(z) - min(z))
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 z = list(map(int, input().split())) print( max(z) - min(z)) ```
3
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" }, { "input": "Danil_and_part_time_job", "output": "YES" }, { "input": "Ann_and_books", "output": "YES" }, { "input": "Olya", "output": "YES" }, { "input": "Nikita", "output": "YES" }, { "input": "Slava", "output": "YES" }, { "input": "Vanya", "output": "NO" }, { "input": "I_dont_know_what_to_write_here", "output": "NO" }, { "input": "danil_and_work", "output": "NO" }, { "input": "Ann", "output": "YES" }, { "input": "Batman_Nananananananan_Batman", "output": "NO" }, { "input": "Olya_Nikita_Ann_Slava_Danil", "output": "NO" }, { "input": "its_me_Mario", "output": "NO" }, { "input": "A", "output": "NO" }, { "input": "Wake_up_Neo", "output": "NO" }, { "input": "Hardest_problem_ever", "output": "NO" }, { "input": "Nikita_Nikita", "output": "NO" }, { "input": "____________________________________________________________________________________________________", "output": "NO" }, { "input": "Nikitb", "output": "NO" }, { "input": "Unn", "output": "NO" }, { "input": "oLya_adn_smth", "output": "NO" }, { "input": "FloorISLava", "output": "NO" }, { "input": "ann", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "AAnnnnn", "output": "YES" }, { "input": "AnnAnn", "output": "NO" }, { "input": "Annn", "output": "YES" }, { "input": "Dilzhan", "output": "NO" }, { "input": "Danilaaa", "output": "YES" }, { "input": "AndAnn", "output": "YES" }, { "input": "OlyaAnnAnn", "output": "NO" }, { "input": "DanilDanilOlya", "output": "NO" }, { "input": "DDanil", "output": "YES" }, { "input": "AnnAnnDanil", "output": "NO" }, { "input": "And_Danil", "output": "YES" }, { "input": "abcddddDanil", "output": "YES" }, { "input": "DanilOlyaOlya", "output": "NO" }, { "input": "Nikitaaa", "output": "YES" }, { "input": "aaabbba", "output": "NO" }, { "input": "Ann_Ann_Danil", "output": "NO" }, { "input": "Danil_Danil_Nikita", "output": "NO" }, { "input": "AlexaaaaaaBBBBBOlyaDDDDD", "output": "YES" }, { "input": "IloveDaniland", "output": "YES" }, { "input": "AnAnn", "output": "YES" }, { "input": "Danil_Danil_Olya", "output": "NO" }, { "input": "DanilDanilSlava", "output": "NO" }, { "input": "DanilDanil", "output": "NO" }, { "input": "OlyOlya", "output": "YES" }, { "input": "NikitaNikitb", "output": "YES" }, { "input": "ababaca", "output": "NO" }, { "input": "AnnNikitaNikitaNikitaNikita__good_luck", "output": "NO" } ]
1,611,095,798
398
PyPy 3
OK
TESTS
55
108
0
s = str(input()) c = 0 c += s.count('Danil') c += s.count('Olya') c += s.count('Slava') c += s.count('Ann') c += s.count('Nikita') if c == 1: print('YES') else: print('NO')
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input Specification: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Output Specification: Print "YES", if problem is from this contest, and "NO" otherwise. Demo Input: ['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n'] Demo Output: ['NO', 'YES', 'NO'] Note: none
```python s = str(input()) c = 0 c += s.count('Danil') c += s.count('Olya') c += s.count('Slava') c += s.count('Ann') c += s.count('Nikita') if c == 1: print('YES') else: print('NO') ```
3
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
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. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,694,661,032
2,147,483,647
Python 3
OK
TESTS
34
92
0
# -*- coding: utf-8 -*- """ Created on Thu Sep 14 11:07:49 2023 @author: ljy """ n=input() luc=0 for i in range(len(n)): if n[i]=='4' or n[i]=='7': luc+=1 #print(luc) if luc==4 or luc==7: print('YES') else:print('NO')
Title: Nearly Lucky Number 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. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python # -*- coding: utf-8 -*- """ Created on Thu Sep 14 11:07:49 2023 @author: ljy """ n=input() luc=0 for i in range(len(n)): if n[i]=='4' or n[i]=='7': luc+=1 #print(luc) if luc==4 or luc==7: print('YES') else:print('NO') ```
3.977
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,693,062,555
2,147,483,647
Python 3
OK
TESTS
36
92
0
n=(input()) x=1 for i in range(len(n)): if n[i]=='4': x=x elif n[i]=='7': x=x else: x=0 if int(n)%4==0 or int(n)%7==0 or int(n)%44==0 or int(n)%47==0 or int(n)%74==0 or int(n)%77==0 or int(n)%444==0 or int(n)%777==0 or int(n)%447==0 or int(n)%474==0 or int(n)%747==0 or int(n)%774==0 or int(n)%744==0: x=1 if x==1: 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=(input()) x=1 for i in range(len(n)): if n[i]=='4': x=x elif n[i]=='7': x=x else: x=0 if int(n)%4==0 or int(n)%7==0 or int(n)%44==0 or int(n)%47==0 or int(n)%74==0 or int(n)%77==0 or int(n)%444==0 or int(n)%777==0 or int(n)%447==0 or int(n)%474==0 or int(n)%747==0 or int(n)%774==0 or int(n)%744==0: x=1 if x==1: print('YES') else: print('NO') ```
3
764
B
Timofey and cubes
PROGRAMMING
900
[ "constructive algorithms", "implementation" ]
null
null
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
[ "7\n4 3 7 6 9 1 2\n", "8\n6 1 4 2 5 6 9 2\n" ]
[ "2 3 9 6 7 1 4", "2 1 6 2 5 4 9 6" ]
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
1,000
[ { "input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4" }, { "input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6" }, { "input": "1\n1424", "output": "1424" }, { "input": "9\n-7 9 -4 9 -6 11 15 2 -10", "output": "-10 9 15 9 -6 11 -4 2 -7" }, { "input": "2\n21968 5686", "output": "5686 21968" }, { "input": "5\n241218936 -825949895 -84926813 491336344 -872198236", "output": "-872198236 -825949895 -84926813 491336344 241218936" }, { "input": "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 615958219 -5050584 322982437 -146046730 759453379 129267920 -819827396 -348156048 805080102 390723009 -771277251 -79011872 -592313207 528489973 656201270 -127795621 17284747 145139617 -565641608 83452176 -223074608 545811186 -657981923 -204657836 154779765 -476867246 180386291 202782486", "output": "202782486 828320986 -476867246 -62979938 -204657836 -945983652 545811186 832293378 83452176 432027535 145139617 568183540 -127795621 73543295 528489973 -5050584 -79011872 -146046730 390723009 129267920 -348156048 -819827396 805080102 759453379 -771277251 322982437 -592313207 615958219 656201270 961782904 17284747 88438103 -565641608 -82572118 -223074608 -139095040 -657981923 -681259411 154779765 -345782722 180386291 -557774624" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "6\n1 2 3 4 5 6", "output": "6 2 4 3 5 1" }, { "input": "4\n0 1 2 3", "output": "3 1 2 0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10 2 8 4 6 5 7 3 9 1" }, { "input": "2\n4 5", "output": "5 4" }, { "input": "2\n1 5", "output": "5 1" }, { "input": "2\n2 5", "output": "5 2" }, { "input": "2\n3 4", "output": "4 3" }, { "input": "2\n10 0", "output": "0 10" }, { "input": "66\n8229 5299 5562 1259 2258 1126 5026 8796 3497 7111 6680 1180 1426 4821 3322 3502 400 2951 4187 417 5234 1266 7525 7648 417 9297 174 670 1790 4121 9737 938 4616 3402 2009 2461 474 3728 327 3353 9773 6818 8781 874 2209 1260 1647 6126 9287 9638 5049 1256 4459 863 1835 4822 6809 348 5053 7784 6927 2140 9173 7817 5095 4184", "output": "4184 5299 7817 1259 2140 1126 7784 8796 348 7111 4822 1180 863 4821 1256 3502 9638 2951 6126 417 1260 1266 874 7648 6818 9297 3353 670 3728 4121 2461 938 3402 4616 2009 9737 474 1790 327 174 9773 417 8781 7525 2209 5234 1647 4187 9287 400 5049 3322 4459 1426 1835 6680 6809 3497 5053 5026 6927 2258 9173 5562 5095 8229" } ]
1,620,211,967
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
204,800
n=int(input()) a=list(map(int,input().split())) out="" if(n%2!=0): out=str(a[n//2]) # print(out) for i in range((n//2)-1,-1,-1): if(i%2==0): out=str(a[-i-1])+out+str(a[i]) else: out=str(a[i])+out+str(a[-i-1]) # print(out) print(" ".join(out))
Title: Timofey and cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. Output Specification: Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique. Demo Input: ['7\n4 3 7 6 9 1 2\n', '8\n6 1 4 2 5 6 9 2\n'] Demo Output: ['2 3 9 6 7 1 4', '2 1 6 2 5 4 9 6'] Note: Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
```python n=int(input()) a=list(map(int,input().split())) out="" if(n%2!=0): out=str(a[n//2]) # print(out) for i in range((n//2)-1,-1,-1): if(i%2==0): out=str(a[-i-1])+out+str(a[i]) else: out=str(a[i])+out+str(a[-i-1]) # print(out) print(" ".join(out)) ```
0
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,698,596,729
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
def draw_st(text1, text2): if text1 == text2: return 0 elif text1 > text2: return 1 else: return -1 text1 = input().lower() text2 = input().lower result = draw_st(text1, text2) print(result)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python def draw_st(text1, text2): if text1 == text2: return 0 elif text1 > text2: return 1 else: return -1 text1 = input().lower() text2 = input().lower result = draw_st(text1, text2) print(result) ```
-1
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
1,692,251,617
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
156
0
n=int(input()) if n%2>0: print(-1) v=1 nn=n//2 for i in range(nn): print(v+1,end=" ") print(v,end=" ") v+=1
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. Input Specification: A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. Output Specification: If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. Demo Input: ['1\n', '2\n', '4\n'] Demo Output: ['-1\n', '2 1 \n', '2 1 4 3 \n'] Note: none
```python n=int(input()) if n%2>0: print(-1) v=1 nn=n//2 for i in range(nn): print(v+1,end=" ") print(v,end=" ") v+=1 ```
0
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,678,920,868
2,147,483,647
Python 3
OK
TESTS
32
92
0
##nums = map(int, input().split()) ##s1 = list(map(int, input().split())) ##s1 = list(map(int, ' '.join(input()).split())) n = int(input()) s = list(map(int, input().split())) ch = Nch = nch = Nnch = 0 for i in range(len(s)): if s[i]%2 == 0: ch +=1 Nch = i + 1 else: nch += 1 Nnch = i + 1 if ch < nch: print(Nch) else: print(Nnch)
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 ##nums = map(int, input().split()) ##s1 = list(map(int, input().split())) ##s1 = list(map(int, ' '.join(input()).split())) n = int(input()) s = list(map(int, input().split())) ch = Nch = nch = Nnch = 0 for i in range(len(s)): if s[i]%2 == 0: ch +=1 Nch = i + 1 else: nch += 1 Nnch = i + 1 if ch < nch: print(Nch) else: print(Nnch) ```
3.977
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game?
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, { "input": "1 3", "output": "Akshat" }, { "input": "2 1", "output": "Akshat" }, { "input": "2 2", "output": "Malvika" }, { "input": "3 1", "output": "Akshat" }, { "input": "3 2", "output": "Malvika" }, { "input": "68 42", "output": "Malvika" }, { "input": "1 35", "output": "Akshat" }, { "input": "25 70", "output": "Akshat" }, { "input": "59 79", "output": "Akshat" }, { "input": "65 63", "output": "Akshat" }, { "input": "46 6", "output": "Malvika" }, { "input": "28 82", "output": "Malvika" }, { "input": "98 98", "output": "Malvika" }, { "input": "98 99", "output": "Malvika" }, { "input": "98 100", "output": "Malvika" }, { "input": "99 98", "output": "Malvika" }, { "input": "99 99", "output": "Akshat" }, { "input": "99 100", "output": "Akshat" }, { "input": "100 98", "output": "Malvika" }, { "input": "100 99", "output": "Akshat" }, { "input": "100 100", "output": "Malvika" }, { "input": "3 4", "output": "Akshat" } ]
1,683,377,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
def f(): L=[] p1="Akshat" p2="Malvika" n,m=list(map(int,input().split())) if n==m: if n%2==0: print(p2) else: print(p1) elif min(n,m)%2==0: print(p2) f()
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? Input Specification: The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Output Specification: Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Demo Input: ['2 2\n', '2 3\n', '3 3\n'] Demo Output: ['Malvika\n', 'Malvika\n', 'Akshat\n'] Note: Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty. In the empty grid, Akshat cannot make any move, hence he will lose. Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
```python def f(): L=[] p1="Akshat" p2="Malvika" n,m=list(map(int,input().split())) if n==m: if n%2==0: print(p2) else: print(p1) elif min(n,m)%2==0: print(p2) f() ```
0
873
B
Balanced Substring
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*.
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
[ "8\n11010111\n", "3\n111\n" ]
[ "4\n", "0\n" ]
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
0
[ { "input": "8\n11010111", "output": "4" }, { "input": "3\n111", "output": "0" }, { "input": "11\n00001000100", "output": "2" }, { "input": "10\n0100000000", "output": "2" }, { "input": "13\n0001000011010", "output": "6" }, { "input": "14\n00000100101011", "output": "10" }, { "input": "14\n01111101111111", "output": "2" }, { "input": "18\n110010101101111111", "output": "10" }, { "input": "11\n00010000011", "output": "4" }, { "input": "10\n1000010110", "output": "6" }, { "input": "15\n100000100000011", "output": "4" }, { "input": "18\n011010101110111101", "output": "8" }, { "input": "10\n0011011111", "output": "6" }, { "input": "3\n011", "output": "2" }, { "input": "14\n11111111111111", "output": "0" }, { "input": "65\n11001000110001001011011110111100000000101001001010101111000100010", "output": "48" }, { "input": "10\n0011111000", "output": "10" }, { "input": "13\n1110000001110", "output": "12" }, { "input": "3\n110", "output": "2" }, { "input": "4\n1110", "output": "2" }, { "input": "9\n001011001", "output": "8" }, { "input": "2\n10", "output": "2" }, { "input": "2\n01", "output": "2" }, { "input": "12\n110000110000", "output": "8" }, { "input": "3\n001", "output": "2" }, { "input": "14\n11000011000000", "output": "8" }, { "input": "19\n0000011111111100000", "output": "18" }, { "input": "45\n011010001100001111110001011100000001101100111", "output": "44" }, { "input": "18\n000001111111100000", "output": "16" }, { "input": "4\n0101", "output": "4" }, { "input": "12\n000101011001", "output": "10" } ]
1,508,501,237
2,147,483,647
Python 3
OK
TESTS
53
124
14,131,200
n = input() s = input() res = 0 ans = 0 dp = {} dp[0] = -1 for i in range(int(n)): if s[i] == '1': res += 1 else: res -= 1 if res not in dp: dp[res] = i else: ans = max(ans, i - dp[res]) print(ans)
Title: Balanced Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of *s*. Input Specification: The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*. The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. Output Specification: If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. Demo Input: ['8\n11010111\n', '3\n111\n'] Demo Output: ['4\n', '0\n'] Note: In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring.
```python n = input() s = input() res = 0 ans = 0 dp = {} dp[0] = -1 for i in range(int(n)): if s[i] == '1': res += 1 else: res -= 1 if res not in dp: dp[res] = i else: ans = max(ans, i - dp[res]) print(ans) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,691,609,427
2,147,483,647
PyPy 3-64
OK
TESTS
44
62
0
s=input() start="a" x=0 for i in s: x=x+min(abs(ord(start)-ord(i)),26-abs(ord(start)-ord(i))) start=i print(x)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python s=input() start="a" x=0 for i in s: x=x+min(abs(ord(start)-ord(i)),26-abs(ord(start)-ord(i))) start=i print(x) ```
3
268
B
Buttons
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
[ "2\n", "3\n" ]
[ "3\n", "7\n" ]
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
1,000
[ { "input": "2", "output": "3" }, { "input": "3", "output": "7" }, { "input": "4", "output": "14" }, { "input": "1", "output": "1" }, { "input": "10", "output": "175" }, { "input": "2000", "output": "1333335000" }, { "input": "1747", "output": "888644743" }, { "input": "889", "output": "117099969" }, { "input": "1999", "output": "1331335999" }, { "input": "914", "output": "127259419" }, { "input": "996", "output": "164675486" }, { "input": "17", "output": "833" }, { "input": "50", "output": "20875" }, { "input": "91", "output": "125671" }, { "input": "92", "output": "129858" }, { "input": "256", "output": "2796416" }, { "input": "512", "output": "22370048" }, { "input": "666", "output": "49235271" }, { "input": "667", "output": "49457383" }, { "input": "314", "output": "5160119" }, { "input": "1241", "output": "318541121" }, { "input": "1500", "output": "562501250" }, { "input": "1837", "output": "1033182073" }, { "input": "1000", "output": "166667500" } ]
1,674,858,006
2,147,483,647
Python 3
OK
TESTS
24
92
0
n = int(input()) ans = 0 counter = n-1 for i in range (1, n): ans += (i * counter) counter -= 1 ans += n print(ans)
Title: Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. Output Specification: In a single line print the number of times Manao has to push a button in the worst-case scenario. Demo Input: ['2\n', '3\n'] Demo Output: ['3\n', '7\n'] Note: Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
```python n = int(input()) ans = 0 counter = n-1 for i in range (1, n): ans += (i * counter) counter -= 1 ans += n print(ans) ```
3
676
C
Vasya and String
PROGRAMMING
1,500
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
1,500
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { "input": "10 10\nbbbbbbbbbb", "output": "10" }, { "input": "10 2\nbbbbbbbbbb", "output": "10" }, { "input": "10 1\nbbabbabbba", "output": "6" }, { "input": "10 10\nbbabbbaabb", "output": "10" }, { "input": "10 9\nbabababbba", "output": "10" }, { "input": "10 4\nbababbaaab", "output": "9" }, { "input": "10 10\naabaaabaaa", "output": "10" }, { "input": "10 10\naaaabbbaaa", "output": "10" }, { "input": "10 1\nbaaaaaaaab", "output": "9" }, { "input": "10 5\naaaaabaaaa", "output": "10" }, { "input": "10 4\naaaaaaaaaa", "output": "10" }, { "input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab", "output": "93" }, { "input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba", "output": "100" }, { "input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb", "output": "34" }, { "input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab", "output": "100" }, { "input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba", "output": "17" }, { "input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa", "output": "80" }, { "input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa", "output": "61" }, { "input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa", "output": "76" }, { "input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa", "output": "100" }, { "input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" }, { "input": "10 0\nbbbbbbbbbb", "output": "10" }, { "input": "10 0\nbbbbabbbbb", "output": "5" }, { "input": "10 0\nbbabbbabba", "output": "3" }, { "input": "10 0\nbaabbbbaba", "output": "4" }, { "input": "10 0\naababbbbaa", "output": "4" }, { "input": "10 2\nabbbbbaaba", "output": "8" }, { "input": "10 0\nabbaaabaaa", "output": "3" }, { "input": "10 0\naabbaaabaa", "output": "3" }, { "input": "10 1\naaaaaababa", "output": "8" }, { "input": "10 0\nbaaaaaaaaa", "output": "9" }, { "input": "10 0\naaaaaaaaaa", "output": "10" }, { "input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "100" }, { "input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab", "output": "40" }, { "input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb", "output": "65" }, { "input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb", "output": "33" }, { "input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab", "output": "65" }, { "input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb", "output": "26" }, { "input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba", "output": "22" }, { "input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa", "output": "49" }, { "input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa", "output": "56" }, { "input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba", "output": "86" }, { "input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "100" } ]
1,692,179,201
2,147,483,647
Python 3
OK
TESTS
117
93
102,400
def max_beauty_string(n, k, s): max_beauty = 0 window_start = 0 a_count = 0 b_count = 0 for window_end in range(n): if s[window_end] == 'a': a_count += 1 else: b_count += 1 # Check if we need to shrink the window while min(a_count, b_count) > k: if s[window_start] == 'a': a_count -= 1 else: b_count -= 1 window_start += 1 max_beauty = max(max_beauty, window_end - window_start + 1) return max_beauty # Read input n, k = map(int, input().split()) s = input() result = max_beauty_string(n, k, s) print(result)
Title: Vasya and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. Output Specification: Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. Demo Input: ['4 2\nabba\n', '8 1\naabaabaa\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
```python def max_beauty_string(n, k, s): max_beauty = 0 window_start = 0 a_count = 0 b_count = 0 for window_end in range(n): if s[window_end] == 'a': a_count += 1 else: b_count += 1 # Check if we need to shrink the window while min(a_count, b_count) > k: if s[window_start] == 'a': a_count -= 1 else: b_count -= 1 window_start += 1 max_beauty = max(max_beauty, window_end - window_start + 1) return max_beauty # Read input n, k = map(int, input().split()) s = input() result = max_beauty_string(n, k, s) print(result) ```
3
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above.
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { "input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543", "output": "NO" }, { "input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869", "output": "YES" }, { "input": "3\n408 410 409", "output": "YES" }, { "input": "3\n903 902 904", "output": "YES" }, { "input": "3\n399 400 398", "output": "YES" }, { "input": "3\n450 448 449", "output": "YES" }, { "input": "3\n390 389 388", "output": "YES" }, { "input": "3\n438 439 440", "output": "YES" }, { "input": "11\n488 688 490 94 564 615 641 170 489 517 669", "output": "YES" }, { "input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954", "output": "YES" }, { "input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318", "output": "YES" }, { "input": "6\n10 79 306 334 304 305", "output": "YES" }, { "input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365", "output": "YES" }, { "input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73", "output": "YES" }, { "input": "11\n325 325 324 324 324 325 325 324 324 324 324", "output": "NO" }, { "input": "7\n517 517 518 517 518 518 518", "output": "NO" }, { "input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710", "output": "NO" }, { "input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29", "output": "NO" }, { "input": "7\n880 880 514 536 881 881 879", "output": "YES" }, { "input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375", "output": "YES" }, { "input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404", "output": "YES" }, { "input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987", "output": "YES" }, { "input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116", "output": "NO" }, { "input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995", "output": "NO" }, { "input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22", "output": "YES" }, { "input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952", "output": "YES" }, { "input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "3\n500 999 1000", "output": "NO" }, { "input": "10\n101 102 104 105 107 109 110 112 113 115", "output": "NO" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "3\n1000 999 998", "output": "YES" }, { "input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456", "output": "NO" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3", "output": "YES" }, { "input": "3\n999 999 1000", "output": "NO" }, { "input": "9\n2 4 5 13 25 100 200 300 400", "output": "NO" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n998 999 1000", "output": "YES" }, { "input": "12\n1 1 1 1 1 1 1 1 1 2 2 4", "output": "NO" }, { "input": "4\n4 3 4 5", "output": "YES" }, { "input": "6\n1 1 1 2 2 2", "output": "NO" }, { "input": "3\n2 3 2", "output": "NO" }, { "input": "5\n10 5 6 3 2", "output": "NO" }, { "input": "3\n1 2 1", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "4\n998 999 1000 1000", "output": "YES" }, { "input": "5\n2 3 9 9 4", "output": "YES" }, { "input": "4\n1 2 4 4", "output": "NO" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "7\n1 2 2 2 4 5 6", "output": "YES" }, { "input": "5\n1 3 10 3 10", "output": "NO" }, { "input": "3\n1 2 2", "output": "NO" }, { "input": "4\n1000 1000 999 998", "output": "YES" }, { "input": "3\n5 3 7", "output": "NO" }, { "input": "6\n1 1 2 2 3 3", "output": "YES" }, { "input": "9\n6 6 6 5 5 5 4 4 4", "output": "YES" }, { "input": "7\n5 6 6 6 7 7 7", "output": "YES" }, { "input": "5\n2 3 3 3 4", "output": "YES" }, { "input": "5\n2 1 2 1 3", "output": "YES" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "3\n1000 1000 1000", "output": "NO" }, { "input": "5\n1 100 2 100 3", "output": "YES" }, { "input": "5\n5 4 6 5 5", "output": "YES" }, { "input": "12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "YES" }, { "input": "5\n9 9 1 2 3", "output": "YES" }, { "input": "6\n1 2 3 1 2 3", "output": "YES" }, { "input": "7\n1 1 1 1 2 3 3", "output": "YES" }, { "input": "3\n13 13 13", "output": "NO" }, { "input": "3\n42 42 42", "output": "NO" }, { "input": "8\n1 1 1 1 2 2 2 2", "output": "NO" }, { "input": "6\n1 1 1 1 2 3", "output": "YES" }, { "input": "6\n1 1 2 2 6 6", "output": "NO" }, { "input": "6\n1 2 5 5 5 5", "output": "NO" }, { "input": "9\n1 2 3 1 2 3 1 2 3", "output": "YES" }, { "input": "4\n1 2 1 100", "output": "NO" }, { "input": "5\n1 1 2 2 3", "output": "YES" } ]
1,680,589,564
2,147,483,647
Python 3
OK
TESTS
84
46
0
# take input values N = int(input()) T = list(map(int, input().split())) # remove duplicate house numbers and sort the list T = sorted(set(T)) # iterate over the sorted list and check for three consecutive houses for i in range(len(T)-2): if T[i+2] - T[i] <= 2: print("YES") exit() # if we can't find three consecutive houses, print "NO" print("NO")
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above. Input Specification: The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. Output Specification: Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). Demo Input: ['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
```python # take input values N = int(input()) T = list(map(int, input().split())) # remove duplicate house numbers and sort the list T = sorted(set(T)) # iterate over the sorted list and check for three consecutive houses for i in range(len(T)-2): if T[i+2] - T[i] <= 2: print("YES") exit() # if we can't find three consecutive houses, print "NO" print("NO") ```
3
639
C
Bear and Polynomials
PROGRAMMING
2,200
[ "hashing", "implementation", "math" ]
null
null
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0.
Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0.
[ "3 1000000000\n10 -9 -3 5\n", "3 12\n10 -9 -3 5\n", "2 20\n14 -7 19\n" ]
[ "3\n", "2\n", "0\n" ]
In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
1,000
[ { "input": "3 1000000000\n10 -9 -3 5", "output": "3" }, { "input": "3 12\n10 -9 -3 5", "output": "2" }, { "input": "2 20\n14 -7 19", "output": "0" }, { "input": "5 5\n0 -4 -2 -2 0 5", "output": "1" }, { "input": "6 10\n-2 -1 7 -3 2 7 -6", "output": "2" }, { "input": "7 100\n2 21 11 45 58 85 -59 38", "output": "1" }, { "input": "100 1000\n-62 57 -27 -67 49 -10 66 -64 -36 -78 62 -75 -39 75 -47 -36 41 -88 62 -43 22 29 -20 58 40 16 71 -2 -87 12 86 -90 -92 67 -12 -48 -10 -26 78 68 22 -3 66 -95 -81 34 14 -76 -27 76 -60 87 -84 3 35 -60 46 -65 29 -29 2 -44 -55 18 -75 91 36 34 -86 53 59 -54 -29 33 -95 66 9 72 67 -44 37 44 32 -52 -34 -4 -99 58 7 -22 -53 11 10 10 -25 -100 -95 -27 43 -46 25", "output": "10" }, { "input": "1 5\n5 -3", "output": "0" }, { "input": "1 10\n-6 2", "output": "2" }, { "input": "5 10000\n-160 3408 -4620 5869 7434 -6253", "output": "1" }, { "input": "10 1\n0 0 0 0 0 0 0 0 0 0 1", "output": "0" }, { "input": "10 1\n0 0 1 -1 1 0 0 1 1 -1 -1", "output": "0" }, { "input": "10 2\n-2 -2 1 2 -1 -2 1 -2 1 2 -1", "output": "2" }, { "input": "20 100\n52 -82 36 90 -62 -35 -93 -98 -80 -40 29 8 43 26 35 55 -56 -99 -17 13 11", "output": "1" }, { "input": "90 10\n-4 2 2 5 -1 3 4 1 -2 10 -9 -2 -4 3 8 0 -8 -3 9 1 2 4 8 2 0 2 -10 4 -4 -6 2 -9 3 -9 -3 8 8 9 -7 -10 3 9 -2 -7 5 -7 -5 6 1 5 1 -8 3 8 0 -6 2 2 3 -10 2 1 4 8 -3 1 5 7 -7 -3 2 -2 -9 7 7 -2 7 -6 7 -3 2 -5 10 0 0 9 -1 -4 1 -8 4", "output": "4" }, { "input": "101 20\n4 16 -5 8 -13 -6 -19 -4 18 9 -5 5 3 13 -12 -2 -1 -4 -13 14 2 15 -11 -17 -15 6 9 -15 -10 16 18 -7 8 -19 17 11 -6 -5 -16 -7 -14 5 -17 -6 18 19 -14 -5 1 11 -17 18 4 9 -1 19 1 8 9 -14 11 -8 -18 -12 15 14 -8 0 8 16 2 -20 -19 17 14 -2 3 -9 -13 4 6 -16 3 -12 19 -14 -8 -16 7 -4 5 9 17 7 -3 -15 6 18 -13 10 -8 2", "output": "1" }, { "input": "10 1000\n-538 -553 -281 -270 209 -989 -418 486 330 725 -430", "output": "1" }, { "input": "30 1000\n622 815 -733 -613 -741 571 -761 -432 -7 201 554 730 607 415 -453 820 161 147 406 875 -413 462 998 481 698 661 18 -331 752 -232 -72", "output": "2" }, { "input": "5 2000000\n1038520 -406162 -106421 106958 -807010 850753", "output": "2" }, { "input": "10 1000000000\n-857095622 -567296277 -923645190 -246044525 610990226 -617677619 -239569893 355377587 222686442 250110001 -200293692", "output": "2" }, { "input": "20 1000000000\n-924490890 231431639 -579465017 -690485236 173663728 144784457 364609617 444830562 48833250 1095623 333652904 -901650010 -850265945 844112020 -9178988 -527869441 93581840 607677914 -521131467 -628140952 329057708", "output": "3" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n1 1 -1", "output": "1" }, { "input": "2 2\n-1 0 -2", "output": "0" }, { "input": "2 2\n-1 -1 1", "output": "1" }, { "input": "2 2\n1 1 -2", "output": "0" }, { "input": "3 2\n2 -1 -1 1", "output": "2" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "35 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "35 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "35 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "32 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "32 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "32 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "55 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "55 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 536870912", "output": "0" }, { "input": "69 1000000000\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "69 1000000000\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -536870912", "output": "0" }, { "input": "61 10\n0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1", "output": "0" }, { "input": "2 10\n1 -2 1", "output": "1" }, { "input": "65 1\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1", "output": "0" } ]
1,465,131,665
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
4,915,200
def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i < n + 1000: if i >= n and not carry: break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 # print(cur, div, mod) res.append(mod) carry = div i += 1 return res, carry n, k = map(int, input().split()) coef = list(map(int, input().split())) b, carry = convert_to_binary(coef) if carry < 0: b, carry = convert_to_binary(list(map(lambda x: -x, coef))) last = len(b) - 1 while b[last] != 1: last -= 1 ans = 0 for i in range(0, n + 1): if last - i > 40: continue cur = 0 for j in range(i, last + 1): cur += b[j] * (2 ** (j - i)) new_coef = coef[i] - cur if abs(new_coef) > k: continue if i == n and new_coef == 0: continue ans += 1 if b[i] == 1: break print(ans)
Title: Bear and Polynomials Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0. Output Specification: Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0. Demo Input: ['3 1000000000\n10 -9 -3 5\n', '3 12\n10 -9 -3 5\n', '2 20\n14 -7 19\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
```python def convert_to_binary(coef): res = [] n = len(coef) carry = 0 i = 0 while i < n + 1000: if i >= n and not carry: break cur = carry if i < n: cur += coef[i] mod = cur % 2 div = cur // 2 # print(cur, div, mod) res.append(mod) carry = div i += 1 return res, carry n, k = map(int, input().split()) coef = list(map(int, input().split())) b, carry = convert_to_binary(coef) if carry < 0: b, carry = convert_to_binary(list(map(lambda x: -x, coef))) last = len(b) - 1 while b[last] != 1: last -= 1 ans = 0 for i in range(0, n + 1): if last - i > 40: continue cur = 0 for j in range(i, last + 1): cur += b[j] * (2 ** (j - i)) new_coef = coef[i] - cur if abs(new_coef) > k: continue if i == n and new_coef == 0: continue ans += 1 if b[i] == 1: break print(ans) ```
0
725
A
Jumping Ball
PROGRAMMING
1,000
[ "implementation" ]
null
null
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '&gt;', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '&lt;'. If there is no such position, in other words if *i*<=-<=1<=&lt;<=1 or *i*<=+<=1<=&gt;<=*n*, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
[ "4\n&lt;&lt;&gt;&lt;\n", "5\n&gt;&gt;&gt;&gt;&gt;\n", "4\n&gt;&gt;&lt;&lt;\n" ]
[ "2", "5", "0" ]
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
500
[ { "input": "4\n<<><", "output": "2" }, { "input": "5\n>>>>>", "output": "5" }, { "input": "4\n>><<", "output": "0" }, { "input": "3\n<<>", "output": "3" }, { "input": "3\n<<<", "output": "3" }, { "input": "3\n><<", "output": "0" }, { "input": "1\n<", "output": "1" }, { "input": "2\n<>", "output": "2" }, { "input": "3\n<>>", "output": "3" }, { "input": "3\n><>", "output": "1" }, { "input": "2\n><", "output": "0" }, { "input": "2\n>>", "output": "2" }, { "input": "2\n<<", "output": "2" }, { "input": "1\n>", "output": "1" }, { "input": "3\n>><", "output": "0" }, { "input": "3\n>>>", "output": "3" }, { "input": "3\n<><", "output": "1" }, { "input": "10\n<<<><<<>>>", "output": "6" }, { "input": "20\n><><<><<<>>>>>>>>>>>", "output": "11" }, { "input": "20\n<<<<<<<<<<><<<<>>>>>", "output": "15" }, { "input": "50\n<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "50" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<>><<>><<<<<>><>><<<>><><<>>><<>>><<<<><><><<><<<<><>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "49" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>><<>><>><>><<><><><><>>>><><<<>>>><<<>>>>>>><><", "output": "50" }, { "input": "100\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", "output": "100" }, { "input": "100\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "output": "100" }, { "input": "12\n<<>><<>><<>>", "output": "4" }, { "input": "6\n<<><>>", "output": "4" }, { "input": "6\n><>>>>", "output": "4" }, { "input": "8\n>>>><<<>", "output": "1" }, { "input": "4\n<><>", "output": "2" }, { "input": "4\n><><", "output": "0" }, { "input": "7\n<<>>><>", "output": "3" }, { "input": "10\n><><>>>>>>", "output": "6" }, { "input": "5\n<><>>", "output": "3" }, { "input": "12\n<><<<<>>>>>>", "output": "7" }, { "input": "6\n<>><<>", "output": "2" }, { "input": "6\n>>><>>", "output": "2" }, { "input": "10\n><><>>>><>", "output": "1" }, { "input": "5\n><>>>", "output": "3" }, { "input": "5\n<<><>", "output": "3" }, { "input": "5\n<><<<", "output": "1" }, { "input": "4\n<><<", "output": "1" }, { "input": "8\n<<>><<>>", "output": "4" }, { "input": "7\n<<><>>>", "output": "5" }, { "input": "5\n><<>>", "output": "2" }, { "input": "10\n<<<<<>>>>>", "output": "10" }, { "input": "6\n><<<<<", "output": "0" }, { "input": "8\n<<><><>>", "output": "4" }, { "input": "10\n<<<<><<<><", "output": "4" }, { "input": "12\n<<<>>>><<>>>", "output": "6" }, { "input": "4\n><>>", "output": "2" }, { "input": "11\n<<><<>><<>>", "output": "4" } ]
1,686,000,716
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
# n = [int(x) for x in input().split(' ')][0] n = int(input()) # x = [x for x in input().split(' ')] x = input() print(n) print(x) max_left = 0 while max_left < n and x[max_left] == '<': max_left += 1 max_right = 0 while x[n - max_right - 1] == '>' and max_right < n - max_left: max_right += 1 print(max_left + max_right)
Title: Jumping Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at position *i* it goes one position to the right (to the position *i*<=+<=1) if the type of this bumper is '&gt;', or one position to the left (to *i*<=-<=1) if the type of the bumper at position *i* is '&lt;'. If there is no such position, in other words if *i*<=-<=1<=&lt;<=1 or *i*<=+<=1<=&gt;<=*n*, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. Output Specification: Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Demo Input: ['4\n&lt;&lt;&gt;&lt;\n', '5\n&gt;&gt;&gt;&gt;&gt;\n', '4\n&gt;&gt;&lt;&lt;\n'] Demo Output: ['2', '5', '0'] Note: In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
```python # n = [int(x) for x in input().split(' ')][0] n = int(input()) # x = [x for x in input().split(' ')] x = input() print(n) print(x) max_left = 0 while max_left < n and x[max_left] == '<': max_left += 1 max_right = 0 while x[n - max_right - 1] == '>' and max_right < n - max_left: max_right += 1 print(max_left + max_right) ```
0
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it.
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" }, { "input": "9", "output": "10" }, { "input": "1", "output": "0" }, { "input": "0", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "10" }, { "input": "7", "output": "10" }, { "input": "8", "output": "10" }, { "input": "19", "output": "20" }, { "input": "100", "output": "100" }, { "input": "997", "output": "1000" }, { "input": "9994", "output": "9990" }, { "input": "10002", "output": "10000" }, { "input": "100000", "output": "100000" }, { "input": "99999", "output": "100000" }, { "input": "999999999", "output": "1000000000" }, { "input": "999999998", "output": "1000000000" }, { "input": "999999995", "output": "999999990" }, { "input": "999999990", "output": "999999990" }, { "input": "1000000", "output": "1000000" }, { "input": "1000010", "output": "1000010" }, { "input": "10000010", "output": "10000010" }, { "input": "100000011", "output": "100000010" }, { "input": "400000003", "output": "400000000" }, { "input": "234234", "output": "234230" }, { "input": "675621", "output": "675620" }, { "input": "43532", "output": "43530" }, { "input": "4576453", "output": "4576450" }, { "input": "65754674", "output": "65754670" }, { "input": "3245526", "output": "3245530" }, { "input": "123445", "output": "123440" }, { "input": "234217", "output": "234220" }, { "input": "23451218", "output": "23451220" }, { "input": "1231239", "output": "1231240" }, { "input": "1923140", "output": "1923140" }, { "input": "307910310", "output": "307910310" }, { "input": "780961030", "output": "780961030" }, { "input": "103509421", "output": "103509420" }, { "input": "576560141", "output": "576560140" }, { "input": "48851642", "output": "48851640" }, { "input": "226935072", "output": "226935070" }, { "input": "844450763", "output": "844450760" }, { "input": "22534183", "output": "22534180" }, { "input": "640049874", "output": "640049870" }, { "input": "818133304", "output": "818133300" }, { "input": "730616285", "output": "730616280" }, { "input": "613732415", "output": "613732410" }, { "input": "380991216", "output": "380991220" }, { "input": "559074636", "output": "559074640" }, { "input": "176590327", "output": "176590330" }, { "input": "354673757", "output": "354673760" }, { "input": "267156738", "output": "267156740" }, { "input": "150272868", "output": "150272870" }, { "input": "62755859", "output": "62755860" }, { "input": "945871979", "output": "945871980" }, { "input": "46", "output": "50" }, { "input": "999", "output": "1000" }, { "input": "1397", "output": "1400" } ]
1,584,673,500
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
109
512,000
n = input() if len(n)==1: if int(n)>5: print("10") elif int(n)<=5: print("0") elif len(n)>1: if n[len(n)-1]=="0": print(n) elif int(n[len(n)-1])>5: a = int(n[len(n)-2])+1 print(n[0:len(n)-2]+str(a)+"0") elif int(n[len(n)-1])<=5: print(n[0:len(n)-1]+"0")
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. Input Specification: The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Output Specification: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Demo Input: ['5\n', '113\n', '1000000000\n', '5432359\n'] Demo Output: ['0\n', '110\n', '1000000000\n', '5432360\n'] Note: In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
```python n = input() if len(n)==1: if int(n)>5: print("10") elif int(n)<=5: print("0") elif len(n)>1: if n[len(n)-1]=="0": print(n) elif int(n[len(n)-1])>5: a = int(n[len(n)-2])+1 print(n[0:len(n)-2]+str(a)+"0") elif int(n[len(n)-1])<=5: print(n[0:len(n)-1]+"0") ```
0