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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,649,353,102 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | n,a,b = map(int,input().split())
if a == 0:
print(n-b)
elif b == 0:
print(n-a)
else:
print (n-min(a,b)) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
n,a,b = map(int,input().split())
if a == 0:
print(n-b)
elif b == 0:
print(n-a)
else:
print (n-min(a,b))
``` | 0 |
|
886 | C | Petya and Catacombs | PROGRAMMING | 1,300 | [
"dsu",
"greedy",
"implementation",
"trees"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*:
- If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 1,500 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13",
"output": "66"
},
{
"input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12",
"output": "71"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6",
"output": "8"
},
{
"input": "2\n0 1",
"output": "1"
}
] | 1,554,043,503 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 218 | 14,643,200 | n = int(input())
tmp = list(map(int, input().split()))
t = [0] * (n + 1)
for x in tmp:
t[x] = 1
count = 1
for i in range(n):
if not t[i]:
count += 1
print(count)
| Title: Petya and Catacombs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*:
- If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook.
Output Specification:
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
Demo Input:
['2\n0 0\n', '5\n0 1 0 1 3\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | ```python
n = int(input())
tmp = list(map(int, input().split()))
t = [0] * (n + 1)
for x in tmp:
t[x] = 1
count = 1
for i in range(n):
if not t[i]:
count += 1
print(count)
``` | 3 |
|
629 | C | Famil Door and Brackets | PROGRAMMING | 2,000 | [
"dp",
"strings"
] | null | null | As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings!
The sequence of round brackets is called valid if and only if:
1. the total number of opening brackets is equal to the total number of closing brackets; 1. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.
Gabi bought a string *s* of length *m* (*m*<=≤<=*n*) and want to complete it to obtain a valid sequence of brackets of length *n*. He is going to pick some strings *p* and *q* consisting of round brackets and merge them in a string *p*<=+<=*s*<=+<=*q*, that is add the string *p* at the beginning of the string *s* and string *q* at the end of the string *s*.
Now he wonders, how many pairs of strings *p* and *q* exists, such that the string *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109<=+<=7. | First line contains *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100<=000,<=*n*<=-<=*m*<=≤<=2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string *s* of length *m* consisting of characters '(' and ')' only. | Print the number of pairs of string *p* and *q* such that *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets modulo 109<=+<=7. | [
"4 1\n(\n",
"4 4\n(())\n",
"4 3\n(((\n"
] | [
"4\n",
"1\n",
"0\n"
] | In the first sample there are four different valid pairs:
1. *p* = "(", *q* = "))" 1. *p* = "()", *q* = ")" 1. *p* = "", *q* = "())" 1. *p* = "", *q* = ")()"
In the second sample the only way to obtain a desired string is choose empty *p* and *q*.
In the third sample there is no way to get a valid sequence of brackets. | 1,750 | [
{
"input": "4 1\n(",
"output": "4"
},
{
"input": "4 4\n(())",
"output": "1"
},
{
"input": "4 3\n(((",
"output": "0"
},
{
"input": "875 50\n)))((())()))((()(())))))())))((((((()))))))()(((((",
"output": "0"
},
{
"input": "1980 464\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))(((()))(())))))()())(())))))())()()((())))))))((()(())))))()()(()((()((()()))(()))(())(()))()((((())()()))))))()(())))()(()())()())(((((()))())))())())(()))()(()))())((())((((()(()(())))(((()()))))()()()))))((()())()((())())))())))()(()(()()(((((()((((()))()(())()))))()(()))(()(((((((()((()(())))(((((())",
"output": "854368836"
},
{
"input": "1542 282\n())())()((()(()))()((())()))((())(()))))(()()))(())((()))()((()())())()))((())(((()(())((()()())((((())))((()((((()(()()))))(()(()()(())()((())())())))))()()())))(()((((()))(()(()(()(()))())((()()()()(()(()))())(((()(())()(())()()())))()))())(()))(((())()))((())()(())))))(())))()()",
"output": "631927032"
},
{
"input": "2 2\n)(",
"output": "0"
},
{
"input": "2 2\n))",
"output": "0"
}
] | 1,686,288,781 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 327 | 37,273,600 | # if you win, you live. you cannot win unless you fight.
import string
import sys
from sys import stdin, setrecursionlimit
# fd=open("cses.txt")
# sys.stdin=fd
input = stdin.readline
rd = lambda: map(lambda s: int(s), input().strip().split())
rdone = lambda: map(lambda s: int(s) - 1, input().strip().split())
ri = lambda: int(input())
rs = lambda: input().strip()
from collections import defaultdict as unsafedict, deque, Counter as unsafecounter
from bisect import bisect_left as bl, bisect_right as br
n,m=rd()
s=rs()
pref,mn=0,float("inf")
for i in s:
pref+=[-1,1][i=="("]
mn=min(mn,pref)
dp=unsafedict(lambda :-1)
mod=10**9+7
dif=n-m
def rec(i,type,bal):
if bal>2000 or bal<0 or i>dif:
return 0
if i==dif and type==1:
return bal==0
if dp[(i,type,bal)]!=-1:
return dp[(i,type,bal)]
ans=0
if type==0:
if mn>=0:
ans=rec(i,1,bal+pref)
elif mn<0 and (bal>abs(mn)):
ans=rec(i,1,bal+pref)
ans+=rec(i+1,0,bal-1)+rec(i+1,0,bal+1)
else:
ans+=rec(i+1,1,bal+1)+rec(i+1,1,bal-1)
ans%=mod
dp[(i,type,bal)]=ans
return ans
print(rec(0,0,0))
| Title: Famil Door and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length *n* more than any other strings!
The sequence of round brackets is called valid if and only if:
1. the total number of opening brackets is equal to the total number of closing brackets; 1. for any prefix of the sequence, the number of opening brackets is greater or equal than the number of closing brackets.
Gabi bought a string *s* of length *m* (*m*<=≤<=*n*) and want to complete it to obtain a valid sequence of brackets of length *n*. He is going to pick some strings *p* and *q* consisting of round brackets and merge them in a string *p*<=+<=*s*<=+<=*q*, that is add the string *p* at the beginning of the string *s* and string *q* at the end of the string *s*.
Now he wonders, how many pairs of strings *p* and *q* exists, such that the string *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets. As this number may be pretty large, he wants to calculate it modulo 109<=+<=7.
Input Specification:
First line contains *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100<=000,<=*n*<=-<=*m*<=≤<=2000) — the desired length of the string and the length of the string bought by Gabi, respectively.
The second line contains string *s* of length *m* consisting of characters '(' and ')' only.
Output Specification:
Print the number of pairs of string *p* and *q* such that *p*<=+<=*s*<=+<=*q* is a valid sequence of round brackets modulo 109<=+<=7.
Demo Input:
['4 1\n(\n', '4 4\n(())\n', '4 3\n(((\n']
Demo Output:
['4\n', '1\n', '0\n']
Note:
In the first sample there are four different valid pairs:
1. *p* = "(", *q* = "))" 1. *p* = "()", *q* = ")" 1. *p* = "", *q* = "())" 1. *p* = "", *q* = ")()"
In the second sample the only way to obtain a desired string is choose empty *p* and *q*.
In the third sample there is no way to get a valid sequence of brackets. | ```python
# if you win, you live. you cannot win unless you fight.
import string
import sys
from sys import stdin, setrecursionlimit
# fd=open("cses.txt")
# sys.stdin=fd
input = stdin.readline
rd = lambda: map(lambda s: int(s), input().strip().split())
rdone = lambda: map(lambda s: int(s) - 1, input().strip().split())
ri = lambda: int(input())
rs = lambda: input().strip()
from collections import defaultdict as unsafedict, deque, Counter as unsafecounter
from bisect import bisect_left as bl, bisect_right as br
n,m=rd()
s=rs()
pref,mn=0,float("inf")
for i in s:
pref+=[-1,1][i=="("]
mn=min(mn,pref)
dp=unsafedict(lambda :-1)
mod=10**9+7
dif=n-m
def rec(i,type,bal):
if bal>2000 or bal<0 or i>dif:
return 0
if i==dif and type==1:
return bal==0
if dp[(i,type,bal)]!=-1:
return dp[(i,type,bal)]
ans=0
if type==0:
if mn>=0:
ans=rec(i,1,bal+pref)
elif mn<0 and (bal>abs(mn)):
ans=rec(i,1,bal+pref)
ans+=rec(i+1,0,bal-1)+rec(i+1,0,bal+1)
else:
ans+=rec(i+1,1,bal+1)+rec(i+1,1,bal-1)
ans%=mod
dp[(i,type,bal)]=ans
return ans
print(rec(0,0,0))
``` | 0 |
|
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307",
"output": "22258199.5000000000"
},
{
"input": "2 1000000000\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "2 555\n200 300",
"output": "255.0000000000"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n0",
"output": "1.0000000000"
},
{
"input": "1 1000000000\n0",
"output": "1000000000.0000000000"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000.0000000000"
},
{
"input": "1 999999999\n499999999",
"output": "500000000.0000000000"
},
{
"input": "4 700\n0 250 475 700",
"output": "125.0000000000"
},
{
"input": "4 700\n0 225 450 700",
"output": "125.0000000000"
},
{
"input": "5 1000\n0 250 500 750 1000",
"output": "125.0000000000"
},
{
"input": "5 2000\n1001 1001 1001 1001 1001",
"output": "1001.0000000000"
},
{
"input": "1 999\n501",
"output": "501.0000000000"
},
{
"input": "2 1000\n400 600",
"output": "400.0000000000"
},
{
"input": "4 15\n1 3 9 11",
"output": "4.0000000000"
},
{
"input": "1 5\n2",
"output": "3.0000000000"
}
] | 1,687,988,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | line1 = input()
line2 = input()
split1 = line1.split()
split2 = line2.split()
n = int(split1[0])
l = int(split1[1])
mylist = []
for i in split2:
mylist.append(int(i))
mylist.sort()
difflist = []
for i in range(len(mylist) - 1):
difflist.append(mylist[i + 1] - mylist[i])
max1 = -1
for i in difflist:
if i > max1:
max1 = i
final = max1 / 2
if mylist[0] != 0:
if mylist[0] > final:
print('entered')
final = mylist[0]
if mylist[-1] != l:
print('entered')
if l - mylist[-1] > final:
final = l - mylist[-1]
print(final) | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
Input Specification:
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Output Specification:
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
Demo Input:
['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n']
Demo Output:
['2.5000000000\n', '2.0000000000\n']
Note:
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | ```python
line1 = input()
line2 = input()
split1 = line1.split()
split2 = line2.split()
n = int(split1[0])
l = int(split1[1])
mylist = []
for i in split2:
mylist.append(int(i))
mylist.sort()
difflist = []
for i in range(len(mylist) - 1):
difflist.append(mylist[i + 1] - mylist[i])
max1 = -1
for i in difflist:
if i > max1:
max1 = i
final = max1 / 2
if mylist[0] != 0:
if mylist[0] > final:
print('entered')
final = mylist[0]
if mylist[-1] != l:
print('entered')
if l - mylist[-1] > final:
final = l - mylist[-1]
print(final)
``` | 0 |
|
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete the *i*-th task, she needs to be in the house number *a**i* and complete all tasks with numbers less than *i*. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 31 70 67 70 62 99 100 47 44 33 78 35 32 37 92 12 95 18 3 22 54 24 22 90 25 22 78 88 51 92 46 84 15 29 28 40 8 5 93 68 77 47 45 76 85 39 84 94 52 69 93 64 31 60 99 17 51 59 62 37 46 47 86 60 88 14 68 22 47 93 50 10 55 87 46 50 43 63 44 43 61 65 91 43 33 97 67 57 66 70",
"output": "4869"
},
{
"input": "78 58\n23 14 73 45 47 14 27 59 65 39 15 23 5 1 50 37 3 51 46 69 75 65 45 68 48 59 77 39 53 21 72 33 46 32 34 5 69 55 56 53 47 31 32 5 42 23 76 15 2 77 65 24 16 68 61 28 55 10",
"output": "2505"
},
{
"input": "14 54\n9 13 14 9 5 12 4 7 3 14 5 12 13 1 1 11 10 2 7 9 5 2 2 8 10 7 3 9 5 11 2 2 6 12 11 5 4 11 11 6 2 11 14 13 8 7 13 9 4 9 11 3 7 13",
"output": "362"
},
{
"input": "100 100\n48 73 63 16 49 88 36 17 66 6 87 13 94 52 58 70 71 52 7 70 25 42 24 36 57 9 79 26 75 39 13 14 38 26 33 66 88 28 75 98 53 48 67 54 63 25 69 87 88 32 72 17 36 35 29 67 74 89 70 47 20 90 78 13 94 57 32 73 29 74 45 78 85 64 81 56 12 65 19 67 34 86 55 71 41 33 76 13 100 47 44 76 86 78 37 15 26 98 83 98",
"output": "4997"
},
{
"input": "99 100\n88 65 10 91 18 35 58 49 42 2 22 57 74 31 53 24 27 93 45 4 71 2 69 39 21 90 97 89 45 73 20 45 82 98 35 90 37 76 68 26 21 65 95 63 24 74 50 59 3 93 65 6 30 37 62 71 18 88 40 12 56 40 89 56 38 71 90 41 97 43 44 23 19 22 10 80 3 24 32 85 26 65 70 60 76 85 66 68 74 11 64 88 12 63 16 15 79 57 93 58",
"output": "4809"
},
{
"input": "65 100\n53 14 5 10 32 60 31 52 52 56 38 6 8 17 52 23 59 3 18 28 15 2 46 26 8 2 40 6 58 30 28 46 49 23 47 24 9 53 3 47 55 12 36 49 12 24 54 55 58 7 50 42 15 4 58 49 34 40 19 4 59 19 31 17 35 65 36 50 45 5 33 11 29 52 55 40 48 11 32 41 31 7 46 55 32 41 56 51 39 13 5 59 58 34 38 50 55 10 43 30",
"output": "3149"
},
{
"input": "10 100\n7 6 2 10 7 2 3 8 10 4 6 1 4 5 7 10 1 2 3 5 4 10 8 2 3 3 6 8 3 9 4 1 9 10 1 2 5 1 8 8 5 9 2 8 1 2 3 2 1 10 10 7 1 3 2 2 7 1 6 6 6 9 2 3 1 7 2 2 9 7 3 3 2 10 7 4 7 3 3 3 2 4 4 2 2 8 4 1 10 10 5 10 6 10 6 10 3 10 8 9",
"output": "428"
},
{
"input": "2 100\n1 1 2 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 1 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 1 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 2 2 1 1 2 2 1 1 2 2 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2",
"output": "47"
},
{
"input": "67 100\n49 5 25 48 37 55 5 33 14 30 59 28 57 46 45 32 47 22 40 28 58 34 27 29 4 52 63 44 31 65 42 61 11 17 32 17 18 1 12 33 38 11 59 46 43 55 23 30 23 2 42 21 45 51 30 19 35 15 10 30 13 21 32 34 33 3 5 59 23 63 6 9 20 43 64 3 42 41 40 4 14 20 40 33 25 44 1 2 50 46 13 10 3 20 22 64 28 42 58 30",
"output": "3245"
},
{
"input": "100 100\n81 62 26 90 7 87 60 35 75 81 54 94 53 71 64 80 58 83 53 70 40 96 87 50 37 63 5 77 83 75 53 28 22 98 52 45 72 70 62 21 1 99 37 93 16 98 68 27 96 37 21 83 92 23 62 96 85 31 85 66 38 77 45 16 90 86 6 21 75 42 18 60 2 17 51 61 94 68 97 79 17 59 66 14 87 78 70 40 63 78 58 22 87 7 90 17 20 97 9 31",
"output": "5530"
},
{
"input": "2 1\n1",
"output": "0"
},
{
"input": "2 10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "2 10\n1 1 1 2 2 2 1 1 1 2",
"output": "3"
},
{
"input": "3 6\n1 2 3 3 2 1",
"output": "6"
}
] | 1,695,478,573 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | s1=input().split()
n=s1[0]
m=s1[1]
s2=input().split()
start=1
t=0
for i in range(len(s2)):
door=int(s2[i])
if door>=start:
t+=door-start
else:
t+=max(start-1,5-start)+door-1
start=door
print(t) | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete the *i*-th task, she needs to be in the house number *a**i* and complete all tasks with numbers less than *i*. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house.
Output Specification:
Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use 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:
['4 3\n3 2 3\n', '4 3\n2 3 3\n']
Demo Output:
['6\n', '2\n']
Note:
In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | ```python
s1=input().split()
n=s1[0]
m=s1[1]
s2=input().split()
start=1
t=0
for i in range(len(s2)):
door=int(s2[i])
if door>=start:
t+=door-start
else:
t+=max(start-1,5-start)+door-1
start=door
print(t)
``` | 0 |
|
754 | B | Ilya and tic-tac-toe game | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). | The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. | Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. | [
"xx..\n.oo.\nx...\noox.\n",
"x.ox\nox..\nx.o.\noo.x\n",
"x..x\n..oo\no...\nx.xo\n",
"o.x.\no...\n.x..\nooxx\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | 1,000 | [
{
"input": "xx..\n.oo.\nx...\noox.",
"output": "YES"
},
{
"input": "x.ox\nox..\nx.o.\noo.x",
"output": "NO"
},
{
"input": "x..x\n..oo\no...\nx.xo",
"output": "YES"
},
{
"input": "o.x.\no...\n.x..\nooxx",
"output": "NO"
},
{
"input": ".xox\no.x.\nx.o.\n..o.",
"output": "YES"
},
{
"input": "o.oo\n.x.o\nx.x.\n.x..",
"output": "YES"
},
{
"input": "xxox\no.x.\nx.oo\nxo.o",
"output": "YES"
},
{
"input": ".xox\n.x..\nxoo.\noox.",
"output": "NO"
},
{
"input": "...x\n.x.o\n.o..\n.x.o",
"output": "NO"
},
{
"input": "oo.x\nxo.o\no.xx\n.oxx",
"output": "YES"
},
{
"input": ".x.o\n..o.\n..ox\nxox.",
"output": "NO"
},
{
"input": "....\n.x..\nx...\n..oo",
"output": "YES"
},
{
"input": "....\n....\n.x.o\n..xo",
"output": "YES"
},
{
"input": "o..o\nx..x\n.o.x\nxo..",
"output": "YES"
},
{
"input": "ox.o\nx..x\nx..o\noo.x",
"output": "NO"
},
{
"input": ".xox\n.x.o\nooxo\n..x.",
"output": "YES"
},
{
"input": "x..o\no..o\n..x.\nx.xo",
"output": "YES"
},
{
"input": "xxoo\no.oo\n...x\nx..x",
"output": "NO"
},
{
"input": "xoox\n.xx.\no..o\n..xo",
"output": "YES"
},
{
"input": "..o.\nxxox\n....\n.oxo",
"output": "YES"
},
{
"input": "xoox\nxxox\noo..\n.ox.",
"output": "YES"
},
{
"input": "..ox\n.o..\nx..o\n.oxx",
"output": "NO"
},
{
"input": ".oo.\n.x..\nx...\nox..",
"output": "YES"
},
{
"input": "o.xx\nxo.o\n...o\n..x.",
"output": "YES"
},
{
"input": "x...\n.ox.\n.oo.\n.xox",
"output": "NO"
},
{
"input": "xoxx\n..x.\no.oo\nx.o.",
"output": "YES"
},
{
"input": ".x.x\n.o.o\no.xx\nx.oo",
"output": "YES"
},
{
"input": "...o\nxo.x\n.x..\nxoo.",
"output": "YES"
},
{
"input": "o...\n...o\noxx.\n.xxo",
"output": "YES"
},
{
"input": "xxox\no..o\nx..o\noxox",
"output": "NO"
},
{
"input": "x.x.\nox.o\n.o.o\nxox.",
"output": "YES"
},
{
"input": "xxo.\n...x\nooxx\n.o.o",
"output": "YES"
},
{
"input": "xoxo\no..x\n.xo.\nox..",
"output": "YES"
},
{
"input": ".o..\nox..\n.o.x\n.x..",
"output": "NO"
},
{
"input": ".oxo\nx...\n.o..\n.xox",
"output": "NO"
},
{
"input": ".oxx\n..o.\n.o.x\n.ox.",
"output": "YES"
},
{
"input": ".xxo\n...o\n..ox\nox..",
"output": "YES"
},
{
"input": "x...\nxo..\noxo.\n..ox",
"output": "NO"
},
{
"input": "xoxo\nx.ox\n....\noxo.",
"output": "YES"
},
{
"input": "x..o\nxo.x\no.xo\nxoox",
"output": "NO"
},
{
"input": ".x..\no..x\n.oo.\nxox.",
"output": "NO"
},
{
"input": "xxox\no.x.\nxo.o\nxo.o",
"output": "NO"
},
{
"input": ".xo.\nx.oo\n...x\n.o.x",
"output": "NO"
},
{
"input": "ox.o\n...x\n..oo\nxxox",
"output": "NO"
},
{
"input": "oox.\nxoo.\no.x.\nx..x",
"output": "NO"
},
{
"input": "oxox\nx.oo\nooxx\nxxo.",
"output": "NO"
},
{
"input": "....\nxo.x\n..x.\noo..",
"output": "NO"
},
{
"input": ".ox.\nx..o\nxo.x\noxo.",
"output": "YES"
},
{
"input": ".xox\nxo..\n..oo\n.x..",
"output": "NO"
},
{
"input": "xxo.\n.oo.\n..x.\n..xo",
"output": "NO"
},
{
"input": "ox..\n..oo\n..x.\nxxo.",
"output": "NO"
},
{
"input": "xxo.\nx..x\noo.o\noxox",
"output": "YES"
},
{
"input": "xx..\noxxo\nxo.o\noox.",
"output": "YES"
},
{
"input": "x..o\no..o\no..x\nxxox",
"output": "NO"
},
{
"input": "oxo.\nxx.x\nooxx\n.o.o",
"output": "YES"
},
{
"input": ".o.x\no..o\nx..x\n..xo",
"output": "NO"
},
{
"input": "xo..\n....\nx...\n..o.",
"output": "YES"
},
{
"input": ".x..\no...\n...x\n.o..",
"output": "YES"
},
{
"input": "...x\n....\n.x.o\n..o.",
"output": "YES"
},
{
"input": "o..x\n....\n...x\n..o.",
"output": "YES"
},
{
"input": ".oo.\nx...\n....\n..x.",
"output": "YES"
},
{
"input": ".o..\n.x..\n..o.\n.x..",
"output": "YES"
},
{
"input": "..o.\n.x..\n....\no..x",
"output": "YES"
},
{
"input": "..o.\n..x.\n....\n.ox.",
"output": "YES"
},
{
"input": ".o..\no..x\n....\n.x..",
"output": "YES"
},
{
"input": "....\n..ox\n....\n.o.x",
"output": "YES"
},
{
"input": ".o..\n....\no...\nx.x.",
"output": "YES"
},
{
"input": "....\n.o..\n....\nox.x",
"output": "YES"
},
{
"input": "oxo.\nxxox\noo.o\nxoxx",
"output": "YES"
},
{
"input": ".xx.\n...x\noo.o\no..x",
"output": "YES"
},
{
"input": "x...\n.x..\n....\noo..",
"output": "YES"
},
{
"input": "oxox\n..ox\nxoxo\nxoxo",
"output": "YES"
},
{
"input": "....\n...x\n...x\noo..",
"output": "YES"
}
] | 1,653,149,091 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | import sys
input = sys.stdin.readline
g = [input()[:-1] for _ in range(4)]
d = ['x.x', '.xx', 'xx.']
ans = 'NO'
for i in range(4):
for j in range(3):
if d[j] in g[i]:
ans = "YES"
break
if ans == 'YES':
break
else:
w = list(map(''.join, zip(*g)))
for i in range(4):
for j in range(3):
if d[j] in w[i]:
ans = "YES"
break
if ans == 'YES':
break
else:
for i in range(2):
for j in range(2):
if g[i][j] == 'x':
if (g[i+1][j+1] == 'x' and g[i+2][j+2] == '.') or (g[i+1][j+1] == '.' and g[i+2][j+2] == 'x'):
ans = 'YES'
break
if ans == 'YES':
break
print(ans) | Title: Ilya and tic-tac-toe game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input Specification:
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output Specification:
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Demo Input:
['xx..\n.oo.\nx...\noox.\n', 'x.ox\nox..\nx.o.\noo.x\n', 'x..x\n..oo\no...\nx.xo\n', 'o.x.\no...\n.x..\nooxx\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | ```python
import sys
input = sys.stdin.readline
g = [input()[:-1] for _ in range(4)]
d = ['x.x', '.xx', 'xx.']
ans = 'NO'
for i in range(4):
for j in range(3):
if d[j] in g[i]:
ans = "YES"
break
if ans == 'YES':
break
else:
w = list(map(''.join, zip(*g)))
for i in range(4):
for j in range(3):
if d[j] in w[i]:
ans = "YES"
break
if ans == 'YES':
break
else:
for i in range(2):
for j in range(2):
if g[i][j] == 'x':
if (g[i+1][j+1] == 'x' and g[i+2][j+2] == '.') or (g[i+1][j+1] == '.' and g[i+2][j+2] == 'x'):
ans = 'YES'
break
if ans == 'YES':
break
print(ans)
``` | 0 |
|
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (*l* — left, *s* — straight, *r* — right) and a light *p* for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible. | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1",
"output": "YES"
},
{
"input": "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 1\n1 1 1 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 0 1\n1 0 1 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 1 1 0\n0 1 0 1\n1 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 0\n0 1 0 0\n1 1 1 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 1 0 0\n1 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 0\n1 0 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n1 0 0 0\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 1 0\n1 1 0 1\n1 0 0 1\n1 1 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n1 1 0 0\n1 1 0 1\n0 0 1 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 1 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 1 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n1 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 1 0",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n1 0 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n1 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 1 0",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 1 1",
"output": "YES"
},
{
"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "1 1 1 0\n1 1 1 0\n1 1 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 1 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n0 0 0 0\n0 1 0 0",
"output": "YES"
},
{
"input": "0 0 0 1\n0 0 0 1\n1 0 0 0\n0 0 0 0",
"output": "YES"
}
] | 1,496,764,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 62 | 0 | a = [list(map(int, input().split())) for i in range(4)]
for i in range(4):
if not a[i][3]:
continue
if any(a[i][:3]) or a[(i + 1) % 4][0] or a[(i + 3) % 4][2]:
print('YES')
exit()
print('NO') | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (*l* — left, *s* — straight, *r* — right) and a light *p* for a pedestrian crossing.
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.
Input Specification:
The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
Output Specification:
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
Demo Input:
['1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n', '0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n', '1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | ```python
a = [list(map(int, input().split())) for i in range(4)]
for i in range(4):
if not a[i][3]:
continue
if any(a[i][:3]) or a[(i + 1) % 4][0] or a[(i + 3) % 4][2]:
print('YES')
exit()
print('NO')
``` | 0 |
|
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,692,478,425 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=raw_input()
p=sum(s.count(x)%2 for x in set(s))
print'First'if p&1 or p==0 else'Second' | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none | ```python
s=raw_input()
p=sum(s.count(x)%2 for x in set(s))
print'First'if p&1 or p==0 else'Second'
``` | -1 |
|
803 | B | Distances to Zero | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109). | Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*. | [
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 1 2 3 4\n",
"7\n5 6 0 1 -2 3 4\n"
] | [
"2 1 0 1 0 0 1 2 3 ",
"0 1 2 3 4 ",
"2 1 0 1 2 3 4 "
] | none | 0 | [
{
"input": "9\n2 1 0 3 0 0 3 2 4",
"output": "2 1 0 1 0 0 1 2 3 "
},
{
"input": "5\n0 1 2 3 4",
"output": "0 1 2 3 4 "
},
{
"input": "7\n5 6 0 1 -2 3 4",
"output": "2 1 0 1 2 3 4 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 1",
"output": "0 1 "
},
{
"input": "2\n1 0",
"output": "1 0 "
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 "
},
{
"input": "5\n-1000000000 -1000000000 0 1000000000 1000000000",
"output": "2 1 0 1 2 "
},
{
"input": "5\n-1000000000 1000000000 1000000000 1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "15\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 0",
"output": "14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
},
{
"input": "15\n0 0 0 0 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000",
"output": "0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 "
},
{
"input": "15\n-1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 0 -1000000000 -1000000000 0 0 1000000000 -1000000000 0 -1000000000",
"output": "6 5 4 3 2 1 0 1 1 0 0 1 1 0 1 "
},
{
"input": "15\n-1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 1000000000 0 0 0 0",
"output": "11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 "
},
{
"input": "4\n0 0 2 0",
"output": "0 0 1 0 "
},
{
"input": "15\n1 2 3 4 0 1 2 3 -5 -4 -3 -1 0 5 4",
"output": "4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 "
},
{
"input": "2\n0 -1",
"output": "0 1 "
},
{
"input": "5\n0 -1 -1 -1 0",
"output": "0 1 2 1 0 "
},
{
"input": "5\n0 0 0 -1 0",
"output": "0 0 0 1 0 "
},
{
"input": "3\n0 0 -1",
"output": "0 0 1 "
},
{
"input": "3\n0 -1 -1",
"output": "0 1 2 "
},
{
"input": "12\n0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0",
"output": "0 1 2 3 4 5 5 4 3 2 1 0 "
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 "
},
{
"input": "30\n0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 -1000000000",
"output": "0 1 "
},
{
"input": "2\n0 1000000000",
"output": "0 1 "
},
{
"input": "2\n-1000000000 0",
"output": "1 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "3\n0 -1000000000 -1000000000",
"output": "0 1 2 "
},
{
"input": "3\n0 1000000000 1000000000",
"output": "0 1 2 "
},
{
"input": "3\n1000000000 1000000000 0",
"output": "2 1 0 "
},
{
"input": "3\n0 0 -1000000000",
"output": "0 0 1 "
},
{
"input": "3\n0 1000000000 0",
"output": "0 1 0 "
},
{
"input": "3\n-1000000000 0 0",
"output": "1 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "4\n0 -1000000000 -1000000000 -1000000000",
"output": "0 1 2 3 "
},
{
"input": "4\n1000000000 -1000000000 0 -1000000000",
"output": "2 1 0 1 "
},
{
"input": "4\n1000000000 -1000000000 1000000000 0",
"output": "3 2 1 0 "
},
{
"input": "4\n0 0 -1000000000 1000000000",
"output": "0 0 1 2 "
},
{
"input": "4\n0 0 1000000000 -1000000000",
"output": "0 0 1 2 "
},
{
"input": "4\n-1000000000 1000000000 0 0",
"output": "2 1 0 0 "
},
{
"input": "4\n0 0 0 -1000000000",
"output": "0 0 0 1 "
},
{
"input": "4\n1000000000 0 0 0",
"output": "1 0 0 0 "
},
{
"input": "4\n1000000000 0 0 0",
"output": "1 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 "
},
{
"input": "5\n1000000000 -1000000000 -1000000000 1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "5\n1000000000 -1000000000 1000000000 -1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "5\n0 0 -1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 "
},
{
"input": "5\n1000000000 0 -1000000000 0 -1000000000",
"output": "1 0 1 0 1 "
},
{
"input": "5\n1000000000 1000000000 1000000000 0 0",
"output": "3 2 1 0 0 "
},
{
"input": "5\n0 0 0 -1000000000 -1000000000",
"output": "0 0 0 1 2 "
},
{
"input": "5\n-1000000000 1000000000 0 0 0",
"output": "2 1 0 0 0 "
},
{
"input": "5\n1000000000 1000000000 0 0 0",
"output": "2 1 0 0 0 "
},
{
"input": "5\n0 0 0 0 -1000000000",
"output": "0 0 0 0 1 "
},
{
"input": "5\n0 0 1000000000 0 0",
"output": "0 0 1 0 0 "
},
{
"input": "5\n1000000000 0 0 0 0",
"output": "1 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "6\n0 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 1 2 3 4 5 "
},
{
"input": "6\n-1000000000 -1000000000 1000000000 1000000000 1000000000 0",
"output": "5 4 3 2 1 0 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0",
"output": "5 4 3 2 1 0 "
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 4 "
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 4 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 -1000000000 0 0",
"output": "4 3 2 1 0 0 "
},
{
"input": "6\n0 0 0 -1000000000 1000000000 1000000000",
"output": "0 0 0 1 2 3 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 0 0 0",
"output": "3 2 1 0 0 0 "
},
{
"input": "6\n-1000000000 -1000000000 1000000000 0 0 0",
"output": "3 2 1 0 0 0 "
},
{
"input": "6\n0 0 0 0 -1000000000 1000000000",
"output": "0 0 0 0 1 2 "
},
{
"input": "6\n0 0 0 -1000000000 1000000000 0",
"output": "0 0 0 1 1 0 "
},
{
"input": "6\n1000000000 1000000000 0 0 0 0",
"output": "2 1 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 1 "
},
{
"input": "6\n0 0 0 1000000000 0 0",
"output": "0 0 0 1 0 0 "
},
{
"input": "6\n1000000000 0 0 0 0 0",
"output": "1 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "7\n0 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000",
"output": "0 1 2 3 4 5 6 "
},
{
"input": "7\n1000000000 1000000000 -1000000000 0 -1000000000 1000000000 -1000000000",
"output": "3 2 1 0 1 2 3 "
},
{
"input": "7\n1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 0",
"output": "6 5 4 3 2 1 0 "
},
{
"input": "7\n0 0 1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 1 2 3 4 5 "
},
{
"input": "7\n0 1000000000 1000000000 -1000000000 1000000000 1000000000 0",
"output": "0 1 2 3 2 1 0 "
},
{
"input": "7\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 0 0",
"output": "5 4 3 2 1 0 0 "
},
{
"input": "7\n0 0 0 1000000000 -1000000000 -1000000000 1000000000",
"output": "0 0 0 1 2 3 4 "
},
{
"input": "7\n-1000000000 0 0 -1000000000 0 -1000000000 1000000000",
"output": "1 0 0 1 0 1 2 "
},
{
"input": "7\n1000000000 1000000000 1000000000 -1000000000 0 0 0",
"output": "4 3 2 1 0 0 0 "
},
{
"input": "7\n0 0 0 0 -1000000000 -1000000000 1000000000",
"output": "0 0 0 0 1 2 3 "
},
{
"input": "7\n0 -1000000000 0 0 0 -1000000000 1000000000",
"output": "0 1 0 0 0 1 2 "
},
{
"input": "7\n1000000000 1000000000 1000000000 0 0 0 0",
"output": "3 2 1 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 -1000000000 1000000000",
"output": "0 0 0 0 0 1 2 "
},
{
"input": "7\n0 -1000000000 0 0 0 0 -1000000000",
"output": "0 1 0 0 0 0 1 "
},
{
"input": "7\n-1000000000 1000000000 0 0 0 0 0",
"output": "2 1 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 0 1 "
},
{
"input": "7\n0 0 0 0 0 1000000000 0",
"output": "0 0 0 0 0 1 0 "
},
{
"input": "7\n1000000000 0 0 0 0 0 0",
"output": "1 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "8\n0 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 1 2 3 4 5 6 7 "
},
{
"input": "8\n0 -1000000000 1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 5 6 7 "
},
{
"input": "8\n1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 0",
"output": "7 6 5 4 3 2 1 0 "
},
{
"input": "8\n0 0 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 1 2 3 4 5 6 "
},
{
"input": "8\n1000000000 0 0 -1000000000 -1000000000 1000000000 -1000000000 -1000000000",
"output": "1 0 0 1 2 3 4 5 "
},
{
"input": "8\n1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 0 0",
"output": "6 5 4 3 2 1 0 0 "
},
{
"input": "8\n0 0 0 1000000000 1000000000 -1000000000 -1000000000 -1000000000",
"output": "0 0 0 1 2 3 4 5 "
},
{
"input": "8\n-1000000000 0 0 1000000000 1000000000 0 -1000000000 1000000000",
"output": "1 0 0 1 1 0 1 2 "
},
{
"input": "8\n1000000000 1000000000 1000000000 -1000000000 -1000000000 0 0 0",
"output": "5 4 3 2 1 0 0 0 "
},
{
"input": "8\n0 0 0 0 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 0 0 1 2 3 4 "
},
{
"input": "8\n1000000000 0 1000000000 -1000000000 0 -1000000000 0 0",
"output": "1 0 1 1 0 1 0 0 "
},
{
"input": "8\n-1000000000 -1000000000 -1000000000 -1000000000 0 0 0 0",
"output": "4 3 2 1 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 1000000000 1000000000 -1000000000",
"output": "0 0 0 0 0 1 2 3 "
},
{
"input": "8\n-1000000000 0 -1000000000 0 0 1000000000 0 0",
"output": "1 0 1 0 0 1 0 0 "
},
{
"input": "8\n1000000000 1000000000 1000000000 0 0 0 0 0",
"output": "3 2 1 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 -1000000000 -1000000000",
"output": "0 0 0 0 0 0 1 2 "
},
{
"input": "8\n0 0 0 1000000000 -1000000000 0 0 0",
"output": "0 0 0 1 1 0 0 0 "
},
{
"input": "8\n1000000000 1000000000 0 0 0 0 0 0",
"output": "2 1 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 0 0 1 "
},
{
"input": "8\n0 1000000000 0 0 0 0 0 0",
"output": "0 1 0 0 0 0 0 0 "
},
{
"input": "8\n1000000000 0 0 0 0 0 0 0",
"output": "1 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
}
] | 1,494,933,243 | 1,732 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | n = int(input())
numIn = input().split()
answer = []
start = numIn.index("0")
for i in range(n):
current = int(numIn[i])
if current == 0:
index = i-1
answer.append(0)
cnt = 1
start = 1
while index >= 0:
if answer[index] > cnt:
answer[index] = cnt
else:
break
else:
answer.append(start)
start += 1
length = len(answer)
for i in range(length):
answer[i] = str(answer[i])
print(' '.join(answer))
| Title: Distances to Zero
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*.
Demo Input:
['9\n2 1 0 3 0 0 3 2 4\n', '5\n0 1 2 3 4\n', '7\n5 6 0 1 -2 3 4\n']
Demo Output:
['2 1 0 1 0 0 1 2 3 ', '0 1 2 3 4 ', '2 1 0 1 2 3 4 ']
Note:
none | ```python
n = int(input())
numIn = input().split()
answer = []
start = numIn.index("0")
for i in range(n):
current = int(numIn[i])
if current == 0:
index = i-1
answer.append(0)
cnt = 1
start = 1
while index >= 0:
if answer[index] > cnt:
answer[index] = cnt
else:
break
else:
answer.append(start)
start += 1
length = len(answer)
for i in range(length):
answer[i] = str(answer[i])
print(' '.join(answer))
``` | 0 |
|
98 | B | Help King | PROGRAMMING | 2,200 | [
"implementation",
"probabilities",
"trees"
] | B. Help King | 2 | 256 | This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be *n* noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1<=/<=*n*). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task. | The first line contains a single integer *n* from the problem's statement (1<=≤<=*n*<=≤<=10000). | Print the sought expected number of tosses as an irreducible fraction in the following form: "*a*/*b*" (without the quotes) without leading zeroes. | [
"2\n",
"3\n",
"4\n"
] | [
"1/1\n",
"8/3\n",
"2/1\n"
] | none | 1,000 | [
{
"input": "2",
"output": "1/1"
},
{
"input": "3",
"output": "8/3"
},
{
"input": "4",
"output": "2/1"
},
{
"input": "8",
"output": "3/1"
},
{
"input": "7",
"output": "24/7"
},
{
"input": "6",
"output": "11/3"
},
{
"input": "1",
"output": "0/1"
},
{
"input": "5",
"output": "18/5"
},
{
"input": "96",
"output": "23/3"
},
{
"input": "54",
"output": "377/57"
},
{
"input": "49",
"output": "1985714/299593"
},
{
"input": "57",
"output": "1118/171"
},
{
"input": "21",
"output": "38/7"
},
{
"input": "43",
"output": "896/129"
},
{
"input": "56",
"output": "45/7"
},
{
"input": "46",
"output": "13719/2047"
},
{
"input": "91",
"output": "704/91"
},
{
"input": "13",
"output": "306/65"
},
{
"input": "82",
"output": "7739/1025"
},
{
"input": "69",
"output": "32740246/4194303"
},
{
"input": "77",
"output": "8215881550/1073741823"
},
{
"input": "27",
"output": "320/57"
},
{
"input": "63",
"output": "128/21"
},
{
"input": "60",
"output": "94/15"
},
{
"input": "42",
"output": "45/7"
},
{
"input": "29",
"output": "89074/16385"
},
{
"input": "99",
"output": "82792/10923"
},
{
"input": "19",
"output": "2936/513"
},
{
"input": "89",
"output": "15942/2047"
},
{
"input": "356",
"output": "20036/2047"
},
{
"input": "377",
"output": "42877948701338/4398046511105"
},
{
"input": "376",
"output": "81794781/8388607"
},
{
"input": "199",
"output": "5416016912792671923933831206744/633825300114114700748351602687"
},
{
"input": "563",
"output": "13880251801665520090148870069821814422429790384486504048582895486382118580803670864520/1295112594817152713946307937882345937761604559368093014167874939825936190136805665451"
},
{
"input": "768",
"output": "32/3"
},
{
"input": "777",
"output": "242912325346/22906492245"
},
{
"input": "721",
"output": "24323770714557246/2251799813685247"
},
{
"input": "629",
"output": "49843473149688266962934/4722366482869645213695"
},
{
"input": "589",
"output": "13383001136884230836493585742/1237940039285380274899124223"
},
{
"input": "698",
"output": "261084475895343697268604849722313704014143081638278003/23945242826029513411849172299223580994042798784118785"
},
{
"input": "897",
"output": "6303910445469575479185224346195379698702/604946430081668379490443746545365709255"
},
{
"input": "100",
"output": "1548/205"
},
{
"input": "898",
"output": "54181807382553033285317903788494851/5192296858534827628530496329220097"
},
{
"input": "778",
"output": "266081190240146347461776796003542832080357458393960689731819/25108406941546723055343157692830665664409421777856138051585"
},
{
"input": "408",
"output": "481/51"
},
{
"input": "915",
"output": "24489920882263416/2329134352741105"
},
{
"input": "659",
"output": "11506864999305980525685467247724160971763964558240405270397991163704744844086671519176045618744739064/1093625362391505962186251113558810682676584715446606218212885303204976499599687961611756588511526913"
},
{
"input": "380",
"output": "17089848754/1762037865"
},
{
"input": "826",
"output": "28584112877549284603281069376719144007233968270323045/2660582536225501490205463588802620110449199864902087"
},
{
"input": "570",
"output": "81780152549/7635497415"
},
{
"input": "8947",
"output": "9221776965061394108063074537665193339719130234791259353035383369908276748232005329587397633526133839630977366288410166284245740877083371222474025826991630911939336371916388075479778450420492837649418370715068725438291562232309367997828789596177392059429297899551357796421577750411209045517378683903876507895356659650107620108241824167563644901510340265372019179673453724120802026261156279978925379653814720997930734349648232984115741566886698873835913569553263892609588155620638724704727598288959685621550249737..."
},
{
"input": "5379",
"output": "369970662679510300707473720654925140999880897391589444623141436368705516892112173326991585567498714963884175295883677699016/27543998699593691622996471168032126659516861790178384136860366469766907968179639409382883768321470201982967167709306596011"
},
{
"input": "2614",
"output": "467288820759363880397722656040592964020719930972683440703193351374700405080631777580381050558531644513848619882285655907104502715940077345333622944378242416293600447930921066507506568704500773773633/37375513539561023231108477793896786533525327931380202951304745106630862169773485150256437750311906506986637800026885384689161869077507588081685801531164378630160340372359290471078905382884178132993"
},
{
"input": "6212",
"output": "718828780749497450032379379564/52818775009509558395695966891"
},
{
"input": "3586",
"output": "1026714465140783036738474632330359205383783819874722347437634384119469704928190591460057095203615899196742515080053210107395/82631996098781074868989413504096379978550585370535152410581099409300723904538918228148651304964410605948901503127919788033"
},
{
"input": "6629",
"output": "2887307659130237302642554273423838808127851411579740408603950850448329124209429578113205979182558694432261838498919298006073282090488747091133824076367223385537560048772408256051559991222428913480943619030448796454451464748405569577077070495809049315150455270612613741854545427076463694803465943631755282225609026765330663439059215627258266275926212560658364641003632351846514061002732653254081394744335331237509798266695411546509090369792904212760685221160746857281893822469878668200610823671894328098385881817..."
},
{
"input": "9861",
"output": "48205401549715737511233606679265031152996036546952288925330285615396586708825956490117819026249283326464870369563186432330830706792989284262067110327971987394928549360770263191516012692848869076552182149927367930957872055698792311482405327082065553619653685393875355497796244989262571944371234203749880818792381890143341459002264984197001955297069409069640536538793687219440766877509028035223421720178766484630650779161811795215598122460003343408475412680746717692338/3290879900222849827608052539430658202162644..."
},
{
"input": "1649",
"output": "1103258059369546/93824992236885"
},
{
"input": "1108",
"output": "829108303866668/70368744177665"
},
{
"input": "6704",
"output": "3747509385261755254210316751920800389821077334621726013635892116/274250759553534340359161530426225084163789310938929977224768171"
},
{
"input": "8771",
"output": "3770311067804988086442280897982793233953991174834038671591744622664235928848771481024534828492198884087581040596792755307166862630362254070801530083149662062951269890316117808935983174156710048296936374305714276676638609402088826404322038255398708095256451326373150897864019805504212731596330281332804357336587199175247125958363190591680678576959242590696722761770737808874948948372052533640442104091203823298252400438183921494229420351844306480773904754871502489649028646657382266084070860349033005494965904934..."
},
{
"input": "4710",
"output": "62214231544449127/4503599627370495"
},
{
"input": "2337",
"output": "6429067313146769086191243390708972817399071295570593226/510831846955296286119449009050103061206246374061200725"
},
{
"input": "7708",
"output": "39413297508974631726391031213171923271142554912679270458193728426423636026646334915727139650713682692479792411879633606353758285856351703126/2977131414714805823690030317109266572712515013375254774912983855843898524112477893944078543723575564536883288499266264815757728270805630975"
},
{
"input": "5484",
"output": "211086977989859276474150/15111572745182864683827"
},
{
"input": "2050",
"output": "2663/205"
},
{
"input": "5157",
"output": "1244202699616577925257908854992502879105187462860652753500143979369064245723363816152901984642185318105227079924186855121298620779636669909099525176016720566980036738379840484201060840762226140891649195248344160034243456960969500434409559402400997785076262368243485151264623913446406300409714366263836544017408112602389622392168343772273329588989257854547075621647134412375571624421845467345018113608142941220069412256286427238705568845394057266549279844034564540504288723831871872613761385100219013571797574528..."
},
{
"input": "9556",
"output": "61105610582596188064013632976018238169594847263124154642386689594807697097885447064570207703083797375229286491941164437689434529990291086697099939303795410031817348526076989232509267027565641811597218817018817025267674646870116016782259903322684685324891049798873702815116504349778081974046190242424181610803910534907237209386333892868457625884598750479036332/4139057561631190052420042715397268145091328063809781231185874234711716512317727312355164552220203407039993009382683073987640607521830928131007598529502..."
},
{
"input": "7901",
"output": "1545248712235484231234951857976545065744617617020030658469109057466859986475148250693905886674893272489053581743278765525029576600572532534838775161015285299867097071351763023768221772211614326132946083723216283578235838641012739144142278748089419497887052400481010672846336748523045688232788476455926025596760805229671163941642019404158795532714920358340283273984860096000931574655035232114889550219531272686479161110317036826198314000803468166009351225032738229182153921483640756378743625620038865132469106047..."
},
{
"input": "8622",
"output": "2346970612497798292051684863778787677688918498337895665035233783242368128286257851467636458012981817792946447606933694463959158768680516918810044760234529638520868683195790661167605124671831213269266007988150361676380026247303195939614144448935172977317349504257500667344413574778276538084533093523373859439640543406392557232735743996270882880554311714917225257533788072187384837827098726745502145040757646538864148126423442625937245/15845010358053163603682882776020046370855826407419789577061413023873354878758..."
},
{
"input": "16",
"output": "4/1"
},
{
"input": "32",
"output": "5/1"
},
{
"input": "64",
"output": "6/1"
},
{
"input": "128",
"output": "7/1"
},
{
"input": "256",
"output": "8/1"
},
{
"input": "512",
"output": "9/1"
},
{
"input": "1024",
"output": "10/1"
},
{
"input": "2048",
"output": "11/1"
},
{
"input": "4096",
"output": "12/1"
},
{
"input": "8192",
"output": "13/1"
},
{
"input": "9749",
"output": "2442073850489536993602927585016307199165621395304075025177694875024679607796284569131767726963170591399402108675638309823508923120869023271471818205166195909414421298770225330343221707377312426015931814666620011704161259290684411521150904067521292013955185317667861253504565429204675752674949251324122812583751343895693341865871684651273036507250959013187746544944138162398891218537343348931977619498001506833868902121065893913936425349903046456157409756042496452120477911621545767772676861905004685673876448424..."
},
{
"input": "9803",
"output": "3273210180788326072665779956874407303695209430301336271835983946088930098968971592446649088493870209185601637297946849124915345946101994703881396454817629317067995483358046696632270413949397783371061147815617923539634120806955265009854911188530306501324761896490486400736980978270851173985761450205468514371802366150508965142349402634775190541932571215772934087049601511151015580218962449832712507548850463067009640345032653747650848021793733486635063672276271184797891474270402353352104959589784879937226619631..."
},
{
"input": "9851",
"output": "1826526826552054078590833159938859608660168689393622926697593614966325247523385486843148169222905802492343158938765988786790268008018346250425185590729454696317705467641275241528094330016670372495410419378141651879792828682641532533284092879418090040903735626785107378204659838740412715571880884453837366724444432895654221478996531206045405344762139424591887085118650734474741760565377558510969213435666224432175984910232854534478442066899535808519463012771143160247271088007881997468588868391395961360449311260..."
},
{
"input": "9859",
"output": "9737556487585955271085725726347548524587201515015415940974212696477918276264308244608931996051014559947727871548525843984646030062506833242765111803441650144268637762679345636011358150115775908768896005580214321628703868435548404239676226435996040392670484414990942576376634145721680636769353606720643265107519869112758891642047680407647874665865802380346668006876206490814588938569751811311435939234659864088396761136789798899162439354805109166450795279173094212597156554710639295669120966978022955523520243885..."
},
{
"input": "9883",
"output": "3585169013008320587733453934540655406968508071250655174069676351966247095891666666457951370861261022535907218197677774600785190516321049571099175528120462561383326438548822604717683501452327840790897918994708328294710567693091965543331903184071652577937298158191755916197924842106107578819028940776121678861464188820255086932973183740793372165945865009415954786595728774195980645745127346052687115724325004061229398519190748075580806663121266449693574278118081790297078495193488775980028423355059820522243653725..."
},
{
"input": "9901",
"output": "1838099364825091485842998238489502638352163208605775246129613825541675258139803932850287467779059152113767067936585018625986257156889365449198856216156597215096982506298229063072584364817360767528951048690402306736891920567120457283597208730483707878597646111737127186752299112571526574444743928839110241560725998077538870670908652964981237795923920133705668072188172055098674658571105524472734987571439013958589827622877679807533101349696441175687163721291688130495577638100992957486490904022264860238167307326..."
},
{
"input": "9907",
"output": "1633354865670482634892575473274177878269848372373759525765811325846788929611278968402771127221384695483915945198456285004476851582174958025985911899376499975337986661537173411180428490907671107896805361798951388912266345066652077866312114944286489782939084013056891167373799137114155515056010000276816186615290579398553645497061457349859874907706345855178899820840538136570385474191197090563464515778875629438803382571649568677198891486414476226932831825123576296441036124053704853315256369077062694497961110434..."
},
{
"input": "9923",
"output": "3760299283807515305392881669921685380087483626665387583310740045779392618490518061864438198412014466565364228291295311284131760183238506480296641521584717001189575119537493891940454933801650905249443352246953782854872613017048635048443614120554701976326536039594670095564945312513189153593550500517921950184962024588992584781239533465993501341159180970745350678104403343694528834994019085606787711931776684194936418570665879951352474415566347678136222813280481902061127946763865268688300550988394467968839427831..."
},
{
"input": "9941",
"output": "3848534499658219667049727329663074105337547166730018729906447543650907057565599099052599064685569838374730308744072576703962547115876952975258439787965733453851059665347937329225608515273601271650034928543860491219634012020498814661622840677950496926059282612940876829862296013101963794076610277533664472961283348371953697283523069103642217248197905842345904997732309684469494496541394358109215746512001993248263898375663673449385592381926788206401567212276907962968353724108187030299614264372186122509235461661..."
},
{
"input": "9949",
"output": "3077194576897431282984928614971803243979867746742349396701033435828399498432602651550466130139454008014151230282733882472359320178948173983098259522962570058314958623895543103765377873930945767189012935127692368514283490255979891724625021542152152743761996609145171758487359833408232379642800156557718632212879833607371512214716299467380836645557808645986902660996771461355482482475905883289978390754379236092379144196172866264243566348794250784667125654370098361595124994920872496780086986738805458903185126030..."
},
{
"input": "9991",
"output": "6382125632197575640171909108366323999672572433833222272392411654952806480364944179628596547334889065794512754663260535014179926913634410060297543083266944529654281991142775738499030710183320227853166673816892482763220210176769895648821886542105816/436994993873214129706097166956708350993678881411295357199729151951767944417616335439228580716318181998128654620651240845861768505204366709906692902245553277900892247131030458103436298545516643924637451297481464347472084863384057367177715867713535"
},
{
"input": "9992",
"output": "882713207347291313029281/60446290980731458735309"
},
{
"input": "9993",
"output": "12637244675354581352253260560857374/865382809755804604755082721536683"
},
{
"input": "9994",
"output": "3281117414508879498426129146296635638706673857559146714758804687655977321336441892014774756310161571021964653093136031059973674988535235552194295743721563055893425769046817776696216427896857321525164709814889404834572227298884316348149960471145881924249349826195785903333523568245055998853462086046866400139120072781311401680748431799894049040989328677849586317964939112513229643421712863477114408475285877161526889717094721450283390765651073229738491488236723709404792790505935059388430226031866694290751309103..."
},
{
"input": "9995",
"output": "1368770541403820619075110203708490210616145992745821521870208914365828115565556194877572535511077690510688277376757546565243584175363368143317667278940670502781186329534839008398699279841764334491329910860701074569229951248069967340109056226002539889667430100999595433067983400778886042165596127864919572486395941238704720403024794261441096255620000217687954366591408789194462597191661175824028310400352/93746319107175952683864071964918454730461746778024627464635174121600584812748548703282543376385452193806936..."
},
{
"input": "9996",
"output": "2016420396858486097238844042485568452071214924046/138111634978483258420134114867245645268334710595"
},
{
"input": "9997",
"output": "115045178372494165897872226686512107429178048300340407805913417043457084371526821355671616896548808082243735275331446/7880401239278895842455808020028722761015947854093089333589658680849144354299442122282853250976983128161325598061363"
},
{
"input": "9998",
"output": "4285402091468445389426164244750423198106729816197961669529078982307315890678968433526215498100171962888335447/293567822846729153486185074598667128421960318613539983838411371441526128139326055432962374798096087878991871"
},
{
"input": "9999",
"output": "396504919788033353440140876437127916065460257739670266843919813860579129943101204509709504/27160479684459814483579275845458375480686245248879150008481872658058417330177822749111965"
},
{
"input": "10000",
"output": "211285126026764324876224334024814529251789998319439411297242149907456038558/14474011154664524427946373126085988481658748083205070504932198000989141205"
}
] | 1,384,281,326 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import math
from fractions import Fraction
knights = int(raw_input())
def ev(n):
num_flips = int(math.ceil(math.log(n, 2)))
num_states = 2**num_flips
free_states = num_states - n
if (free_states != 0) and (free_states != 1) and (n % free_states == 0):
return ev(n / free_states) + Fraction(num_flips, 1)
else:
return Fraction(num_states * num_flips, num_states - free_states)
ans = ev(knights)
if len(str(ans)) == 1:
print ans + '/1'
else:
print ans | Title: Help King
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be *n* noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1<=/<=*n*). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.
Input Specification:
The first line contains a single integer *n* from the problem's statement (1<=≤<=*n*<=≤<=10000).
Output Specification:
Print the sought expected number of tosses as an irreducible fraction in the following form: "*a*/*b*" (without the quotes) without leading zeroes.
Demo Input:
['2\n', '3\n', '4\n']
Demo Output:
['1/1\n', '8/3\n', '2/1\n']
Note:
none | ```python
import math
from fractions import Fraction
knights = int(raw_input())
def ev(n):
num_flips = int(math.ceil(math.log(n, 2)))
num_states = 2**num_flips
free_states = num_states - n
if (free_states != 0) and (free_states != 1) and (n % free_states == 0):
return ev(n / free_states) + Fraction(num_flips, 1)
else:
return Fraction(num_states * num_flips, num_states - free_states)
ans = ev(knights)
if len(str(ans)) == 1:
print ans + '/1'
else:
print ans
``` | -1 |
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*). | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3 1 1 3 1 1 1 1 2 1 1 6 3 2 1 1 1 1 2 2 3 2 1 1 1 2 1 4 2 1 2 3 2 1 1 1 1 2 4 3 4 2 5 1 1 2 1",
"output": "1882"
},
{
"input": "63 5\n76826 79919 83599 93821 79919 46132 46132 46132 79919 76826 79919 79919 76826 79919 79919 76826 76826 46132 76826 40347 79919 46132 76826 83599 79919 79919 46132 46132 46132 83599 83599 79919 46132 83599 93821 76826 81314 79919 79919 83599 76826 76826 76826 76826 46132 76826 46132 79919 76826 83599 79919 40347 76826 46132 46132 93821 76826 79919 46132 83599 93821 46132 46132",
"output": "1356"
},
{
"input": "6 3\n6 6 4 4 6 2",
"output": "2"
},
{
"input": "100 1\n5 2 5 1 1 4 1 5 4 5 5 5 4 4 1 3 2 3 1 5 1 4 2 4 5 5 5 2 1 3 2 5 5 4 2 1 3 2 2 2 4 4 4 2 1 1 5 4 2 5 3 4 5 5 5 3 1 3 5 4 1 4 5 2 3 2 5 3 5 1 4 2 2 3 2 4 4 3 2 3 5 3 1 3 4 1 5 4 2 5 4 3 1 4 3 2 1 5 2 5",
"output": "5050"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "2 1\n42 1000000000",
"output": "3"
},
{
"input": "2 2\n193 193",
"output": "1"
},
{
"input": "2 2\n97 197",
"output": "0"
}
] | 1,678,037,922 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 3,000 | 2,355,200 | import sys
import copy
from collections import Counter
def n2(a, k):
target = 0
valid = []
for i in range(len(a)):
for j in range(i, len(a)):
cnt = Counter(a[i:j+1])
if max(cnt.values()) >= k:
target += 1
# valid.append(("idx", [i, j], "value", a[i: j+1]))
valid.append(f"[{i}, {j}]")
return target, valid
if __name__ == "__main__":
# Read 2 lines
n, k = [int(x) for x in sys.stdin.readline().strip().split(" ")]
a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
# n, k = 20, 2
# a = [int(x) for x in "6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10".split()]
# n, k = 20, 2
# a = [int(x) for x in "6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10".split()]
n2_target, n2_valid = n2(a, k)
print(n2_target)
# l, r = 0, 0
# target = 0
# cnt = {}
# valid = []
# while r < n:
# right = a[r]
# # print("Right index / right:", r, right)
# if right not in cnt:
# cnt[right] = 0
# cnt[right] += 1
# # If this subarray is valid
# if max(cnt.values()) >= k:
# valid.append((l, r))
# target += 1
# for i in range(r+1, n):
# valid.append(f"[{l}, {r}]")
# target += 1
# left = a[l]
# print("left", left, "idx", l)
# print("Curr counter", cnt)
# # This small [l -> r] arr is valid, meaning all superarrays are also valid
# print("curr target", target)
# # Move left
# cnt[left] -= 1
# if cnt[left] == 0:
# del cnt[left]
# l += 1
# r += 1
# while l < n:
# if max(cnt.values()) >= k:
# print("Will add", cnt)
# valid.append(f"[{l}, {r}]")
# target += 1
# print("Curr cnt inside left", cnt)
# left = a[l]
# cnt[left] -= 1
# if cnt[left] == 0:
# del cnt[left]
# l += 1
# # print("Final target:", target)
# # print("N2 taget", n2_target)
# # print("INTERSECTION", set(n2_valid).intersection(set(valid)))
# # print()
# # print("DIFFERENCE", set(n2_valid).difference(set(valid)))
# # 20 2
# # 6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10
# # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*).
Input Specification:
The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['4 2\n1 2 1 2\n', '5 3\n1 2 1 1 3\n', '3 1\n1 1 1\n']
Demo Output:
['3', '2', '6']
Note:
In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | ```python
import sys
import copy
from collections import Counter
def n2(a, k):
target = 0
valid = []
for i in range(len(a)):
for j in range(i, len(a)):
cnt = Counter(a[i:j+1])
if max(cnt.values()) >= k:
target += 1
# valid.append(("idx", [i, j], "value", a[i: j+1]))
valid.append(f"[{i}, {j}]")
return target, valid
if __name__ == "__main__":
# Read 2 lines
n, k = [int(x) for x in sys.stdin.readline().strip().split(" ")]
a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
# n, k = 20, 2
# a = [int(x) for x in "6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10".split()]
# n, k = 20, 2
# a = [int(x) for x in "6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10".split()]
n2_target, n2_valid = n2(a, k)
print(n2_target)
# l, r = 0, 0
# target = 0
# cnt = {}
# valid = []
# while r < n:
# right = a[r]
# # print("Right index / right:", r, right)
# if right not in cnt:
# cnt[right] = 0
# cnt[right] += 1
# # If this subarray is valid
# if max(cnt.values()) >= k:
# valid.append((l, r))
# target += 1
# for i in range(r+1, n):
# valid.append(f"[{l}, {r}]")
# target += 1
# left = a[l]
# print("left", left, "idx", l)
# print("Curr counter", cnt)
# # This small [l -> r] arr is valid, meaning all superarrays are also valid
# print("curr target", target)
# # Move left
# cnt[left] -= 1
# if cnt[left] == 0:
# del cnt[left]
# l += 1
# r += 1
# while l < n:
# if max(cnt.values()) >= k:
# print("Will add", cnt)
# valid.append(f"[{l}, {r}]")
# target += 1
# print("Curr cnt inside left", cnt)
# left = a[l]
# cnt[left] -= 1
# if cnt[left] == 0:
# del cnt[left]
# l += 1
# # print("Final target:", target)
# # print("N2 taget", n2_target)
# # print("INTERSECTION", set(n2_valid).intersection(set(valid)))
# # print()
# # print("DIFFERENCE", set(n2_valid).difference(set(valid)))
# # 20 2
# # 6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10
# # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
``` | 0 |
|
291 | A | Spyke Talks | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.
One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.
Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.
Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people. | The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise.
Consider the secretaries indexed from 1 to *n* in some way. | Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. | [
"6\n0 1 7 1 7 10\n",
"3\n1 1 1\n",
"1\n0\n"
] | [
"2\n",
"-1\n",
"0\n"
] | In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | 500 | [
{
"input": "6\n0 1 7 1 7 10",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n2 2 1 1 3",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n4 21 3 21 21 1 1 2 2 3",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "6\n6 6 0 8 0 0",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 1 0 1 0 1",
"output": "-1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 3 0 0 3 0 0 0 0 0 0 3 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 0",
"output": "0"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "5\n1 0 0 0 1",
"output": "1"
},
{
"input": "15\n380515742 842209759 945171461 664384656 945171461 474872104 0 0 131648973 131648973 474872104 842209759 664384656 0 380515742",
"output": "6"
},
{
"input": "123\n0 6361 8903 10428 0 258 0 10422 0 0 2642 1958 0 0 0 0 0 8249 1958 0 0 2642 0 0 0 11566 4709 1847 3998 0 1331 0 0 10289 2739 6135 3450 0 0 10994 6069 4337 5854 1331 5854 0 630 630 11244 5928 2706 0 683 214 0 9080 0 0 0 10422 683 11566 10994 0 0 3450 11244 11542 3998 1847 2708 9871 2739 2001 0 12216 6069 0 5928 0 10289 1307 0 1307 8903 0 6361 6135 6632 10428 0 0 632 258 9080 12216 4709 4967 2706 0 11542 2001 6632 0 8249 214 0 10301 4967 10301 7296 7296 10914 2708 4337 0 0 632 0 10914 0 9871 0",
"output": "40"
},
{
"input": "10\n0 3 2 3 2 0 1 3 3 0",
"output": "-1"
},
{
"input": "20\n0 1 2 0 0 0 0 5 3 4 0 0 1 1 3 0 4 0 1 0",
"output": "-1"
},
{
"input": "47\n1 6 0 6 1 1 6 4 3 6 5 3 6 3 2 2 5 1 4 7 3 5 6 1 6 7 4 5 6 3 3 3 7 4 1 6 1 1 7 1 3 1 5 5 1 3 6",
"output": "-1"
},
{
"input": "74\n0 0 0 0 0 37 0 0 0 0 0 0 0 8 0 0 9 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 9 0 7 0 0 0 0 0 0 19 19 0 0 0 0 0 0 0 0 0 0 0 0 17 0 30 0 0 0 0 0 0 30 0 0 0 0 0 0 0 37 0",
"output": "5"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n10000 10000 1 1 10000",
"output": "-1"
}
] | 1,620,471,018 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 186 | 20,172,800 | n=int(input()); c=0
l=list(map(int,input().split()))
s=list(set(l))
for i in s:
if l.count(i)==2: c+=1
elif l.count(i)>2: print(-1); quit()
print(c) | Title: Spyke Talks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.
One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.
Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.
Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise.
Consider the secretaries indexed from 1 to *n* in some way.
Output Specification:
Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
Demo Input:
['6\n0 1 7 1 7 10\n', '3\n1 1 1\n', '1\n0\n']
Demo Output:
['2\n', '-1\n', '0\n']
Note:
In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.
In the second test sample the described situation is impossible as conferences aren't allowed. | ```python
n=int(input()); c=0
l=list(map(int,input().split()))
s=list(set(l))
for i in s:
if l.count(i)==2: c+=1
elif l.count(i)>2: print(-1); quit()
print(c)
``` | 0 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,694,928,796 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 61 | 0 | #import re
a = int(input())
print((a+4)//5) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
#import re
a = int(input())
print((a+4)//5)
``` | 3 |
|
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad. | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists. | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,633,610,109 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,963,200 | def cast(cre, typ): return type(typ)(map(cre, typ));
def solution():
n, m = cast(int, input().split());
block = ["B", "W"];
chess = [input() for i in range(n)];
chess2 = ["".join([block[(n+m)%2] for i in range(m)]) for i in range(n)]
for i in range(n):
for j in range(m):
if chess[i][j] == ".": print(chess2[i][j], end="");
else: print("-", end="");
print();
solution();
| Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | ```python
def cast(cre, typ): return type(typ)(map(cre, typ));
def solution():
n, m = cast(int, input().split());
block = ["B", "W"];
chess = [input() for i in range(n)];
chess2 = ["".join([block[(n+m)%2] for i in range(m)]) for i in range(n)]
for i in range(n):
for j in range(m):
if chess[i][j] == ".": print(chess2[i][j], end="");
else: print("-", end="");
print();
solution();
``` | 0 |
|
460 | B | Little Dima and Equation | PROGRAMMING | 1,500 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digits in the decimal representation of number *x*.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: *a*, *b*, *c*. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem. | The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000). | Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. | [
"3 2 8\n",
"1 2 -18\n",
"2 2 -1\n"
] | [
"3\n10 2008 13726 ",
"0\n",
"4\n1 31 337 967 "
] | none | 1,000 | [
{
"input": "3 2 8",
"output": "3\n10 2008 13726 "
},
{
"input": "1 2 -18",
"output": "0"
},
{
"input": "2 2 -1",
"output": "4\n1 31 337 967 "
},
{
"input": "1 1 0",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 37 963",
"output": "16\n1000 1111 1222 1333 1370 1407 1444 1481 1518 1555 1592 1629 1666 1777 1888 1999 "
},
{
"input": "1 298 -1665",
"output": "17\n123 421 1017 1315 1613 1911 2209 2507 2805 4295 4593 4891 5189 5487 5785 6679 6977 "
},
{
"input": "1 3034 -9234",
"output": "23\n12004 21106 24140 30208 33242 39310 42344 48412 51446 54480 57514 60548 63582 66616 69650 72684 75718 78752 81786 87854 90888 96956 99990 "
},
{
"input": "5 9998 9998",
"output": "0"
},
{
"input": "5 10000 10000",
"output": "0"
},
{
"input": "5 65 352",
"output": "1\n208000352 "
},
{
"input": "5 9999 9999",
"output": "0"
},
{
"input": "4 2099 -38",
"output": "0"
},
{
"input": "1 1 -6708",
"output": "0"
},
{
"input": "5 36 -46",
"output": "0"
},
{
"input": "5 8975 -4",
"output": "0"
},
{
"input": "3 2794 -3354",
"output": "5\n165733932 308990694 392855398 415958984 999999980 "
},
{
"input": "5 1 4473",
"output": "11\n1424330 14353380 17214841 52526348 60470649 69348430 164920697 184532598 205967449 418199966 459169497 "
},
{
"input": "5 1 -9999",
"output": "6\n90001 2466100 17200369 52511876 60456177 205952977 "
},
{
"input": "4 4 6",
"output": "13\n10 1030 40006 114250 202506 262150 521290 937030 1562506 2458630 3694090 4743690 7496650 "
},
{
"input": "5 19 -666",
"output": "0"
},
{
"input": "5 5 -865",
"output": "0"
},
{
"input": "2 8468 -3666",
"output": "2\n7117922 14933886 "
},
{
"input": "4 9359 -3039",
"output": "0"
},
{
"input": "5 5706 -1856",
"output": "0"
},
{
"input": "2 6828 -39",
"output": "2\n7435653 17759589 "
},
{
"input": "5 3903 -9847",
"output": "0"
},
{
"input": "3 1727 4771",
"output": "1\n42124574 "
},
{
"input": "4 1870 9912",
"output": "0"
},
{
"input": "3 6300 7035",
"output": "1\n466761435 "
},
{
"input": "5 8704 -6190",
"output": "0"
},
{
"input": "2 68 3",
"output": "1\n45971 "
},
{
"input": "5 6 -95",
"output": "1\n416063647 "
},
{
"input": "2 28 12",
"output": "2\n4044 7180 "
},
{
"input": "3 37 -70",
"output": "0"
},
{
"input": "5 3 53",
"output": "1\n100663349 "
},
{
"input": "3 2570 4109",
"output": "2\n427587859 999777799 "
},
{
"input": "3 1139 6335",
"output": "2\n12134407 499999999 "
},
{
"input": "3 2278 -1329",
"output": "3\n61504671 145790671 999985999 "
},
{
"input": "4 30 719",
"output": "2\n21219149 899597999 "
},
{
"input": "4 9023 312",
"output": "0"
},
{
"input": "5 10000 9",
"output": "0"
},
{
"input": "5 7698 5337",
"output": "0"
},
{
"input": "5 1 0",
"output": "5\n1 17210368 52521875 60466176 205962976 "
},
{
"input": "5 12 3",
"output": "0"
},
{
"input": "5 3903 153",
"output": "0"
},
{
"input": "5 10000 0",
"output": "1\n10000 "
},
{
"input": "3 2570 -6691",
"output": "1\n999766999 "
},
{
"input": "5 5 13",
"output": "1\n579281018 "
}
] | 1,641,553,146 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 139 | 6,041,600 |
import sys
import pprint
import logging
from logging import getLogger
def input(): return sys.stdin.readline().rstrip("\r\n")
logging.basicConfig(format="%(message)s", level=logging.WARNING,)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)
def debug(msg, *args):
logger.info(f'{msg}={pprint.pformat(args)}')
# 30 MINUTES ATLEAST !!!!
###################################################################################################################
def solve():
a, b, c = inp()
ans = []
for i in range(1, 80):
tobe = (b * pow(i, a)) + c
if tobe < 0:
continue
if sum(map(int, str(tobe))) == i:
ans.append(tobe)
print(len(ans), '\n', *ans)
if __name__ == '__main__':
multi = False
t = 1
def inp(): return map(int, input().split())
if multi:
t = int(input())
while t:
t -= 1
solve()
| Title: Little Dima and Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digits in the decimal representation of number *x*.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: *a*, *b*, *c*. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
Input Specification:
The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000).
Output Specification:
Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
Demo Input:
['3 2 8\n', '1 2 -18\n', '2 2 -1\n']
Demo Output:
['3\n10 2008 13726 ', '0\n', '4\n1 31 337 967 ']
Note:
none | ```python
import sys
import pprint
import logging
from logging import getLogger
def input(): return sys.stdin.readline().rstrip("\r\n")
logging.basicConfig(format="%(message)s", level=logging.WARNING,)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)
def debug(msg, *args):
logger.info(f'{msg}={pprint.pformat(args)}')
# 30 MINUTES ATLEAST !!!!
###################################################################################################################
def solve():
a, b, c = inp()
ans = []
for i in range(1, 80):
tobe = (b * pow(i, a)) + c
if tobe < 0:
continue
if sum(map(int, str(tobe))) == i:
ans.append(tobe)
print(len(ans), '\n', *ans)
if __name__ == '__main__':
multi = False
t = 1
def inp(): return map(int, input().split())
if multi:
t = int(input())
while t:
t -= 1
solve()
``` | 0 |
|
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input": "10000 1000",
"output": "8991"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 100000000000000000",
"output": "899999999999999991"
},
{
"input": "1000000000000000000 10000000000000000",
"output": "989999999999999991"
},
{
"input": "1000000000000000000 1000000000000000",
"output": "998999999999999991"
},
{
"input": "1000000000000000000 100000000000000",
"output": "999899999999999991"
},
{
"input": "1000000000000000000 200000000000000000",
"output": "799999999999999991"
},
{
"input": "10 5",
"output": "1"
},
{
"input": "20 5",
"output": "11"
},
{
"input": "20 9",
"output": "11"
},
{
"input": "100 9",
"output": "91"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "130 118",
"output": "1"
},
{
"input": "190 181",
"output": "0"
},
{
"input": "1999 1971",
"output": "10"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "6909094398 719694282",
"output": "6189400069"
},
{
"input": "260 258",
"output": "0"
},
{
"input": "35 19",
"output": "6"
},
{
"input": "100 87",
"output": "1"
},
{
"input": "91 89",
"output": "0"
},
{
"input": "109 89",
"output": "10"
},
{
"input": "109 91",
"output": "10"
},
{
"input": "20331 11580",
"output": "8732"
},
{
"input": "405487470 255750281",
"output": "149737161"
},
{
"input": "17382 12863",
"output": "4493"
},
{
"input": "19725 14457",
"output": "5246"
},
{
"input": "24848 15384",
"output": "9449"
},
{
"input": "25727 15982",
"output": "9728"
},
{
"input": "109 90",
"output": "10"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "1"
},
{
"input": "1000000000000000000 999999999999999998",
"output": "1"
},
{
"input": "1009 980",
"output": "10"
},
{
"input": "999999999999999999 999999999999999838",
"output": "0"
},
{
"input": "1000000000000000000 99999999999999800",
"output": "900000000000000061"
},
{
"input": "8785369357 3377262261",
"output": "5408107058"
},
{
"input": "110 109",
"output": "0"
},
{
"input": "999 777",
"output": "200"
},
{
"input": "327170000015578 77230000029054",
"output": "249939999986479"
},
{
"input": "12515000022229 1791000022317",
"output": "10723999999880"
},
{
"input": "9999999999999 9999999999882",
"output": "10"
},
{
"input": "213 196",
"output": "14"
},
{
"input": "92 82",
"output": "0"
},
{
"input": "148 136",
"output": "0"
},
{
"input": "8 9",
"output": "0"
},
{
"input": "309 299",
"output": "0"
},
{
"input": "9999 9963",
"output": "10"
},
{
"input": "82 81",
"output": "0"
},
{
"input": "9999999 9999936",
"output": "10"
},
{
"input": "171 155",
"output": "2"
},
{
"input": "999 972",
"output": "10"
},
{
"input": "999999999999 999999999891",
"output": "10"
},
{
"input": "9 9",
"output": "0"
},
{
"input": "6900 6885",
"output": "1"
},
{
"input": "96 57",
"output": "27"
},
{
"input": "5 4",
"output": "0"
},
{
"input": "17386 5814",
"output": "11557"
},
{
"input": "493679757404593 316259583979965",
"output": "177420173424564"
},
{
"input": "18474 9478",
"output": "8975"
},
{
"input": "270091571496186 250931112649966",
"output": "19160458846177"
},
{
"input": "565751690089037 381448507916936",
"output": "184303182172038"
},
{
"input": "19 10",
"output": "0"
}
] | 1,497,650,081 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 0 | n, s = map(int, input().split())
res = 0
if s >= n:
print(0)
else:
for n in range(n, 1, -1):
res += n - sum(map(int, str(n))) >= s
print(res)
| Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input Specification:
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Output Specification:
Print one integer — the quantity of really big numbers that are not greater than *n*.
Demo Input:
['12 1\n', '25 20\n', '10 9\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | ```python
n, s = map(int, input().split())
res = 0
if s >= n:
print(0)
else:
for n in range(n, 1, -1):
res += n - sum(map(int, str(n))) >= s
print(res)
``` | 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,513,493,123 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 5,632,000 | n = int(input())
x = 0
y = 0
z = 0
for i in range(n):
line = [int(x) for x in input().split()]
x += line[0]
y += line[1]
z += line[2]
if x == 0 and y == 0 and z == 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())
x = 0
y = 0
z = 0
for i in range(n):
line = [int(x) for x in input().split()]
x += line[0]
y += line[1]
z += line[2]
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO')
``` | 3.95851 |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,693,416,701 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | s = input()
if len(s) == 2:
print('0')
else:
letter = s[1:-1].split(", ")
distinct = set(letter)
print(len(distinct))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
s = input()
if len(s) == 2:
print('0')
else:
letter = s[1:-1].split(", ")
distinct = set(letter)
print(len(distinct))
``` | 3 |
|
612 | B | HDD is Outdated Technology | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.
Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f**i*-th fragment of the file (1<=≤<=*f**i*<=≤<=*n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th.
It takes |*a*<=-<=*b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector. | Print the only integer — the number of time units needed to read the file. | [
"3\n3 1 2\n",
"5\n1 3 5 4 2\n"
] | [
"3\n",
"10\n"
] | In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units - 4->5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units
So the answer to the second example is 4 + 3 + 2 + 1 = 10. | 0 | [
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "5\n1 3 5 4 2",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "40"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "10\n1 3 5 7 9 10 8 6 4 2",
"output": "45"
},
{
"input": "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98",
"output": "3580"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "99"
},
{
"input": "100\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2",
"output": "4950"
}
] | 1,452,116,303 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 11 | 187 | 716,800 | n = int(input())
fragments = list(map(int, input().split()))
def create(dict, src, i, lim):
dict[src[i]] = i + 1
return create(dict, src, i + 1, lim) if i + 1 < lim else dict
fragmentsDict = create({}, fragments, 0, n)
comp = lambda res, i, d, lim: comp(res + abs(d[i] - d[i + 1]), i + 1, d, lim) if i < lim else res
print(comp(0, 1, fragmentsDict, n))
| Title: HDD is Outdated Technology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.
Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f**i*-th fragment of the file (1<=≤<=*f**i*<=≤<=*n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th.
It takes |*a*<=-<=*b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments.
The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector.
Output Specification:
Print the only integer — the number of time units needed to read the file.
Demo Input:
['3\n3 1 2\n', '5\n1 3 5 4 2\n']
Demo Output:
['3\n', '10\n']
Note:
In the second example the head moves in the following way:
- 1->2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2->3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3->4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units - 4->5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units
So the answer to the second example is 4 + 3 + 2 + 1 = 10. | ```python
n = int(input())
fragments = list(map(int, input().split()))
def create(dict, src, i, lim):
dict[src[i]] = i + 1
return create(dict, src, i + 1, lim) if i + 1 < lim else dict
fragmentsDict = create({}, fragments, 0, n)
comp = lambda res, i, d, lim: comp(res + abs(d[i] - d[i + 1]), i + 1, d, lim) if i < lim else res
print(comp(0, 1, fragmentsDict, n))
``` | -1 |
|
359 | A | Table | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times. | The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner. | Print a single number — the minimum number of operations Simon needs to carry out his idea. | [
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n"
] | [
"4\n",
"2\n"
] | In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1). | 500 | [
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\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\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\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 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "4 32\n0 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\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\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\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",
"output": "2"
},
{
"input": "7 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "2"
},
{
"input": "13 15\n0 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\n0 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\n0 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\n1 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\n0 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\n0 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\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 3\n0 1 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "4 3\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 0\n1 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "4 4\n0 0 0 0\n0 1 1 0\n0 1 1 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 1 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 1 1\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "5 5\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
}
] | 1,616,504,926 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 307,200 | n ,m =[int(x) for x in input().split()]
list = []
for _ in range(n):
list.append([int(x) for x in input().split()])
for _ in range(1 , n-1 , 1):
if list[_][0] == 1:
print(2)
exit()
for _ in range(1, m-1 , 1):
if list[0][_] ==1 or list[-1][_] ==1:
print(2)
exit()
print(4)
| Title: Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
Input Specification:
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
Output Specification:
Print a single number — the minimum number of operations Simon needs to carry out his idea.
Demo Input:
['3 3\n0 0 0\n0 1 0\n0 0 0\n', '4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1). | ```python
n ,m =[int(x) for x in input().split()]
list = []
for _ in range(n):
list.append([int(x) for x in input().split()])
for _ in range(1 , n-1 , 1):
if list[_][0] == 1:
print(2)
exit()
for _ in range(1, m-1 , 1):
if list[0][_] ==1 or list[-1][_] ==1:
print(2)
exit()
print(4)
``` | 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,684,404,773 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | d=input()
if len(d)>10:
n=str(len(d)-2)
d=d[0]+n+d[len(d)-1]
print(d) | 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
d=input()
if len(d)>10:
n=str(len(d)-2)
d=d[0]+n+d[len(d)-1]
print(d)
``` | 0 |
31 | C | Schedule | PROGRAMMING | 1,700 | [
"implementation"
] | C. Schedule | 2 | 256 | At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.
The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that. | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=106) — starting and finishing times of lesson of the *i*-th group. It is possible that initially no two lessons intersect (see sample 1). | Output integer *k* — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order. | [
"3\n3 10\n20 30\n1 3\n",
"4\n3 10\n20 30\n1 3\n1 39\n",
"3\n1 5\n2 6\n3 7\n"
] | [
"3\n1 2 3 ",
"1\n4 ",
"0\n"
] | none | 1,500 | [
{
"input": "3\n3 10\n20 30\n1 3",
"output": "3\n1 2 3 "
},
{
"input": "4\n3 10\n20 30\n1 3\n1 39",
"output": "1\n4 "
},
{
"input": "3\n1 5\n2 6\n3 7",
"output": "0"
},
{
"input": "4\n1 5\n5 7\n6 9\n9 10",
"output": "2\n2 3 "
},
{
"input": "11\n717170 795210\n866429 970764\n163324 322182\n677099 717170\n241684 393937\n50433 114594\n970764 997956\n393937 664883\n235698 241684\n795210 832346\n114594 232438",
"output": "1\n3 "
},
{
"input": "16\n203671 381501\n58867 59732\n817520 962123\n125391 163027\n601766 617692\n381501 444610\n761937 817520\n16 10551\n21096 38291\n718073 761937\n583868 601766\n554859 731755\n678098 718073\n962123 992003\n163027 203671\n87917 96397",
"output": "1\n12 "
}
] | 1,695,779,297 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 6,758,400 | def solution():
def solve(people):
n = len(people)
people.sort(key=lambda x: x[1])
res = []
tot = 0
for i in range(n):
curr, interval = 0, True
for j in range(n):
if i != j:
if people[j][1] >= curr:
curr = people[j][2]
else:
interval = False
if interval:
tot += 1
res.append(people[i][0] + 1)
res.sort()
print(tot)
print(*res)
t = int(input())
people = []
for i in range(t):
people.append([i, *[int(x) for x in input().split()]])
solve(people)
solution()
| Title: Schedule
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.
The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=106) — starting and finishing times of lesson of the *i*-th group. It is possible that initially no two lessons intersect (see sample 1).
Output Specification:
Output integer *k* — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.
Demo Input:
['3\n3 10\n20 30\n1 3\n', '4\n3 10\n20 30\n1 3\n1 39\n', '3\n1 5\n2 6\n3 7\n']
Demo Output:
['3\n1 2 3 ', '1\n4 ', '0\n']
Note:
none | ```python
def solution():
def solve(people):
n = len(people)
people.sort(key=lambda x: x[1])
res = []
tot = 0
for i in range(n):
curr, interval = 0, True
for j in range(n):
if i != j:
if people[j][1] >= curr:
curr = people[j][2]
else:
interval = False
if interval:
tot += 1
res.append(people[i][0] + 1)
res.sort()
print(tot)
print(*res)
t = int(input())
people = []
for i in range(t):
people.append([i, *[int(x) for x in input().split()]])
solve(people)
solution()
``` | 0 |
78 | C | Beaver Game | PROGRAMMING | 2,000 | [
"dp",
"games",
"number theory"
] | C. Beaver Game | 1 | 256 | Two beavers, Timur and Marsel, play the following game.
There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than *k* meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.
Timur makes the first move. The players play in the optimal way. Determine the winner. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=109). | Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes. | [
"1 15 4\n",
"4 9 5\n"
] | [
"Timur",
"Marsel"
] | In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as *k* = 4. Thus, the winner is Timur.
In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly. | 1,500 | [
{
"input": "1 15 4",
"output": "Timur"
},
{
"input": "4 9 5",
"output": "Marsel"
},
{
"input": "14 30 9",
"output": "Marsel"
},
{
"input": "81 180 53",
"output": "Timur"
},
{
"input": "225 187 20",
"output": "Marsel"
},
{
"input": "501 840 11",
"output": "Timur"
},
{
"input": "3 11 6",
"output": "Marsel"
},
{
"input": "1 2 1",
"output": "Timur"
},
{
"input": "1 1 2",
"output": "Marsel"
},
{
"input": "1 1 1",
"output": "Marsel"
},
{
"input": "1 2 2",
"output": "Marsel"
},
{
"input": "2 1 1",
"output": "Marsel"
},
{
"input": "2 1 2",
"output": "Marsel"
},
{
"input": "2 2 1",
"output": "Marsel"
},
{
"input": "2 2 2",
"output": "Marsel"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "Marsel"
},
{
"input": "999999999 735134400 1",
"output": "Timur"
},
{
"input": "999999999 735134400 100",
"output": "Timur"
},
{
"input": "787965358 999999986 2",
"output": "Marsel"
},
{
"input": "588462355 999999986 2",
"output": "Timur"
},
{
"input": "994427144 999999986 10",
"output": "Marsel"
},
{
"input": "36948983 999999986 10",
"output": "Timur"
},
{
"input": "431525232 999999986 250000000",
"output": "Marsel"
},
{
"input": "502291145 999999986 250000000",
"output": "Timur"
},
{
"input": "612116696 999999986 499999993",
"output": "Marsel"
},
{
"input": "559551717 999999986 499999993",
"output": "Timur"
},
{
"input": "844774784 999999894 30",
"output": "Marsel"
},
{
"input": "776970029 999999894 30",
"output": "Timur"
},
{
"input": "726014914 999950443 31643",
"output": "Marsel"
},
{
"input": "350735191 999950443 31643",
"output": "Timur"
},
{
"input": "114514534 999950443 31601",
"output": "Marsel"
},
{
"input": "689283015 999950443 31601",
"output": "Timur"
},
{
"input": "585863414 999002449 31607",
"output": "Marsel"
},
{
"input": "271824601 999002449 31607",
"output": "Timur"
},
{
"input": "57784860 999002449 1",
"output": "Marsel"
},
{
"input": "844093323 999002449 1",
"output": "Timur"
},
{
"input": "623425842 999002449 10",
"output": "Marsel"
},
{
"input": "283831003 999002449 10",
"output": "Timur"
},
{
"input": "884219706 735134400 1",
"output": "Marsel"
},
{
"input": "519313933 735134400 1",
"output": "Timur"
},
{
"input": "483982088 735134400 2",
"output": "Marsel"
},
{
"input": "966249765 735134400 2",
"output": "Timur"
},
{
"input": "362305942 735134400 367567201",
"output": "Marsel"
},
{
"input": "311659875 735134400 367567201",
"output": "Marsel"
},
{
"input": "717978658 735134400 100000000",
"output": "Marsel"
},
{
"input": "367890897 735134400 100000000",
"output": "Timur"
},
{
"input": "52049820 735134400 200000000",
"output": "Marsel"
},
{
"input": "395681265 735134400 200000000",
"output": "Timur"
},
{
"input": "195335332 735134400 300000000",
"output": "Marsel"
},
{
"input": "2240305 735134400 300000000",
"output": "Timur"
},
{
"input": "166548792 901800900 30030",
"output": "Marsel"
},
{
"input": "708577575 901800900 30030",
"output": "Timur"
},
{
"input": "304908040 901800900 901800900",
"output": "Marsel"
},
{
"input": "799852313 901800900 901800900",
"output": "Marsel"
},
{
"input": "624970498 901800900 901800901",
"output": "Marsel"
},
{
"input": "373293701 901800900 901800901",
"output": "Marsel"
},
{
"input": "1608018 999999937 1",
"output": "Marsel"
},
{
"input": "830273749 999999937 1",
"output": "Timur"
},
{
"input": "859437048 999999937 2",
"output": "Marsel"
},
{
"input": "672396661 999999937 2",
"output": "Marsel"
},
{
"input": "763677180 999999937 111",
"output": "Marsel"
},
{
"input": "605998637 999999937 111",
"output": "Marsel"
},
{
"input": "938316524 999999937 1000000000",
"output": "Marsel"
},
{
"input": "885233939 999999937 1000000000",
"output": "Marsel"
},
{
"input": "522619786 1000000000 500000000",
"output": "Marsel"
},
{
"input": "780954779 1000000000 500000000",
"output": "Timur"
},
{
"input": "568419816 1000000000 500000001",
"output": "Marsel"
},
{
"input": "300872687 1000000000 500000001",
"output": "Marsel"
},
{
"input": "628290298 1000000000 1250",
"output": "Marsel"
},
{
"input": "56021277 1000000000 1250",
"output": "Timur"
},
{
"input": "538604320 536870912 268435456",
"output": "Marsel"
},
{
"input": "719320775 536870912 268435456",
"output": "Timur"
},
{
"input": "911637544 536870912 134217728",
"output": "Marsel"
},
{
"input": "104077283 536870912 134217728",
"output": "Timur"
},
{
"input": "167283896 935821597 191101",
"output": "Marsel"
},
{
"input": "753528595 935821597 191101",
"output": "Timur"
},
{
"input": "907605112 935821597 11274959",
"output": "Marsel"
},
{
"input": "327082339 935821597 11274959",
"output": "Timur"
},
{
"input": "316344442 935821597 22824917",
"output": "Marsel"
},
{
"input": "244672063 935821597 22824917",
"output": "Timur"
},
{
"input": "1000000000 1000000000 36",
"output": "Marsel"
},
{
"input": "1 1000000000 1000000000",
"output": "Marsel"
},
{
"input": "2 10 1",
"output": "Marsel"
},
{
"input": "1 999999991 488888888",
"output": "Marsel"
},
{
"input": "4 9 4",
"output": "Marsel"
},
{
"input": "1 3 2",
"output": "Marsel"
},
{
"input": "1 1000000000 1",
"output": "Timur"
},
{
"input": "1 999999938 999999937",
"output": "Marsel"
},
{
"input": "1 7 1",
"output": "Timur"
},
{
"input": "101 1 1",
"output": "Marsel"
},
{
"input": "999999999 1000000000 1000000000",
"output": "Marsel"
},
{
"input": "1 200000 100000",
"output": "Timur"
},
{
"input": "1 9 3",
"output": "Timur"
}
] | 1,500,128,648 | 1,748 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,608,000 | from sys import stdin, stdout
def check(m, k):
for i in range(1, int(m ** 0.5) + 1):
if not m % i and (i >= k or m // i >= k):
return 1
else:
return 0
n, m, k = map(int, stdin.readline().split())
if m < 2 * k or not check(m, k):
stdout.write('Marsel')
elif n % 2:
stdout.write('Timur')
else:
stdout.write('Marsel') | Title: Beaver Game
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Two beavers, Timur and Marsel, play the following game.
There are *n* logs, each of exactly *m* meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than *k* meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.
Timur makes the first move. The players play in the optimal way. Determine the winner.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=109).
Output Specification:
Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.
Demo Input:
['1 15 4\n', '4 9 5\n']
Demo Output:
['Timur', 'Marsel']
Note:
In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as *k* = 4. Thus, the winner is Timur.
In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly. | ```python
from sys import stdin, stdout
def check(m, k):
for i in range(1, int(m ** 0.5) + 1):
if not m % i and (i >= k or m // i >= k):
return 1
else:
return 0
n, m, k = map(int, stdin.readline().split())
if m < 2 * k or not check(m, k):
stdout.write('Marsel')
elif n % 2:
stdout.write('Timur')
else:
stdout.write('Marsel')
``` | 0 |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "12883340691714056185860211260984431382156326935244",
"output": "424"
},
{
"input": "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031",
"output": "1528"
},
{
"input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119521202062222947560634301788787748428236988789594458520867663257476744168528121470923031438015546006185059454402637036376247785881323277542968298682307854655591317046086531554595892680980142608",
"output": "30826"
},
{
"input": "123456",
"output": "7"
},
{
"input": "4",
"output": "1"
},
{
"input": "123",
"output": "1"
}
] | 1,493,109,687 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,608,000 | num = input()
i = 0
counter = 0
max = len(num)
for l in range(max):
while (i + l) < max:
print("i+l =",i+l)
if int(num[i:i+l+1]) % 4 == 0:
counter += 1
i += 1
print(counter) | Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Output Specification:
Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['124\n', '04\n', '5810438174\n']
Demo Output:
['4\n', '3\n', '9\n']
Note:
none | ```python
num = input()
i = 0
counter = 0
max = len(num)
for l in range(max):
while (i + l) < max:
print("i+l =",i+l)
if int(num[i:i+l+1]) % 4 == 0:
counter += 1
i += 1
print(counter)
``` | 0 |
|
46 | B | T-shirts from Sponsor | PROGRAMMING | 1,100 | [
"implementation"
] | B. T-shirts from Sponsor | 2 | 256 | One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size. | The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*. | For each contestant, print a line containing the size of the T-shirt he/she got. | [
"1 0 2 0 1\n3\nXL\nXXL\nM\n"
] | [
"XXL\nL\nL\n"
] | none | 0 | [
{
"input": "1 0 2 0 1\n3\nXL\nXXL\nM",
"output": "XXL\nL\nL"
},
{
"input": "0 0 0 0 1\n1\nS",
"output": "XXL"
},
{
"input": "1 0 1 0 1\n1\nS",
"output": "S"
},
{
"input": "1 0 0 0 1\n2\nS\nL",
"output": "S\nXXL"
},
{
"input": "1 1 1 1 1\n2\nXL\nM",
"output": "XL\nM"
},
{
"input": "1 0 1 1 1\n3\nS\nXXL\nL",
"output": "S\nXXL\nL"
},
{
"input": "1 0 2 1 1\n4\nS\nXXL\nL\nM",
"output": "S\nXXL\nL\nL"
},
{
"input": "1 0 3 0 1\n5\nS\nS\nS\nXL\nL",
"output": "S\nL\nL\nXXL\nL"
},
{
"input": "2 1 0 1 3\n4\nXL\nM\nS\nS",
"output": "XL\nM\nS\nS"
},
{
"input": "2 2 0 2 1\n6\nS\nXXL\nM\nXL\nXXL\nXL",
"output": "S\nXXL\nM\nXL\nXL\nM"
},
{
"input": "3 1 1 4 1\n10\nXL\nL\nL\nXXL\nXXL\nXL\nL\nXXL\nS\nM",
"output": "XL\nL\nXL\nXXL\nXL\nXL\nM\nS\nS\nS"
},
{
"input": "14 3 1 0 2\n10\nS\nXL\nM\nXL\nS\nXXL\nL\nXXL\nS\nL",
"output": "S\nXXL\nM\nXXL\nS\nL\nM\nM\nS\nS"
},
{
"input": "44 314 100 272 270\n10\nXXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL",
"output": "XXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL"
},
{
"input": "2 22 11 9 6\n20\nXL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nS\nXL",
"output": "XL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nM\nXL"
},
{
"input": "13 0 2 4 41\n20\nS\nXXL\nXXL\nL\nXXL\nM\nL\nM\nXXL\nM\nXXL\nL\nXXL\nXL\nM\nXL\nXL\nL\nL\nM",
"output": "S\nXXL\nXXL\nL\nXXL\nL\nXL\nS\nXXL\nS\nXXL\nXL\nXXL\nXL\nS\nXL\nXXL\nXXL\nXXL\nS"
},
{
"input": "5 7 2 9 7\n30\nS\nM\nS\nXL\nXXL\nL\nXL\nL\nL\nXXL\nS\nM\nXXL\nXXL\nS\nL\nXL\nS\nL\nXXL\nXXL\nS\nM\nM\nM\nXXL\nS\nXXL\nS\nL",
"output": "S\nM\nS\nXL\nXXL\nL\nXL\nL\nXL\nXXL\nS\nM\nXXL\nXXL\nS\nXL\nXL\nS\nXL\nXXL\nXXL\nM\nM\nM\nM\nXXL\nM\nXL\nXL\nXL"
},
{
"input": "3 17 3 21 16\n50\nL\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nS\nXXL\nXXL\nXL\nM\nL\nS\nXL\nS\nM\nS\nL\nXL\nM\nXL\nL\nXL\nXL\nL\nL\nM\nXL\nS\nXXL\nL\nL\nM\nL\nS\nM\nL\nXXL\nXL\nS\nL",
"output": "L\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nM\nXXL\nXXL\nXL\nM\nL\nM\nXL\nM\nM\nM\nL\nXL\nM\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL\nM\nXXL\nXL\nXL\nM\nXL\nM\nM\nXL\nXXL\nXL\nM\nXL"
},
{
"input": "2 36 4 48 10\n50\nXXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nS\nXL\nXL\nS\nXXL\nS\nS\nS\nL\nM\nM\nXXL\nS\nS\nM\nXXL\nXL\nL\nS\nM\nXL\nXL\nS\nXXL\nM\nL\nXXL\nXL\nXXL\nXXL\nXL\nL\nL\nXXL\nXL\nXXL\nL\nL\nL\nS\nXL",
"output": "XXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nM\nXL\nXL\nM\nXXL\nM\nM\nM\nL\nM\nM\nXXL\nM\nM\nM\nXXL\nXL\nL\nM\nM\nXL\nXL\nM\nXXL\nM\nL\nXXL\nXL\nXXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL"
},
{
"input": "450 65 82 309 94\n50\nM\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL",
"output": "M\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL"
},
{
"input": "200 910 49 294 547\n50\nXXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL",
"output": "XXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL"
},
{
"input": "85 80 1 27 7\n100\nXXL\nM\nM\nS\nL\nL\nXL\nM\nXXL\nXXL\nXL\nL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nL\nM\nXL\nM\nS\nL\nM\nXXL\nL\nXXL\nS\nM\nS\nM\nL\nXXL\nXXL\nM\nS\nS\nL\nXXL\nM\nXXL\nM\nS\nM\nXXL\nM\nM\nXL\nXXL\nL\nXXL\nXL\nXXL\nS\nL\nL\nS\nS\nS\nL\nM\nL\nXXL\nL\nL\nXXL\nS\nS\nS\nXL\nXXL\nXL\nS\nL\nXXL\nS\nS\nM\nL\nXXL\nXL\nXL\nL\nXXL",
"output": "XXL\nM\nM\nS\nL\nXL\nXL\nM\nXXL\nXXL\nXL\nXL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nXL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nXL\nM\nXL\nM\nS\nXL\nM\nXXL\nXL\nXXL\nS\nM\nS\nM\nXL\nXL\nXL\nM\nS\nS\nXL\nXL\nM\nXL\nM\nS\nM\nXL\nM\nM\nXL\nXL\nXL\nXL\nM\nM\nS\nM\nM\nS\nS\nS\nM\nM\nM\nM\nM\nM\nM\nS\nS\nS\nM\nM\nM\nS\nM\nM\nS\nS\nM\nM\nM\nM\nM\nM\nM"
},
{
"input": "302 143 40 63 452\n100\nXXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL",
"output": "XXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL"
}
] | 1,642,828,483 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 310 | 6,553,600 | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
from collections import defaultdict
d = defaultdict()
d["S"],d["M"],d["L"],d["XL"],d["XXL"] = M()
valst = defaultdict()
valst[0],valst[1],valst[2],valst[3],valst[4] = "S","M","L","XL","XXL"
k = I()
for i in range(k):
p = S()
if d[p]!=0:
print(p)
d[p]-=1
else:
if p=="S":
j =0
k=0
elif p=="M":
j=1
k=1
elif p=="L":
j=2
k=2
elif p=="XL":
j=3
k=3
elif p=="XXL":
j=4
k=4
# increase j and decrease k
pos = j
while j<4 and d[valst[j]]==0 :
j+=1
while k>0 and d[valst[k]]==0 :
k-=1
if d[valst[j]]!=0 and d[valst[k]]!=0:
if abs(pos-j)<=abs(pos-k):
print(valst[j])
d[valst[j]]-=1
else:
print(valst[k])
d[valst[k]]-=1
elif d[valst[j]]!=0 and d[valst[k]]==0:
print(valst[j])
d[valst[j]]-=1
else:
print(valst[k])
d[valst[k]]-=1
| Title: T-shirts from Sponsor
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.
Input Specification:
The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*.
Output Specification:
For each contestant, print a line containing the size of the T-shirt he/she got.
Demo Input:
['1 0 2 0 1\n3\nXL\nXXL\nM\n']
Demo Output:
['XXL\nL\nL\n']
Note:
none | ```python
import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
from collections import defaultdict
d = defaultdict()
d["S"],d["M"],d["L"],d["XL"],d["XXL"] = M()
valst = defaultdict()
valst[0],valst[1],valst[2],valst[3],valst[4] = "S","M","L","XL","XXL"
k = I()
for i in range(k):
p = S()
if d[p]!=0:
print(p)
d[p]-=1
else:
if p=="S":
j =0
k=0
elif p=="M":
j=1
k=1
elif p=="L":
j=2
k=2
elif p=="XL":
j=3
k=3
elif p=="XXL":
j=4
k=4
# increase j and decrease k
pos = j
while j<4 and d[valst[j]]==0 :
j+=1
while k>0 and d[valst[k]]==0 :
k-=1
if d[valst[j]]!=0 and d[valst[k]]!=0:
if abs(pos-j)<=abs(pos-k):
print(valst[j])
d[valst[j]]-=1
else:
print(valst[k])
d[valst[k]]-=1
elif d[valst[j]]!=0 and d[valst[k]]==0:
print(valst[j])
d[valst[j]]-=1
else:
print(valst[k])
d[valst[k]]-=1
``` | 3.910293 |
429 | B | Working out | PROGRAMMING | 1,600 | [
"dp"
] | null | null | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column.
Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*].
There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.
If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs. | The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105). | The output contains a single number — the maximum total gain possible. | [
"3 3\n100 100 100\n100 1 100\n100 100 100\n"
] | [
"800"
] | Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3]. | 1,000 | [
{
"input": "3 3\n100 100 100\n100 1 100\n100 100 100",
"output": "800"
},
{
"input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280",
"output": "747898"
},
{
"input": "3 3\n3 1 2\n3 2 0\n2 3 2",
"output": "16"
},
{
"input": "3 3\n1 10 1\n1 10 1\n1 10 1",
"output": "26"
},
{
"input": "3 3\n0 0 0\n0 10000 0\n0 0 0",
"output": "0"
},
{
"input": "3 3\n1 1 1\n0 10000 0\n1 1 1",
"output": "6"
},
{
"input": "3 3\n9 0 9\n0 9 9\n9 9 9",
"output": "54"
},
{
"input": "3 3\n0 0 0\n0 100 0\n0 0 0",
"output": "0"
},
{
"input": "3 3\n100000 100000 100000\n1 100000 100000\n1 1 100000",
"output": "500003"
},
{
"input": "3 3\n100 0 100\n1 100 100\n0 100 100",
"output": "501"
}
] | 1,628,536,035 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 22,425,600 | import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
m = len(A[0])
d = {}
for i in range(n):
for j in range(m):
d[(i, j)] = [0, 0, 0, 0]
if i > 0:
above = d[(i-1, j)][0]
else:
above = 0
if j > 0:
left = d[(i, j-1)][0]
else:
left = 0
d[(i, j)][0] = A[i][j]+max(left, above)
for j in range(m-1, -1, -1):
if i > 0:
above = d[(i-1, j)][1]
else:
above = 0
if j < m-1:
right = d[(i, j+1)][1]
else:
right = 0
d[(i, j)][1] = A[i][j]+max(above, right)
for i in range(n-1, -1, -1):
for j in range(m):
if i < n-1:
below = d[(i+1, j)][2]
else:
below = 0
if j > 0:
left = d[(i, j-1)][2]
else:
left = 0
d[(i, j)][2] = A[i][j]+max(left, below)
for j in range(m-1, -1, -1):
if i < n-1:
below = d[(i+1, j)][3]
else:
below = 0
if j < m-1:
right = d[(i, j+1)][3]
else:
right = 0
d[(i, j)][3] = A[i][j]+max(below, right)
answer = -1*float('inf')
for i in range(n):
for j in range(m):
answer = max(answer, sum(d[(i, j)])-4*A[i][j])
return answer
n, m = [int(x) for x in input().split()]
A = []
for i in range(n):
row = [int(x) for x in input().split()]
A.append(row)
print(process(row)) | Title: Working out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix *a* with *n* lines and *m* columns. Let number *a*[*i*][*j*] represents the calories burned by performing workout at the cell of gym in the *i*-th line and the *j*-th column.
Iahub starts with workout located at line 1 and column 1. He needs to finish with workout *a*[*n*][*m*]. After finishing workout *a*[*i*][*j*], he can go to workout *a*[*i*<=+<=1][*j*] or *a*[*i*][*j*<=+<=1]. Similarly, Iahubina starts with workout *a*[*n*][1] and she needs to finish with workout *a*[1][*m*]. After finishing workout from cell *a*[*i*][*j*], she goes to either *a*[*i*][*j*<=+<=1] or *a*[*i*<=-<=1][*j*].
There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.
If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.
Input Specification:
The first line of the input contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* integers: *j*-th number from *i*-th line denotes element *a*[*i*][*j*] (0<=≤<=*a*[*i*][*j*]<=≤<=105).
Output Specification:
The output contains a single number — the maximum total gain possible.
Demo Input:
['3 3\n100 100 100\n100 1 100\n100 100 100\n']
Demo Output:
['800']
Note:
Iahub will choose exercises *a*[1][1] → *a*[1][2] → *a*[2][2] → *a*[3][2] → *a*[3][3]. Iahubina will choose exercises *a*[3][1] → *a*[2][1] → *a*[2][2] → *a*[2][3] → *a*[1][3]. | ```python
import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
m = len(A[0])
d = {}
for i in range(n):
for j in range(m):
d[(i, j)] = [0, 0, 0, 0]
if i > 0:
above = d[(i-1, j)][0]
else:
above = 0
if j > 0:
left = d[(i, j-1)][0]
else:
left = 0
d[(i, j)][0] = A[i][j]+max(left, above)
for j in range(m-1, -1, -1):
if i > 0:
above = d[(i-1, j)][1]
else:
above = 0
if j < m-1:
right = d[(i, j+1)][1]
else:
right = 0
d[(i, j)][1] = A[i][j]+max(above, right)
for i in range(n-1, -1, -1):
for j in range(m):
if i < n-1:
below = d[(i+1, j)][2]
else:
below = 0
if j > 0:
left = d[(i, j-1)][2]
else:
left = 0
d[(i, j)][2] = A[i][j]+max(left, below)
for j in range(m-1, -1, -1):
if i < n-1:
below = d[(i+1, j)][3]
else:
below = 0
if j < m-1:
right = d[(i, j+1)][3]
else:
right = 0
d[(i, j)][3] = A[i][j]+max(below, right)
answer = -1*float('inf')
for i in range(n):
for j in range(m):
answer = max(answer, sum(d[(i, j)])-4*A[i][j])
return answer
n, m = [int(x) for x in input().split()]
A = []
for i in range(n):
row = [int(x) for x in input().split()]
A.append(row)
print(process(row))
``` | -1 |
|
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,632,686,860 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 6,963,200 |
n = int(input())
count = 0
a=['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
for i in range(n):
s = input()
if s[0]>='0' and s[0]<='9' and int(s)<18 or s in a:
count += 1
print(count)
| 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
n = int(input())
count = 0
a=['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
for i in range(n):
s = input()
if s[0]>='0' and s[0]<='9' and int(s)<18 or s in a:
count += 1
print(count)
``` | 3.95603 |
186 | B | Growing Mushrooms | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier). | The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose. | Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. | [
"2 3 3 50\n2 4\n4 2\n",
"4 1 1 1\n544 397\n280 101\n280 101\n693 970\n"
] | [
"1 15.00\n2 15.00\n",
"4 1656.07\n1 937.03\n2 379.99\n3 379.99\n"
] | - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | 1,000 | [
{
"input": "2 3 3 50\n2 4\n4 2",
"output": "1 15.00\n2 15.00"
},
{
"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970",
"output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"
},
{
"input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737",
"output": "8 1641.50\n6 1417.00\n7 1368.25\n10 1067.00\n4 1005.25\n1 981.75\n9 861.75\n3 814.00\n5 671.75\n2 559.00"
},
{
"input": "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978",
"output": "5 3788.56\n10 3673.36\n2 3360.12\n6 3289.08\n4 2606.20\n3 2598.64\n9 2525.24\n7 2315.84\n1 2210.84\n8 1184.72"
},
{
"input": "8 1 4 55\n507 82\n681 492\n602 849\n367 557\n438 320\n798 699\n338 302\n391 814",
"output": "3 3666.90\n6 3506.55\n8 3431.95\n2 2945.40\n4 2393.15\n1 2064.90\n5 1896.00\n7 1487.90"
},
{
"input": "9 6 4 80\n95 269\n95 269\n781 724\n22 269\n173 655\n972 850\n22 269\n95 269\n642 666",
"output": "6 4908.00\n3 3992.80\n9 3434.40\n5 2827.60\n1 1190.00\n2 1190.00\n8 1190.00\n4 1102.40\n7 1102.40"
},
{
"input": "7 1 8 25\n98 713\n876 112\n990 771\n57 395\n171 899\n86 600\n459 320",
"output": "3 8498.25\n5 7320.25\n2 7092.00\n1 5777.50\n6 4864.50\n7 3912.00\n4 3202.75"
},
{
"input": "6 1 5 9\n105 771\n105 771\n105 771\n557 985\n105 771\n105 771",
"output": "4 5431.87\n1 3950.55\n2 3950.55\n3 3950.55\n5 3950.55\n6 3950.55"
},
{
"input": "6 2 2 78\n942 465\n593 600\n480 359\n733 648\n995 55\n526 538",
"output": "1 2088.60\n5 2014.20\n4 1751.12\n2 1460.92\n6 1307.44\n3 1117.96"
},
{
"input": "2 1 1 1\n2 2\n2 2",
"output": "1 3.98\n2 3.98"
},
{
"input": "2 1 1 100\n3 4\n4 3",
"output": "1 4.00\n2 4.00"
},
{
"input": "1 1 1 1\n1 1",
"output": "1 1.99"
}
] | 1,626,465,856 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 278 | 22,835,200 | def main():
n, t1, t2, k = [int(i) for i in input().split()]
v = []
for i in range(n):
a, b = [int(i) for i in input().split()]
v.append([a, b])
res = []
for i in range(n):
a, b = v[i]
h1 = a * t1 * (1 - k / 100) + b * t2
h2 = b * t1 * (1 - k / 100) + a * t2
h = max(h1, h2)
res.append([i + 1, h])
for i, rec in sorted(res, key=lambda x: x[1], reverse=True):
print(f'{i} {rec:.2f}')
if __name__ == '__main__':
main()
| Title: Growing Mushrooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input Specification:
The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose.
Output Specification:
Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Demo Input:
['2 3 3 50\n2 4\n4 2\n', '4 1 1 1\n544 397\n280 101\n280 101\n693 970\n']
Demo Output:
['1 15.00\n2 15.00\n', '4 1656.07\n1 937.03\n2 379.99\n3 379.99\n']
Note:
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | ```python
def main():
n, t1, t2, k = [int(i) for i in input().split()]
v = []
for i in range(n):
a, b = [int(i) for i in input().split()]
v.append([a, b])
res = []
for i in range(n):
a, b = v[i]
h1 = a * t1 * (1 - k / 100) + b * t2
h2 = b * t1 * (1 - k / 100) + a * t2
h = max(h1, h2)
res.append([i + 1, h])
for i, rec in sorted(res, key=lambda x: x[1], reverse=True):
print(f'{i} {rec:.2f}')
if __name__ == '__main__':
main()
``` | 3 |
|
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".". | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,692,890,483 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 216 | 16,384,000 | n, k = map(int, input().split())
w = input()
r = max(len(y) for y in w.split("."))
print(["NO","YES"][r < k]) | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n, k = map(int, input().split())
w = input()
r = max(len(y) for y in w.split("."))
print(["NO","YES"][r < k])
``` | 3 |
|
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,596,011,032 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 280 | 22,118,400 | s=input()
su=0
j=0
while(len(s)>1):
su=0
for i in s:
su+=int(i)
s=''
for i in str(su):
s+=str(i)
j+=1
print(j) | 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
s=input()
su=0
j=0
while(len(s)>1):
su=0
for i in s:
su+=int(i)
s=''
for i in str(su):
s+=str(i)
j+=1
print(j)
``` | 3.8902 |
441 | C | Valera and Tubes | PROGRAMMING | 1,500 | [
"constructive algorithms",
"dfs and similar",
"implementation"
] | null | null | Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*).
Valera wants to place exactly *k* tubes on his rectangle table. A tube is such sequence of table cells (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**r*,<=*y**r*), that:
- *r*<=≥<=2; - for any integer *i* (1<=≤<=*i*<=≤<=*r*<=-<=1) the following equation |*x**i*<=-<=*x**i*<=+<=1|<=+<=|*y**i*<=-<=*y**i*<=+<=1|<==<=1 holds; - each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
- no pair of tubes has common cells; - each cell of the table belongs to some tube.
Help Valera to arrange *k* tubes on his rectangle table in a fancy manner. | The first line contains three space-separated integers *n*,<=*m*,<=*k* (2<=≤<=*n*,<=*m*<=≤<=300; 2<=≤<=2*k*<=≤<=*n*·*m*) — the number of rows, the number of columns and the number of tubes, correspondingly. | Print *k* lines. In the *i*-th line print the description of the *i*-th tube: first print integer *r**i* (the number of tube cells), then print 2*r**i* integers *x**i*1,<=*y**i*1,<=*x**i*2,<=*y**i*2,<=...,<=*x**ir**i*,<=*y**ir**i* (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists. | [
"3 3 3\n",
"2 3 1\n"
] | [
"3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3\n",
"6 1 1 1 2 1 3 2 3 2 2 2 1\n"
] | Picture for the first sample:
Picture for the second sample: | 1,500 | [
{
"input": "3 3 3",
"output": "3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3"
},
{
"input": "2 3 1",
"output": "6 1 1 1 2 1 3 2 3 2 2 2 1"
},
{
"input": "2 3 1",
"output": "6 1 1 1 2 1 3 2 3 2 2 2 1"
},
{
"input": "300 300 2",
"output": "2 1 1 1 2\n89998 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 10..."
},
{
"input": "300 300 150",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "300 299 299",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "300 300 45000",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "300 299 44850",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "2 2 2",
"output": "2 1 1 1 2\n2 2 2 2 1"
},
{
"input": "2 3 3",
"output": "2 1 1 1 2\n2 1 3 2 3\n2 2 2 2 1"
},
{
"input": "3 3 4",
"output": "2 1 1 1 2\n2 1 3 2 3\n2 2 2 2 1\n3 3 1 3 2 3 3"
},
{
"input": "5 5 12",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 4 5\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n3 5 3 5 4 5 5"
},
{
"input": "7 5 17",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 4 5\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n2 5 3 5 4\n2 5 5 6 5\n2 6 4 6 3\n2 6 2 6 1\n2 7 1 7 2\n3 7 3 7 4 7 5"
},
{
"input": "135 91 4352",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "32 27 153",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 2 27\n2 2 26 2 25\n2 2 24 2 23\n2 2 22 2 21\n2 2 20 2 19\n2 2 18 2 17\n2 2 16 2 15\n2 2 14 2 13\n2 2 12 2 11\n2 2 10 2 9\n2 2 8 2 7\n2 2 6 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 3 6\n2 3 7 3 8\n2 3 9 3 10\n2 3 11 3 12\n2 3 13 3 14\n2 3 15 3 16\n2 3 17 3 18\n2 3 19 3 20\n2 3 21 3 22\n2 3 23 3 24\n2 3 25 3 26\n2 3 27 4 27\n2 4 2..."
},
{
"input": "74 83 2667",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "296 218 5275",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "89 82 2330",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "15 68 212",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 2 68 2 67\n2 2 66 2 65\n2 2 64 2 63\n2 2 62 2 61\n2 2 60 2 59\n2 2 58 2 57\n..."
},
{
"input": "95 4 177",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n2 5 3 5 4\n2 6 4 6 3\n2 6 2 6 1\n2 7 1 7 2\n2 7 3 7 4\n2 8 4 8 3\n2 8 2 8 1\n2 9 1 9 2\n2 9 3 9 4\n2 10 4 10 3\n2 10 2 10 1\n2 11 1 11 2\n2 11 3 11 4\n2 12 4 12 3\n2 12 2 12 1\n2 13 1 13 2\n2 13 3 13 4\n2 14 4 14 3\n2 14 2 14 1\n2 15 1 15 2\n2 15 3 15 4\n2 16 4 16 3\n2 16 2 16 1\n2 17 1 17 2\n2 17 3 17 4\n2 18 4 18 3\n2 18 2 18 1\n2 19 1 19 2\n2 19 3 19 4\n2 20 4 20 3\n2 20 2 20 1\n2 21 1 21 2\n2 21 3 21 4\n2..."
},
{
"input": "60 136 8",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n8146 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99..."
},
{
"input": "91 183 7827",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "2 15 3",
"output": "2 1 1 1 2\n2 1 3 1 4\n26 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 2 15 2 14 2 13 2 12 2 11 2 10 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1"
},
{
"input": "139 275 10770",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "114 298 7143",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "260 182 9496",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "42 297 3703",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "236 156 9535",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "201 226 1495",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "299 299 100",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "299 298 100",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "298 299 100",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "299 299 2",
"output": "2 1 1 1 2\n89399 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 10..."
},
{
"input": "299 299 1",
"output": "89401 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1..."
},
{
"input": "298 299 1",
"output": "89102 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1..."
},
{
"input": "299 298 11",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n89082 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97..."
},
{
"input": "298 300 12",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n89378 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1..."
},
{
"input": "298 2 1",
"output": "596 1 1 1 2 2 2 2 1 3 1 3 2 4 2 4 1 5 1 5 2 6 2 6 1 7 1 7 2 8 2 8 1 9 1 9 2 10 2 10 1 11 1 11 2 12 2 12 1 13 1 13 2 14 2 14 1 15 1 15 2 16 2 16 1 17 1 17 2 18 2 18 1 19 1 19 2 20 2 20 1 21 1 21 2 22 2 22 1 23 1 23 2 24 2 24 1 25 1 25 2 26 2 26 1 27 1 27 2 28 2 28 1 29 1 29 2 30 2 30 1 31 1 31 2 32 2 32 1 33 1 33 2 34 2 34 1 35 1 35 2 36 2 36 1 37 1 37 2 38 2 38 1 39 1 39 2 40 2 40 1 41 1 41 2 42 2 42 1 43 1 43 2 44 2 44 1 45 1 45 2 46 2 46 1 47 1 47 2 48 2 48 1 49 1 49 2 50 2 50 1 51 1 51 2 52 2 52 1 53 1 ..."
},
{
"input": "2 298 1",
"output": "596 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1 1..."
},
{
"input": "300 300 500",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "300 300 501",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "300 300 44999",
"output": "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n..."
},
{
"input": "5 5 3",
"output": "2 1 1 1 2\n2 1 3 1 4\n21 1 5 2 5 2 4 2 3 2 2 2 1 3 1 3 2 3 3 3 4 3 5 4 5 4 4 4 3 4 2 4 1 5 1 5 2 5 3 5 4 5 5"
},
{
"input": "2 4 3",
"output": "2 1 1 1 2\n2 1 3 1 4\n4 2 4 2 3 2 2 2 1"
}
] | 1,525,078,078 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 607 | 16,486,400 | def print_tube(a):
print(len(a),end = " ")
print(" ".join(map(lambda x: " ".join(str(i) for i in x), a)))
n, m, k = map(int, input().split())
res = [(x+1,y+1) for x in range(n) for y in range(m)[::(1 if (x%2 == 0) else -1)]]
for i in range(k-1):
print_tube(res[2*i:2*i+2])
print_tube(res[2*k-2:]) | Title: Valera and Tubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*).
Valera wants to place exactly *k* tubes on his rectangle table. A tube is such sequence of table cells (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**r*,<=*y**r*), that:
- *r*<=≥<=2; - for any integer *i* (1<=≤<=*i*<=≤<=*r*<=-<=1) the following equation |*x**i*<=-<=*x**i*<=+<=1|<=+<=|*y**i*<=-<=*y**i*<=+<=1|<==<=1 holds; - each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
- no pair of tubes has common cells; - each cell of the table belongs to some tube.
Help Valera to arrange *k* tubes on his rectangle table in a fancy manner.
Input Specification:
The first line contains three space-separated integers *n*,<=*m*,<=*k* (2<=≤<=*n*,<=*m*<=≤<=300; 2<=≤<=2*k*<=≤<=*n*·*m*) — the number of rows, the number of columns and the number of tubes, correspondingly.
Output Specification:
Print *k* lines. In the *i*-th line print the description of the *i*-th tube: first print integer *r**i* (the number of tube cells), then print 2*r**i* integers *x**i*1,<=*y**i*1,<=*x**i*2,<=*y**i*2,<=...,<=*x**ir**i*,<=*y**ir**i* (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Demo Input:
['3 3 3\n', '2 3 1\n']
Demo Output:
['3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3\n', '6 1 1 1 2 1 3 2 3 2 2 2 1\n']
Note:
Picture for the first sample:
Picture for the second sample: | ```python
def print_tube(a):
print(len(a),end = " ")
print(" ".join(map(lambda x: " ".join(str(i) for i in x), a)))
n, m, k = map(int, input().split())
res = [(x+1,y+1) for x in range(n) for y in range(m)[::(1 if (x%2 == 0) else -1)]]
for i in range(k-1):
print_tube(res[2*i:2*i+2])
print_tube(res[2*k-2:])
``` | 3 |
|
420 | A | Start Up | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | [
"AHA\n",
"Z\n",
"XO\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "AHA",
"output": "YES"
},
{
"input": "Z",
"output": "NO"
},
{
"input": "XO",
"output": "NO"
},
{
"input": "AAA",
"output": "YES"
},
{
"input": "AHHA",
"output": "YES"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "OMMMAAMMMO",
"output": "YES"
},
{
"input": "YYHUIUGYI",
"output": "NO"
},
{
"input": "TT",
"output": "YES"
},
{
"input": "UUU",
"output": "YES"
},
{
"input": "WYYW",
"output": "YES"
},
{
"input": "MITIM",
"output": "YES"
},
{
"input": "VO",
"output": "NO"
},
{
"input": "WWS",
"output": "NO"
},
{
"input": "VIYMAXXAVM",
"output": "NO"
},
{
"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM",
"output": "NO"
},
{
"input": "CC",
"output": "NO"
},
{
"input": "QOQ",
"output": "NO"
},
{
"input": "AEEA",
"output": "NO"
},
{
"input": "OQQQO",
"output": "NO"
},
{
"input": "HNCMEEMCNH",
"output": "NO"
},
{
"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ",
"output": "NO"
},
{
"input": "A",
"output": "YES"
},
{
"input": "B",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "D",
"output": "NO"
},
{
"input": "E",
"output": "NO"
},
{
"input": "F",
"output": "NO"
},
{
"input": "G",
"output": "NO"
},
{
"input": "H",
"output": "YES"
},
{
"input": "I",
"output": "YES"
},
{
"input": "J",
"output": "NO"
},
{
"input": "K",
"output": "NO"
},
{
"input": "L",
"output": "NO"
},
{
"input": "M",
"output": "YES"
},
{
"input": "N",
"output": "NO"
},
{
"input": "O",
"output": "YES"
},
{
"input": "P",
"output": "NO"
},
{
"input": "Q",
"output": "NO"
},
{
"input": "R",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "T",
"output": "YES"
},
{
"input": "U",
"output": "YES"
},
{
"input": "V",
"output": "YES"
},
{
"input": "W",
"output": "YES"
},
{
"input": "X",
"output": "YES"
},
{
"input": "Y",
"output": "YES"
},
{
"input": "JL",
"output": "NO"
},
{
"input": "AAAKTAAA",
"output": "NO"
},
{
"input": "AKA",
"output": "NO"
},
{
"input": "AAJAA",
"output": "NO"
},
{
"input": "ABA",
"output": "NO"
},
{
"input": "AAAAAABAAAAAA",
"output": "NO"
},
{
"input": "ZZ",
"output": "NO"
},
{
"input": "ADA",
"output": "NO"
},
{
"input": "N",
"output": "NO"
},
{
"input": "P",
"output": "NO"
},
{
"input": "LAL",
"output": "NO"
},
{
"input": "AABAA",
"output": "NO"
},
{
"input": "AZA",
"output": "NO"
},
{
"input": "V",
"output": "YES"
},
{
"input": "SSS",
"output": "NO"
},
{
"input": "NNN",
"output": "NO"
},
{
"input": "S",
"output": "NO"
},
{
"input": "I",
"output": "YES"
},
{
"input": "SS",
"output": "NO"
},
{
"input": "E",
"output": "NO"
}
] | 1,585,589,662 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 204,800 | x = input()
l =[]
l[:0] = x
i = 0
for _ in range(i, len(l)):
if l[i] == "A" or "H" or "I" or "M" or "O" or "T" or "U" or "V" or "W" or "X" or "Y":
a = True
else:
a = False
if l == l[:: -1]:
b = True
else:
b = False
if a == True and b == True:
print("yes")
else:
print("NO")
| Title: Start Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input Specification:
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Output Specification:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Demo Input:
['AHA\n', 'Z\n', 'XO\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
x = input()
l =[]
l[:0] = x
i = 0
for _ in range(i, len(l)):
if l[i] == "A" or "H" or "I" or "M" or "O" or "T" or "U" or "V" or "W" or "X" or "Y":
a = True
else:
a = False
if l == l[:: -1]:
b = True
else:
b = False
if a == True and b == True:
print("yes")
else:
print("NO")
``` | 0 |
|
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output": "4"
},
{
"input": "8 8 2 2 2",
"output": "6"
},
{
"input": "5 50 5 5 60",
"output": "110"
},
{
"input": "100 100 100 100 100",
"output": "200"
},
{
"input": "1 1 1 1 1",
"output": "2"
},
{
"input": "29 29 20 20 20",
"output": "58"
},
{
"input": "20 29 20 29 20",
"output": "58"
},
{
"input": "31 31 20 20 20",
"output": "60"
},
{
"input": "20 20 20 31 31",
"output": "60"
},
{
"input": "20 31 20 31 20",
"output": "60"
},
{
"input": "20 20 20 30 30",
"output": "60"
},
{
"input": "30 30 20 20 20",
"output": "60"
},
{
"input": "8 1 8 8 8",
"output": "9"
},
{
"input": "1 1 1 8 1",
"output": "9"
},
{
"input": "1 2 3 4 5",
"output": "15"
},
{
"input": "100 99 98 97 96",
"output": "490"
},
{
"input": "1 1 100 100 100",
"output": "2"
},
{
"input": "100 100 99 99 98",
"output": "296"
},
{
"input": "98 99 100 99 100",
"output": "296"
},
{
"input": "1 90 1 91 1",
"output": "181"
},
{
"input": "60 1 75 1 92",
"output": "227"
},
{
"input": "15 40 90 40 90",
"output": "95"
},
{
"input": "1 1 15 20 20",
"output": "17"
},
{
"input": "90 11 11 10 10",
"output": "110"
},
{
"input": "20 21 22 23 24",
"output": "110"
},
{
"input": "1 1 2 98 99",
"output": "199"
},
{
"input": "3 7 7 7 10",
"output": "13"
},
{
"input": "1 3 3 3 1",
"output": "2"
},
{
"input": "1 9 9 9 10",
"output": "11"
},
{
"input": "100 1 1 1 1",
"output": "101"
},
{
"input": "2 2 2 100 100",
"output": "6"
},
{
"input": "1 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2 2 5",
"output": "7"
},
{
"input": "1 2 3 4 1",
"output": "9"
},
{
"input": "11 10 10 10 10",
"output": "21"
},
{
"input": "2 2 2 10 10",
"output": "6"
},
{
"input": "1 1 1 1 4",
"output": "5"
},
{
"input": "98 98 98 98 23",
"output": "121"
},
{
"input": "1 2 3 100 100",
"output": "6"
},
{
"input": "2 2 5 10 10",
"output": "9"
},
{
"input": "2 2 3 3 3",
"output": "4"
},
{
"input": "1 1 1 1 2",
"output": "3"
},
{
"input": "12 12 7 7 7",
"output": "21"
}
] | 1,657,839,840 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | list1 = list(map(int,input().split()))
n =0
for i in set(list1):
if (list1.count(i)>1):
n = max(n,i*min(3,list1.count(i)))
print(sum(list1)-n)
| Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input Specification:
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Output Specification:
Print the minimum possible sum of numbers written on remaining cards.
Demo Input:
['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n']
Demo Output:
['26\n', '28\n', '20\n']
Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | ```python
list1 = list(map(int,input().split()))
n =0
for i in set(list1):
if (list1.count(i)>1):
n = max(n,i*min(3,list1.count(i)))
print(sum(list1)-n)
``` | 3 |
|
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat. | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "0"
},
{
"input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS",
"output": "0"
},
{
"input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS",
"output": "30"
},
{
"input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..",
"output": "80"
},
{
"input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS",
"output": "0"
},
{
"input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..",
"output": "17"
},
{
"input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS",
"output": "0"
},
{
"input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S",
"output": "64"
},
{
"input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S",
"output": "28"
},
{
"input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S",
"output": "10"
},
{
"input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.",
"output": "0"
},
{
"input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS",
"output": "0"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "3 2\nS.\n.S\nS.",
"output": "0"
},
{
"input": "4 3\n.S.\nS.S\n.S.\nS.S",
"output": "0"
},
{
"input": "2 3\n...\nSSS",
"output": "3"
},
{
"input": "2 4\nS.SS\nS.SS",
"output": "2"
},
{
"input": "2 2\n..\n.S",
"output": "3"
},
{
"input": "3 2\n.S\n.S\nSS",
"output": "0"
},
{
"input": "2 4\nSS.S\n..S.",
"output": "0"
},
{
"input": "2 3\n...\nS..",
"output": "5"
}
] | 1,632,426,971 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 186 | 20,172,800 | a,b=input().split()
c=[]
a = int(a)
b=int(b)
count=0
for i in range(0,a):
d=[x for x in input()]
c.append(d)
for i in range(0,a):
for j in range(0,b):
if(c[i][j]=='S'):
break
else:
for j in range(0,b):
c[i][j]=0
count+=b
for i in range(0,b):
for j in range(0,a):
if(c[j][i])=='S':
break
else:
for j in range(0,a):
if(c[j][i]!=0):
count+=1
print(count)
| Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.
Please output the maximum number of cake cells that the cakeminator can eat.
Input Specification:
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
- '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output Specification:
Output the maximum number of cake cells that the cakeminator can eat.
Demo Input:
['3 4\nS...\n....\n..S.\n']
Demo Output:
['8\n']
Note:
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | ```python
a,b=input().split()
c=[]
a = int(a)
b=int(b)
count=0
for i in range(0,a):
d=[x for x in input()]
c.append(d)
for i in range(0,a):
for j in range(0,b):
if(c[i][j]=='S'):
break
else:
for j in range(0,b):
c[i][j]=0
count+=b
for i in range(0,b):
for j in range(0,a):
if(c[j][i])=='S':
break
else:
for j in range(0,a):
if(c[j][i]!=0):
count+=1
print(count)
``` | 3 |
|
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,679,824,475 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | n,m = map(int,input().split())
count = 0
arr = []
for i in range(n):
if i%2==0:
s = "#"*m
arr.append(s)
if i%2!=0:
dot = "."*(m-1)
if count%2==0:
s = dot+"#"
else:
s = "#"+dot
count+=1
arr.append(s)
for i in arr:
print(i) | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
n,m = map(int,input().split())
count = 0
arr = []
for i in range(n):
if i%2==0:
s = "#"*m
arr.append(s)
if i%2!=0:
dot = "."*(m-1)
if count%2==0:
s = dot+"#"
else:
s = "#"+dot
count+=1
arr.append(s)
for i in arr:
print(i)
``` | 3 |
|
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..."
},
{
"input": "20 401",
"output": "-1"
},
{
"input": "100 3574",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 \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..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 \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..."
},
{
"input": "100 10001",
"output": "-1"
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "1 1000000",
"output": "-1"
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "1 11",
"output": "-1"
},
{
"input": "1 12",
"output": "-1"
},
{
"input": "1 13",
"output": "-1"
},
{
"input": "1 14",
"output": "-1"
},
{
"input": "1 15",
"output": "-1"
},
{
"input": "1 16",
"output": "-1"
},
{
"input": "1 17",
"output": "-1"
},
{
"input": "1 18",
"output": "-1"
},
{
"input": "1 19",
"output": "-1"
},
{
"input": "1 20",
"output": "-1"
},
{
"input": "1 21",
"output": "-1"
},
{
"input": "1 22",
"output": "-1"
},
{
"input": "1 23",
"output": "-1"
},
{
"input": "1 24",
"output": "-1"
},
{
"input": "1 25",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "2 2",
"output": "1 0 \n0 1 "
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "2 4",
"output": "1 1 \n1 1 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "2 11",
"output": "-1"
},
{
"input": "2 12",
"output": "-1"
},
{
"input": "2 13",
"output": "-1"
},
{
"input": "2 14",
"output": "-1"
},
{
"input": "2 15",
"output": "-1"
},
{
"input": "2 16",
"output": "-1"
},
{
"input": "2 17",
"output": "-1"
},
{
"input": "2 18",
"output": "-1"
},
{
"input": "2 19",
"output": "-1"
},
{
"input": "2 20",
"output": "-1"
},
{
"input": "2 21",
"output": "-1"
},
{
"input": "2 22",
"output": "-1"
},
{
"input": "2 23",
"output": "-1"
},
{
"input": "2 24",
"output": "-1"
},
{
"input": "2 25",
"output": "-1"
},
{
"input": "2 26",
"output": "-1"
},
{
"input": "3 0",
"output": "0 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 1",
"output": "1 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "3 7",
"output": "1 1 1 \n1 1 0 \n1 0 1 "
},
{
"input": "3 8",
"output": "1 1 1 \n1 1 1 \n1 1 0 "
},
{
"input": "3 9",
"output": "1 1 1 \n1 1 1 \n1 1 1 "
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "3 11",
"output": "-1"
},
{
"input": "3 12",
"output": "-1"
},
{
"input": "3 13",
"output": "-1"
},
{
"input": "3 14",
"output": "-1"
},
{
"input": "3 15",
"output": "-1"
},
{
"input": "3 16",
"output": "-1"
},
{
"input": "3 17",
"output": "-1"
},
{
"input": "3 18",
"output": "-1"
},
{
"input": "3 19",
"output": "-1"
},
{
"input": "3 20",
"output": "-1"
},
{
"input": "3 21",
"output": "-1"
},
{
"input": "3 22",
"output": "-1"
},
{
"input": "3 23",
"output": "-1"
},
{
"input": "3 24",
"output": "-1"
},
{
"input": "3 25",
"output": "-1"
},
{
"input": "3 26",
"output": "-1"
},
{
"input": "4 0",
"output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 1",
"output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 2",
"output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 4",
"output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 6",
"output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 7",
"output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 8",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 9",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 "
},
{
"input": "4 10",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 "
},
{
"input": "4 11",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 "
},
{
"input": "4 12",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 "
},
{
"input": "4 13",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 "
},
{
"input": "4 14",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 "
},
{
"input": "4 15",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 "
},
{
"input": "4 16",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 "
},
{
"input": "4 17",
"output": "-1"
},
{
"input": "4 18",
"output": "-1"
},
{
"input": "4 19",
"output": "-1"
},
{
"input": "4 20",
"output": "-1"
},
{
"input": "4 21",
"output": "-1"
},
{
"input": "4 22",
"output": "-1"
},
{
"input": "4 23",
"output": "-1"
},
{
"input": "4 24",
"output": "-1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "4 26",
"output": "-1"
},
{
"input": "5 0",
"output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 1",
"output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 2",
"output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 3",
"output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 4",
"output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5",
"output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 7",
"output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 8",
"output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 9",
"output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 11",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 12",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 13",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 14",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 15",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 16",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 17",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 18",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 "
},
{
"input": "5 19",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 "
},
{
"input": "5 20",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 "
},
{
"input": "5 21",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 "
},
{
"input": "5 22",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 "
},
{
"input": "5 23",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "5 25",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 "
},
{
"input": "5 26",
"output": "-1"
},
{
"input": "100 0",
"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 \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 \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..."
},
{
"input": "100 1",
"output": "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 0 0 0 0 0 0 0 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 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..."
},
{
"input": "100 2",
"output": "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 0 0 0 0 0 0 0 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 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 0 0 0 0 0 0 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..."
},
{
"input": "100 3",
"output": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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 0 0 0 0 0 0 0 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..."
},
{
"input": "100 99",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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..."
},
{
"input": "100 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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..."
},
{
"input": "100 101",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \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..."
},
{
"input": "100 9999",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 \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..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 \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..."
},
{
"input": "100 10001",
"output": "-1"
}
] | 1,698,331,105 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # -*- coding: utf-8 -*-
"""
Created on Thu Oct 26 21:37:12 2023
@author: HXY
"""
n,k=map(int,input().split())
matrix=[[0]*n for _ in range(n)]
if k>n*n:
print(-1)
for i in range(1,n+1,-1):
if k<2i:
if k%2==0:
matrix[1][1]=1
for x in range(k/2-1):
matrix[n-i][x]=1
matrix[x][0]=1
if k%2!=0:
for y in range(k//2):
matrix[y][n-i]=1
matrix[n-i][y]=1
print(matrix)
break
else:
k-=2i-1
for z in range(i):
matrix[y][n-i]=1
matrix[n-i][y]=1
| Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
Output Specification:
If the answer exists then output resulting matrix. Otherwise output -1.
Demo Input:
['2 1\n', '3 2\n', '2 5\n']
Demo Output:
['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 26 21:37:12 2023
@author: HXY
"""
n,k=map(int,input().split())
matrix=[[0]*n for _ in range(n)]
if k>n*n:
print(-1)
for i in range(1,n+1,-1):
if k<2i:
if k%2==0:
matrix[1][1]=1
for x in range(k/2-1):
matrix[n-i][x]=1
matrix[x][0]=1
if k%2!=0:
for y in range(k//2):
matrix[y][n-i]=1
matrix[n-i][y]=1
print(matrix)
break
else:
k-=2i-1
for z in range(i):
matrix[y][n-i]=1
matrix[n-i][y]=1
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,694,581,604 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,867,200 | y = int(input())
w = int(input())
m = max(y,w)
d = [1,2,3,4,5,6]
prob = 6-m+1
if prob%2==0 and prob%3==0:
print('1/1')
elif prob%2 == 0:
print(f'{prob//2}/3')
elif prob%3 == 0:
print('1/2')
else:
print('1/6') | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
y = int(input())
w = int(input())
m = max(y,w)
d = [1,2,3,4,5,6]
prob = 6-m+1
if prob%2==0 and prob%3==0:
print('1/1')
elif prob%2 == 0:
print(f'{prob//2}/3')
elif prob%3 == 0:
print('1/2')
else:
print('1/6')
``` | -1 |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one. | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 "
},
{
"input": "100 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100 10",
"output": "10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "64 8",
"output": "8 8 8 8 8 8 8 8 "
},
{
"input": "81 27",
"output": "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100 99",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 "
},
{
"input": "100 51",
"output": "1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100 49",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 "
},
{
"input": "100 13",
"output": "7 7 7 7 8 8 8 8 8 8 8 8 8 "
},
{
"input": "97 11",
"output": "8 8 9 9 9 9 9 9 9 9 9 "
},
{
"input": "19 3",
"output": "6 6 7 "
},
{
"input": "99 10",
"output": "9 10 10 10 10 10 10 10 10 10 "
},
{
"input": "88 5",
"output": "17 17 18 18 18 "
},
{
"input": "87 34",
"output": "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "97 55",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
}
] | 1,628,574,107 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 6,758,400 | candies, friends = input().split(' ')
candies = int(candies)
friends = int(friends)
output = ''
for i in range(friends - candies % friends):
output += str(candies // friends) + ' '
for i in range(candies % friends):
output += str(candies // friends + 1) + ' '
print(output[0: len(output)-1]) | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one.
Input Specification:
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Output Specification:
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
Demo Input:
['12 3\n', '15 4\n', '18 7\n']
Demo Output:
['4 4 4 ', '3 4 4 4 ', '2 2 2 3 3 3 3 ']
Note:
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | ```python
candies, friends = input().split(' ')
candies = int(candies)
friends = int(friends)
output = ''
for i in range(friends - candies % friends):
output += str(candies // friends) + ' '
for i in range(candies % friends):
output += str(candies // friends + 1) + ' '
print(output[0: len(output)-1])
``` | 3 |
|
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces. | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
}
] | 1,590,526,311 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 685 | 307,200 | #Antonio Hernandez Monsalvo
miLista = []
enter = input().split()
n = int(enter[0])
a = int(enter[1])
b = int(enter[2])
2<=n<=2000
def bubbleSort(tareas):
for long in range (len(tareas) -1, 0, -1):
for i in range (0, long):
if tareas[i] > tareas[i + 1]: #Cambio
temp = tareas[i]
tareas[i] = tareas[i + 1]
tareas[i + 1] = temp
tareas = []
numbers = input().split()
for i in range (0,n):
tareas.append(int(numbers[i]))
if (a + b == n):
bubbleSort(tareas)
print(tareas[b] - tareas[b-1])
else:
print("Error, el numero de tareas por persona no coincide con el no de tareas totales") | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | ```python
#Antonio Hernandez Monsalvo
miLista = []
enter = input().split()
n = int(enter[0])
a = int(enter[1])
b = int(enter[2])
2<=n<=2000
def bubbleSort(tareas):
for long in range (len(tareas) -1, 0, -1):
for i in range (0, long):
if tareas[i] > tareas[i + 1]: #Cambio
temp = tareas[i]
tareas[i] = tareas[i + 1]
tareas[i + 1] = temp
tareas = []
numbers = input().split()
for i in range (0,n):
tareas.append(int(numbers[i]))
if (a + b == n):
bubbleSort(tareas)
print(tareas[b] - tareas[b-1])
else:
print("Error, el numero de tareas por persona no coincide con el no de tareas totales")
``` | 3 |
|
394 | A | Counting Sticks | PROGRAMMING | 0 | [
"brute force",
"implementation"
] | null | null | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*.
We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us? | The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. | If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples. | [
"||+|=|||||\n",
"|||||+||=||\n",
"|+|=||||||\n",
"||||+||=||||||\n"
] | [
"|||+|=||||\n",
"Impossible\n",
"Impossible\n",
"||||+||=||||||\n"
] | In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks. | 500 | [
{
"input": "||+|=|||||",
"output": "|||+|=||||"
},
{
"input": "|||||+||=||",
"output": "Impossible"
},
{
"input": "|+|=||||||",
"output": "Impossible"
},
{
"input": "||||+||=||||||",
"output": "||||+||=||||||"
},
{
"input": "||||||||||||+|||||||||||=||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "|+|=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||=|",
"output": "Impossible"
},
{
"input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+|=|",
"output": "|+|=||"
},
{
"input": "|+||=|",
"output": "|+|=||"
},
{
"input": "|+|=||",
"output": "|+|=||"
},
{
"input": "|||+|=|",
"output": "Impossible"
},
{
"input": "|||+|=|",
"output": "Impossible"
},
{
"input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
},
{
"input": "|+|=|||",
"output": "Impossible"
},
{
"input": "|+|=||||",
"output": "||+|=|||"
},
{
"input": "|+||=|",
"output": "|+|=||"
},
{
"input": "|+||||||=|||||",
"output": "|+|||||=||||||"
},
{
"input": "|+|||=||",
"output": "|+||=|||"
},
{
"input": "|+||||=|||",
"output": "|+|||=||||"
},
{
"input": "|+|||||=||||",
"output": "|+||||=|||||"
},
{
"input": "||+||=||",
"output": "|+||=|||"
},
{
"input": "||+|||=|||",
"output": "|+|||=||||"
},
{
"input": "|||||+||=||||||||||",
"output": "Impossible"
},
{
"input": "|||+|||=||||",
"output": "||+|||=|||||"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "|||||+|||||=||||||||||||",
"output": "||||||+|||||=|||||||||||"
},
{
"input": "||+|||||||=|||||||",
"output": "|+|||||||=||||||||"
},
{
"input": "||||+||||=||||||",
"output": "|||+||||=|||||||"
},
{
"input": "||||+|||=|||||",
"output": "|||+|||=||||||"
},
{
"input": "||+|||=|||||||",
"output": "|||+|||=||||||"
},
{
"input": "||+|=|",
"output": "|+|=||"
},
{
"input": "|||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
},
{
"input": "||+|=||||||",
"output": "Impossible"
},
{
"input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",
"output": "Impossible"
}
] | 1,586,259,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 21 | 140 | 819,200 | import re
def count(x):
return x.count("|")
text = input()
x=(re.split('\+|\=',text))
lst=list(map(count,x))
if x[0]+x[1]==x[2]:
print(x[0]+"+"+x[1]+"="+x[2])
elif (lst[0]-1)+(lst[1]+1)==lst[2]:
print("|"*(lst[0]-1)+"+"+"|"*(lst[1]+1)+"="+"|"*lst[2])
elif (lst[0]+1)+(lst[1]-1)==lst[2]:
print("|"*(lst[0]+1)+"+"+"|"*(lst[1]-1)+"="+"|"*lst[2])
elif (lst[0]-1)+(lst[1])==lst[2]+1:
print("|"*(lst[0]-1)+"+"+"|"*(lst[1])+"="+"|"*(lst[2]+1))
elif (lst[0]+1)+(lst[1])==lst[2]-1:
print("|"*(lst[0]+1)+"+"+"|"*(lst[1])+"="+"|"*(lst[2]-1))
elif (lst[0])+(lst[1]+1)==lst[2]-1:
print("|"*(lst[0])+"+"+"|"*(lst[1]+1)+"="+"|"*(lst[2]-1))
elif (lst[0])+(lst[1]+1)==lst[2]+1:
print("|"*(lst[0])+"+"+"|"*(lst[1]-1)+"="+"|"*(lst[2]+1))
else:
print("Impossible") | Title: Counting Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:
An expression of counting sticks is an expression of type:
Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*.
We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.
We really aren't fabulous at arithmetics. Can you help us?
Input Specification:
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
Output Specification:
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
Demo Input:
['||+|=|||||\n', '|||||+||=||\n', '|+|=||||||\n', '||||+||=||||||\n']
Demo Output:
['|||+|=||||\n', 'Impossible\n', 'Impossible\n', '||||+||=||||||\n']
Note:
In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks. | ```python
import re
def count(x):
return x.count("|")
text = input()
x=(re.split('\+|\=',text))
lst=list(map(count,x))
if x[0]+x[1]==x[2]:
print(x[0]+"+"+x[1]+"="+x[2])
elif (lst[0]-1)+(lst[1]+1)==lst[2]:
print("|"*(lst[0]-1)+"+"+"|"*(lst[1]+1)+"="+"|"*lst[2])
elif (lst[0]+1)+(lst[1]-1)==lst[2]:
print("|"*(lst[0]+1)+"+"+"|"*(lst[1]-1)+"="+"|"*lst[2])
elif (lst[0]-1)+(lst[1])==lst[2]+1:
print("|"*(lst[0]-1)+"+"+"|"*(lst[1])+"="+"|"*(lst[2]+1))
elif (lst[0]+1)+(lst[1])==lst[2]-1:
print("|"*(lst[0]+1)+"+"+"|"*(lst[1])+"="+"|"*(lst[2]-1))
elif (lst[0])+(lst[1]+1)==lst[2]-1:
print("|"*(lst[0])+"+"+"|"*(lst[1]+1)+"="+"|"*(lst[2]-1))
elif (lst[0])+(lst[1]+1)==lst[2]+1:
print("|"*(lst[0])+"+"+"|"*(lst[1]-1)+"="+"|"*(lst[2]+1))
else:
print("Impossible")
``` | 0 |
|
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,609,182,675 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 109 | 0 | import sys
n = str( sys.stdin.readline( ).strip() )
p = 0
for i, c in enumerate(n):
i += 1
if c == '4':
p = (2*p) + 1
else:
p = (2*p) + 2
print(p) | 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
import sys
n = str( sys.stdin.readline( ).strip() )
p = 0
for i, c in enumerate(n):
i += 1
if c == '4':
p = (2*p) + 1
else:
p = (2*p) + 2
print(p)
``` | 3 |
|
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
"input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227",
"output": "6"
},
{
"input": "4 2\n194041605 706221269 69909135 257655784",
"output": "3"
},
{
"input": "4 2\n9581849 67346651 530497 272158241",
"output": "4"
},
{
"input": "3 47\n378261451 163985731 230342101",
"output": "3"
},
{
"input": "2 3\n247776868 480572137",
"output": "1"
},
{
"input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796",
"output": "7"
},
{
"input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085",
"output": "40"
},
{
"input": "1 8\n55521105",
"output": "1"
},
{
"input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843",
"output": "44"
},
{
"input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601",
"output": "22"
},
{
"input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105",
"output": "20"
},
{
"input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629",
"output": "44"
},
{
"input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191",
"output": "8"
},
{
"input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529",
"output": "38"
},
{
"input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547",
"output": "18"
},
{
"input": "1 1\n44",
"output": "0"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "10 3\n444 447 774 777 7777 4447 4 7 7 4",
"output": "8"
}
] | 1,656,522,372 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | (n, k) = map(int, input().split(' '))
a = input().split()
for i in range(n):
a[i] = int(a[i])
numbers = 0
for number in a:
if len(str(number)) < k:
numbers += 1
else:
numbers_of_lucky_digits = str(number).count('4') + str(number).count('7')
if numbers_of_lucky_digits <= k:
numbers += 1
print(numbers ) | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
Input Specification:
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['3 4\n1 2 4\n', '3 2\n447 44 77\n']
Demo Output:
['3\n', '2\n']
Note:
In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | ```python
(n, k) = map(int, input().split(' '))
a = input().split()
for i in range(n):
a[i] = int(a[i])
numbers = 0
for number in a:
if len(str(number)) < k:
numbers += 1
else:
numbers_of_lucky_digits = str(number).count('4') + str(number).count('7')
if numbers_of_lucky_digits <= k:
numbers += 1
print(numbers )
``` | 3 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,693,325,752 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
sum=0
s=0
for i in range(n):
if a[i]==-1 and sum==0:
s+=1
elif a[i]!=1:
sum+=a[i]
print(s)
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
n=int(input())
a=list(map(int,input().split()))
sum=0
s=0
for i in range(n):
if a[i]==-1 and sum==0:
s+=1
elif a[i]!=1:
sum+=a[i]
print(s)
``` | 0 |
|
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,697,134,414 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
s = input().split()
s_ = [int(_) for _ in s]
x = sum(s_) / n
print(x)
| 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())
s = input().split()
s_ = [int(_) for _ in s]
x = sum(s_) / n
print(x)
``` | 3 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1"
}
] | 1,692,337,528 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | def find_gift_givers(n, gift_receivers):
gift_givers = [0] * t
for i in range(t):
gift_givers[gift_receivers[i] - 1] = i + 1
return gift_givers
t = int(input())
gift_receivers = list(map(int, input().split()))
result = find_gift_givers(t, gift_receivers)
print(*result) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
def find_gift_givers(n, gift_receivers):
gift_givers = [0] * t
for i in range(t):
gift_givers[gift_receivers[i] - 1] = i + 1
return gift_givers
t = int(input())
gift_receivers = list(map(int, input().split()))
result = find_gift_givers(t, gift_receivers)
print(*result)
``` | 3 |
|
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,675,124,321 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 296 | 0 | ss=0
for _ in range(int(input())):
s=input()
ss+=4 if s=="Tetrahedron" else 6 if s=="Cube" else 8 if s=="Octahedron" else 12 if s=="Dodecahedron" else 20
print(ss) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | ```python
ss=0
for _ in range(int(input())):
s=input()
ss+=4 if s=="Tetrahedron" else 6 if s=="Cube" else 8 if s=="Octahedron" else 12 if s=="Dodecahedron" else 20
print(ss)
``` | 3 |
|
784 | A | Numbers Joke | PROGRAMMING | 1,700 | [
"*special"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer. | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). | Output a single integer. | [
"3\n"
] | [
"27\n"
] | none | 0 | [
{
"input": "3",
"output": "27"
},
{
"input": "1",
"output": "4"
},
{
"input": "2",
"output": "22"
},
{
"input": "4",
"output": "58"
},
{
"input": "5",
"output": "85"
},
{
"input": "6",
"output": "94"
},
{
"input": "7",
"output": "121"
},
{
"input": "8",
"output": "166"
},
{
"input": "9",
"output": "202"
},
{
"input": "10",
"output": "265"
},
{
"input": "11",
"output": "274"
},
{
"input": "12",
"output": "319"
},
{
"input": "13",
"output": "346"
},
{
"input": "14",
"output": "355"
},
{
"input": "15",
"output": "378"
},
{
"input": "16",
"output": "382"
},
{
"input": "17",
"output": "391"
},
{
"input": "18",
"output": "438"
},
{
"input": "19",
"output": "454"
},
{
"input": "20",
"output": "483"
},
{
"input": "21",
"output": "517"
},
{
"input": "22",
"output": "526"
},
{
"input": "23",
"output": "535"
},
{
"input": "24",
"output": "562"
},
{
"input": "25",
"output": "576"
},
{
"input": "26",
"output": "588"
},
{
"input": "27",
"output": "627"
},
{
"input": "28",
"output": "634"
},
{
"input": "29",
"output": "636"
},
{
"input": "30",
"output": "645"
}
] | 1,491,232,001 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=(int)raw_input();
print a**a; | Title: Numbers Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer.
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output Specification:
Output a single integer.
Demo Input:
['3\n']
Demo Output:
['27\n']
Note:
none | ```python
a=(int)raw_input();
print a**a;
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given *n* points in the plane, find a pair of points between which the distance is minimized. Distance between (*x*1,<=*y*1) and (*x*2,<=*y*2) is .
The pseudo code of the unexpected code is as follows:
Here, *tot* can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, *tot* should not be more than *k* in order not to get Time Limit Exceeded.
You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? | A single line which contains two space-separated integers *n* and *k* (2<=≤<=*n*<=≤<=2000, 1<=≤<=*k*<=≤<=109). | If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print *n* lines, and the *i*-th line contains two integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) representing the coordinates of the *i*-th point.
The conditions below must be held:
- All the points must be distinct. - |*x**i*|,<=|*y**i*|<=≤<=109. - After running the given code, the value of *tot* should be larger than *k*. | [
"4 3\n",
"2 100\n"
] | [
"0 0\n0 1\n1 0\n1 1\n",
"no solution\n"
] | none | 0 | [
{
"input": "4 3",
"output": "0 0\n0 1\n1 0\n1 1"
},
{
"input": "2 100",
"output": "no solution"
},
{
"input": "5 6",
"output": "0 0\n0 1\n0 2\n0 3\n0 4"
},
{
"input": "8 20",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7"
},
{
"input": "6 15",
"output": "no solution"
},
{
"input": "1808 505823289",
"output": "no solution"
},
{
"input": "1850 507001807",
"output": "no solution"
},
{
"input": "1892 948371814",
"output": "no solution"
},
{
"input": "1788 94774524",
"output": "no solution"
},
{
"input": "1947 944738707",
"output": "no solution"
},
{
"input": "1989 367830",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1885 1096142",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1854 631695",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1750 215129",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1792 341122",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1834 1680860",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1657 1371995",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1699 1442450",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "1595 1271214",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "2000 1998999",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "2000 1000000000",
"output": "no solution"
},
{
"input": "2 1",
"output": "no solution"
},
{
"input": "3 2",
"output": "0 0\n0 1\n0 2"
},
{
"input": "5 1",
"output": "0 0\n0 1\n0 2\n0 3\n0 4"
},
{
"input": "1000 500",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
},
{
"input": "342 340",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 24\n0 25\n0 26\n0 27\n0 28\n0 29\n0 30\n0 31\n0 32\n0 33\n0 34\n0 35\n0 36\n0 37\n0 38\n0 39\n0 40\n0 41\n0 42\n0 43\n0 44\n0 45\n0 46\n0 47\n0 48\n0 49\n0 50\n0 51\n0 52\n0 53\n0 54\n0 55\n0 56\n0 57\n0 58\n0 59\n0 60\n0 61\n0 62\n0 63\n0 64\n0 65\n0 66\n0 67\n0 68\n0 69\n0 70\n0 71\n0 72\n0 73\n0 74\n0 75\n0 76\n0 77\n0 78\n0 79\n0 80\n0 81\n0 82\n0 83\n0 84\n0 85\n0 86\n..."
}
] | 1,555,139,081 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 512,000 | n,k=map(int, input().split())
if(n*(n-1)//2 <=k):
print('no solution')
else:
for i in range(n):
print(0,i) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given *n* points in the plane, find a pair of points between which the distance is minimized. Distance between (*x*1,<=*y*1) and (*x*2,<=*y*2) is .
The pseudo code of the unexpected code is as follows:
Here, *tot* can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, *tot* should not be more than *k* in order not to get Time Limit Exceeded.
You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
Input Specification:
A single line which contains two space-separated integers *n* and *k* (2<=≤<=*n*<=≤<=2000, 1<=≤<=*k*<=≤<=109).
Output Specification:
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print *n* lines, and the *i*-th line contains two integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) representing the coordinates of the *i*-th point.
The conditions below must be held:
- All the points must be distinct. - |*x**i*|,<=|*y**i*|<=≤<=109. - After running the given code, the value of *tot* should be larger than *k*.
Demo Input:
['4 3\n', '2 100\n']
Demo Output:
['0 0\n0 1\n1 0\n1 1\n', 'no solution\n']
Note:
none | ```python
n,k=map(int, input().split())
if(n*(n-1)//2 <=k):
print('no solution')
else:
for i in range(n):
print(0,i)
``` | 3 |
|
346 | A | Alice and Bob | PROGRAMMING | 1,600 | [
"games",
"math",
"number theory"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 500 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
{
"input": "10\n98 63 42 56 14 77 70 35 84 21",
"output": "Bob"
},
{
"input": "2\n1 1000000000",
"output": "Bob"
},
{
"input": "2\n1000000000 999999999",
"output": "Bob"
},
{
"input": "3\n2 4 6",
"output": "Bob"
},
{
"input": "2\n4 6",
"output": "Alice"
},
{
"input": "2\n2 6",
"output": "Alice"
},
{
"input": "2\n6 2",
"output": "Alice"
},
{
"input": "10\n100000000 200000000 300000000 400000000 500000000 600000000 700000000 800000000 900000000 1000000000",
"output": "Bob"
},
{
"input": "2\n1 2",
"output": "Bob"
},
{
"input": "10\n1 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991",
"output": "Alice"
},
{
"input": "3\n6 14 21",
"output": "Bob"
},
{
"input": "3\n4 12 18",
"output": "Bob"
},
{
"input": "4\n2 3 15 30",
"output": "Bob"
},
{
"input": "2\n10 4",
"output": "Alice"
}
] | 1,627,251,276 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 278 | 21,811,200 | import functools
import math
n = int(input())
tab = list(map(int, input().split()))
pgcd = functools.reduce(lambda x, y: math.gcd(x, y), tab)
nbturns = max(tab) / pgcd - n
print('Alice' if nbturns % 2 == 1 else 'Bob')
| Title: Alice and Bob
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one).
If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set.
Output Specification:
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
Demo Input:
['2\n2 3\n', '2\n5 3\n', '3\n5 6 7\n']
Demo Output:
['Alice\n', 'Alice\n', 'Bob\n']
Note:
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | ```python
import functools
import math
n = int(input())
tab = list(map(int, input().split()))
pgcd = functools.reduce(lambda x, y: math.gcd(x, y), tab)
nbturns = max(tab) / pgcd - n
print('Alice' if nbturns % 2 == 1 else 'Bob')
``` | 3 |
|
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan! | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'. | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them. | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\nME,YOU.",
"output": "LEFT\nLEFT\nPRINT M\nRIGHT\nPRINT E\nRIGHT\nPRINT ,\nRIGHT\nPRINT Y\nRIGHT\nPRINT O\nRIGHT\nPRINT U\nRIGHT\nPRINT ."
},
{
"input": "10 1\nEK5JQMS5QN",
"output": "PRINT E\nRIGHT\nPRINT K\nRIGHT\nPRINT 5\nRIGHT\nPRINT J\nRIGHT\nPRINT Q\nRIGHT\nPRINT M\nRIGHT\nPRINT S\nRIGHT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT N"
},
{
"input": "85 84\n73IW80UODC8B,UR7S8WMNATV0JSRF4W0B2VV8LCAX6SGCYY8?LHDKJEO29WXQWT9.WY1VY7408S1W04GNDZPK",
"output": "RIGHT\nPRINT K\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT G\nLEFT\nPRINT 4\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT 1\nLEFT\nPRINT S\nLEFT\nPRINT 8\nLEFT\nPRINT 0\nLEFT\nPRINT 4\nLEFT\nPRINT 7\nLEFT\nPRINT Y\nLEFT\nPRINT V\nLEFT\nPRINT 1\nLEFT\nPRINT Y\nLEFT\nPRINT W\nLEFT\nPRINT .\nLEFT\nPRINT 9\nLEFT\nPRINT T\nLEFT\nPRINT W\nLEFT\nPRINT Q\nLEFT\nPRINT X\nLEFT\nPRINT W\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT O\nLEFT\nPRINT E\nLEFT\nPRINT J\nLEFT\nPRINT K\nLEFT\nPRINT D\n..."
},
{
"input": "59 53\n7NWD!9PC11C8S4TQABBTJO,?CO6YGOM!W0QR94CZJBD9U1YJY23YB354,8F",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT F\nLEFT\nPRINT 8\nLEFT\nPRINT ,\nLEFT\nPRINT 4\nLEFT\nPRINT 5\nLEFT\nPRINT 3\nLEFT\nPRINT B\nLEFT\nPRINT Y\nLEFT\nPRINT 3\nLEFT\nPRINT 2\nLEFT\nPRINT Y\nLEFT\nPRINT J\nLEFT\nPRINT Y\nLEFT\nPRINT 1\nLEFT\nPRINT U\nLEFT\nPRINT 9\nLEFT\nPRINT D\nLEFT\nPRINT B\nLEFT\nPRINT J\nLEFT\nPRINT Z\nLEFT\nPRINT C\nLEFT\nPRINT 4\nLEFT\nPRINT 9\nLEFT\nPRINT R\nLEFT\nPRINT Q\nLEFT\nPRINT 0\nLEFT\nPRINT W\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRIN..."
},
{
"input": "100 79\nF2.58O.L4A!QX!,.,YQUE.RZW.ENQCZKUFNG?.J6FT?L59BIHKFB?,44MAHSTD8?Z.UP3N!76YW6KVI?4AKWDPP0?3HPERM3PCUR",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT R\nLEFT\nPRINT U\nLEFT\nPRINT C\nLEFT\nPRINT P\nLEFT\nPRINT 3\nLEFT\nPRINT M\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT 3\nLEFT\nPRINT ?\nLEFT\nPRINT 0\nLEFT\nPRINT P\nLEFT\nPRINT P\nLEFT\nPRINT D\nLEFT\nPRINT W\nLEFT\nPRINT K\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT ?\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT K\nLEFT\nPRIN..."
},
{
"input": "1 1\n!",
"output": "PRINT !"
},
{
"input": "34 20\n.C0QPPSWQKGBSH0,VGM!N,5SX.M9Q,D1DT",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT T\nLEFT\nPRINT D\nLEFT\nPRINT 1\nLEFT\nPRINT D\nLEFT\nPRINT ,\nLEFT\nPRINT Q\nLEFT\nPRINT 9\nLEFT\nPRINT M\nLEFT\nPRINT .\nLEFT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT 5\nLEFT\nPRINT ,\nLEFT\nPRINT N\nLEFT\nPRINT !\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT V\nLEFT\nPRINT ,\nLEFT\nPRINT 0\nLEFT\nPRINT H\nLEFT\nPRINT S\nLEFT\nPRINT B\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT Q\nLEFT\nPRINT W\nLEFT\nPRINT S\n..."
},
{
"input": "99 98\nR8MZTEG240LNHY33H7.2CMWM73ZK,P5R,RGOA,KYKMIOG7CMPNHV3R2KM,N374IP8HN97XVMG.PSIPS8H3AXFGK0CJ76,EVKRZ9",
"output": "RIGHT\nPRINT 9\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT K\nLEFT\nPRINT V\nLEFT\nPRINT E\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT 7\nLEFT\nPRINT J\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT K\nLEFT\nPRINT G\nLEFT\nPRINT F\nLEFT\nPRINT X\nLEFT\nPRINT A\nLEFT\nPRINT 3\nLEFT\nPRINT H\nLEFT\nPRINT 8\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT I\nLEFT\nPRINT S\nLEFT\nPRINT P\nLEFT\nPRINT .\nLEFT\nPRINT G\nLEFT\nPRINT M\nLEFT\nPRINT V\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT N\nLEFT\nPRINT H\n..."
},
{
"input": "98 72\n.1?7CJ!EFZHO5WUKDZV,0EE92PTAGY078WKN!!41E,Q7381U60!9C,VONEZ6!SFFNDBI86MACX0?D?9!U2UV7S,977PNDSF0HY",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT Y\nLEFT\nPRINT H\nLEFT\nPRINT 0\nLEFT\nPRINT F\nLEFT\nPRINT S\nLEFT\nPRINT D\nLEFT\nPRINT N\nLEFT\nPRINT P\nLEFT\nPRINT 7\nLEFT\nPRINT 7\nLEFT\nPRINT 9\nLEFT\nPRINT ,\nLEFT\nPRINT S\nLEFT\nPRINT 7\nLEFT\nPRINT V\nLEFT\nPRINT U\nLEFT\nPRINT 2\nLEFT\nPRINT U\nLEFT\nPRINT !\nLEFT\nPRINT 9\nLEFT\nPRINT ?\nLEFT\nPRINT D\nLEFT\n..."
},
{
"input": "97 41\nGQSPZGGRZ0KWUMI79GOXP7!RR9E?Z5YO?6WUL!I7GCXRS8T,PEFQM7CZOUG8HLC7198J1?C69JD00Q!QY1AK!27I?WB?UAUIG",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT G\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT P\nRIGHT\nPRINT Z\nRIGHT\nPRINT G\nRIGHT\nPRINT G\nRIGHT\nPRINT R\nRIGHT\nPRINT Z\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT W\nRIGHT\nPRINT U\nRIGHT\nPRINT M\nRIGHT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT 9\nRIGHT\n..."
},
{
"input": "96 28\nZCF!PLS27YGXHK8P46H,C.A7MW90ED,4BA!T0!XKIR2GE0HD..YZ0O20O8TA7E35G5YT3L4W5ESSYBHG8.TIQENS4I.R8WE,",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT Z\nRIGHT\nPRINT C\nRIGHT\nPRINT F\nRIGHT\nPRINT !\nRIGHT\nPRINT P\nRIGHT\nPRINT L\nRIGHT\nPRINT S\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT Y\nRIGHT\nPRINT G\nRIGHT\nPRINT X\nRIGHT\nPRINT H\nRIGHT\nPRINT K\nRIGHT\nPRINT 8\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT 6\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT .\nRIGH..."
},
{
"input": "15 3\n!..!?!,!,..,?!.",
"output": "LEFT\nLEFT\nPRINT !\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT !\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT !\nRIGHT\nPRINT ,\nRIGHT\nPRINT .\nRIGHT\nPRINT .\nRIGHT\nPRINT ,\nRIGHT\nPRINT ?\nRIGHT\nPRINT !\nRIGHT\nPRINT ."
},
{
"input": "93 81\nGMIBVKYLURQLWHBGTFNJZZAZNUJJTPQKCPGDMGCDTTGXOANWKTDZSIYBUPFUXGQHCMVIEQCTINRTIUSPGMVZPGWBHPIXC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT X\nLEFT\nPRINT I\nLEFT\nPRINT P\nLEFT\nPRINT H\nLEFT\nPRINT B\nLEFT\nPRINT W\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT Z\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT G\nLEFT\nPRINT P\nLEFT\nPRINT S\nLEFT\nPRINT U\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT R\nLEFT\nPRINT N\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT C\nLEFT\nPRINT Q\nLEFT\nPRINT E\nLEFT\nPRINT I\nLEFT\nPRINT V\nLEFT\nPRINT M\nLEFT\nPRINT C..."
},
{
"input": "88 30\n5847857685475132927321580125243001071762130696139249809763381765504146602574972381323476",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT 8\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 7\nRIGHT\nPRINT 6\nRIGHT\nPRINT 8\nRIGHT\nPRINT 5\nRIGHT\nPRINT 4\nRIGHT\nPRINT 7\nRIGHT\nPRINT 5\nRIGHT\nPRINT 1\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nPRINT 9\nRIGHT\nPRINT 2\nRIGHT\nPRINT 7\nRIGHT\nPRINT 3\nRIGHT\nPRINT 2\nRIGHT\nP..."
},
{
"input": "100 50\n5B2N,CXCWOIWH71XV!HCFEUCN3U88JDRIFRO2VHY?!N.RGH.?W14X5S.Y00RIY6YA19BPD0T,WECXYI,O2RF1U4NX9,F5AVLPOYK",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 5\nRIGHT\nPRINT B\nRIGHT\nPRINT 2\nRIGHT\nPRINT N\nRIGHT\nPRINT ,\nRIGHT\nPRINT C\nRIGHT\nPRINT X\nRIGHT\nPRINT C\nRIGHT\nPRINT W\nRIGHT\nPRINT O\nRIGHT\nPRINT I\nRIGHT\nPRINT W\nRIGHT\nPRINT H\nRIGHT\nPRINT 7\n..."
},
{
"input": "100 51\n!X85PT!WJDNS9KA6D2SJBR,U,G7M914W07EK3EAJ4XG..UHA3KOOFYJ?M0MEFDC6KNCNGKS0A!S,C02H4TSZA1U7NDBTIY?,7XZ4",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT 4\nLEFT\nPRINT Z\nLEFT\nPRINT X\nLEFT\nPRINT 7\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT Y\nLEFT\nPRINT I\nLEFT\nPRINT T\nLEFT\nPRINT B\nLEFT\nPRINT D\nLEFT\nPRI..."
},
{
"input": "100 52\n!MLPE.0K72RW9XKHR60QE?69ILFSIKYSK5AG!TA5.02VG5OMY0967G2RI.62CNK9L8G!7IG9F0XNNCGSDOTFD?I,EBP31HRERZSX",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT X\nLEFT\nPRINT S\nLEFT\nPRINT Z\nLEFT\nPRINT R\nLEFT\nPRINT E\nLEFT\nPRINT R\nLEFT\nPRINT H\nLEFT\nPRINT 1\nLEFT\nPRINT 3\nLEFT\nPRINT P\nLEFT\nPRINT B\nLEFT\nPRINT E\nL..."
},
{
"input": "100 49\n86C0NR7V,BE09,7,ER715OQ3GZ,P014H4BSQ5YS?OFNDD7YWI?S?UMKIWHSBDZ4398?SSDZLTDU1L?G4QVAB53HNDS!4PYW5C!VI",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT 8\nRIGHT\nPRINT 6\nRIGHT\nPRINT C\nRIGHT\nPRINT 0\nRIGHT\nPRINT N\nRIGHT\nPRINT R\nRIGHT\nPRINT 7\nRIGHT\nPRINT V\nRIGHT\nPRINT ,\nRIGHT\nPRINT B\nRIGHT\nPRINT E\nRIGHT\nPRINT 0\nRIGHT\nPRINT 9\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "100 48\nFO,IYI4AAV?4?N5PWMZX1AINZLKAUJCKMDWU4CROT?.LYWYLYU5S80,15A6VGP!V0N,O.70CP?GEA52WG59UYWU1MMMU4BERVY.!",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT F\nRIGHT\nPRINT O\nRIGHT\nPRINT ,\nRIGHT\nPRINT I\nRIGHT\nPRINT Y\nRIGHT\nPRINT I\nRIGHT\nPRINT 4\nRIGHT\nPRINT A\nRIGHT\nPRINT A\nRIGHT\nPRINT V\nRIGHT\nPRINT ?\nRIGHT\nPRINT 4\nRIGHT\nPRINT ?\nRIGHT\nPRINT N\nRIGHT\nPRINT..."
},
{
"input": "100 100\nE?F,W.,,O51!!G13ZWP?YHWRT69?RQPW7,V,EM3336F1YAIKJIME1M45?LJM42?45V7221?P.DIO9FK245LXKMR4ALKPDLA5YI2Y",
"output": "PRINT Y\nLEFT\nPRINT 2\nLEFT\nPRINT I\nLEFT\nPRINT Y\nLEFT\nPRINT 5\nLEFT\nPRINT A\nLEFT\nPRINT L\nLEFT\nPRINT D\nLEFT\nPRINT P\nLEFT\nPRINT K\nLEFT\nPRINT L\nLEFT\nPRINT A\nLEFT\nPRINT 4\nLEFT\nPRINT R\nLEFT\nPRINT M\nLEFT\nPRINT K\nLEFT\nPRINT X\nLEFT\nPRINT L\nLEFT\nPRINT 5\nLEFT\nPRINT 4\nLEFT\nPRINT 2\nLEFT\nPRINT K\nLEFT\nPRINT F\nLEFT\nPRINT 9\nLEFT\nPRINT O\nLEFT\nPRINT I\nLEFT\nPRINT D\nLEFT\nPRINT .\nLEFT\nPRINT P\nLEFT\nPRINT ?\nLEFT\nPRINT 1\nLEFT\nPRINT 2\nLEFT\nPRINT 2\nLEFT\nPRINT 7\nLEFT\nP..."
},
{
"input": "100 1\nJJ0ZOX4CY,SQ9L0K!2C9TM3C6K.6R21717I37VDSXGHBMR2!J820AI75D.O7NYMT6F.AGJ8R0RDETWOACK3P6UZAUYRKMKJ!G3WF",
"output": "PRINT J\nRIGHT\nPRINT J\nRIGHT\nPRINT 0\nRIGHT\nPRINT Z\nRIGHT\nPRINT O\nRIGHT\nPRINT X\nRIGHT\nPRINT 4\nRIGHT\nPRINT C\nRIGHT\nPRINT Y\nRIGHT\nPRINT ,\nRIGHT\nPRINT S\nRIGHT\nPRINT Q\nRIGHT\nPRINT 9\nRIGHT\nPRINT L\nRIGHT\nPRINT 0\nRIGHT\nPRINT K\nRIGHT\nPRINT !\nRIGHT\nPRINT 2\nRIGHT\nPRINT C\nRIGHT\nPRINT 9\nRIGHT\nPRINT T\nRIGHT\nPRINT M\nRIGHT\nPRINT 3\nRIGHT\nPRINT C\nRIGHT\nPRINT 6\nRIGHT\nPRINT K\nRIGHT\nPRINT .\nRIGHT\nPRINT 6\nRIGHT\nPRINT R\nRIGHT\nPRINT 2\nRIGHT\nPRINT 1\nRIGHT\nPRINT 7\nRIGHT\n..."
},
{
"input": "99 50\nLQJ!7GDFJ,SKQ8J2R?I4VA0K2.NDY.AZ?7K275NA81.YK!DO,PCQCJYL6BUU30XQ300FP0,LB!5TYTRSGOB4ELZ8IBKGVDNW8?B",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT B\nLEFT\nPRINT ?\nLEFT\nPRINT 8\nLEFT\nPRINT W\nLEFT\nPRINT N\nLEFT\nPRINT D\nLEFT\nPRINT V\nLEFT\nPRINT G\nLEFT\nPRINT K\nLEFT\nPRINT B\nLEFT\nPRINT I\nLEFT\nPRI..."
},
{
"input": "99 51\nD9QHZXG46IWHHLTD2E,AZO0.M40R4B1WU6F,0QNZ37NQ0ACSU6!7Z?H02AD?0?9,5N5RG6PVOWIE6YA9QBCOHVNU??YT6,29SAC",
"output": "RIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nRIGHT\nPRINT C\nLEFT\nPRINT A\nLEFT\nPRINT S\nLEFT\nPRINT 9\nLEFT\nPRINT 2\nLEFT\nPRINT ,\nLEFT\nPRINT 6\nLEFT\nPRINT T\nLEFT\nPRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT ?\nLEFT\nPRINT U\nL..."
},
{
"input": "99 49\nOLUBX0Q3VPNSH,QCAWFVSKZA3NUURJ9PXBS3?72PMJ,27QTA7Z1N?6Q2CSJE,W0YX8XWS.W6B?K?M!PYAD30BX?8.VJCC,P8QL9",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT O\nRIGHT\nPRINT L\nRIGHT\nPRINT U\nRIGHT\nPRINT B\nRIGHT\nPRINT X\nRIGHT\nPRINT 0\nRIGHT\nPRINT Q\nRIGHT\nPRINT 3\nRIGHT\nPRINT V\nRIGHT\nPRINT P\nRIGHT\nPRINT N\nRIGHT\nPRINT S\nRIGHT\nPRINT H\nRIGHT\nPRINT ,\nRIGHT\n..."
},
{
"input": "99 48\nW0GU5MNE5!JVIOO2SR5OO7RWLHDFH.HLCCX89O21SLD9!CU0MFG3RFZUFT!R0LWNVNSS.W54.67N4VAN1Q2J9NMO9Q6.UE8U6B8",
"output": "LEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nLEFT\nPRINT W\nRIGHT\nPRINT 0\nRIGHT\nPRINT G\nRIGHT\nPRINT U\nRIGHT\nPRINT 5\nRIGHT\nPRINT M\nRIGHT\nPRINT N\nRIGHT\nPRINT E\nRIGHT\nPRINT 5\nRIGHT\nPRINT !\nRIGHT\nPRINT J\nRIGHT\nPRINT V\nRIGHT\nPRINT I\nRIGHT\nPRINT O\nRIGHT\nPRINT..."
},
{
"input": "2 1\nOA",
"output": "PRINT O\nRIGHT\nPRINT A"
},
{
"input": "2 2\nGW",
"output": "PRINT W\nLEFT\nPRINT G"
},
{
"input": "3 1\n.VP",
"output": "PRINT .\nRIGHT\nPRINT V\nRIGHT\nPRINT P"
},
{
"input": "3 2\nUD0",
"output": "RIGHT\nPRINT 0\nLEFT\nPRINT D\nLEFT\nPRINT U"
},
{
"input": "3 3\nMYE",
"output": "PRINT E\nLEFT\nPRINT Y\nLEFT\nPRINT M"
},
{
"input": "4 1\nC5EJ",
"output": "PRINT C\nRIGHT\nPRINT 5\nRIGHT\nPRINT E\nRIGHT\nPRINT J"
},
{
"input": "4 2\n5QSW",
"output": "LEFT\nPRINT 5\nRIGHT\nPRINT Q\nRIGHT\nPRINT S\nRIGHT\nPRINT W"
},
{
"input": "4 3\n!F3D",
"output": "RIGHT\nPRINT D\nLEFT\nPRINT 3\nLEFT\nPRINT F\nLEFT\nPRINT !"
},
{
"input": "4 4\nS!?Y",
"output": "PRINT Y\nLEFT\nPRINT ?\nLEFT\nPRINT !\nLEFT\nPRINT S"
},
{
"input": "5 1\nIP4!N",
"output": "PRINT I\nRIGHT\nPRINT P\nRIGHT\nPRINT 4\nRIGHT\nPRINT !\nRIGHT\nPRINT N"
},
{
"input": "5 2\nI7??5",
"output": "LEFT\nPRINT I\nRIGHT\nPRINT 7\nRIGHT\nPRINT ?\nRIGHT\nPRINT ?\nRIGHT\nPRINT 5"
},
{
"input": "5 3\nASNUW",
"output": "RIGHT\nRIGHT\nPRINT W\nLEFT\nPRINT U\nLEFT\nPRINT N\nLEFT\nPRINT S\nLEFT\nPRINT A"
},
{
"input": "5 4\n3?,4L",
"output": "RIGHT\nPRINT L\nLEFT\nPRINT 4\nLEFT\nPRINT ,\nLEFT\nPRINT ?\nLEFT\nPRINT 3"
},
{
"input": "5 5\n30COA",
"output": "PRINT A\nLEFT\nPRINT O\nLEFT\nPRINT C\nLEFT\nPRINT 0\nLEFT\nPRINT 3"
},
{
"input": "4 2\nABCD",
"output": "LEFT\nPRINT A\nRIGHT\nPRINT B\nRIGHT\nPRINT C\nRIGHT\nPRINT D"
}
] | 1,629,751,440 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 108 | 20,172,800 | def poster(n,k,s):
k-=1
if n%2 == 0:
if k < n//2:
while k > 0:
print("LEFT")
k -= 1
while k < n:
print("PRINT", s[k])
if k != n-1:
print("RIGHT")
k += 1
else:
while k < n-1:
print("RIGHT")
k += 1
while k > -1:
print("PRINT", s[k])
if k != 0:
print("LEFT")
k-=1
else:
if k > n//2:
while k < n-1:
print("RIGHT")
k += 1
while k > -1:
print("PRINT", s[k])
if k != 0:
print("LEFT")
k-=1
else:
while k > 0:
print("LEFT")
k -= 1
while k < n:
print("PRINT", s[k])
if k != n-1:
print("RIGHT")
k += 1
n,k = map(int, input().split())
s = input()
poster(n,k,s) | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
Output Specification:
In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder".
The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
Demo Input:
['2 2\nR1\n', '2 1\nR1\n', '6 4\nGO?GO!\n']
Demo Output:
['PRINT 1\nLEFT\nPRINT R\n', 'PRINT R\nRIGHT\nPRINT 1\n', 'RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n']
Note:
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | ```python
def poster(n,k,s):
k-=1
if n%2 == 0:
if k < n//2:
while k > 0:
print("LEFT")
k -= 1
while k < n:
print("PRINT", s[k])
if k != n-1:
print("RIGHT")
k += 1
else:
while k < n-1:
print("RIGHT")
k += 1
while k > -1:
print("PRINT", s[k])
if k != 0:
print("LEFT")
k-=1
else:
if k > n//2:
while k < n-1:
print("RIGHT")
k += 1
while k > -1:
print("PRINT", s[k])
if k != 0:
print("LEFT")
k-=1
else:
while k > 0:
print("LEFT")
k -= 1
while k < n:
print("PRINT", s[k])
if k != n-1:
print("RIGHT")
k += 1
n,k = map(int, input().split())
s = input()
poster(n,k,s)
``` | 3 |
|
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "10 2 1 1",
"output": "5"
},
{
"input": "1 1000 1 2",
"output": "1"
},
{
"input": "1 1000 3 2",
"output": "2"
},
{
"input": "10 3 1 2",
"output": "7"
},
{
"input": "995 1 2 1",
"output": "995"
},
{
"input": "556 2 16 15",
"output": "4170"
},
{
"input": "477 2 16 14",
"output": "3346"
},
{
"input": "101 110 1 100",
"output": "100"
},
{
"input": "9 3 3 10",
"output": "27"
},
{
"input": "100 8 10 1",
"output": "13"
},
{
"input": "6 4 1 3",
"output": "5"
},
{
"input": "8 5 2 8",
"output": "14"
},
{
"input": "1000 2 1 1000",
"output": "1000"
}
] | 1,688,916,988 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n,m,a,b = map(int,input().split())
one = n * a
if n % m == 0:
two = n // m * b
else:
two = n // m * b + (n%m) * a
print(min(one,two))
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides?
Input Specification:
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Output Specification:
Print a single integer — the minimum sum in rubles that Ann will need to spend.
Demo Input:
['6 2 1 2\n', '5 2 2 3\n']
Demo Output:
['6\n', '8\n']
Note:
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | ```python
n,m,a,b = map(int,input().split())
one = n * a
if n % m == 0:
two = n // m * b
else:
two = n // m * b + (n%m) * a
print(min(one,two))
``` | 0 |
|
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 1,562,802,786 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 342 | 0 | class point:
x= 0
y = 0
def __init__(self,a,b):
self.x = a
self.y = b
def dist(a,b):
return (((b.x-a.x)*(b.x-a.x))+((b.y-a.y)*(b.y-a.y)))**.5
arr = []
n,k = list(map(int,input().split()))
for i in range(0,n,1):
a,b = list(map(int,input().split()))
p = point(a,b)
arr.append(p)
dista = 0.0
for i in range(0, n-1,1):
dista += (dist(arr[i],arr[(i+1)]))
#print(i,(i+1)%tam)
print('{0:.8f}'.format((dista*k)/50))
| Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Output Specification:
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
Demo Input:
['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n']
Demo Output:
['0.200000000', '6.032163204', '3.000000000']
Note:
none | ```python
class point:
x= 0
y = 0
def __init__(self,a,b):
self.x = a
self.y = b
def dist(a,b):
return (((b.x-a.x)*(b.x-a.x))+((b.y-a.y)*(b.y-a.y)))**.5
arr = []
n,k = list(map(int,input().split()))
for i in range(0,n,1):
a,b = list(map(int,input().split()))
p = point(a,b)
arr.append(p)
dista = 0.0
for i in range(0, n-1,1):
dista += (dist(arr[i],arr[(i+1)]))
#print(i,(i+1)%tam)
print('{0:.8f}'.format((dista*k)/50))
``` | 3 |
|
602 | A | Two Bases | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. | The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the digits of *X*. They are given in the order from the most significant digit to the least significant one.
The following two lines describe *Y* in the same way: the third line contains two space-separated integers *m* and *b**y* (1<=≤<=*m*<=≤<=10, 2<=≤<=*b**y*<=≤<=40, *b**x*<=≠<=*b**y*), where *m* is the number of digits in the *b**y*-based representation of *Y*, and the fourth line contains *m* space-separated integers *y*1,<=*y*2,<=...,<=*y**m* (0<=≤<=*y**i*<=<<=*b**y*) — the digits of *Y*.
There will be no leading zeroes. Both *X* and *Y* will be positive. All digits of both numbers are given in the standard decimal numeral system. | Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y* | [
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n"
] | [
"=\n",
"<\n",
">\n"
] | In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In the third sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/603a342b0ae3e56fed542d1c50c0a5ff6ce2cbaa.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *Y* = 4803150<sub class="lower-index">9</sub>. We may notice that *X* starts with much larger digits and *b*<sub class="lower-index">*x*</sub> is much larger than *b*<sub class="lower-index">*y*</sub>, so *X* is clearly larger than *Y*. | 500 | [
{
"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7",
"output": "="
},
{
"input": "3 3\n1 0 2\n2 5\n2 4",
"output": "<"
},
{
"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "2 2\n1 0\n2 3\n1 0",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n1",
"output": ">"
},
{
"input": "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2",
"output": "<"
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0",
"output": ">"
},
{
"input": "5 5\n4 4 4 4 4\n4 6\n5 5 5 5",
"output": ">"
},
{
"input": "2 8\n1 0\n4 2\n1 0 0 0",
"output": "="
},
{
"input": "5 2\n1 0 0 0 1\n6 8\n1 4 7 2 0 0",
"output": "<"
},
{
"input": "6 7\n1 1 2 1 2 1\n6 6\n2 3 2 2 2 2",
"output": "="
},
{
"input": "9 35\n34 3 20 29 27 30 2 8 5\n7 33\n17 3 22 31 1 11 6",
"output": ">"
},
{
"input": "1 8\n5\n9 27\n23 23 23 23 23 23 23 23 23",
"output": "<"
},
{
"input": "4 7\n3 0 6 6\n3 11\n7 10 10",
"output": ">"
},
{
"input": "1 40\n1\n2 5\n1 0",
"output": "<"
},
{
"input": "1 36\n35\n4 5\n2 4 4 1",
"output": "<"
},
{
"input": "1 30\n1\n1 31\n1",
"output": "="
},
{
"input": "1 3\n1\n1 2\n1",
"output": "="
},
{
"input": "1 2\n1\n1 40\n1",
"output": "="
},
{
"input": "6 29\n1 1 1 1 1 1\n10 21\n1 1 1 1 1 1 1 1 1 1",
"output": "<"
},
{
"input": "3 5\n1 0 0\n3 3\n2 2 2",
"output": "<"
},
{
"input": "2 8\n1 0\n2 3\n2 2",
"output": "="
},
{
"input": "2 4\n3 3\n2 15\n1 0",
"output": "="
},
{
"input": "2 35\n1 0\n2 6\n5 5",
"output": "="
},
{
"input": "2 6\n5 5\n2 34\n1 0",
"output": ">"
},
{
"input": "2 7\n1 0\n2 3\n2 2",
"output": "<"
},
{
"input": "2 2\n1 0\n1 3\n2",
"output": "="
},
{
"input": "2 9\n5 5\n4 3\n1 0 0 0",
"output": ">"
},
{
"input": "1 24\n6\n3 9\n1 1 1",
"output": "<"
},
{
"input": "5 37\n9 9 9 9 9\n6 27\n13 0 0 0 0 0",
"output": "<"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 1\n10 34\n14 14 14 14 14 14 14 14 14 14",
"output": "<"
},
{
"input": "7 26\n8 0 0 0 0 0 0\n9 9\n3 3 3 3 3 3 3 3 3",
"output": ">"
},
{
"input": "2 40\n2 0\n5 13\n4 0 0 0 0",
"output": "<"
},
{
"input": "1 22\n15\n10 14\n3 3 3 3 3 3 3 3 3 3",
"output": "<"
},
{
"input": "10 22\n3 3 3 3 3 3 3 3 3 3\n3 40\n19 19 19",
"output": ">"
},
{
"input": "2 29\n11 11\n6 26\n11 11 11 11 11 11",
"output": "<"
},
{
"input": "5 3\n1 0 0 0 0\n4 27\n1 0 0 0",
"output": "<"
},
{
"input": "10 3\n1 0 0 0 0 0 0 0 0 0\n8 13\n1 0 0 0 0 0 0 0",
"output": "<"
},
{
"input": "4 20\n1 1 1 1\n5 22\n1 1 1 1 1",
"output": "<"
},
{
"input": "10 39\n34 2 24 34 11 6 33 12 22 21\n10 36\n25 35 17 24 30 0 1 32 14 35",
"output": ">"
},
{
"input": "10 39\n35 12 31 35 28 27 25 8 22 25\n10 40\n23 21 18 12 15 29 38 32 4 8",
"output": ">"
},
{
"input": "10 38\n16 19 37 32 16 7 14 33 16 11\n10 39\n10 27 35 15 31 15 17 16 38 35",
"output": ">"
},
{
"input": "10 39\n20 12 10 32 24 14 37 35 10 38\n9 40\n1 13 0 10 22 20 1 5 35",
"output": ">"
},
{
"input": "10 40\n18 1 2 25 28 2 10 2 17 37\n10 39\n37 8 12 8 21 11 23 11 25 21",
"output": "<"
},
{
"input": "9 39\n10 20 16 36 30 29 28 9 8\n9 38\n12 36 10 22 6 3 19 12 34",
"output": "="
},
{
"input": "7 39\n28 16 13 25 19 23 4\n7 38\n33 8 2 19 3 21 14",
"output": "="
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n10 9\n4 8 0 3 1 5 4 8 1 0",
"output": ">"
},
{
"input": "7 22\n1 13 9 16 7 13 3\n4 4\n3 0 2 1",
"output": ">"
},
{
"input": "10 29\n10 19 8 27 1 24 13 15 13 26\n2 28\n20 14",
"output": ">"
},
{
"input": "6 16\n2 13 7 13 15 6\n10 22\n17 17 21 9 16 11 4 4 13 17",
"output": "<"
},
{
"input": "8 26\n6 6 17 25 24 8 8 25\n4 27\n24 7 5 24",
"output": ">"
},
{
"input": "10 23\n5 21 4 15 12 7 10 7 16 21\n4 17\n3 11 1 14",
"output": ">"
},
{
"input": "10 21\n4 7 7 2 13 7 19 19 18 19\n3 31\n6 11 28",
"output": ">"
},
{
"input": "1 30\n9\n7 37\n20 11 18 14 0 36 27",
"output": "<"
},
{
"input": "5 35\n22 18 28 29 11\n2 3\n2 0",
"output": ">"
},
{
"input": "7 29\n14 26 14 22 11 11 8\n6 28\n2 12 10 17 0 14",
"output": ">"
},
{
"input": "2 37\n25 2\n3 26\n13 13 12",
"output": "<"
},
{
"input": "8 8\n4 0 4 3 4 1 5 6\n8 24\n19 8 15 6 10 7 2 18",
"output": "<"
},
{
"input": "4 22\n18 16 1 2\n10 26\n23 0 12 24 16 2 24 25 1 11",
"output": "<"
},
{
"input": "7 31\n14 6 16 6 26 18 17\n7 24\n22 10 4 5 14 6 9",
"output": ">"
},
{
"input": "10 29\n15 22 0 5 11 12 17 22 4 27\n4 22\n9 2 8 14",
"output": ">"
},
{
"input": "2 10\n6 0\n10 26\n16 14 8 18 24 4 9 5 22 25",
"output": "<"
},
{
"input": "7 2\n1 0 0 0 1 0 1\n9 6\n1 1 5 1 2 5 3 5 3",
"output": "<"
},
{
"input": "3 9\n2 5 4\n1 19\n15",
"output": ">"
},
{
"input": "6 16\n4 9 13 4 2 8\n4 10\n3 5 2 4",
"output": ">"
},
{
"input": "2 12\n1 4\n8 16\n4 4 10 6 15 10 8 15",
"output": "<"
},
{
"input": "3 19\n9 18 16\n4 10\n4 3 5 4",
"output": "<"
},
{
"input": "7 3\n1 1 2 1 2 0 2\n2 2\n1 0",
"output": ">"
},
{
"input": "3 2\n1 1 1\n1 3\n1",
"output": ">"
},
{
"input": "4 4\n1 3 1 3\n9 3\n1 1 0 1 2 2 2 2 1",
"output": "<"
},
{
"input": "9 3\n1 0 0 1 1 0 0 1 2\n6 4\n1 2 0 1 3 2",
"output": ">"
},
{
"input": "3 5\n1 1 3\n10 4\n3 3 2 3 0 0 0 3 1 1",
"output": "<"
},
{
"input": "6 4\n3 3 2 2 0 2\n6 5\n1 1 1 1 0 3",
"output": ">"
},
{
"input": "6 5\n4 4 4 3 1 3\n7 6\n4 2 2 2 5 0 4",
"output": "<"
},
{
"input": "2 5\n3 3\n6 6\n4 2 0 1 1 0",
"output": "<"
},
{
"input": "10 6\n3 5 4 2 4 2 3 5 4 2\n10 7\n3 2 1 1 3 1 0 3 4 5",
"output": "<"
},
{
"input": "9 7\n2 0 3 2 6 6 1 4 3\n9 6\n4 4 1 1 4 5 5 0 2",
"output": ">"
},
{
"input": "1 7\n2\n4 8\n3 2 3 2",
"output": "<"
},
{
"input": "2 8\n4 1\n1 7\n1",
"output": ">"
},
{
"input": "1 10\n7\n3 9\n2 1 7",
"output": "<"
},
{
"input": "9 9\n2 2 3 6 3 6 3 8 4\n6 10\n4 7 7 0 3 8",
"output": ">"
},
{
"input": "3 11\n6 5 2\n8 10\n5 0 1 8 3 5 1 4",
"output": "<"
},
{
"input": "6 11\n10 6 1 0 2 2\n9 10\n4 3 4 1 1 6 3 4 1",
"output": "<"
},
{
"input": "2 19\n4 8\n8 18\n7 8 6 8 4 11 9 1",
"output": "<"
},
{
"input": "2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11",
"output": "<"
},
{
"input": "8 36\n23 5 27 1 10 7 26 27\n10 35\n28 33 9 22 10 28 26 4 27 29",
"output": "<"
},
{
"input": "6 37\n22 15 14 10 1 8\n6 36\n18 5 28 10 1 17",
"output": ">"
},
{
"input": "5 38\n1 31 2 21 21\n9 37\n8 36 32 30 13 9 24 2 35",
"output": "<"
},
{
"input": "3 39\n27 4 3\n8 38\n32 15 11 34 35 27 30 15",
"output": "<"
},
{
"input": "2 40\n22 38\n5 39\n8 9 32 4 1",
"output": "<"
},
{
"input": "9 37\n1 35 7 33 20 21 26 24 5\n10 40\n39 4 11 9 33 12 26 32 11 8",
"output": "<"
},
{
"input": "4 39\n13 25 23 35\n6 38\n19 36 20 4 12 33",
"output": "<"
},
{
"input": "5 37\n29 29 5 7 27\n3 39\n13 1 10",
"output": ">"
},
{
"input": "7 28\n1 10 7 0 13 14 11\n6 38\n8 11 27 5 14 35",
"output": "="
},
{
"input": "2 34\n1 32\n2 33\n2 0",
"output": "="
},
{
"input": "7 5\n4 0 4 1 3 0 4\n4 35\n1 18 7 34",
"output": "="
},
{
"input": "9 34\n5 8 4 4 26 1 30 5 24\n10 27\n1 6 3 10 8 13 22 3 12 8",
"output": "="
},
{
"input": "10 36\n1 13 13 23 31 35 5 32 18 21\n9 38\n32 1 20 14 12 37 13 15 23",
"output": "="
},
{
"input": "10 40\n1 1 14 5 6 3 3 11 3 25\n10 39\n1 11 24 33 25 34 38 29 27 33",
"output": "="
},
{
"input": "9 37\n2 6 1 9 19 6 11 28 35\n9 40\n1 6 14 37 1 8 31 4 9",
"output": "="
},
{
"input": "4 5\n1 4 2 0\n4 4\n3 2 2 3",
"output": "="
},
{
"input": "6 4\n1 1 1 2 2 2\n7 3\n1 2 2 0 1 0 0",
"output": "="
},
{
"input": "2 5\n3 3\n5 2\n1 0 0 1 0",
"output": "="
},
{
"input": "1 9\n2\n1 10\n2",
"output": "="
},
{
"input": "6 19\n4 9 14 1 3 1\n8 10\n1 1 1 7 3 7 3 0",
"output": "="
},
{
"input": "7 15\n8 5 8 10 13 6 13\n8 13\n1 6 9 10 12 3 12 8",
"output": "="
},
{
"input": "8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10",
"output": "="
},
{
"input": "8 21\n5 19 0 14 13 13 10 5\n10 13\n1 0 0 6 11 10 8 2 8 1",
"output": "="
},
{
"input": "8 28\n3 1 10 19 10 14 21 15\n8 21\n14 0 18 13 2 1 18 6",
"output": ">"
},
{
"input": "7 34\n21 22 28 16 30 4 27\n7 26\n5 13 21 10 8 12 10",
"output": ">"
},
{
"input": "6 26\n7 6 4 18 6 1\n6 25\n5 3 11 1 8 15",
"output": ">"
},
{
"input": "10 31\n6 27 17 22 14 16 25 9 13 26\n10 39\n6 1 3 26 12 32 28 19 9 19",
"output": "<"
},
{
"input": "3 5\n2 2 3\n3 6\n4 3 5",
"output": "<"
},
{
"input": "2 24\n4 18\n2 40\n29 24",
"output": "<"
},
{
"input": "5 38\n2 24 34 14 17\n8 34\n4 24 31 2 14 15 8 15",
"output": "<"
},
{
"input": "9 40\n39 39 39 39 39 39 39 39 39\n6 35\n34 34 34 34 34 34",
"output": ">"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 8\n7 7 7 7 7 7 7 7 7 7",
"output": ">"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 39\n38 38 38 38 38 38 38 38 38 38",
"output": ">"
}
] | 1,472,352,434 | 2,147,483,647 | Python 3 | OK | TESTS | 118 | 62 | 4,608,000 | # coding=utf8
if __name__ == '__main__':
n_x, b_x = str(input()).split()
n_x = int(n_x)
b_x = int(b_x)
line_x = str(input()).split()
sum_x = 0
for i in range(n_x):
sum_x += pow(b_x, i) * int(line_x[n_x - 1 - i])
n_y, b_y = str(input()).split()
n_y = int(n_y)
b_y = int(b_y)
line_y = str(input()).split()
sum_y = 0
for i in range(n_y):
sum_y += pow(b_y, i) * int(line_y[n_y - 1 - i])
if sum_x == sum_y:
print('=')
elif sum_x > sum_y:
print('>')
elif sum_x < sum_y:
print('<')
| Title: Two Bases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations.
You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers.
Input Specification:
The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=<<=*b**x*) — the digits of *X*. They are given in the order from the most significant digit to the least significant one.
The following two lines describe *Y* in the same way: the third line contains two space-separated integers *m* and *b**y* (1<=≤<=*m*<=≤<=10, 2<=≤<=*b**y*<=≤<=40, *b**x*<=≠<=*b**y*), where *m* is the number of digits in the *b**y*-based representation of *Y*, and the fourth line contains *m* space-separated integers *y*1,<=*y*2,<=...,<=*y**m* (0<=≤<=*y**i*<=<<=*b**y*) — the digits of *Y*.
There will be no leading zeroes. Both *X* and *Y* will be positive. All digits of both numbers are given in the standard decimal numeral system.
Output Specification:
Output a single character (quotes for clarity):
- '<' if *X*<=<<=*Y* - '>' if *X*<=><=*Y* - '=' if *X*<==<=*Y*
Demo Input:
['6 2\n1 0 1 1 1 1\n2 10\n4 7\n', '3 3\n1 0 2\n2 5\n2 4\n', '7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n']
Demo Output:
['=\n', '<\n', '>\n']
Note:
In the first sample, *X* = 101111<sub class="lower-index">2</sub> = 47<sub class="lower-index">10</sub> = *Y*.
In the second sample, *X* = 102<sub class="lower-index">3</sub> = 21<sub class="lower-index">5</sub> and *Y* = 24<sub class="lower-index">5</sub> = 112<sub class="lower-index">3</sub>, thus *X* < *Y*.
In the third sample, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/603a342b0ae3e56fed542d1c50c0a5ff6ce2cbaa.png" style="max-width: 100.0%;max-height: 100.0%;"/> and *Y* = 4803150<sub class="lower-index">9</sub>. We may notice that *X* starts with much larger digits and *b*<sub class="lower-index">*x*</sub> is much larger than *b*<sub class="lower-index">*y*</sub>, so *X* is clearly larger than *Y*. | ```python
# coding=utf8
if __name__ == '__main__':
n_x, b_x = str(input()).split()
n_x = int(n_x)
b_x = int(b_x)
line_x = str(input()).split()
sum_x = 0
for i in range(n_x):
sum_x += pow(b_x, i) * int(line_x[n_x - 1 - i])
n_y, b_y = str(input()).split()
n_y = int(n_y)
b_y = int(b_y)
line_y = str(input()).split()
sum_y = 0
for i in range(n_y):
sum_y += pow(b_y, i) * int(line_y[n_y - 1 - i])
if sum_x == sum_y:
print('=')
elif sum_x > sum_y:
print('>')
elif sum_x < sum_y:
print('<')
``` | 3 |
|
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 1,665,705,908 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 28,774,400 | x = input()
y = []
p = True
x = x.strip("0")
for l in x:
y.append(l)
for z in range(0, len(y)):
if y[z] != y[len(y)-z-1]:
p = False
if p == False:
print("NO")
else:
print("YES") | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number.
Input Specification:
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Output Specification:
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
Demo Input:
['131\n', '320\n', '2010200\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
x = input()
y = []
p = True
x = x.strip("0")
for l in x:
y.append(l)
for z in range(0, len(y)):
if y[z] != y[len(y)-z-1]:
p = False
if p == False:
print("NO")
else:
print("YES")
``` | 3 |
|
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n.#.#",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n.#.#\n.#.#\n.#.#",
"output": "NO"
},
{
"input": "#..#\n.##.\n####\n####",
"output": "YES"
},
{
"input": "#.#.\n.###\n#.#.\n.###",
"output": "YES"
},
{
"input": "#..#\n.##.\n.##.\n#..#",
"output": "YES"
},
{
"input": ".##.\n.#..\n##.#\n#..#",
"output": "YES"
},
{
"input": ".##.\n##..\n#..#\n..##",
"output": "YES"
},
{
"input": "##..\n##..\n..##\n..##",
"output": "YES"
},
{
"input": ".#..\n###.\n.#.#\n..#.",
"output": "YES"
},
{
"input": "###.\n###.\n...#\n...#",
"output": "YES"
},
{
"input": "#.##\n##.#\n#.##\n##.#",
"output": "YES"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.##",
"output": "YES"
},
{
"input": "##..\n..##\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..##\n##..\n..##",
"output": "YES"
},
{
"input": "##..\n...#\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..#.\n.#..\n..#.",
"output": "YES"
},
{
"input": "....\n....\n....\n.#.#",
"output": "YES"
},
{
"input": "....\n....\n....\n...#",
"output": "YES"
}
] | 1,580,635,776 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 0 | li = []
for _ in range(4):
li.append(input())
for i in range(3):
for j in range(3):
if li[i][j] == '#':
t = 1
if li[i+1][j] == '#':
t += 1
if li[i][j+1] == '#':
t += 1
if li[i+1][j+1] == '#':
t += 1
if t == 4 or t == 3:
print('YES')
exit()
print('NO') | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color.
Input Specification:
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Output Specification:
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Demo Input:
['####\n.#..\n####\n....\n', '####\n....\n####\n....\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | ```python
li = []
for _ in range(4):
li.append(input())
for i in range(3):
for j in range(3):
if li[i][j] == '#':
t = 1
if li[i+1][j] == '#':
t += 1
if li[i][j+1] == '#':
t += 1
if li[i+1][j+1] == '#':
t += 1
if t == 4 or t == 3:
print('YES')
exit()
print('NO')
``` | 0 |
|
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*. | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#". | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#",
"output": "21"
},
{
"input": "5 4 1 4\n####\n..##\n##..\n..#.\n#..#",
"output": "8"
},
{
"input": "1 1 1 2\n.",
"output": "0"
},
{
"input": "3 44 2 18\n####..###.#.##........##...###.####.#.....##\n...#....##.###.###.##.#####.#######.#..#..#.\n#...#.####.#.##.#.#.#.....##.##..###.#....##",
"output": "39"
},
{
"input": "69 1 1 2\n#\n.\n#\n#\n.\n#\n#\n.\n.\n#\n.\n.\n#\n.\n#\n#\n.\n#\n#\n#\n#\n#\n.\n#\n.\n.\n#\n#\n#\n.\n.\n.\n.\n#\n#\n.\n#\n#\n.\n#\n.\n.\n#\n.\n.\n.\n#\n.\n.\n#\n#\n.\n.\n#\n.\n.\n.\n#\n#\n#\n#\n#\n.\n#\n.\n#\n#\n#\n#",
"output": "31"
},
{
"input": "56 2 2 2\n##\n##\n##\n..\n..\n##\n.#\n#.\n..\n##\n##\n..\n..\n#.\n#.\n#.\n#.\n##\n..\n.#\n..\n##\n##\n.#\n#.\n.#\n..\n..\n#.\n..\n##\n..\n#.\n.#\n#.\n#.\n#.\n##\n#.\n##\n##\n.#\n#.\n##\n..\n.#\n#.\n#.\n##\n..\n..\n#.\n##\n..\n..\n##",
"output": "55"
}
] | 1,508,664,483 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 4,915,200 | dp = {}
h, w, x, y = 0, 0, 0, 0
a = [0] * 1000
def calc(k, s):
if (k, s) in dp:
return dp[(k, s)]
if s > k:
dp[(k, s)] = 999999999
elif s >= 1:
dp[(k, s)] = calc(k - 1, s - 1) + h - a[k]
elif s == 0:
dp[(k, 0)] = min([calc(k - 1, 0)] + [calc(k - 1, s0) for s0 in range(x, y + 1)]) + a[k]
return dp[(k, s)]
h, w, x, y = map(int, input().split())
for i in range(h):
st = str(input())
a = [a[i] + (st[i] == '#') for i in range(w)]
dp[(0, 0)] = a[0]
dp[(0, 1)] = h - a[0]
ans = 999999999
for s in range(0, y + 1):
g = calc(w - 1, s)
if s == 0 or x <= s <= y:
ans = min(ans, g)
print(ans)
dp = {}
h, w, x, y = 0, 0, 0, 0
a = [0] * 1000
def calc(k, s):
if (k, s) in dp:
return dp[(k, s)]
if s > k:
dp[(k, s)] = 999999999
elif s >= 1:
dp[(k, s)] = calc(k - 1, s - 1) + h - a[k]
elif s == 0:
dp[(k, 0)] = min([calc(k - 1, 0)] + [calc(k - 1, s0) for s0 in range(x, y + 1)]) + a[k]
return dp[(k, s)]
h, w, x, y = map(int, input().split())
for i in range(h):
st = str(input())
a = [a[i] + (st[i] == '#') for i in range(w)]
dp[(0, 0)] = a[0]
dp[(0, 1)] = h - a[0]
ans = 999999999
for s in range(0, y + 1):
g = calc(w - 1, s)
if s == 0 or x <= s <= y:
ans = min(ans, g)
print(ans)
| Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*.
Input Specification:
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".
Output Specification:
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
Demo Input:
['6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n', '2 5 1 1\n#####\n.....\n']
Demo Output:
['11\n', '5\n']
Note:
In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | ```python
dp = {}
h, w, x, y = 0, 0, 0, 0
a = [0] * 1000
def calc(k, s):
if (k, s) in dp:
return dp[(k, s)]
if s > k:
dp[(k, s)] = 999999999
elif s >= 1:
dp[(k, s)] = calc(k - 1, s - 1) + h - a[k]
elif s == 0:
dp[(k, 0)] = min([calc(k - 1, 0)] + [calc(k - 1, s0) for s0 in range(x, y + 1)]) + a[k]
return dp[(k, s)]
h, w, x, y = map(int, input().split())
for i in range(h):
st = str(input())
a = [a[i] + (st[i] == '#') for i in range(w)]
dp[(0, 0)] = a[0]
dp[(0, 1)] = h - a[0]
ans = 999999999
for s in range(0, y + 1):
g = calc(w - 1, s)
if s == 0 or x <= s <= y:
ans = min(ans, g)
print(ans)
dp = {}
h, w, x, y = 0, 0, 0, 0
a = [0] * 1000
def calc(k, s):
if (k, s) in dp:
return dp[(k, s)]
if s > k:
dp[(k, s)] = 999999999
elif s >= 1:
dp[(k, s)] = calc(k - 1, s - 1) + h - a[k]
elif s == 0:
dp[(k, 0)] = min([calc(k - 1, 0)] + [calc(k - 1, s0) for s0 in range(x, y + 1)]) + a[k]
return dp[(k, s)]
h, w, x, y = map(int, input().split())
for i in range(h):
st = str(input())
a = [a[i] + (st[i] == '#') for i in range(w)]
dp[(0, 0)] = a[0]
dp[(0, 1)] = h - a[0]
ans = 999999999
for s in range(0, y + 1):
g = calc(w - 1, s)
if s == 0 or x <= s <= y:
ans = min(ans, g)
print(ans)
``` | -1 |
|
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As 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. Don't use the function input() in Python2 instead of it use the function raw_input(). | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
"input": "0\n0000",
"output": "="
},
{
"input": "1213121\n1213121",
"output": "="
},
{
"input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479",
"output": ">"
},
{
"input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8",
"output": ">"
},
{
"input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772",
"output": "<"
},
{
"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "="
},
{
"input": "0000000001\n2",
"output": "<"
},
{
"input": "1000000000000000000000000000000000\n1000000000000000000000000000000001",
"output": "<"
},
{
"input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456",
"output": "<"
},
{
"input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222",
"output": "<"
},
{
"input": "123456789999999\n123456789999999",
"output": "="
},
{
"input": "111111111111111111111111111111\n222222222222222222222222222222",
"output": "<"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111",
"output": "="
},
{
"input": "587345873489573457357834\n47957438573458347574375348",
"output": "<"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333",
"output": "<"
},
{
"input": "11111111111111111111111111111111111\n44444444444444444444444444444444444",
"output": "<"
},
{
"input": "11111111111111111111111111111111111\n22222222222222222222222222222222222",
"output": "<"
},
{
"input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "<"
},
{
"input": "1\n2",
"output": "<"
},
{
"input": "9\n0",
"output": ">"
},
{
"input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222",
"output": "<"
},
{
"input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "<"
},
{
"input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111",
"output": "<"
},
{
"input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444",
"output": "<"
},
{
"input": "01\n2",
"output": "<"
},
{
"input": "00\n01",
"output": "<"
},
{
"input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999",
"output": "="
},
{
"input": "43278947323248843213443272432\n793439250984509434324323453435435",
"output": "<"
},
{
"input": "0\n1",
"output": "<"
},
{
"input": "010\n011",
"output": "<"
},
{
"input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999",
"output": "="
},
{
"input": "0001001\n0001010",
"output": "<"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111",
"output": "="
},
{
"input": "00000\n00",
"output": "="
},
{
"input": "999999999999999999999999999\n999999999999999999999999999",
"output": "="
},
{
"input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
"output": "="
},
{
"input": "001\n000000000010",
"output": "<"
},
{
"input": "01\n10",
"output": "<"
},
{
"input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555",
"output": "="
},
{
"input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555",
"output": "="
},
{
"input": "01\n02",
"output": "<"
},
{
"input": "001111\n0001111",
"output": "="
},
{
"input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555",
"output": "="
},
{
"input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283",
"output": "="
},
{
"input": "001\n2",
"output": "<"
},
{
"input": "000000000\n000000000",
"output": "="
},
{
"input": "000000\n10",
"output": "<"
},
{
"input": "000000000000000\n001",
"output": "<"
},
{
"input": "0000001\n2",
"output": "<"
},
{
"input": "0000\n123",
"output": "<"
},
{
"input": "951\n960",
"output": "<"
},
{
"input": "002\n0001",
"output": ">"
},
{
"input": "0000001\n01",
"output": "="
},
{
"input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999",
"output": "="
},
{
"input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012",
"output": "="
},
{
"input": "02\n01",
"output": ">"
},
{
"input": "00000111111\n00000110111",
"output": ">"
},
{
"input": "0123\n123",
"output": "="
},
{
"input": "123771237912798378912\n91239712798379812897389123123123123",
"output": "<"
},
{
"input": "00001\n002",
"output": "<"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "="
},
{
"input": "000000001\n00002",
"output": "<"
},
{
"input": "00002\n00003",
"output": "<"
},
{
"input": "000123456\n123457",
"output": "<"
},
{
"input": "01\n00",
"output": ">"
},
{
"input": "00\n0",
"output": "="
},
{
"input": "10\n11",
"output": "<"
},
{
"input": "0011\n12",
"output": "<"
},
{
"input": "00\n1",
"output": "<"
},
{
"input": "0\n0",
"output": "="
},
{
"input": "00\n10",
"output": "<"
},
{
"input": "011\n10",
"output": ">"
},
{
"input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091",
"output": "<"
},
{
"input": "0000001\n00",
"output": ">"
},
{
"input": "01\n1",
"output": "="
},
{
"input": "010\n001",
"output": ">"
},
{
"input": "100\n111",
"output": "<"
},
{
"input": "1\n0",
"output": ">"
},
{
"input": "000000\n000000000000000000000",
"output": "="
},
{
"input": "010101\n010101",
"output": "="
},
{
"input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111",
"output": ">"
},
{
"input": "0000000\n0",
"output": "="
},
{
"input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123",
"output": "<"
},
{
"input": "0010\n030",
"output": "<"
}
] | 1,587,302,959 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 10,547,200 | from sys import stdin
a=int(stdin.readline())
b=int(stdin.readline())
if a>b:
print(">")
elif a<b:
print("<")
else:
print("=") | Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As 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. Don't use the function input() in Python2 instead of it use the function raw_input().
Input Specification:
The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits.
Output Specification:
Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=".
Demo Input:
['9\n10\n', '11\n10\n', '00012345\n12345\n', '0123\n9\n', '0123\n111\n']
Demo Output:
['<\n', '>\n', '=\n', '>\n', '>\n']
Note:
none | ```python
from sys import stdin
a=int(stdin.readline())
b=int(stdin.readline())
if a>b:
print(">")
elif a<b:
print("<")
else:
print("=")
``` | 0 |
|
142 | E | Help Greg the Dwarf 2 | PROGRAMMING | 3,000 | [
"geometry"
] | null | null | Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. That's why he wants to find the shortest route from the excavation point to his crypt. Greg has recollected how the Codeforces participants successfully solved the problem of transporting his coffin to a crypt. So, in some miraculous way Greg appeared in your bedroom and asks you to help him in a highly persuasive manner. As usual, you didn't feel like turning him down.
After some thought, you formalized the task as follows: as the Neverland mountain has a regular shape and ends with a rather sharp peak, it can be represented as a cone whose base radius equals *r* and whose height equals *h*. The graveyard where Greg is busy excavating and his crypt can be represented by two points on the cone's surface. All you've got to do is find the distance between points on the cone's surface.
The task is complicated by the fact that the mountain's base on the ground level and even everything below the mountain has been dug through by gnome (one may wonder whether they've been looking for the same stuff as Greg...). So, one can consider the shortest way to pass not only along the side surface, but also along the cone's base (and in a specific case both points can lie on the cone's base — see the first sample test)
Greg will be satisfied with the problem solution represented as the length of the shortest path between two points — he can find his way pretty well on his own. He gave you two hours to solve the problem and the time is ticking! | The first input line contains space-separated integers *r* and *h* (1<=≤<=*r*,<=*h*<=≤<=1000) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in the systems of coordinates where the origin of coordinates is located in the centre of the cone's base and its rotation axis matches the *OZ* axis. In this coordinate system the vertex of the cone is located at the point (0,<=0,<=*h*), the base of the cone is a circle whose center is at the point (0,<=0,<=0), lying on the *XOY* plane, and all points on the cone surface have a non-negative coordinate *z*. It is guaranteed that the distances from the points to the cone surface do not exceed 10<=-<=12. All real numbers in the input have no more than 16 digits after decimal point. | Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10<=-<=6. | [
"2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n",
"2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n",
"2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0\n",
"2 2\n1.0 0.0 0.0\n0.0 1.0 1.0\n"
] | [
"2.000000000",
"2.414213562",
"2.534324263",
"3.254470198"
] | none | 2,500 | [
{
"input": "2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0",
"output": "2.0000000000000000"
},
{
"input": "2 2\n1.0 0.0 0.0\n1.0 0.0 1.0",
"output": "2.414213562373095"
},
{
"input": "2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0",
"output": "2.534324262661599"
},
{
"input": "2 2\n1.0 0.0 0.0\n0.0 1.0 1.0",
"output": "3.254470197706959"
},
{
"input": "2 2\n1 0 1\n1 0 1",
"output": "0.000000000000000"
},
{
"input": "2 2\n0 2 0\n2 0 0",
"output": "2.8284271247461903"
},
{
"input": "1 3\n0.333333333333333 0 2\n-0.666666666666666 0 1",
"output": "1.769124183375466"
},
{
"input": "4 2\n0 2 1\n0 -3 0",
"output": "7.617495113916503"
},
{
"input": "1 1\n0 0 1\n0 0 0",
"output": "2.414213562373095"
},
{
"input": "100 100\n99 0 1\n-99 0 1",
"output": "202.828427124746210"
},
{
"input": "88 105\n-83.647129195665613 27.334186970232459 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "88.0000000000000000"
},
{
"input": "95 115\n-94.798837559409705 6.179028838308848 0.000000000000000\n3.342582693513654 12.928467665102536 98.835138349494315",
"output": "141.297194476396560"
},
{
"input": "139 163\n-7.064282061617403 -119.648796858761900 22.448079209184119\n-3.099235383286207 130.020758014221030 10.486305761961773",
"output": "320.994208466804080"
},
{
"input": "89 165\n-77.601546118264423 -40.138626159725227 3.026234987879706\n-32.536564505566112 79.820562899551433 5.196277486773833",
"output": "138.055005811202530"
},
{
"input": "167 201\n-44.045042116268228 2.240298676664706 147.919173318547560\n-1.653062448517331 166.991818316171730 0.000000000000000",
"output": "229.161875457891940"
},
{
"input": "209 155\n10.339810149948200 207.429619805582460 0.973633003803984\n207.268022593198170 13.679741073068795 0.950049728912131",
"output": "280.113608256360580"
},
{
"input": "214 197\n-139.010054266533840 145.275848992143410 11.903485508393622\n201.707752886360570 -61.822489603821438 2.789960360351068",
"output": "435.069479445623240"
},
{
"input": "220 199\n7.702486930770317 -17.352156624704840 181.827313666644470\n-19.019292298570587 -58.442551586093003 143.407124141606430",
"output": "62.376512949023279"
},
{
"input": "125 223\n91.992953839808365 76.334473682993220 9.741805344154667\n-84.359519829273182 -91.096969326992280 1.502290062829727",
"output": "262.322409454934590"
},
{
"input": "135 242\n59.558351552645604 -52.913315274992456 99.187441396521223\n-24.675990127584633 -14.025205052053790 191.120333614367500",
"output": "136.624783180323310"
},
{
"input": "253 27\n-23.383556363495956 -3.075490409857886 24.483030221151189\n72.245718245226726 -82.324921811851368 15.311020040812947",
"output": "124.691284935369720"
},
{
"input": "254 54\n0.000000000000000 0.000000000000000 54.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "513.676722098843470"
},
{
"input": "267 42\n61.269272425153595 5.673599488606665 32.320903001753486\n-63.797770810112304 -38.267051239340162 30.297514320612102",
"output": "133.678382741735420"
},
{
"input": "38 278\n5.399109546042840 -8.432443753698909 204.748343438560110\n-5.230748245976885 1.555327155842188 238.077119640322790",
"output": "38.093735046969364"
},
{
"input": "78 282\n-1.664125131541297 -59.562854026849507 66.573343539272599\n71.149972890338546 -22.703911105882042 11.986524947742422",
"output": "102.658307334262700"
},
{
"input": "245 283\n-65.200025215297188 211.893667712412820 26.916275024999653\n81.954925476524096 -210.905000365566200 21.636551653267666",
"output": "553.847834491559980"
},
{
"input": "160 284\n-11.848288916318076 151.632288175726250 14.032286789548566\n55.204568662902133 -137.884714926791870 20.367746237801001",
"output": "355.266014577463070"
},
{
"input": "296 125\n0.000000000000000 0.000000000000000 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "0.0000000000000000"
},
{
"input": "307 13\n-270.438955322231150 -145.298903795659300 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "307.0000000000000000"
},
{
"input": "248 318\n-104.624749910959410 138.999195918964920 94.919838172486877\n228.999165107773990 95.201798197000812 0.000000000000000",
"output": "378.618071232051190"
},
{
"input": "320 305\n133.785417250379680 -214.950689891414610 63.683625243294543\n31.210648478715274 -54.393542268080502 245.227875205476610",
"output": "263.170090569639000"
},
{
"input": "279 320\n176.409341581619770 -216.149818882041610 0.000000000000000\n-80.839498717221858 -72.772525941007075 195.246130236928480",
"output": "362.984167377827590"
},
{
"input": "166 326\n-159.080559959952890 47.427581034961378 0.000000000000000\n64.219952084615173 -58.053751680168347 155.988180576648150",
"output": "350.312896450586380"
},
{
"input": "313 326\n268.206244981551440 -161.351821039912720 0.000000000000000\n32.335370169772631 -20.887667026020182 285.906088038778530",
"output": "396.367934965696240"
},
{
"input": "337 155\n103.562025742828280 213.837241376601870 45.720328048223415\n-12.785007455865372 -193.917849947259270 65.615662078921559",
"output": "451.739183365123150"
},
{
"input": "391 393\n69.363017479144332 381.996349660945500 2.771345269553063\n-4.314168772882780 -327.594317606469870 63.701456901510852",
"output": "872.611999302211980"
},
{
"input": "453 388\n-81.104385878292348 94.096725495772120 281.598867297277200\n319.890281685634530 320.747888041504270 0.000000000000000",
"output": "547.976632686011840"
},
{
"input": "462 27\n-159.864787795012400 -17.769652438662003 17.599713760563326\n-43.201695776047600 16.275482559188674 24.302000751547617",
"output": "121.714300862770440"
},
{
"input": "408 497\n267.962525371795490 -106.500517621999510 145.748954986607150\n406.530738343103910 -34.594201569204905 0.000000000000000",
"output": "213.676529817838540"
},
{
"input": "4 501\n1.256027912095488 1.550849382650718 251.041040422217460\n2.794539216444501 -2.861913794605588 0.000000000000000",
"output": "251.094303330067670"
},
{
"input": "505 405\n-171.258217521977260 26.368423921428572 266.035850862244220\n-322.844337173239810 -330.811068528084830 34.293877778928582",
"output": "454.191411638506740"
},
{
"input": "93 528\n36.658812293708685 85.470061900145083 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "93.0000000000000000"
},
{
"input": "19 536\n-2.323956629404414 0.854918404455399 466.144562395750310\n-11.970821418787578 -14.754641119305361 0.000000000000000",
"output": "466.515075604037010"
},
{
"input": "543 213\n-11.022498941354053 -208.184746146469020 131.221988486140450\n-261.342433954058090 237.839371010998720 74.386870834762945",
"output": "529.265581335714840"
},
{
"input": "552 538\n-219.196257175740500 505.979100989387290 0.567204598667054\n-13.005338942244901 -501.382586206790510 49.169271940131331",
"output": "1147.290245679384000"
},
{
"input": "290 555\n-35.294429133672416 -33.484539794537760 461.892222209193390\n-252.058361325518750 -143.410538266524330 0.000000000000000",
"output": "521.936684362155690"
},
{
"input": "557 356\n412.616943315331810 -374.160738305226630 0.000000000000000\n-119.143786824695810 28.916320481813823 277.639995153037090",
"output": "758.644272670264740"
},
{
"input": "108 567\n-77.326538888682109 -75.396328713652466 0.000000000000000\n-85.325412036343849 1.454640554847149 118.976494340335650",
"output": "142.855584570014320"
},
{
"input": "604 507\n256.435816856724730 546.860742632915960 0.000000000000000\n0.000000000000000 0.000000000000000 507.000000000000000",
"output": "788.584174327637130"
},
{
"input": "206 610\n85.003724396840582 -183.792743756824360 10.370249946816582\n-132.372286093682990 124.137988504975570 72.626760718535252",
"output": "489.630683838895320"
},
{
"input": "12 621\n-6.805901628792963 -2.400041575385406 247.536715624015390\n-9.888929727632208 -6.797725269673083 0.000000000000000",
"output": "247.595041963414560"
},
{
"input": "186 636\n125.502577654577490 -76.943123644053074 132.632626038618070\n10.998850276346941 11.375883701939239 581.893591807090730",
"output": "472.553289667418480"
},
{
"input": "194 640\n-185.594418018322020 -28.430658132256557 20.587563671749706\n162.386754505225720 71.184945374190377 55.079159027002405",
"output": "462.832453430235830"
},
{
"input": "381 647\n314.650162349171300 199.407123669264730 14.407770163811673\n-199.461288368305470 -305.260525670149090 27.766889571708951",
"output": "792.391879168826340"
},
{
"input": "663 558\n185.667839327817890 0.821162517806038 401.735041310258740\n541.204579549448680 -169.787472718591060 80.617413258449716",
"output": "508.589197900185520"
},
{
"input": "665 337\n-81.930040429089274 477.240591033892090 91.612221878619039\n-94.047744970766075 579.582133079572710 39.445199819169396",
"output": "115.507697648901770"
},
{
"input": "670 162\n128.165741407183870 -19.582009069376959 130.651054537534490\n-669.944585774285540 8.616959540400943 0.000000000000000",
"output": "819.927464516420400"
},
{
"input": "681 160\n-613.743030379663540 -295.094040367452070 0.000000000000000\n-138.987119977579430 -666.666018693271890 0.000000000000000",
"output": "602.8755340355712600"
},
{
"input": "700 694\n-491.323781315873530 391.487036614876730 71.164119861786261\n369.587380114008230 585.823923455896420 7.272344266525618",
"output": "925.471286233843440"
},
{
"input": "392 711\n275.256598579833170 279.101782398931620 0.000000000000000\n370.063048151715410 37.629657168787716 36.327559021646451",
"output": "265.894529685532690"
},
{
"input": "496 720\n-81.481055925005222 -489.261522629100850 0.000000000000000\n0.000000000000000 0.000000000000000 720.000000000000000",
"output": "874.308869908119620"
},
{
"input": "307 732\n-263.300272665471650 149.674800448139620 9.850014526791911\n252.974089914966560 152.268689048374710 27.979618318814200",
"output": "564.688286438940510"
},
{
"input": "708 735\n-372.227682278060970 -591.827556222709400 9.185583606570070\n-158.326918524255120 656.057627975817580 34.370737282300794",
"output": "1359.983114591124600"
},
{
"input": "562 761\n447.905573469315980 327.128350332647590 9.957782797299041\n-426.805719967420540 -331.040778689403110 29.600587789132693",
"output": "1173.053559827348900"
},
{
"input": "770 459\n88.786807039677768 -138.447991737814420 360.957772634164770\n183.265921873443600 -185.090929054817020 303.732327011363680",
"output": "119.910138117875160"
},
{
"input": "775 303\n220.814458005458700 -81.823041961067929 210.932255816936160\n-194.572073117032460 238.686633634201710 182.603770274642930",
"output": "547.658318653906580"
},
{
"input": "310 795\n-37.954433819069251 175.532754257961810 334.440556394379200\n-110.110062248727290 289.785738419925340 0.000000000000000",
"output": "360.711396236277610"
},
{
"input": "754 796\n216.565988894870090 153.972540922843820 515.476132607224140\n-47.509812467842735 752.501706123826920 0.000000000000000",
"output": "838.208600447662770"
},
{
"input": "800 645\n752.626854703574510 271.206227028445370 0.000000000000000\n-95.598746603765832 -604.427250606550160 151.622809761020480",
"output": "1320.622324323393100"
},
{
"input": "805 653\n687.624915941348040 -164.311988032427020 79.508586205624965\n762.951730761017420 256.767709279745700 0.000000000000000",
"output": "437.165612527832140"
},
{
"input": "816 723\n-409.404815276986650 251.893602766220970 297.094693677376310\n-102.999857434057130 -809.473303678733940 0.000000000000000",
"output": "1222.018824276540700"
},
{
"input": "857 741\n-856.534963081445990 28.228655991135017 0.000000000000000\n-145.707872297531990 -844.522478061138490 0.000000000000000",
"output": "1125.5974835534469000"
},
{
"input": "874 748\n-704.291967415513110 456.985614182417630 29.473929299402851\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "919.329269786949230"
},
{
"input": "881 682\n-39.602632901035470 880.109442891794970 0.000000000000000\n-232.291083077826440 -675.068070887951990 129.343123219787340",
"output": "1793.990810649566800"
},
{
"input": "893 2\n-87.049912924255025 -888.747046498540840 0.000000000000000\n-102.087930879379740 -77.695608292576296 1.712674372195576",
"output": "811.192659983106640"
},
{
"input": "893 745\n-744.291957980134610 493.435387144150350 0.000000000000000\n-229.382232313548710 -863.036958362069870 0.000000000000000",
"output": "1450.9132467894781000"
},
{
"input": "894 380\n62.028165472337882 891.845562128408120 0.000000000000000\n-281.506413354874670 848.522326895453260 0.000000000000000",
"output": "346.2555552782370100"
},
{
"input": "894 795\n-79.319376955375546 737.053160611378190 135.782330090001180\n-276.945076779847170 -850.022014095755370 0.000000000000000",
"output": "1863.330948809297300"
},
{
"input": "895 266\n-460.946965864515730 600.620195555266720 40.981602257928387\n178.077028677831550 166.078812707948770 193.629343617797820",
"output": "790.950234454675300"
},
{
"input": "902 469\n-665.302587586102280 0.024106493977479 123.072157668834680\n58.789007076917628 -165.366933065562050 377.744642427558010",
"output": "799.180998688435470"
},
{
"input": "909 879\n695.074972696372130 413.045294912773730 97.145264807840434\n-705.229230890123060 -517.817269433920730 32.956360377477495",
"output": "2002.737605542867900"
},
{
"input": "196 936\n-1.157629940182491 -1.112914249009275 928.331349563707700\n-43.366603227838930 -132.521475146312530 270.118439199950160",
"output": "672.528850625547190"
},
{
"input": "939 172\n760.602725383313210 550.640076764737840 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "939.0000000000001100"
},
{
"input": "952 565\n389.334410842084650 868.747786491710600 0.000000000000000\n492.169149678581280 807.768438499273320 3.622308459447762",
"output": "119.630652845404640"
},
{
"input": "588 957\n219.263290283055740 515.577240145252860 45.140983359549089\n-516.487259323793180 -279.513083799093290 1.187280610002339",
"output": "1161.121426778588100"
},
{
"input": "754 959\n344.733007448335230 -670.126881792474360 0.510505088991700\n-508.306819760418310 499.529742923366650 52.560459621746233",
"output": "1555.419070886616100"
},
{
"input": "406 962\n-49.783332082275358 -248.776028266368480 360.848848877620410\n-1.952167810020501 -3.487333391971083 952.530329833034900",
"output": "642.294343165613210"
},
{
"input": "973 436\n47.525346927433176 69.727668618789224 398.187783288826440\n-827.862618951791770 511.246011370534060 0.000000000000000",
"output": "1061.333336198369400"
},
{
"input": "974 336\n-412.402783094129350 395.821170200124020 138.808395601866750\n-31.097990341177809 10.151078095017953 324.715080477288270",
"output": "573.326026015034130"
},
{
"input": "997 897\n966.907255849128660 63.326755791696719 25.210646226492816\n-691.417709012145790 -678.273873083398140 25.584924238061610",
"output": "1940.382463863425300"
},
{
"input": "1000 1000\n0.000000000000000 0.000000000000000 0.000000000000000\n0.000000000000000 0.000000000000000 0.000000000000000",
"output": "0.0000000000000000"
},
{
"input": "1000 1000\n0.000000000000000 0.000000000000000 1000.000000000000000\n0.000000000000000 0.000000000000000 1000.000000000000000",
"output": "0.000000000000000"
},
{
"input": "1000 1000\n0.000000000000000 0.000000000000000 0.000000000000000\n0.000000000000000 0.000000000000000 1000.000000000000000",
"output": "2414.213562373095100"
},
{
"input": "1000 1000\n519.430292507390280 822.183052823439540 27.481207829697631\n-925.681320081855800 -271.775638373096170 35.247231690112748",
"output": "1953.674308800189900"
},
{
"input": "1000 1000\n-865.729850457726000 -306.217565767793640 81.709538567284440\n891.442934337587080 215.701160976332830 82.831806031769716",
"output": "2229.685117365914700"
},
{
"input": "1000 1000\n-451.257094270773560 -345.250138251562930 431.818142587758190\n68.190857559004940 -27.380462017482774 926.517466327546120",
"output": "801.825262695840930"
},
{
"input": "1000 1000\n-876.740604189171450 -386.919633788012220 41.678086421560081\n659.134284294775630 733.795718905435480 13.635887809815506",
"output": "2031.701640955472400"
},
{
"input": "1000 1000\n-20.534295190826231 133.273184243935670 865.154166109953510\n-711.474516721095600 -638.507879949720520 44.024947657417599",
"output": "1355.676743956396400"
},
{
"input": "1000 1000\n969.207183920193190 -213.270785951424980 7.605424489407109\n-631.538647292108290 -722.789524216293670 40.174099463677607",
"output": "1778.286143061074400"
},
{
"input": "1000 1000\n-378.383150861597360 -21.882887748889253 620.984605019557530\n291.284330016681450 461.398444104171010 454.348934634031140",
"output": "930.253674386416260"
}
] | 1,689,443,513 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689443513.8014555")# 1689443513.8014755 | Title: Help Greg the Dwarf 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. That's why he wants to find the shortest route from the excavation point to his crypt. Greg has recollected how the Codeforces participants successfully solved the problem of transporting his coffin to a crypt. So, in some miraculous way Greg appeared in your bedroom and asks you to help him in a highly persuasive manner. As usual, you didn't feel like turning him down.
After some thought, you formalized the task as follows: as the Neverland mountain has a regular shape and ends with a rather sharp peak, it can be represented as a cone whose base radius equals *r* and whose height equals *h*. The graveyard where Greg is busy excavating and his crypt can be represented by two points on the cone's surface. All you've got to do is find the distance between points on the cone's surface.
The task is complicated by the fact that the mountain's base on the ground level and even everything below the mountain has been dug through by gnome (one may wonder whether they've been looking for the same stuff as Greg...). So, one can consider the shortest way to pass not only along the side surface, but also along the cone's base (and in a specific case both points can lie on the cone's base — see the first sample test)
Greg will be satisfied with the problem solution represented as the length of the shortest path between two points — he can find his way pretty well on his own. He gave you two hours to solve the problem and the time is ticking!
Input Specification:
The first input line contains space-separated integers *r* and *h* (1<=≤<=*r*,<=*h*<=≤<=1000) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in the systems of coordinates where the origin of coordinates is located in the centre of the cone's base and its rotation axis matches the *OZ* axis. In this coordinate system the vertex of the cone is located at the point (0,<=0,<=*h*), the base of the cone is a circle whose center is at the point (0,<=0,<=0), lying on the *XOY* plane, and all points on the cone surface have a non-negative coordinate *z*. It is guaranteed that the distances from the points to the cone surface do not exceed 10<=-<=12. All real numbers in the input have no more than 16 digits after decimal point.
Output Specification:
Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10<=-<=6.
Demo Input:
['2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n', '2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n', '2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0\n', '2 2\n1.0 0.0 0.0\n0.0 1.0 1.0\n']
Demo Output:
['2.000000000', '2.414213562', '2.534324263', '3.254470198']
Note:
none | ```python
print("_RANDOM_GUESS_1689443513.8014555")# 1689443513.8014755
``` | 0 |
|
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "3754606979"
},
{
"input": "99999999999999999",
"output": "50000000000000000"
},
{
"input": "21",
"output": "11"
},
{
"input": "712394453192",
"output": "712394453193"
},
{
"input": "172212168",
"output": "172212169"
},
{
"input": "822981260158260519",
"output": "411490630079130260"
},
{
"input": "28316250877914571",
"output": "14158125438957286"
},
{
"input": "779547116602436424",
"output": "779547116602436425"
},
{
"input": "578223540024979436",
"output": "578223540024979437"
},
{
"input": "335408917861648766",
"output": "335408917861648767"
},
{
"input": "74859962623690078",
"output": "74859962623690079"
},
{
"input": "252509054433933439",
"output": "126254527216966720"
},
{
"input": "760713016476190622",
"output": "760713016476190623"
},
{
"input": "919845426262703496",
"output": "919845426262703497"
},
{
"input": "585335723211047194",
"output": "585335723211047195"
},
{
"input": "522842184971407769",
"output": "261421092485703885"
},
{
"input": "148049062628894320",
"output": "148049062628894321"
},
{
"input": "84324828731963974",
"output": "84324828731963975"
},
{
"input": "354979173822804781",
"output": "177489586911402391"
},
{
"input": "1312150450968413",
"output": "656075225484207"
},
{
"input": "269587449430302150",
"output": "269587449430302151"
},
{
"input": "645762258982631926",
"output": "645762258982631927"
},
{
"input": "615812229161735895",
"output": "307906114580867948"
},
{
"input": "0",
"output": "0"
},
{
"input": "349993004923078531",
"output": "174996502461539266"
},
{
"input": "891351282707723851",
"output": "445675641353861926"
},
{
"input": "563324731189330734",
"output": "563324731189330735"
},
{
"input": "520974001910286909",
"output": "260487000955143455"
},
{
"input": "666729339802329204",
"output": "666729339802329205"
},
{
"input": "856674611404539671",
"output": "428337305702269836"
},
{
"input": "791809296303238499",
"output": "395904648151619250"
},
{
"input": "711066337317063338",
"output": "711066337317063339"
},
{
"input": "931356503492686566",
"output": "931356503492686567"
},
{
"input": "234122432773361866",
"output": "234122432773361867"
},
{
"input": "1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "63",
"output": "32"
},
{
"input": "24",
"output": "25"
},
{
"input": "8",
"output": "9"
},
{
"input": "15",
"output": "8"
}
] | 1,527,322,099 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 92 | 0 | slices = int(input())+1
if slices%2==0:
print(slices//2)
else:
print(slices)
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
Input Specification:
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
Output Specification:
A single integer — the number of straight cuts Shiro needs.
Demo Input:
['3\n', '4\n']
Demo Output:
['2', '5']
Note:
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | ```python
slices = int(input())+1
if slices%2==0:
print(slices//2)
else:
print(slices)
``` | 0 |
|
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=><=*a**i*. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "95"
},
{
"input": "1\n995",
"output": "0"
},
{
"input": "10\n103 101 103 103 101 102 100 100 101 104",
"output": "7"
},
{
"input": "20\n102 100 102 104 102 101 104 103 100 103 105 105 100 105 100 100 101 105 105 102",
"output": "15"
},
{
"input": "20\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998",
"output": "15"
},
{
"input": "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9",
"output": "84"
}
] | 1,634,312,423 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n = int(input())
a = list(map(int, input().split()))
if(len(set(a)) == len(a)):
print(len(a)-1)
else:
print(len(set(a))-1+len(a)-len(set(a))-1)
| Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=><=*a**i*.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting.
Output Specification:
Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement.
Demo Input:
['5\n20 30 10 50 40\n', '4\n200 100 100 200\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | ```python
n = int(input())
a = list(map(int, input().split()))
if(len(set(a)) == len(a)):
print(len(a)-1)
else:
print(len(set(a))-1+len(a)-len(set(a))-1)
``` | 0 |
|
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa. | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query. | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
{
"input": "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8",
"output": "zctycopttp"
},
{
"input": "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 8 7\n2 7 5",
"output": "bylwlwylbb"
},
{
"input": "thisisahacktest\n1\n1 2 1",
"output": "htisisahacktest"
},
{
"input": "ozozumuhackleyan\n1\n1 4 1",
"output": "zozoumuhackleyan"
},
{
"input": "lacongaithattuyet\n1\n1 1 1",
"output": "lacongaithattuyet"
}
] | 1,647,117,349 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 1,433,600 | s = list(input())
m = int(input())
for _ in range(m):
l, r, k = tuple(map(int, input().split()))
l = l-1
r = r-1
lenss = r-l+1
k0 = k % lenss
for _ in range(k0):
ss = s[l:r]
s[l] = s[r]
s[l+1:r+1] = ss
print(''.join(s)) | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa.
Input Specification:
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query.
Output Specification:
Print the resulting string *s* after processing all *m* queries.
Demo Input:
['abacaba\n2\n3 6 1\n1 4 2\n']
Demo Output:
['baabcaa\n']
Note:
The sample is described in problem statement. | ```python
s = list(input())
m = int(input())
for _ in range(m):
l, r, k = tuple(map(int, input().split()))
l = l-1
r = r-1
lenss = r-l+1
k0 = k % lenss
for _ in range(k0):
ss = s[l:r]
s[l] = s[r]
s[l+1:r+1] = ss
print(''.join(s))
``` | 0 |
|
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not. | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
"output": "YES"
},
{
"input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae",
"output": "NO"
},
{
"input": " furuike ya\nkawazu tobikomu\nmizu no oto ",
"output": "YES"
},
{
"input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ",
"output": "NO"
},
{
"input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det",
"output": "YES"
},
{
"input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel",
"output": "NO"
},
{
"input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti",
"output": "NO"
},
{
"input": "kutaburete\nyado karu koro ya\nfuji no hana",
"output": "YES"
},
{
"input": " beginnings of poetry\n the rice planting songs \n of the interior",
"output": "NO"
},
{
"input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden",
"output": "NO"
},
{
"input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut",
"output": "YES"
},
{
"input": "writing in the dark\nunaware that my pen\nhas run out of ink",
"output": "NO"
},
{
"input": "kusaaiu\nuieueua\nuo efaa",
"output": "YES"
},
{
"input": "v\nh\np",
"output": "NO"
},
{
"input": "i\ni\nu",
"output": "NO"
},
{
"input": "awmio eoj\nabdoolceegood\nwaadeuoy",
"output": "YES"
},
{
"input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo",
"output": "YES"
},
{
"input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr",
"output": "YES"
},
{
"input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd",
"output": "YES"
},
{
"input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ",
"output": "YES"
},
{
"input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs",
"output": "YES"
},
{
"input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn",
"output": "NO"
},
{
"input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl",
"output": "NO"
},
{
"input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr",
"output": "NO"
},
{
"input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf",
"output": "NO"
},
{
"input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi",
"output": "NO"
},
{
"input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu",
"output": "NO"
},
{
"input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt",
"output": "NO"
},
{
"input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo",
"output": "NO"
},
{
"input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau",
"output": "NO"
},
{
"input": "ab\na\na",
"output": "NO"
},
{
"input": "on codeforcs\nbeta round is runnineg\na rustling of keys",
"output": "NO"
},
{
"input": "coooooooooooooooood\nd\nd",
"output": "NO"
},
{
"input": "on codeforces \nbeta round is runninog\n a rustling of keys",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaa\na\na",
"output": "NO"
},
{
"input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "YES"
},
{
"input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "NO"
},
{
"input": "aaaaaa\naaaaaa\naaaaa",
"output": "NO"
}
] | 1,588,625,753 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | r=0
for i in [0,1,2]:r|=sum(x in 'aeiou' for x in input())!=5+i%2*2
print('YNEOS'[r::2]) | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input Specification:
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output Specification:
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Demo Input:
['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
r=0
for i in [0,1,2]:r|=sum(x in 'aeiou' for x in input())!=5+i%2*2
print('YNEOS'[r::2])
``` | 3.9455 |
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,592,836,658 | 2,147,483,647 | PyPy 3 | OK | TESTS | 117 | 420 | 12,083,200 | import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
#from math import *
from itertools import permutations
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def li():
return [int(x) for x in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
def bo(i):
return ord(i)-ord('a')
def can(mid):
d=[0,0]
mini=n
for i in range(n):
if i>=mid:
mini=min(d[0],min(d[1],mini))
d[bo(a[i-mid])]-=1
d[bo(a[i])]+=1
mini=min(d[0],min(d[1],mini))
return mini<=k
n,k=mi()
a=si()
l=0
r=ans=n
while l<=r:
mid=(l+r)//2
if can(mid):
ans=mid
l=mid+1
else:
r=mid-1
print(ans)
| 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
import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
#from math import *
from itertools import permutations
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def li():
return [int(x) for x in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
def bo(i):
return ord(i)-ord('a')
def can(mid):
d=[0,0]
mini=n
for i in range(n):
if i>=mid:
mini=min(d[0],min(d[1],mini))
d[bo(a[i-mid])]-=1
d[bo(a[i])]+=1
mini=min(d[0],min(d[1],mini))
return mini<=k
n,k=mi()
a=si()
l=0
r=ans=n
while l<=r:
mid=(l+r)//2
if can(mid):
ans=mid
l=mid+1
else:
r=mid-1
print(ans)
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,661,787,164 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | t1=input()
t2=input()
if t1[::-1]==t2:
print("Yes")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
t1=input()
t2=input()
if t1[::-1]==t2:
print("Yes")
else:
print("NO")
``` | 0 |
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"output": "2"
},
{
"input": "2 2\n0 4\n7 4",
"output": "4"
},
{
"input": "4 1\n-12 1\n-14 1\n4 1\n-11 1",
"output": "5"
},
{
"input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1",
"output": "2"
},
{
"input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6",
"output": "6"
},
{
"input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9",
"output": "35"
},
{
"input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34",
"output": "16"
},
{
"input": "3 501\n827 327\n-85 480\n-999 343",
"output": "6"
},
{
"input": "2 999\n-999 471\n530 588",
"output": "4"
},
{
"input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31",
"output": "30"
},
{
"input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3",
"output": "16"
},
{
"input": "4 512\n-997 354\n-568 216\n-234 221\n603 403",
"output": "4"
},
{
"input": "3 966\n988 5\n15 2\n-992 79",
"output": "6"
},
{
"input": "2 1000\n-995 201\n206 194",
"output": "4"
},
{
"input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2",
"output": "9"
},
{
"input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1",
"output": "43"
},
{
"input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7",
"output": "96"
},
{
"input": "1 1000\n0 1000",
"output": "2"
}
] | 1,651,413,014 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | n,t=map(int,input().split(' '))
a=[]
for i in range(n):
a.append(list(map(int,input().split(' '))))
count=0
for i in range(1,n):
if (a[i][0]-a[i-1][0])-((a[i][1]/2)+(a[i-1][1]/2))>t:
count+=2
elif (a[i][0]-a[i-1][0])-((a[i][1]/2)+(a[i-1][1]/2))==t:
count+=1
count+=2
print(count) | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
Input Specification:
The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000).
Output Specification:
Output the amount of possible positions of the new house.
Demo Input:
['2 2\n0 4\n6 2\n', '2 2\n0 4\n5 2\n', '2 3\n0 4\n5 2\n']
Demo Output:
['4\n', '3\n', '2\n']
Note:
It is possible for the *x*-coordinate of the new house to have non-integer value. | ```python
n,t=map(int,input().split(' '))
a=[]
for i in range(n):
a.append(list(map(int,input().split(' '))))
count=0
for i in range(1,n):
if (a[i][0]-a[i-1][0])-((a[i][1]/2)+(a[i-1][1]/2))>t:
count+=2
elif (a[i][0]-a[i-1][0])-((a[i][1]/2)+(a[i-1][1]/2))==t:
count+=1
count+=2
print(count)
``` | 0 |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,661,264,997 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 60 | 0 | n = int(input())
arr = [int(i) for i in input().split()]
m = int(input())
brr = [int(i) for i in input().split()]
vas = 0
pet = 0
for i in range(n):
if arr[i] in brr:
vas += i +1
pet += n-i
l = [vas, pet]
print(*l) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
n = int(input())
arr = [int(i) for i in input().split()]
m = int(input())
brr = [int(i) for i in input().split()]
vas = 0
pet = 0
for i in range(n):
if arr[i] in brr:
vas += i +1
pet += n-i
l = [vas, pet]
print(*l)
``` | 0 |
|
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 1,503,420,216 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | x1,y1,x2,y2=map(int,input().split())
x,y=map(int,input().split())
k1=abs(x2-x1)
k2=abs(y2-y1)
if k1%x or k2%y:
print('NO')
else:
q=k1//x
if k2%(y*2)==0:
print('YES')
else:
print('NO')
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
Input Specification:
The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle.
Output Specification:
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
Demo Input:
['0 0 0 6\n2 3\n', '1 1 3 6\n1 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | ```python
x1,y1,x2,y2=map(int,input().split())
x,y=map(int,input().split())
k1=abs(x2-x1)
k2=abs(y2-y1)
if k1%x or k2%y:
print('NO')
else:
q=k1//x
if k2%(y*2)==0:
print('YES')
else:
print('NO')
``` | 0 |
|
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,680,665,555 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 5,427,200 | from itertools import combinations
def check(num):
for i in range(2, num):
if num % i == 0:
return True
return False
n = int(input())
c = []
for i in range(4, n):
if check(i):
c.append(i)
for i in combinations(c, 2):
if sum(i) == n:
print(i[0], i[1])
break | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
from itertools import combinations
def check(num):
for i in range(2, num):
if num % i == 0:
return True
return False
n = int(input())
c = []
for i in range(4, n):
if check(i):
c.append(i)
for i in combinations(c, 2):
if sum(i) == n:
print(i[0], i[1])
break
``` | 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,415,857 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
word_1 = input()
word_2 = input()
word_3 = input()
word_4 = input()
print(n)
if len(word_1) > 10 :
word_1 = word_1[0] + str(len(word_1)) + word_1[-1]
print(word_1)
else :
print(word_1)
if len(word_2) > 10 :
word_2 = word_2[0] + str(len(word_2)) + word_2[-1]
print(word_2)
else :
print(word_2)
if len(word_3) > 10 :
word_3 = word_3[0] + str(len(word_3)) + word_3[-1]
print(word_3)
else :
print(word_3)
if len(word_4) > 10 :
word_4 = word_4[0] + str(len(word_4)) + word_4[-1]
print(word_4)
else :
print(word_4)
| 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())
word_1 = input()
word_2 = input()
word_3 = input()
word_4 = input()
print(n)
if len(word_1) > 10 :
word_1 = word_1[0] + str(len(word_1)) + word_1[-1]
print(word_1)
else :
print(word_1)
if len(word_2) > 10 :
word_2 = word_2[0] + str(len(word_2)) + word_2[-1]
print(word_2)
else :
print(word_2)
if len(word_3) > 10 :
word_3 = word_3[0] + str(len(word_3)) + word_3[-1]
print(word_3)
else :
print(word_3)
if len(word_4) > 10 :
word_4 = word_4[0] + str(len(word_4)) + word_4[-1]
print(word_4)
else :
print(word_4)
``` | 0 |
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,647,591,849 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 512,000 | from collections import Counter
s = input()
freq = Counter(s)
rem = []
for k,v in freq.items():
if v % 2 == 1:
rem.append(k)
if len(rem) == 0:
print("Firs`t")
else:
if len(rem) % 2 == 0:
print("Second")
else:
print("First")
| Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none | ```python
from collections import Counter
s = input()
freq = Counter(s)
rem = []
for k,v in freq.items():
if v % 2 == 1:
rem.append(k)
if len(rem) == 0:
print("Firs`t")
else:
if len(rem) % 2 == 0:
print("Second")
else:
print("First")
``` | 0 |
|
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 1 -1",
"output": "100"
},
{
"input": "100 54 100",
"output": "54"
},
{
"input": "100 37 -100",
"output": "37"
},
{
"input": "99 41 0",
"output": "41"
},
{
"input": "97 37 -92",
"output": "42"
},
{
"input": "99 38 59",
"output": "97"
},
{
"input": "35 34 1",
"output": "35"
},
{
"input": "48 1 -1",
"output": "48"
},
{
"input": "87 65 -76",
"output": "76"
},
{
"input": "76 26 29",
"output": "55"
},
{
"input": "100 65 0",
"output": "65"
},
{
"input": "2 1 100",
"output": "1"
},
{
"input": "3 2 -100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "1 1 -100",
"output": "1"
},
{
"input": "3 1 -100",
"output": "3"
},
{
"input": "4 3 -100",
"output": "3"
},
{
"input": "3 2 -12",
"output": "2"
},
{
"input": "2 2 -100",
"output": "2"
},
{
"input": "3 2 -90",
"output": "2"
},
{
"input": "6 2 -10",
"output": "4"
},
{
"input": "3 3 -100",
"output": "2"
},
{
"input": "5 2 4",
"output": "1"
},
{
"input": "6 4 5",
"output": "3"
},
{
"input": "3 2 -6",
"output": "2"
},
{
"input": "5 1 -99",
"output": "2"
},
{
"input": "6 2 5",
"output": "1"
},
{
"input": "10 1 -100",
"output": "1"
},
{
"input": "2 2 1",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "2"
},
{
"input": "17 17 2",
"output": "2"
},
{
"input": "6 6 1",
"output": "1"
},
{
"input": "5 3 -2",
"output": "1"
},
{
"input": "6 2 -100",
"output": "4"
},
{
"input": "5 3 -100",
"output": "3"
},
{
"input": "5 4 3",
"output": "2"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "5 5 2",
"output": "2"
},
{
"input": "3 2 5",
"output": "1"
},
{
"input": "5 5 -1",
"output": "4"
},
{
"input": "5 3 3",
"output": "1"
},
{
"input": "4 2 3",
"output": "1"
},
{
"input": "88 76 74",
"output": "62"
}
] | 1,564,547,381 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | n,a,b=map(int,input().split())
res=(a-1+b+n)%n
print(res)
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input Specification:
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Output Specification:
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
Demo Input:
['6 2 -5\n', '5 1 3\n', '3 2 7\n']
Demo Output:
['3\n', '4\n', '3\n']
Note:
The first example is illustrated by the picture in the statements. | ```python
n,a,b=map(int,input().split())
res=(a-1+b+n)%n
print(res)
``` | 0 |
|
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
"output": "90"
},
{
"input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88",
"output": "90"
},
{
"input": "90\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n1",
"output": "16"
},
{
"input": "5\n15 30 45 60 75",
"output": "90"
},
{
"input": "6\n14 29 43 59 70 74",
"output": "58"
},
{
"input": "1\n15",
"output": "30"
},
{
"input": "1\n16",
"output": "15"
},
{
"input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89",
"output": "90"
},
{
"input": "76\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n90",
"output": "15"
},
{
"input": "6\n13 17 32 47 60 66",
"output": "81"
},
{
"input": "84\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84",
"output": "90"
},
{
"input": "9\n6 20 27 28 40 53 59 70 85",
"output": "90"
},
{
"input": "12\n14 22 27 31 35 44 62 69 74 79 88 89",
"output": "59"
},
{
"input": "5\n15 30 45 60 74",
"output": "89"
},
{
"input": "72\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89",
"output": "54"
},
{
"input": "8\n1 16 30 31 32 33 34 50",
"output": "49"
},
{
"input": "12\n1 3 6 10 15 21 28 36 45 55 66 78",
"output": "90"
},
{
"input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90",
"output": "80"
},
{
"input": "8\n5 17 20 35 42 53 67 76",
"output": "90"
},
{
"input": "9\n15 28 39 48 55 60 63 64 74",
"output": "89"
},
{
"input": "10\n15 28 39 48 55 60 63 64 74 82",
"output": "90"
},
{
"input": "2\n1 18",
"output": "16"
},
{
"input": "9\n10 20 30 40 50 60 70 80 84",
"output": "90"
},
{
"input": "2\n16 50",
"output": "15"
},
{
"input": "6\n15 30 45 60 75 84",
"output": "90"
},
{
"input": "8\n15 20 30 40 50 60 73 83",
"output": "90"
},
{
"input": "8\n10 20 30 40 50 60 70 80",
"output": "90"
},
{
"input": "3\n1 20 90",
"output": "16"
},
{
"input": "6\n15 30 45 60 74 89",
"output": "90"
}
] | 1,630,943,616 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 6,758,400 | n = int(input())
t = list(map(int,input().split()))
watchTime = 1
for i in t:
if i-watchTime<15:
watchTime=i
else:
break
print(min(watchTime+15, 90)) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order.
Output Specification:
Print the number of minutes Limak will watch the game.
Demo Input:
['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n']
Demo Output:
['35\n', '15\n', '90\n']
Note:
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | ```python
n = int(input())
t = list(map(int,input().split()))
watchTime = 1
for i in t:
if i-watchTime<15:
watchTime=i
else:
break
print(min(watchTime+15, 90))
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*:
- If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook. | In the only line print a single integer — the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 22 4 20 20 17 17 20 37 53 17 3 3 15 1 46 11 24 31 6 12 6 11 18 13 1 5 0 19 10 24 41 16 41 18 52 46 39 16 30 18 23 53 13",
"output": "66"
},
{
"input": "100\n0 0 0 0 1 2 0 0 3 3 2 2 6 4 1 6 2 9 8 0 2 0 2 2 0 0 10 0 4 20 4 11 3 9 0 3 8 2 6 3 13 2 1 23 20 20 16 7 1 37 6 1 25 25 14 30 6 23 18 3 2 16 0 4 37 9 4 6 2 14 15 11 16 35 36 7 32 26 8 1 0 37 35 38 27 3 16 8 3 7 7 25 13 13 30 11 5 28 0 12",
"output": "71"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6",
"output": "8"
},
{
"input": "2\n0 1",
"output": "1"
}
] | 1,510,503,823 | 1,123 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | n = int(input())
'''arr = [input() for i in range(n)]
arr.sort()
ans = []'''
arr = list(map(int, input().split()))
d = dict()
d[0] = 1
for i in arr:
if i in d:
d[i] += 1
else:
d[i] = 1
ans = 0
a = [d[i] for i in d]
c = 0
for i in a:
ans += i // 2
c += i % 2
print(ans + (c + 1) // 2)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute *i*, he makes a note in his logbook with number *t**i*:
- If Petya has visited this room before, he writes down the minute he was in this room last time; - Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute *i*.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number *t*0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=<<=*i*) — notes in the logbook.
Output Specification:
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
Demo Input:
['2\n0 0\n', '5\n0 1 0 1 3\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1. | ```python
n = int(input())
'''arr = [input() for i in range(n)]
arr.sort()
ans = []'''
arr = list(map(int, input().split()))
d = dict()
d[0] = 1
for i in arr:
if i in d:
d[i] += 1
else:
d[i] = 1
ans = 0
a = [d[i] for i in d]
c = 0
for i in a:
ans += i // 2
c += i % 2
print(ans + (c + 1) // 2)
``` | 0 |
|
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"input": "9149",
"output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..."
},
{
"input": "2877",
"output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..."
},
{
"input": "2956",
"output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..."
},
{
"input": "3035",
"output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..."
},
{
"input": "3114",
"output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..."
},
{
"input": "3193",
"output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..."
},
{
"input": "3273",
"output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..."
},
{
"input": "7000",
"output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..."
},
{
"input": "7079",
"output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..."
},
{
"input": "4653",
"output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..."
},
{
"input": "9995",
"output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..."
},
{
"input": "9996",
"output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..."
},
{
"input": "9997",
"output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..."
},
{
"input": "9998",
"output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..."
},
{
"input": "9999",
"output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..."
},
{
"input": "10000",
"output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..."
}
] | 1,681,303,212 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n = int(input())
route = [1]
left, right = 1, n
for i in range(n-1):
if i % 2 == 0:
left += 1
route.append(left)
else:
right -= 1
route.append(right)
print(*route) | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
Input Specification:
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Output Specification:
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any.
Demo Input:
['2\n', '3\n']
Demo Output:
['1 2 ', '1 3 2 ']
Note:
none | ```python
n = int(input())
route = [1]
left, right = 1, n
for i in range(n-1):
if i % 2 == 0:
left += 1
route.append(left)
else:
right -= 1
route.append(right)
print(*route)
``` | 0 |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,498,710,712 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 5,529,600 | import math
n = int(input())
digits = 0
a = int(math.log10(n)) + 1
for x in range(1, a):
digits += 10 ** (x - 1) * 9 * x
digits += (n - 10 ** (a - 1) + 1) * a
print(digits) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
import math
n = int(input())
digits = 0
a = int(math.log10(n)) + 1
for x in range(1, a):
digits += 10 ** (x - 1) * 9 * x
digits += (n - 10 ** (a - 1) + 1) * a
print(digits)
``` | 3 |
|
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff. | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
"input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7",
"output": "23 8"
},
{
"input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22",
"output": "6 47"
},
{
"input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37",
"output": "23 58"
},
{
"input": "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50",
"output": "1 40"
},
{
"input": "1 1\n0 0",
"output": "0 2"
},
{
"input": "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21",
"output": "0 0"
},
{
"input": "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32",
"output": "0 0"
},
{
"input": "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21",
"output": "0 0"
},
{
"input": "1 5\n1 0",
"output": "0 0"
},
{
"input": "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "1 30\n0 29",
"output": "1 0"
},
{
"input": "1 2\n3 0",
"output": "0 0"
},
{
"input": "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "25 0"
},
{
"input": "1 5\n0 6",
"output": "0 0"
},
{
"input": "2 60\n0 59\n23 59",
"output": "2 0"
},
{
"input": "1 58\n0 1",
"output": "1 0"
},
{
"input": "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "2 3\n0 3\n0 30",
"output": "0 7"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9",
"output": "24 0"
},
{
"input": "1 60\n2 0",
"output": "0 0"
},
{
"input": "2 60\n0 0\n5 0",
"output": "1 1"
},
{
"input": "1 30\n0 31",
"output": "0 0"
},
{
"input": "2 60\n0 59\n3 1",
"output": "2 0"
},
{
"input": "2 60\n0 59\n5 0",
"output": "2 0"
},
{
"input": "1 59\n0 0",
"output": "1 0"
},
{
"input": "3 25\n0 0\n1 0\n2 0",
"output": "0 26"
},
{
"input": "1 2\n2 3",
"output": "0 0"
}
] | 1,525,012,591 | 4,891 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 7,065,600 | n,s=map(int,input().split())
arr=[]
for i in range(n):
a,b=map(int,input().split())
arr.append(a*60+b)
if arr[0]>=s:
print(0,0)
else:
flag=0
k=1
while k<len(arr):
if (arr[k]-arr[k-1])//2>s:
print((arr[k-1]+s+1)//60,(arr[k-1]+s+1)%60)
flag=1
break
k+=1
if flag==0:
print((arr[len(arr)-1]+s+1)//60,(arr[len(arr)-1]+s+1)%60) | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
Input Specification:
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
Output Specification:
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
Demo Input:
['6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n', '16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n', '3 17\n0 30\n1 0\n12 0\n']
Demo Output:
['6 1\n', '24 50\n', '0 0\n']
Note:
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | ```python
n,s=map(int,input().split())
arr=[]
for i in range(n):
a,b=map(int,input().split())
arr.append(a*60+b)
if arr[0]>=s:
print(0,0)
else:
flag=0
k=1
while k<len(arr):
if (arr[k]-arr[k-1])//2>s:
print((arr[k-1]+s+1)//60,(arr[k-1]+s+1)%60)
flag=1
break
k+=1
if flag==0:
print((arr[len(arr)-1]+s+1)//60,(arr[len(arr)-1]+s+1)%60)
``` | 0 |
|
915 | F | Imbalance Value of a Tree | PROGRAMMING | 2,400 | [
"data structures",
"dsu",
"graphs",
"trees"
] | null | null | You are given a tree *T* consisting of *n* vertices. A number is written on each vertex; the number written on vertex *i* is *a**i*. Let's denote the function *I*(*x*,<=*y*) as the difference between maximum and minimum value of *a**i* on a simple path connecting vertices *x* and *y*.
Your task is to calculate . | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=106) — the number of vertices in the tree.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the numbers written on the vertices.
Then *n*<=-<=1 lines follow. Each line contains two integers *x* and *y* denoting an edge connecting vertex *x* and vertex *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*). It is guaranteed that these edges denote a tree. | Print one number equal to . | [
"4\n2 2 3 1\n1 2\n1 3\n1 4\n"
] | [
"6\n"
] | none | 0 | [
{
"input": "4\n2 2 3 1\n1 2\n1 3\n1 4",
"output": "6"
}
] | 1,683,256,605 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 93 | 2,867,200 | # Problem: F. Imbalance Value of a Tree
# Contest: Codeforces - Educational Codeforces Round 36 (Rated for Div. 2)
# URL: https://codeforces.com/problemset/problem/915/F
# Memory Limit: 256 MB
# Time Limit: 4000 ms
import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib import redirect_stdout
from itertools import *
from array import *
from functools import lru_cache, reduce
from types import GeneratorType
from heapq import *
from math import sqrt, gcd, inf
if sys.version >= '3.8': # ACW没有comb
from math import comb
RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法
MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/problemset/problem/915/F
输入 n (1≤n≤1e6) 和长为 n 的数组 a(1≤a[i]≤1e6),下标从 1 开始。
然后输入一棵树的 n-1 条边,节点编号从 1 开始。
定义 Δ(x,y) 表示从 x 到 y 的简单路径上的 a[i] 的最大值与最小值的差。
输出所有 Δ(i,j) 的和,其中 1≤i≤j≤n。
输入
4
2 2 3 1
1 2
1 3
1 4
输出 6
"""
class DSU:
def __init__(self, n):
self.fathers = list(range(n))
self.size = [1] * n # 本家族size
self.edge_size = [0] * n # 本家族边数(带自环/重边)
self.n = n
self.setCount = n # 共几个家族
def find_fa(self, x):
fs = self.fathers
t = x
while fs[x] != x:
x = fs[x]
while t != x:
fs[t], t = x, fs[t]
return x
def union(self, x: int, y: int) -> bool:
x = self.find_fa(x)
y = self.find_fa(y)
if x == y:
self.edge_size[y] += 1
return False
# if self.size[x] > self.size[y]: # 注意如果要定向合并x->y,需要干掉这个;实际上上边改成find_fa后,按轶合并没必要了,所以可以常关
# x, y = y, x
self.fathers[x] = y
self.size[y] += self.size[x]
self.edge_size[y] += 1 + self.edge_size[x]
self.setCount -= 1
return True
# ms
def solve():
n, = RI()
a = RILST()
es = []
for _ in range(n - 1):
u, v = RI()
u -= 1
v -= 1
if a[u] > a[v]:
u, v = v, u
es.append((u, v))
ans = 0
# 最大
es.sort(key=lambda x: a[x[1]])
dsu = DSU(n)
for u, v in es:
u, v = dsu.find_fa(u), dsu.find_fa(v)
ans += a[v] * dsu.size[u] * dsu.size[v]
dsu.union(u, v)
es.sort(key=lambda x: a[x[0]], reverse=True)
dsu = DSU(n)
for u, v in es:
u, v = dsu.find_fa(u), dsu.find_fa(v)
ans -= a[u] * dsu.size[u] * dsu.size[v]
dsu.union(u, v)
print(ans)
if __name__ == '__main__':
solve()
| Title: Imbalance Value of a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree *T* consisting of *n* vertices. A number is written on each vertex; the number written on vertex *i* is *a**i*. Let's denote the function *I*(*x*,<=*y*) as the difference between maximum and minimum value of *a**i* on a simple path connecting vertices *x* and *y*.
Your task is to calculate .
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=106) — the number of vertices in the tree.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the numbers written on the vertices.
Then *n*<=-<=1 lines follow. Each line contains two integers *x* and *y* denoting an edge connecting vertex *x* and vertex *y* (1<=≤<=*x*,<=*y*<=≤<=*n*, *x*<=≠<=*y*). It is guaranteed that these edges denote a tree.
Output Specification:
Print one number equal to .
Demo Input:
['4\n2 2 3 1\n1 2\n1 3\n1 4\n']
Demo Output:
['6\n']
Note:
none | ```python
# Problem: F. Imbalance Value of a Tree
# Contest: Codeforces - Educational Codeforces Round 36 (Rated for Div. 2)
# URL: https://codeforces.com/problemset/problem/915/F
# Memory Limit: 256 MB
# Time Limit: 4000 ms
import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib import redirect_stdout
from itertools import *
from array import *
from functools import lru_cache, reduce
from types import GeneratorType
from heapq import *
from math import sqrt, gcd, inf
if sys.version >= '3.8': # ACW没有comb
from math import comb
RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法
MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/problemset/problem/915/F
输入 n (1≤n≤1e6) 和长为 n 的数组 a(1≤a[i]≤1e6),下标从 1 开始。
然后输入一棵树的 n-1 条边,节点编号从 1 开始。
定义 Δ(x,y) 表示从 x 到 y 的简单路径上的 a[i] 的最大值与最小值的差。
输出所有 Δ(i,j) 的和,其中 1≤i≤j≤n。
输入
4
2 2 3 1
1 2
1 3
1 4
输出 6
"""
class DSU:
def __init__(self, n):
self.fathers = list(range(n))
self.size = [1] * n # 本家族size
self.edge_size = [0] * n # 本家族边数(带自环/重边)
self.n = n
self.setCount = n # 共几个家族
def find_fa(self, x):
fs = self.fathers
t = x
while fs[x] != x:
x = fs[x]
while t != x:
fs[t], t = x, fs[t]
return x
def union(self, x: int, y: int) -> bool:
x = self.find_fa(x)
y = self.find_fa(y)
if x == y:
self.edge_size[y] += 1
return False
# if self.size[x] > self.size[y]: # 注意如果要定向合并x->y,需要干掉这个;实际上上边改成find_fa后,按轶合并没必要了,所以可以常关
# x, y = y, x
self.fathers[x] = y
self.size[y] += self.size[x]
self.edge_size[y] += 1 + self.edge_size[x]
self.setCount -= 1
return True
# ms
def solve():
n, = RI()
a = RILST()
es = []
for _ in range(n - 1):
u, v = RI()
u -= 1
v -= 1
if a[u] > a[v]:
u, v = v, u
es.append((u, v))
ans = 0
# 最大
es.sort(key=lambda x: a[x[1]])
dsu = DSU(n)
for u, v in es:
u, v = dsu.find_fa(u), dsu.find_fa(v)
ans += a[v] * dsu.size[u] * dsu.size[v]
dsu.union(u, v)
es.sort(key=lambda x: a[x[0]], reverse=True)
dsu = DSU(n)
for u, v in es:
u, v = dsu.find_fa(u), dsu.find_fa(v)
ans -= a[u] * dsu.size[u] * dsu.size[v]
dsu.union(u, v)
print(ans)
if __name__ == '__main__':
solve()
``` | 0 |
|
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3 25\n+ * +",
"output": "63"
},
{
"input": "13 87 4 17\n* * *",
"output": "76908"
},
{
"input": "7 0 8 15\n+ + *",
"output": "0"
},
{
"input": "52 0 43 239\n+ + +",
"output": "334"
},
{
"input": "1000 1000 999 1000\n* * *",
"output": "999000000000"
},
{
"input": "720 903 589 804\n* * *",
"output": "307887168960"
},
{
"input": "631 149 496 892\n* * +",
"output": "445884"
},
{
"input": "220 127 597 394\n* + +",
"output": "28931"
},
{
"input": "214 862 466 795\n+ + +",
"output": "2337"
},
{
"input": "346 290 587 525\n* * *",
"output": "30922279500"
},
{
"input": "323 771 559 347\n+ * *",
"output": "149067730"
},
{
"input": "633 941 836 254\n* + +",
"output": "162559"
},
{
"input": "735 111 769 553\n+ * *",
"output": "92320032"
},
{
"input": "622 919 896 120\n* * +",
"output": "667592"
},
{
"input": "652 651 142 661\n+ + +",
"output": "2106"
},
{
"input": "450 457 975 35\n* * *",
"output": "7017806250"
},
{
"input": "883 954 804 352\n* * +",
"output": "1045740"
},
{
"input": "847 206 949 358\n* + *",
"output": "62660050"
},
{
"input": "663 163 339 76\n+ + +",
"output": "1241"
},
{
"input": "990 330 253 553\n+ * +",
"output": "85033"
},
{
"input": "179 346 525 784\n* * *",
"output": "25492034400"
},
{
"input": "780 418 829 778\n+ + *",
"output": "997766"
},
{
"input": "573 598 791 124\n* * *",
"output": "33608874936"
},
{
"input": "112 823 202 223\n* * +",
"output": "137222"
},
{
"input": "901 166 994 315\n* + *",
"output": "47278294"
},
{
"input": "393 342 840 486\n+ * *",
"output": "178222356"
},
{
"input": "609 275 153 598\n+ + *",
"output": "226746"
},
{
"input": "56 828 386 57\n+ * *",
"output": "3875088"
},
{
"input": "944 398 288 986\n+ + *",
"output": "670464"
},
{
"input": "544 177 162 21\n+ + *",
"output": "18543"
},
{
"input": "105 238 316 265\n+ + +",
"output": "924"
},
{
"input": "31 353 300 911\n* * *",
"output": "2990721900"
},
{
"input": "46 378 310 194\n* * +",
"output": "77528"
},
{
"input": "702 534 357 657\n+ * *",
"output": "259077042"
},
{
"input": "492 596 219 470\n+ + *",
"output": "341202"
},
{
"input": "482 842 982 902\n+ * +",
"output": "407728"
},
{
"input": "827 578 394 351\n* * *",
"output": "66105361764"
},
{
"input": "901 884 426 451\n* + *",
"output": "170223210"
},
{
"input": "210 295 12 795\n* * +",
"output": "71490"
},
{
"input": "40 734 948 202\n+ * *",
"output": "13590560"
},
{
"input": "136 611 963 195\n+ + *",
"output": "240584"
},
{
"input": "695 74 871 760\n+ * +",
"output": "53061"
},
{
"input": "666 884 772 54\n* + +",
"output": "37620"
},
{
"input": "975 785 753 224\n+ * +",
"output": "170432"
},
{
"input": "35 187 126 596\n+ + +",
"output": "944"
},
{
"input": "243 386 431 35\n* + *",
"output": "3298015"
},
{
"input": "229 602 133 635\n* * +",
"output": "222313"
},
{
"input": "916 207 238 891\n+ + *",
"output": "423315"
},
{
"input": "922 145 883 357\n+ + *",
"output": "313490"
},
{
"input": "69 355 762 111\n* + +",
"output": "8776"
},
{
"input": "209 206 34 67\n* + *",
"output": "476374"
},
{
"input": "693 824 375 361\n* * +",
"output": "557339"
},
{
"input": "45 712 635 467\n* + +",
"output": "22362"
},
{
"input": "426 283 179 211\n+ + +",
"output": "1099"
},
{
"input": "802 387 686 12\n+ + +",
"output": "1887"
}
] | 1,630,696,335 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 6,963,200 | a,b,c,d=map(int,input().split())
p,q,r=map(str,input().split())
plus=0
if p=="+":
plus+=1
if q=="+":
plus+=1
if r=="+":
plus+=1
if plus==3:
print(a+b+c+d)
elif plus==1:
print(min(a*b*c +d,a*b*d+c,a*c*d +b ,b*c*d +a,a*b+c*d,a*c+b*d,a*d+b*c))
elif plus==2:
s=a+b+c+d
print(min((s-a)*a,(s-b)*b,(s-c)*c,(s-d)*d,(a+b)*(c+d),(a+c)*(b+d),(a+d)*(b+c)))
else:
print(a*b*c*d) | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.
Input Specification:
First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)
Output Specification:
Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).
Demo Input:
['1 1 1 1\n+ + *\n', '2 2 2 2\n* * +\n', '1 2 3 4\n* + +\n']
Demo Output:
['3\n', '8\n', '9\n']
Note:
none | ```python
a,b,c,d=map(int,input().split())
p,q,r=map(str,input().split())
plus=0
if p=="+":
plus+=1
if q=="+":
plus+=1
if r=="+":
plus+=1
if plus==3:
print(a+b+c+d)
elif plus==1:
print(min(a*b*c +d,a*b*d+c,a*c*d +b ,b*c*d +a,a*b+c*d,a*c+b*d,a*d+b*c))
elif plus==2:
s=a+b+c+d
print(min((s-a)*a,(s-b)*b,(s-c)*c,(s-d)*d,(a+b)*(c+d),(a+c)*(b+d),(a+d)*(b+c)))
else:
print(a*b*c*d)
``` | 0 |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"output": "653"
},
{
"input": "194",
"output": "120"
},
{
"input": "906",
"output": "786"
},
{
"input": "659",
"output": "535"
},
{
"input": "75",
"output": "37"
},
{
"input": "787",
"output": "664"
},
{
"input": "851",
"output": "730"
},
{
"input": "563",
"output": "446"
},
{
"input": "979",
"output": "862"
},
{
"input": "395",
"output": "291"
},
{
"input": "755",
"output": "634"
},
{
"input": "171",
"output": "103"
},
{
"input": "883",
"output": "759"
},
{
"input": "400",
"output": "294"
},
{
"input": "817",
"output": "693"
},
{
"input": "177",
"output": "107"
},
{
"input": "593",
"output": "476"
},
{
"input": "305",
"output": "214"
},
{
"input": "721",
"output": "595"
},
{
"input": "785",
"output": "664"
},
{
"input": "497",
"output": "383"
},
{
"input": "913",
"output": "791"
},
{
"input": "625",
"output": "507"
},
{
"input": "334",
"output": "236"
},
{
"input": "10000",
"output": "12471"
},
{
"input": "9999",
"output": "12467"
}
] | 1,583,598,286 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 409,600 | '''
Auther: ghoshashis545 Ashis Ghosh
college: jalpaiguri Govt Enggineering College
Date:07/03/2020
'''
from math import ceil,sqrt,gcd,log,floor
from collections import deque
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def li(): return list(mi())
#for _ in range(ii()):
n=ii()
ans=0
for i in range(1,n-1):
for j in range(i+1,n-1):
c=(i*i)+(j*j)
x=sqrt(c)
x=int(x)
if(x*x==c and x<=n):
#print(i,j,x)
ans+=1
print(ans) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
Input Specification:
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5\n', '74\n']
Demo Output:
['1\n', '35\n']
Note:
none | ```python
'''
Auther: ghoshashis545 Ashis Ghosh
college: jalpaiguri Govt Enggineering College
Date:07/03/2020
'''
from math import ceil,sqrt,gcd,log,floor
from collections import deque
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def li(): return list(mi())
#for _ in range(ii()):
n=ii()
ans=0
for i in range(1,n-1):
for j in range(i+1,n-1):
c=(i*i)+(j*j)
x=sqrt(c)
x=int(x)
if(x*x==c and x<=n):
#print(i,j,x)
ans+=1
print(ans)
``` | 0 |
|
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"input": "8\n4\n1\n10\n59392",
"output": "59392"
},
{
"input": "4\n1\n8\n7\n44835",
"output": "44835"
},
{
"input": "6\n1\n7\n2\n62982",
"output": "62982"
},
{
"input": "2\n7\n4\n9\n56937",
"output": "35246"
},
{
"input": "2\n9\n8\n1\n75083",
"output": "75083"
},
{
"input": "8\n7\n7\n6\n69038",
"output": "24656"
},
{
"input": "4\n4\n2\n3\n54481",
"output": "36320"
},
{
"input": "6\n4\n9\n8\n72628",
"output": "28244"
},
{
"input": "9\n7\n8\n10\n42357",
"output": "16540"
},
{
"input": "5\n6\n4\n3\n60504",
"output": "36302"
},
{
"input": "7\n2\n3\n8\n21754",
"output": "15539"
},
{
"input": "1\n2\n10\n4\n39901",
"output": "39901"
},
{
"input": "3\n4\n7\n1\n58048",
"output": "58048"
},
{
"input": "9\n10\n4\n6\n52003",
"output": "21956"
},
{
"input": "5\n10\n9\n3\n70149",
"output": "32736"
},
{
"input": "5\n5\n5\n10\n55592",
"output": "11118"
},
{
"input": "1\n5\n2\n6\n49547",
"output": "49547"
},
{
"input": "3\n7\n7\n7\n84046",
"output": "36019"
},
{
"input": "10\n2\n1\n8\n63537",
"output": "63537"
},
{
"input": "7\n2\n10\n5\n81684",
"output": "53678"
},
{
"input": "7\n1\n6\n8\n99831",
"output": "99831"
},
{
"input": "3\n9\n3\n3\n61082",
"output": "20360"
},
{
"input": "5\n5\n8\n9\n79228",
"output": "29931"
},
{
"input": "1\n5\n5\n6\n89535",
"output": "89535"
},
{
"input": "5\n5\n2\n1\n7682",
"output": "7682"
},
{
"input": "7\n4\n8\n8\n25829",
"output": "9224"
},
{
"input": "3\n4\n3\n3\n87079",
"output": "43539"
},
{
"input": "5\n8\n4\n9\n5226",
"output": "2438"
},
{
"input": "4\n9\n6\n6\n1070",
"output": "415"
},
{
"input": "10\n10\n10\n10\n100000",
"output": "10000"
},
{
"input": "1\n1\n1\n1\n1",
"output": "1"
},
{
"input": "10\n10\n10\n10\n1",
"output": "0"
},
{
"input": "10\n10\n1\n10\n10",
"output": "10"
},
{
"input": "10\n10\n1\n10\n100",
"output": "100"
},
{
"input": "2\n2\n2\n2\n1",
"output": "0"
}
] | 1,689,669,469 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | def ok(ak, d):
for k in ak:
if d < k:
continue
if d % k == 0:
return True
return False
ak = [int(input()), int(input()), int(input()), int(input())]
d = int(input())
s = 0
for i in range(1, d + 1):
if ok(ak, i):
s += 1
print(s)
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input Specification:
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output Specification:
Output the number of damaged dragons.
Demo Input:
['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n']
Demo Output:
['12\n', '17\n']
Note:
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | ```python
def ok(ak, d):
for k in ak:
if d < k:
continue
if d % k == 0:
return True
return False
ak = [int(input()), int(input()), int(input()), int(input())]
d = int(input())
s = 0
for i in range(1, d + 1):
if ok(ak, i):
s += 1
print(s)
``` | 3 |
|
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items. | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week). | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
{
"input": "5 3\n28 17 20 45 45\n39 12 41 27 9",
"output": "101"
},
{
"input": "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31",
"output": "243"
},
{
"input": "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 166 114 53 144 106 141 106 191 123 44 199 35 18 84 169 46 52 129 102 155 130 63 169 116 145 154 41\n155 187 79 106 136 173 17 146 9 47 173 21 37 183 110 74 185 14 82 156 147 25 162 195 26 25 22 80 171 180 7 92 53 18 100 17 159 184 37 127 116 192 163 49 94 95 118 102 8 30",
"output": "4680"
},
{
"input": "5 2\n1 1 1 1 1\n2 2 2 2 2",
"output": "5"
},
{
"input": "5 2\n2 4 4 4 4\n3 1 1 1 1",
"output": "9"
},
{
"input": "6 3\n9 9 9 2 2 2\n6 6 6 1 1 1",
"output": "24"
},
{
"input": "5 3\n10 17 23 26 35\n7 18 18 29 32",
"output": "103"
},
{
"input": "2 1\n10 12\n5 6",
"output": "16"
}
] | 1,488,268,260 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | n,k = map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
diff=[]
wants=[]
res=0
z=0
for i in range(n):
diff.append(b[i]-a[i])
for i in range(k):
print(a)
print(b)
print(res)
z=diff.index(min(diff))
if min(diff)>=0:
res+=a[z]
a.pop(z)
b.pop(z)
diff.pop(z)
for i in range(len(a)):
print("res:", res)
if a[i]>=b[i]:
res+=b[i]
else:
res+=a[i]
print(res) | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items.
Input Specification:
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week).
Output Specification:
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
Demo Input:
['3 1\n5 4 6\n3 1 5\n', '5 3\n3 4 7 10 3\n4 5 5 12 5\n']
Demo Output:
['10\n', '25\n']
Note:
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. | ```python
n,k = map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
diff=[]
wants=[]
res=0
z=0
for i in range(n):
diff.append(b[i]-a[i])
for i in range(k):
print(a)
print(b)
print(res)
z=diff.index(min(diff))
if min(diff)>=0:
res+=a[z]
a.pop(z)
b.pop(z)
diff.pop(z)
for i in range(len(a)):
print("res:", res)
if a[i]>=b[i]:
res+=b[i]
else:
res+=a[i]
print(res)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,584,617,848 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | s = input()
visited = {
'h':0,
'e':0,
'l':0,
'o':0
}
count = 0
said_hello = True
for i in s:
if i == 'h' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 1:
said_hello = False
break
if i == 'e' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 2:
said_hello = False
break
if i == 'l' and visited[i] != 2:
count += 1
visited[i] += 1
if count != 3 and count != 4:
said_hello = False
break
if i == 'o' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 5:
said_hello = False
break
if said_hello:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
visited = {
'h':0,
'e':0,
'l':0,
'o':0
}
count = 0
said_hello = True
for i in s:
if i == 'h' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 1:
said_hello = False
break
if i == 'e' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 2:
said_hello = False
break
if i == 'l' and visited[i] != 2:
count += 1
visited[i] += 1
if count != 3 and count != 4:
said_hello = False
break
if i == 'o' and visited[i] != 1:
count += 1
visited[i] += 1
if count != 5:
said_hello = False
break
if said_hello:
print("YES")
else:
print("NO")
``` | 0 |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1",
"output": "LIVE\nDEAD"
},
{
"input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3",
"output": "DEAD\nLIVE"
},
{
"input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1",
"output": "LIVE\nLIVE"
},
{
"input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3",
"output": "DEAD\nDEAD"
}
] | 1,578,863,238 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 218 | 307,200 | n=int(input())
a,b=[0,0],[0,0]
for i in range(n):
s=list(map(int, input().split()))
if s[0]==1:
a[0]+=s[1]
a[1]+=s[2]
else:
b[0]+=s[1]
b[1]+=s[2]
if a[0]>=a[1]: print("LIVE")
else: print("DEAD")
if b[0]>=b[1]: print("LIVE")
else: print("DEAD")
| Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
Output Specification:
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format.
Demo Input:
['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n']
Demo Output:
['LIVE\nLIVE\n', 'LIVE\nDEAD\n']
Note:
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | ```python
n=int(input())
a,b=[0,0],[0,0]
for i in range(n):
s=list(map(int, input().split()))
if s[0]==1:
a[0]+=s[1]
a[1]+=s[2]
else:
b[0]+=s[1]
b[1]+=s[2]
if a[0]>=a[1]: print("LIVE")
else: print("DEAD")
if b[0]>=b[1]: print("LIVE")
else: print("DEAD")
``` | 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,174,349 | 2,147,483,647 | Python 3 | OK | TESTS | 117 | 93 | 102,400 | def max_beauty(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
# Calculate the length of the current window
window_length = window_end - window_start + 1
# Calculate the number of characters to change to match the current window type
to_change = min(a_count, b_count)
# If we can change more characters than allowed, move the window's start
while to_change > k:
if s[window_start] == 'a':
a_count -= 1
else:
b_count -= 1
window_start += 1
window_length -= 1
to_change = min(a_count, b_count)
# Update the maximum beauty
max_beauty = max(max_beauty, window_length)
return max_beauty
# Read input
n, k = map(int, input().split())
s = input()
# Calculate and print the maximum beauty
result = max_beauty(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(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
# Calculate the length of the current window
window_length = window_end - window_start + 1
# Calculate the number of characters to change to match the current window type
to_change = min(a_count, b_count)
# If we can change more characters than allowed, move the window's start
while to_change > k:
if s[window_start] == 'a':
a_count -= 1
else:
b_count -= 1
window_start += 1
window_length -= 1
to_change = min(a_count, b_count)
# Update the maximum beauty
max_beauty = max(max_beauty, window_length)
return max_beauty
# Read input
n, k = map(int, input().split())
s = input()
# Calculate and print the maximum beauty
result = max_beauty(n, k, s)
print(result)
``` | 3 |
|
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,696,072,577 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | LowerFirst=input("Enter the first String:")
LowerSecond=input("Enter the second String:")
f=LowerFirst.lower()
s=LowerSecond.lower()
if f>s:
print(1)
elif f<s:
print(-1)
elif f==s:
print(0) | 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
LowerFirst=input("Enter the first String:")
LowerSecond=input("Enter the second String:")
f=LowerFirst.lower()
s=LowerSecond.lower()
if f>s:
print(1)
elif f<s:
print(-1)
elif f==s:
print(0)
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,575,443,871 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 409,600 | from collections import OrderedDict
n=input()
s="".join(OrderedDict.fromkeys(n))
if("helo" in s):
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
from collections import OrderedDict
n=input()
s="".join(OrderedDict.fromkeys(n))
if("helo" in s):
print("YES")
else:
print("NO")
``` | 0 |
675 | B | Restoring Painting | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below.
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. | The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. | Print one integer — the number of distinct valid squares. | [
"2 1 1 1 2\n",
"3 3 1 2 3\n"
] | [
"2\n",
"6\n"
] | Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 1 1 1 2",
"output": "2"
},
{
"input": "3 3 1 2 3",
"output": "6"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1000 522 575 426 445",
"output": "774000"
},
{
"input": "99000 52853 14347 64237 88869",
"output": "1296306000"
},
{
"input": "100000 2 2 2 2",
"output": "10000000000"
},
{
"input": "2 1 1 2 2",
"output": "0"
},
{
"input": "10 9 10 8 10",
"output": "70"
},
{
"input": "100 19 16 35 83",
"output": "1700"
},
{
"input": "1000 102 583 606 929",
"output": "150000"
},
{
"input": "10000 1816 3333 6908 7766",
"output": "4750000"
},
{
"input": "100000 80015 84290 50777 30497",
"output": "1696900000"
},
{
"input": "100000 64022 49026 55956 88430",
"output": "6866200000"
},
{
"input": "100000 10263 46628 10268 22948",
"output": "5095500000"
},
{
"input": "100000 81311 81584 51625 57276",
"output": "4600600000"
},
{
"input": "100000 77594 3226 21255 8541",
"output": "1291800000"
},
{
"input": "100000 65131 35523 58220 87645",
"output": "5478900000"
},
{
"input": "100000 83958 32567 91083 95317",
"output": "3012500000"
},
{
"input": "100000 36851 54432 21164 85520",
"output": "1806300000"
},
{
"input": "100000 55732 17473 23832 75148",
"output": "7422500000"
},
{
"input": "100000 60789 25296 49585 25237",
"output": "4015900000"
},
{
"input": "100000 92060 77234 58709 36956",
"output": "2637100000"
},
{
"input": "100000 87223 66046 27153 40823",
"output": "1470700000"
},
{
"input": "100000 3809 35468 34556 51158",
"output": "5173900000"
},
{
"input": "100000 35038 37363 95275 88903",
"output": "0"
},
{
"input": "100000 45274 9250 36558 49486",
"output": "6848000000"
},
{
"input": "100000 1 1 1 1",
"output": "10000000000"
},
{
"input": "100000 1 1 1 100000",
"output": "100000"
},
{
"input": "100000 1 1 100000 1",
"output": "100000"
},
{
"input": "100000 1 1 100000 100000",
"output": "0"
},
{
"input": "100000 1 100000 1 1",
"output": "100000"
},
{
"input": "100000 1 100000 1 100000",
"output": "0"
},
{
"input": "100000 1 100000 100000 1",
"output": "10000000000"
},
{
"input": "100000 1 100000 100000 100000",
"output": "100000"
},
{
"input": "100000 100000 1 1 1",
"output": "100000"
},
{
"input": "100000 100000 1 1 100000",
"output": "10000000000"
},
{
"input": "100000 100000 1 100000 1",
"output": "0"
},
{
"input": "100000 100000 1 100000 100000",
"output": "100000"
},
{
"input": "100000 100000 100000 1 1",
"output": "0"
},
{
"input": "100000 100000 100000 1 100000",
"output": "100000"
},
{
"input": "100000 100000 100000 100000 1",
"output": "100000"
},
{
"input": "100000 100000 100000 100000 100000",
"output": "10000000000"
},
{
"input": "3 3 3 1 1",
"output": "0"
},
{
"input": "10 1 2 5 10",
"output": "0"
},
{
"input": "5 1 1 5 5",
"output": "0"
},
{
"input": "4 4 4 1 1",
"output": "0"
},
{
"input": "10 10 10 1 1",
"output": "0"
},
{
"input": "5 5 5 1 1",
"output": "0"
},
{
"input": "100 100 100 1 1",
"output": "0"
},
{
"input": "3 1 1 3 3",
"output": "0"
},
{
"input": "10 2 10 1 10",
"output": "0"
},
{
"input": "7 7 7 1 1",
"output": "0"
},
{
"input": "5 5 3 4 1",
"output": "0"
},
{
"input": "7 1 1 7 7",
"output": "0"
},
{
"input": "100 1 1 100 100",
"output": "0"
},
{
"input": "123 1 2 3 100",
"output": "2829"
},
{
"input": "10 1 1 10 10",
"output": "0"
},
{
"input": "803 525 6 623 8",
"output": "0"
}
] | 1,600,831,695 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 124 | 307,200 | #!/usr/bin/env python3
(n, a, b, c, d) = input().split()
n = int(n)
a = int(a)
b = int(b)
c = int(c)
d = int(d)
diff2 = b - c
diff4 = a - d
diff5 = a + b - c - d
(lower, _, upper) = sorted((diff2, diff4, diff5))
lower_bound = 1 - min(0, lower)
upper_bound = n - max(0, upper)
if lower_bound > upper_bound:
print(0)
else:
print((upper_bound - lower_bound + 1) * n)
| Title: Restoring Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below.
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
Input Specification:
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Output Specification:
Print one integer — the number of distinct valid squares.
Demo Input:
['2 1 1 1 2\n', '3 3 1 2 3\n']
Demo Output:
['2\n', '6\n']
Note:
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
#!/usr/bin/env python3
(n, a, b, c, d) = input().split()
n = int(n)
a = int(a)
b = int(b)
c = int(c)
d = int(d)
diff2 = b - c
diff4 = a - d
diff5 = a + b - c - d
(lower, _, upper) = sorted((diff2, diff4, diff5))
lower_bound = 1 - min(0, lower)
upper_bound = n - max(0, upper)
if lower_bound > upper_bound:
print(0)
else:
print((upper_bound - lower_bound + 1) * n)
``` | 3 |
|
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem? | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "10\n0 -1 2 2 -1 1 0 0 0 2",
"output": "0"
},
{
"input": "10\n-1 -1 1 -1 0 1 0 1 1 1",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "9"
},
{
"input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3",
"output": "3"
},
{
"input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3",
"output": "0"
},
{
"input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2",
"output": "0"
},
{
"input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2",
"output": "1"
},
{
"input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2",
"output": "6"
},
{
"input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n10000",
"output": "0"
},
{
"input": "1\n-10000",
"output": "0"
}
] | 1,583,585,514 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 307,200 | import sys
input = sys.stdin.readline
nums = list(map(int, input().split()))
params = list(map(int, input().split()))
refAns = int(sum(params)/2)
result = 0
if len(set(params)) == 1:
result = len(params) - 1
elif int(sum(params)) % 2 == 0:
for i in range(nums[0]):
if sum(params[:i+1]) == refAns and len(params[i+1:]) > 0:
result += 1
print(result)
| Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output Specification:
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
Demo Input:
['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
none | ```python
import sys
input = sys.stdin.readline
nums = list(map(int, input().split()))
params = list(map(int, input().split()))
refAns = int(sum(params)/2)
result = 0
if len(set(params)) == 1:
result = len(params) - 1
elif int(sum(params)) % 2 == 0:
for i in range(nums[0]):
if sum(params[:i+1]) == refAns and len(params[i+1:]) > 0:
result += 1
print(result)
``` | 0 |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,509,368,331 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m = intput().strip().split()
n = int(n)
m = int(m)
if n = 0 and m = 0:
print('NO')
elif n-m > 1 or m-n > 1:
print('NO')
else:
print('YES') | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
n,m = intput().strip().split()
n = int(n)
m = int(m)
if n = 0 and m = 0:
print('NO')
elif n-m > 1 or m-n > 1:
print('NO')
else:
print('YES')
``` | -1 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,694,245,141 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 31 | 0 | t=int(input())
k=0
for i in range(t):
p,q=map(int,input().split())
if(q-p>=2):
k=k+1
print(k) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
t=int(input())
k=0
for i in range(t):
p,q=map(int,input().split())
if(q-p>=2):
k=k+1
print(k)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about. | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter. | 0 | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "20",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "37",
"output": "19\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 "
},
{
"input": "211",
"output": "61\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 169 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 "
},
{
"input": "557",
"output": "123\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 "
},
{
"input": "907",
"output": "179\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "953",
"output": "186\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "289",
"output": "78\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 "
},
{
"input": "400",
"output": "97\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 "
},
{
"input": "900",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "625",
"output": "136\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 "
},
{
"input": "729",
"output": "152\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "784",
"output": "160\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "31",
"output": "17\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 31 "
},
{
"input": "44",
"output": "21\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 41 43 "
},
{
"input": "160",
"output": "50\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 "
},
{
"input": "322",
"output": "83\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 "
},
{
"input": "894",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "998",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "30",
"output": "16\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 "
}
] | 1,688,802,442 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import sys
import math
def get_sieve(n):
# n * log log n
primes = set()
sieve = [1] * (n + 1)
sieve[0] = sieve[1] = 0
for i in range(2, n + 1):
if sieve[i]:
for j in range(i * i, n + 1, i):
sieve[j] = 0
primes.add(i)
return primes
def main():
read = sys.stdin.readline
n = int(read())
primes = get_sieve(n)
result = ['2', '4', '3']
if n > 4:
for i in range(5, n + 1):
if i in primes:
result.append(str(i))
if math.sqrt(i) in primes:
result.append(str(i))
print(len(result))
print(' '.join(result))
if __name__ == '__main__':
main() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about.
Input Specification:
A single line contains number *n* (1<=≤<=*n*<=≤<=103).
Output Specification:
Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Demo Input:
['4\n', '6\n']
Demo Output:
['3\n2 4 3 \n', '4\n2 4 3 5 \n']
Note:
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter. | ```python
import sys
import math
def get_sieve(n):
# n * log log n
primes = set()
sieve = [1] * (n + 1)
sieve[0] = sieve[1] = 0
for i in range(2, n + 1):
if sieve[i]:
for j in range(i * i, n + 1, i):
sieve[j] = 0
primes.add(i)
return primes
def main():
read = sys.stdin.readline
n = int(read())
primes = get_sieve(n)
result = ['2', '4', '3']
if n > 4:
for i in range(5, n + 1):
if i in primes:
result.append(str(i))
if math.sqrt(i) in primes:
result.append(str(i))
print(len(result))
print(' '.join(result))
if __name__ == '__main__':
main()
``` | 0 |
|
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
{
"input": "8",
"output": "2 4 7 3 8 6 5"
},
{
"input": "9",
"output": "2 4 7 2 7 4 2 1"
},
{
"input": "2",
"output": "2"
},
{
"input": "11",
"output": "2 4 7 11 5 11 7 4 2 1"
},
{
"input": "12",
"output": "2 4 7 11 4 10 5 1 10 8 7"
},
{
"input": "13",
"output": "2 4 7 11 3 9 3 11 7 4 2 1"
},
{
"input": "20",
"output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11"
},
{
"input": "25",
"output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1"
},
{
"input": "30",
"output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16"
},
{
"input": "35",
"output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1"
},
{
"input": "40",
"output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21"
},
{
"input": "45",
"output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1"
},
{
"input": "50",
"output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26"
},
{
"input": "55",
"output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "60",
"output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31"
},
{
"input": "65",
"output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "70",
"output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36"
},
{
"input": "75",
"output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "80",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41"
},
{
"input": "85",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "90",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46"
},
{
"input": "95",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "96",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49"
},
{
"input": "97",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "98",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50"
},
{
"input": "99",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "100",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51"
}
] | 1,466,869,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | a=int(input())
v=a
g=1
i=1
while i<v:
g=g+i
b=g%10
i+=1
print(b," ")
| Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
Output Specification:
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
Demo Input:
['10\n', '3\n']
Demo Output:
['2 4 7 1 6 2 9 7 6\n', '2 1\n']
Note:
none | ```python
a=int(input())
v=a
g=1
i=1
while i<v:
g=g+i
b=g%10
i+=1
print(b," ")
``` | 0 |
278 | B | New Problem | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is string *s**l**s**l*<=+<=1... *s**r*.
String *x*<==<=*x*1*x*2... *x**p* is lexicographically smaller than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=<<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there exists such number *r* (*r*<=<<=*p*,<=*r*<=<<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=<<=*y**r*<=+<=1. The string characters are compared by their ASCII codes. | The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. | Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title. | [
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n"
] | [
"j\n",
"ab\n"
] | In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,000 | [
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear",
"output": "j"
},
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc",
"output": "ab"
},
{
"input": "1\na",
"output": "b"
},
{
"input": "1\nb",
"output": "a"
},
{
"input": "1\nz",
"output": "a"
},
{
"input": "5\nsplt\nohqykk\nxqpz\nknojbur\npmfm",
"output": "a"
},
{
"input": "2\nrxscdzkkezud\nwjehahqgouqvjienq",
"output": "b"
},
{
"input": "2\nxlaxwpjabtpwddc\ntxwdjmohrrszorrnomc",
"output": "e"
},
{
"input": "1\nepkotfpkkrhhmuipmtdk",
"output": "a"
},
{
"input": "2\nhk\nobsp",
"output": "a"
},
{
"input": "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng",
"output": "a"
},
{
"input": "10\nkpmwcdoysw\ngtpr\nkuzoxmiixxbl\ncrgqtuo\njhbplhpklrgwnaugdf\nzuxdaat\naycv\nqwghrkqwkobrgevsjrk\ntdxgc\nlxyzgcmbzulcst",
"output": "ab"
},
{
"input": "30\nwaiphwcqrrinr\no\nqiqehzmgsjdoqd\nkjexeesevrlowxhghq\njudikhzkj\nz\nxo\nlsdzypkfqro\nsshgcxsky\ngecntpcmoojfwp\nsvmytmcfhc\njrsrvsvbaiumlmkptn\ns\nwpcsovfjlyspviflk\nktvyzvddgllht\nszahigtmklglrcocbo\nznligfxkgxzkcfeu\nliryvzmqwhr\nxgrxkgiehxztv\netrjxdczppafly\njrdgajschhwsci\ndoxnxbjwptnimjmsuijx\nzciwkbvrhgsjhrr\nehh\nbzlnmd\nxpbtbpftimnn\nkhbknqbvdkdd\nmldj\nskrvnyz\navptgpjmenfzfxwckmt",
"output": "aa"
},
{
"input": "30\ne\nx\nitaubd\nxcn\nv\nx\ni\nci\naqs\nzbi\nq\ncvdu\na\njos\nqy\nfjf\nnayke\nge\ns\nq\nqwad\ngvz\no\nubn\nnzoc\nh\nwnjwjrf\nt\nbq\nbw",
"output": "l"
},
{
"input": "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu",
"output": "e"
},
{
"input": "5\nojdfhi\nabcdefghijklmnopqrst\nuvwxyz\nddfhdfhlasjt\nqqq",
"output": "aa"
},
{
"input": "5\ndfijdfhi\nabcdefghijklmnopqrst\nuvwxy\nkopsdfgiopjipw\njty",
"output": "z"
},
{
"input": "5\nzzxpfk\nabcdefghijklmnopqrst\nuvwxz\nsrgkjaskldfkln\nvgnsdfdgfh",
"output": "y"
}
] | 1,663,147,461 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 154 | 2,252,800 | import math
def functie_divizori(numar):
dictionar={}
matrice=[]
if numar==1:
a=[1]*2
a.append(0)
a.append(0)
matrice.append(a)
else:
for j in range(1,math.floor(numar**(1/2))+1):
# print("j=",j)
if numar%j==0:
tupleta=[]
# print(dictionar)
tupleta.append(j)
tupleta.append(numar//j)
tupleta.append(0)
tupleta.append(0)
matrice.append(tupleta)
tupleta=[]
if numar//j!=j:
tupleta=[]
tupleta.append(numar//j)
tupleta.append(j)
tupleta.append(0)
tupleta.append(0)
matrice.append(tupleta)
return matrice
#n,m,k=list(map(int, input().split()))
alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}
alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g", '8':"h", '9':"i", '10':"j", '11':"k", '12':"l", '13':"m", '14':"n", '15':"o", '16':"p", '17':"q", '18':"r", '19':"s", '20':"t", '21':"u", '22':"v", '23':"w", '24':"x", '25':"y", '26':"z"}
dictionar_1={}
dictionar_2={}
dictionar_1=alfabet
for i in range(1,27):
for j in range(1,27):
element=alfabet_2[str(i)] + alfabet_2[str(j)]
dictionar_2[element]=(i-1)*26+j
dictionar_unu=dict(dictionar_1)
dictionar_doi=dict(dictionar_2)
#print(dictionar_1)
#print(dictionar_2)
cazuri=int(input())
#vector_a=list(map(int,input().split()))
#vector_b=list(map(int,input().split()))
#print(functie_divizori(2))
for tt in range(cazuri):
#print("tt=",tt)
#n,x=map(int,input().split())
# bloc=list(map(int, input().split()))
#bloc.sort()
# bloc=bloc[::-1]
#print(functie_divizori(9))
s=input()
for i in dictionar_1:
if i in s:
if i in dictionar_unu:
del dictionar_unu[i]
for x in dictionar_2:
if x in s:
if x in dictionar_doi:
del dictionar_doi[x]
maximul=1000
answ=''
if len(dictionar_unu)>0:
for j in dictionar_unu:
if dictionar_unu[j]<maximul:
maximul=dictionar_unu[j]
answ=j
else:
for j in dictionar_doi:
if dictionar_doi[j]<maximul:
maximul=dictionar_doi[j]
answ=j
print(answ) | Title: New Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is string *s**l**s**l*<=+<=1... *s**r*.
String *x*<==<=*x*1*x*2... *x**p* is lexicographically smaller than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=<<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there exists such number *r* (*r*<=<<=*p*,<=*r*<=<<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=<<=*y**r*<=+<=1. The string characters are compared by their ASCII codes.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.
Output Specification:
Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.
Demo Input:
['5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n', '4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n']
Demo Output:
['j\n', 'ab\n']
Note:
In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | ```python
import math
def functie_divizori(numar):
dictionar={}
matrice=[]
if numar==1:
a=[1]*2
a.append(0)
a.append(0)
matrice.append(a)
else:
for j in range(1,math.floor(numar**(1/2))+1):
# print("j=",j)
if numar%j==0:
tupleta=[]
# print(dictionar)
tupleta.append(j)
tupleta.append(numar//j)
tupleta.append(0)
tupleta.append(0)
matrice.append(tupleta)
tupleta=[]
if numar//j!=j:
tupleta=[]
tupleta.append(numar//j)
tupleta.append(j)
tupleta.append(0)
tupleta.append(0)
matrice.append(tupleta)
return matrice
#n,m,k=list(map(int, input().split()))
alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}
alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g", '8':"h", '9':"i", '10':"j", '11':"k", '12':"l", '13':"m", '14':"n", '15':"o", '16':"p", '17':"q", '18':"r", '19':"s", '20':"t", '21':"u", '22':"v", '23':"w", '24':"x", '25':"y", '26':"z"}
dictionar_1={}
dictionar_2={}
dictionar_1=alfabet
for i in range(1,27):
for j in range(1,27):
element=alfabet_2[str(i)] + alfabet_2[str(j)]
dictionar_2[element]=(i-1)*26+j
dictionar_unu=dict(dictionar_1)
dictionar_doi=dict(dictionar_2)
#print(dictionar_1)
#print(dictionar_2)
cazuri=int(input())
#vector_a=list(map(int,input().split()))
#vector_b=list(map(int,input().split()))
#print(functie_divizori(2))
for tt in range(cazuri):
#print("tt=",tt)
#n,x=map(int,input().split())
# bloc=list(map(int, input().split()))
#bloc.sort()
# bloc=bloc[::-1]
#print(functie_divizori(9))
s=input()
for i in dictionar_1:
if i in s:
if i in dictionar_unu:
del dictionar_unu[i]
for x in dictionar_2:
if x in s:
if x in dictionar_doi:
del dictionar_doi[x]
maximul=1000
answ=''
if len(dictionar_unu)>0:
for j in dictionar_unu:
if dictionar_unu[j]<maximul:
maximul=dictionar_unu[j]
answ=j
else:
for j in dictionar_doi:
if dictionar_doi[j]<maximul:
maximul=dictionar_doi[j]
answ=j
print(answ)
``` | 3 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,694,238,356 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 31 | 0 | x=int(input())
c=0
for i in range(x):
a,b=map(int,input().split())
if (b-a)>=2:
c+=1
print(c) | Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
x=int(input())
c=0
for i in range(x):
a,b=map(int,input().split())
if (b-a)>=2:
c+=1
print(c)
``` | 3 |
|
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3"
},
{
"input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2",
"output": "7\n7"
},
{
"input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1",
"output": "7"
},
{
"input": "2 2\n8 4\n1\n1",
"output": "2\n2"
},
{
"input": "1 5\n5\n1\n1\n1\n1\n1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4",
"output": "1\n4\n3\n2\n3\n1\n1"
},
{
"input": "4 3\n9 1 7 1\n1\n4\n2",
"output": "3\n1\n2"
},
{
"input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7",
"output": "4\n3\n2"
},
{
"input": "1 1\n1\n1",
"output": "1"
}
] | 1,668,066,341 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 46 | 4,915,200 | # https://codeforces.com/problemset/problem/368/B
n, m = map(int, input().split())
a = list(map(int, input().split()))
buf = {1: len(set(a))}
def func(i: int) -> int:
if i in buf:
return buf[i]
pre = func(i-1)
try:
a.index(a[i-2], i-1)
except ValueError:
pre -= 1
buf[i] = pre
return pre
for _ in range(m):
print(func(int(input())))
| Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Output Specification:
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
Demo Input:
['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n']
Demo Output:
['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n']
Note:
none | ```python
# https://codeforces.com/problemset/problem/368/B
n, m = map(int, input().split())
a = list(map(int, input().split()))
buf = {1: len(set(a))}
def func(i: int) -> int:
if i in buf:
return buf[i]
pre = func(i-1)
try:
a.index(a[i-2], i-1)
except ValueError:
pre -= 1
buf[i] = pre
return pre
for _ in range(m):
print(func(int(input())))
``` | -1 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,694,542,263 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 280 | 11,980,800 | _list = [input() for _ in range(int(input()))]
print(len([i for i in range(len(_list) - 1) if _list[i] != _list[i + 1]]) + 1) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
_list = [input() for _ in range(int(input()))]
print(len([i for i in range(len(_list) - 1) if _list[i] != _list[i + 1]]) + 1)
``` | 3 |
|
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,653,751,459 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | def pos(n,f,d):
return n-max(f+1,n-b)+1;
n,f,b=map(int,input().split(' '))
print(pos(n,f,b)) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
def pos(n,f,d):
return n-max(f+1,n-b)+1;
n,f,b=map(int,input().split(' '))
print(pos(n,f,b))
``` | 3 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,698,425,744 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | x = int(input()) # Read the coordinate of the friend's house
steps = (x + 4) // 5 # Calculate the minimum number of steps
print(steps) # Output the minimum number of steps | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
x = int(input()) # Read the coordinate of the friend's house
steps = (x + 4) // 5 # Calculate the minimum number of steps
print(steps) # Output the minimum number of steps
``` | 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,458,421,100 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 46 | 4,608,000 | n = int(input())
li = sorted(set(map(int,input().split())))
for i in range(2,n):
if li[i]-li[i-2]==2:
print('YES')
exit()
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
n = int(input())
li = sorted(set(map(int,input().split())))
for i in range(2,n):
if li[i]-li[i-2]==2:
print('YES')
exit()
print('NO')
``` | -1 |
|
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n2 2 1 1 1",
"output": "2"
},
{
"input": "7\n1 1 2 2 1 2 1",
"output": "3"
},
{
"input": "10\n1 2 2 1 2 2 1 2 1 1",
"output": "5"
},
{
"input": "5\n2 2 2 1 2",
"output": "1"
},
{
"input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2",
"output": "10"
},
{
"input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2",
"output": "34"
},
{
"input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2",
"output": "32"
},
{
"input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2",
"output": "9"
},
{
"input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1",
"output": "11"
},
{
"input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2",
"output": "100"
},
{
"input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2",
"output": "123"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "3\n2 2 1",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "1"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n1 1 1 1 2",
"output": "2"
},
{
"input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "38\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2",
"output": "1"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "3"
},
{
"input": "5\n2 1 1 1 1",
"output": "2"
},
{
"input": "9\n1 1 1 1 1 1 2 2 2",
"output": "4"
},
{
"input": "10\n2 2 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "2"
}
] | 1,632,347,275 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 187 | 32,665,600 | n=int(input())
a=[*map(int,input().split())]
print(max((a.count(1)-min(a.count(2),a.count(1)))//3+min(a.count(2),a.count(1)),min(a.count(2),a.count(1)),a.count(1)//3,0))
| Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Output Specification:
Print the maximum number of teams of three people the coach can form.
Demo Input:
['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n']
Demo Output:
['1\n', '0\n', '3\n', '1\n']
Note:
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | ```python
n=int(input())
a=[*map(int,input().split())]
print(max((a.count(1)-min(a.count(2),a.count(1)))//3+min(a.count(2),a.count(1)),min(a.count(2),a.count(1)),a.count(1)//3,0))
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.