contestId
int64 0
1.01k
| index
stringclasses 26
values | name
stringlengths 2
54
| type
stringclasses 2
values | rating
int64 0
2.9k
| tags
sequencelengths 0
6
| title
stringclasses 201
values | time-limit
stringclasses 6
values | memory-limit
stringclasses 4
values | problem-description
stringlengths 0
2.61k
| input-specification
stringlengths 4
1.44k
| output-specification
stringlengths 4
969
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
3k
| test_cases
listlengths 1
314
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 22
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 1
value | testset
stringclasses 3
values | passedTestCount
int64 2
360
| timeConsumedMillis
int64 31
3.65k
| memoryConsumedBytes
int64 0
263M
| code
stringlengths 24
23.8k
| prompt
stringlengths 312
7.33k
| response
stringlengths 38
23.8k
| score
float64 3
3.99
| state
stringlengths 0
21.4k
| correct_completion
stringlengths 1
236
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=200) β the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. | Print a single integer β the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n"
] | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",
"output": "2"
},
{
"input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp",
"output": "2"
},
{
"input": "1\niuNtwVf reposted POlYcarP",
"output": "2"
},
{
"input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS",
"output": "11"
},
{
"input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl",
"output": "6"
},
{
"input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj",
"output": "9"
},
{
"input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI",
"output": "3"
}
] | 1,644,752,893 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
name = [0, 'polycarp']
rb = [[] for i in range(2)]
for _ in range(n):
a, c, b = input().split()
a = a.lower()
b = b.lower()
name.append(a)
rb.append([])
rb[-1].append(name.index(b))
rb[name.index(b)].append(_ + 2)
use = [0] * (len(rb))
d = [10 ** 9] * (len(rb))
d[1] = 0
oc = [1]
def bfs(v):
global oc
use[v] = 1
for i in rb[v]:
if use[i] == 0:
d[i] = min(d[i], d[v] + 1)
oc.append(i)
oc = oc[1:]
while len(oc) > 0:
bfs(oc[0])
d[0] = -10
print(max(d) + 1)
| Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
Input Specification:
The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=200) β the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Output Specification:
Print a single integer β the maximum length of a repost chain.
Demo Input:
['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n']
Demo Output:
['6\n', '2\n', '2\n']
Note:
none | ```python
n = int(input())
name = [0, 'polycarp']
rb = [[] for i in range(2)]
for _ in range(n):
a, c, b = input().split()
a = a.lower()
b = b.lower()
name.append(a)
rb.append([])
rb[-1].append(name.index(b))
rb[name.index(b)].append(_ + 2)
use = [0] * (len(rb))
d = [10 ** 9] * (len(rb))
d[1] = 0
oc = [1]
def bfs(v):
global oc
use[v] = 1
for i in rb[v]:
if use[i] == 0:
d[i] = min(d[i], d[v] + 1)
oc.append(i)
oc = oc[1:]
while len(oc) > 0:
bfs(oc[0])
d[0] = -10
print(max(d) + 1)
``` | 3 | n = int(input())
name = [0, 'polycarp']
rb = [[] for i in range(2)]
for _ in range(n):
a, c, b = input().split()
a = a.lower()
b = b.lower()
name.append(a)
rb.append([])
rb[-1].append(name.index(b))
rb[name.index(b)].append(_ + 2)
use = [0] * (len(rb))
d = [10 ** 9] * (len(rb))
d[1] = 0
oc = [1]
def bfs(v):
global oc
| use[v] = 1
for i in rb[v]:
if use[i] == 0:
|
|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=1015, 1<=β€<=*k*<=β€<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"output": "-1"
},
{
"input": "1000000000000000 1000000000",
"output": "-1"
},
{
"input": "1000000000000000 100",
"output": "1953125"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "9 3",
"output": "9"
},
{
"input": "21 3",
"output": "7"
},
{
"input": "67280421310721 1",
"output": "1"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "16 3",
"output": "4"
},
{
"input": "1 1000",
"output": "-1"
},
{
"input": "16 4",
"output": "8"
},
{
"input": "36 8",
"output": "18"
},
{
"input": "49 4",
"output": "-1"
},
{
"input": "9 4",
"output": "-1"
},
{
"input": "16 1",
"output": "1"
},
{
"input": "16 6",
"output": "-1"
},
{
"input": "16 5",
"output": "16"
},
{
"input": "25 4",
"output": "-1"
},
{
"input": "4010815561 2",
"output": "63331"
},
{
"input": "49 3",
"output": "49"
},
{
"input": "36 6",
"output": "9"
},
{
"input": "36 10",
"output": "-1"
},
{
"input": "25 3",
"output": "25"
},
{
"input": "22876792454961 28",
"output": "7625597484987"
},
{
"input": "1234 2",
"output": "2"
},
{
"input": "179458711 2",
"output": "179458711"
},
{
"input": "900104343024121 100000",
"output": "-1"
},
{
"input": "8 3",
"output": "4"
},
{
"input": "100 6",
"output": "20"
},
{
"input": "15500 26",
"output": "-1"
},
{
"input": "111111 1",
"output": "1"
},
{
"input": "100000000000000 200",
"output": "160000000000"
},
{
"input": "1000000000000 100",
"output": "6400000"
},
{
"input": "100 10",
"output": "-1"
},
{
"input": "1000000000039 2",
"output": "1000000000039"
},
{
"input": "64 5",
"output": "16"
},
{
"input": "999999961946176 33",
"output": "63245552"
},
{
"input": "376219076689 3",
"output": "376219076689"
},
{
"input": "999999961946176 63",
"output": "999999961946176"
},
{
"input": "1048576 12",
"output": "2048"
},
{
"input": "745 21",
"output": "-1"
},
{
"input": "748 6",
"output": "22"
},
{
"input": "999999961946176 50",
"output": "161082468097"
},
{
"input": "10 3",
"output": "5"
},
{
"input": "1099511627776 22",
"output": "2097152"
},
{
"input": "1000000007 100010",
"output": "-1"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "100 8",
"output": "50"
},
{
"input": "100 7",
"output": "25"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "999999961946176 64",
"output": "-1"
},
{
"input": "20 5",
"output": "10"
},
{
"input": "999999999999989 2",
"output": "999999999999989"
},
{
"input": "100000000000000 114",
"output": "10240000"
},
{
"input": "99999640000243 3",
"output": "9999991"
},
{
"input": "999998000001 566",
"output": "333332666667"
},
{
"input": "99999820000081 2",
"output": "9999991"
},
{
"input": "49000042000009 3",
"output": "49000042000009"
},
{
"input": "151491429961 4",
"output": "-1"
},
{
"input": "32416190071 2",
"output": "32416190071"
},
{
"input": "1000 8",
"output": "25"
},
{
"input": "1999967841 15",
"output": "1999967841"
},
{
"input": "26880 26880",
"output": "-1"
},
{
"input": "151491429961 3",
"output": "151491429961"
},
{
"input": "90000000000 300",
"output": "100000000"
},
{
"input": "98765004361 10",
"output": "-1"
},
{
"input": "15 2",
"output": "3"
},
{
"input": "16 2",
"output": "2"
},
{
"input": "1996 2",
"output": "2"
},
{
"input": "1997 2",
"output": "1997"
},
{
"input": "1999 2",
"output": "1999"
},
{
"input": "1998 2",
"output": "2"
},
{
"input": "1998 1",
"output": "1"
},
{
"input": "1998 7",
"output": "27"
},
{
"input": "1998 8",
"output": "37"
},
{
"input": "100000380000361 2",
"output": "10000019"
},
{
"input": "15 1",
"output": "1"
},
{
"input": "100000000000000 226",
"output": "-1"
},
{
"input": "844030857550613 517",
"output": "-1"
},
{
"input": "4567890 14",
"output": "430"
},
{
"input": "123123123 123123123",
"output": "-1"
},
{
"input": "24 4",
"output": "4"
},
{
"input": "999999993568952 17",
"output": "31622777"
},
{
"input": "99999999994190 9",
"output": "241656799"
},
{
"input": "999997874844049 4",
"output": "-1"
},
{
"input": "99999999999931 2",
"output": "99999999999931"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "67280421310721 2",
"output": "67280421310721"
}
] | 1,649,345,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 701 | 3,072,000 | import sys
input = sys.stdin.readline
def prime(num):
b=num
for i in range(2,num):
if i*i>num:
break
if b%i==0:
return False
return True
for i in range(1):
n,k=map(int,input().split())
L=[]
for i in range(1,int(n**.5)+1):
if n%i==0:
L.append(i)
if i*i!=n:
L.append(n//i)
L.sort()
if len(L)<k:
print(-1)
else:
print(L[k-1])
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specification:
The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=1015, 1<=β€<=*k*<=β€<=109).
Output Specification:
If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*.
Demo Input:
['4 2\n', '5 3\n', '12 5\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | ```python
import sys
input = sys.stdin.readline
def prime(num):
b=num
for i in range(2,num):
if i*i>num:
break
if b%i==0:
return False
return True
for i in range(1):
n,k=map(int,input().split())
L=[]
for i in range(1,int(n**.5)+1):
if n%i==0:
L.append(i)
if i*i!=n:
L.append(n//i)
L.sort()
if len(L)<k:
print(-1)
else:
print(L[k-1])
``` | 3 | import sys
input = sys.stdin.readline
def prime(num):
b=num
for i in range(2,num):
if i*i>num:
| break
if b%i==0:
return False
return True
for i in range(1):
|
|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,687,438,786 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | s1=input()
s2=input()
count=0
for x in range(len(s2)):
if s1[count]==s2[x]:
count+=1
print(count+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
s1=input()
s2=input()
count=0
for x in range(len(s2)):
if s1[count]==s2[x]:
count+=1
print(count+1)
``` | 3 | s1=input()
s2=input()
count=0
for x in range(len(s2)):
| if s1[count]==s2[x]:
count+=1
|
|
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=β€<=*a*<=<<=*b*<=<<=*c*<=β€<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=β€<=*a*<=<<=*b*<=<<=*c*<=β€<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. | The single line contains two positive space-separated integers *l*, *r* (1<=β€<=*l*<=β€<=*r*<=β€<=1018; *r*<=-<=*l*<=β€<=50). | Print three positive space-separated integers *a*, *b*, *c*Β β three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2,β4) is not coprime and pairs (2,β3) and (3,β4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "640097987171091792 640097987171091793 640097987171091794"
},
{
"input": "19534350415104721 19534350415104725",
"output": "19534350415104722 19534350415104723 19534350415104724"
},
{
"input": "933700505788726243 933700505788726280",
"output": "933700505788726244 933700505788726245 933700505788726246"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "2 3 4"
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "266540997167959130 266540997167959164",
"output": "266540997167959130 266540997167959131 266540997167959132"
},
{
"input": "267367244641009850 267367244641009899",
"output": "267367244641009850 267367244641009851 267367244641009852"
},
{
"input": "268193483524125978 268193483524125993",
"output": "268193483524125978 268193483524125979 268193483524125980"
},
{
"input": "269019726702209402 269019726702209432",
"output": "269019726702209402 269019726702209403 269019726702209404"
},
{
"input": "269845965585325530 269845965585325576",
"output": "269845965585325530 269845965585325531 269845965585325532"
},
{
"input": "270672213058376250 270672213058376260",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492378",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608523",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691962",
"output": "273150934002691930 273150934002691931 273150934002691932"
},
{
"input": "996517375802030516 996517375802030524",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146694",
"output": "997343614685146644 997343614685146645 997343614685146646"
},
{
"input": "998169857863230068 998169857863230083",
"output": "998169857863230068 998169857863230069 998169857863230070"
},
{
"input": "998996101041313492 998996101041313522",
"output": "998996101041313492 998996101041313493 998996101041313494"
},
{
"input": "999822344219396916 999822344219396961",
"output": "999822344219396916 999822344219396917 999822344219396918"
},
{
"input": "648583102513043 648583102513053",
"output": "648583102513044 648583102513045 648583102513046"
},
{
"input": "266540997167959130 266540997167959131",
"output": "-1"
},
{
"input": "267367244641009850 267367244641009850",
"output": "-1"
},
{
"input": "268193483524125978 268193483524125979",
"output": "-1"
},
{
"input": "269019726702209402 269019726702209402",
"output": "-1"
},
{
"input": "269845965585325530 269845965585325530",
"output": "-1"
},
{
"input": "270672213058376250 270672213058376254",
"output": "270672213058376250 270672213058376251 270672213058376252"
},
{
"input": "271498451941492378 271498451941492379",
"output": "-1"
},
{
"input": "272324690824608506 272324690824608508",
"output": "272324690824608506 272324690824608507 272324690824608508"
},
{
"input": "273150934002691930 273150934002691931",
"output": "-1"
},
{
"input": "996517375802030516 996517375802030518",
"output": "996517375802030516 996517375802030517 996517375802030518"
},
{
"input": "997343614685146644 997343614685146644",
"output": "-1"
},
{
"input": "2147483647 2147483649",
"output": "-1"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "1 7",
"output": "2 3 4"
},
{
"input": "9 12",
"output": "9 11 12"
},
{
"input": "4 4",
"output": "-1"
},
{
"input": "11 13",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
}
] | 1,650,174,686 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 46 | 0 | l , r = list(map(int,input().split()))
if r - l > 2 :
a = (l+1)//2 * 2
print(a,a+1,a+2)
elif r - l == 2 :
if l % 2 == 0 :
print(l,l+1,r)
else :
print('-1')
else :
print('-1') | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=β€<=*a*<=<<=*b*<=<<=*c*<=β€<=*r*.
More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=β€<=*a*<=<<=*b*<=<<=*c*<=β€<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
Input Specification:
The single line contains two positive space-separated integers *l*, *r* (1<=β€<=*l*<=β€<=*r*<=β€<=1018; *r*<=-<=*l*<=β€<=50).
Output Specification:
Print three positive space-separated integers *a*, *b*, *c*Β β three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
Demo Input:
['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n']
Demo Output:
['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n']
Note:
In the first sample pair (2,β4) is not coprime and pairs (2,β3) and (3,β4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | ```python
l , r = list(map(int,input().split()))
if r - l > 2 :
a = (l+1)//2 * 2
print(a,a+1,a+2)
elif r - l == 2 :
if l % 2 == 0 :
print(l,l+1,r)
else :
print('-1')
else :
print('-1')
``` | 3 | l , r = list(map(int,input().split()))
if r - l > 2 :
a = (l | +1)//2 * 2
print(a,a+1,a+2)
elif r - l == |
|
914 | B | Conan and Agasa play a Card Game | PROGRAMMING | 1,200 | [
"games",
"greedy",
"implementation"
] | null | null | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the *i*-th card, he removes that card and removes the *j*-th card for all *j* such that *a**j*<=<<=*a**i*.
A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally. | The first line contains an integer *n* (1<=β€<=*n*<=β€<=105)Β β the number of cards Conan has.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105), where *a**i* is the number on the *i*-th card. | If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). | [
"3\n4 5 7\n",
"2\n1 1\n"
] | [
"Conan\n",
"Agasa\n"
] | In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again. | 1,000 | [
{
"input": "3\n4 5 7",
"output": "Conan"
},
{
"input": "2\n1 1",
"output": "Agasa"
},
{
"input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282",
"output": "Conan"
},
{
"input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165",
"output": "Agasa"
},
{
"input": "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176",
"output": "Conan"
},
{
"input": "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846",
"output": "Conan"
},
{
"input": "3\n1 2 3",
"output": "Conan"
},
{
"input": "4\n2 3 4 5",
"output": "Conan"
},
{
"input": "10\n30757 30757 33046 41744 39918 39914 41744 39914 33046 33046",
"output": "Conan"
},
{
"input": "10\n50096 50096 50096 50096 50096 50096 28505 50096 50096 50096",
"output": "Conan"
},
{
"input": "10\n54842 54842 54842 54842 57983 54842 54842 57983 57983 54842",
"output": "Conan"
},
{
"input": "10\n87900 87900 5761 87900 87900 87900 5761 87900 87900 87900",
"output": "Agasa"
},
{
"input": "10\n53335 35239 26741 35239 35239 26741 35239 35239 53335 35239",
"output": "Agasa"
},
{
"input": "10\n75994 64716 75994 64716 75994 75994 56304 64716 56304 64716",
"output": "Agasa"
},
{
"input": "1\n1",
"output": "Conan"
},
{
"input": "5\n2 2 1 1 1",
"output": "Conan"
},
{
"input": "5\n1 4 4 5 5",
"output": "Conan"
},
{
"input": "3\n1 3 3",
"output": "Conan"
},
{
"input": "3\n2 2 2",
"output": "Conan"
},
{
"input": "5\n1 1 1 2 2",
"output": "Conan"
},
{
"input": "4\n1 2 1 2",
"output": "Agasa"
},
{
"input": "7\n7 7 7 7 6 6 6",
"output": "Conan"
},
{
"input": "3\n2 3 3",
"output": "Conan"
},
{
"input": "3\n1 1 100000",
"output": "Conan"
},
{
"input": "1\n100000",
"output": "Conan"
},
{
"input": "5\n3 3 3 4 4",
"output": "Conan"
},
{
"input": "3\n1 2 2",
"output": "Conan"
},
{
"input": "3\n4 4 5",
"output": "Conan"
},
{
"input": "1\n2",
"output": "Conan"
},
{
"input": "3\n97 97 100",
"output": "Conan"
},
{
"input": "5\n100000 100000 100000 1 1",
"output": "Conan"
},
{
"input": "7\n7 7 6 6 5 5 4",
"output": "Conan"
},
{
"input": "5\n100000 100000 100000 2 2",
"output": "Conan"
},
{
"input": "4\n3 3 2 1",
"output": "Conan"
},
{
"input": "1\n485",
"output": "Conan"
},
{
"input": "3\n4 4 100000",
"output": "Conan"
},
{
"input": "3\n1 1 2",
"output": "Conan"
},
{
"input": "3\n1 1 1",
"output": "Conan"
},
{
"input": "5\n1 1 2 2 2",
"output": "Conan"
}
] | 1,586,806,714 | 2,147,483,647 | Python 3 | OK | TESTS | 91 | 171 | 7,782,400 | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
if a.count(max(a)) % 2 == 1:
print("Conan")
else:
c = Counter(a)
li = []
for x in c:
li += [x]
li.sort(reverse=True)
for x in li:
if c[x] % 2 == 1:
print("Conan")
exit()
print("Agasa")
| Title: Conan and Agasa play a Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the *i*-th card, he removes that card and removes the *j*-th card for all *j* such that *a**j*<=<<=*a**i*.
A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.
Input Specification:
The first line contains an integer *n* (1<=β€<=*n*<=β€<=105)Β β the number of cards Conan has.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105), where *a**i* is the number on the *i*-th card.
Output Specification:
If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).
Demo Input:
['3\n4 5 7\n', '2\n1 1\n']
Demo Output:
['Conan\n', 'Agasa\n']
Note:
In the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.
In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again. | ```python
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
if a.count(max(a)) % 2 == 1:
print("Conan")
else:
c = Counter(a)
li = []
for x in c:
li += [x]
li.sort(reverse=True)
for x in li:
if c[x] % 2 == 1:
print("Conan")
exit()
print("Agasa")
``` | 3 | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
if a.count(max(a)) % 2 == 1:
print("Conan")
else:
c = Counter(a)
li = []
for x in c:
li += [x]
li.sort(reverse=True)
for x in li:
if c[x] % 2 == | 1:
print("Conan")
exit()
print("Agasa")
|
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,637,729,615 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | text=input()
lc_count=0
uc_count=0
for i in range(len(text)):
if text[i].isupper():
uc_count+=1
elif text[i].islower():
lc_count+=1
if uc_count<lc_count:
print(text.lower())
elif uc_count>lc_count:
print(text.upper())
else:
print(text.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
text=input()
lc_count=0
uc_count=0
for i in range(len(text)):
if text[i].isupper():
uc_count+=1
elif text[i].islower():
lc_count+=1
if uc_count<lc_count:
print(text.lower())
elif uc_count>lc_count:
print(text.upper())
else:
print(text.lower())
``` | 3.977 | text=input()
lc_count=0
uc_count=0
for i in range(len(text)):
if text[i].isupper():
uc_count+=1
elif text[i].islower():
lc_count+=1
if uc_count<lc_count:
print(text.lower())
elif uc_count>lc_count:
print(text.upper())
| else:
print(text.lower()) |
682 | B | Alyona and Mex | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=β€<=*b**i*<=β€<=*a**i* for every 1<=β€<=*i*<=β€<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109)Β β the elements of the array. | Print one positive integerΒ β the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | [
"5\n1 3 3 3 6\n",
"2\n2 1\n"
] | [
"5\n",
"3\n"
] | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | 1,000 | [
{
"input": "5\n1 3 3 3 6",
"output": "5"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "1\n1000000000",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n1 3",
"output": "3"
},
{
"input": "2\n2 2",
"output": "3"
},
{
"input": "2\n2 3",
"output": "3"
},
{
"input": "2\n3 3",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "3"
},
{
"input": "3\n3 1 1",
"output": "3"
},
{
"input": "3\n1 1 4",
"output": "3"
},
{
"input": "3\n2 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "4"
},
{
"input": "3\n2 4 1",
"output": "4"
},
{
"input": "3\n3 3 1",
"output": "4"
},
{
"input": "3\n1 3 4",
"output": "4"
},
{
"input": "3\n4 1 4",
"output": "4"
},
{
"input": "3\n2 2 2",
"output": "3"
},
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "3\n4 2 2",
"output": "4"
},
{
"input": "3\n2 3 3",
"output": "4"
},
{
"input": "3\n4 2 3",
"output": "4"
},
{
"input": "3\n4 4 2",
"output": "4"
},
{
"input": "3\n3 3 3",
"output": "4"
},
{
"input": "3\n4 3 3",
"output": "4"
},
{
"input": "3\n4 3 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "4\n1 1 1 1",
"output": "2"
},
{
"input": "4\n1 1 2 1",
"output": "3"
},
{
"input": "4\n1 1 3 1",
"output": "3"
},
{
"input": "4\n1 4 1 1",
"output": "3"
},
{
"input": "4\n1 2 1 2",
"output": "3"
},
{
"input": "4\n1 3 2 1",
"output": "4"
},
{
"input": "4\n2 1 4 1",
"output": "4"
},
{
"input": "4\n3 3 1 1",
"output": "4"
},
{
"input": "4\n1 3 4 1",
"output": "4"
},
{
"input": "4\n1 1 4 4",
"output": "4"
},
{
"input": "4\n2 2 2 1",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "4"
},
{
"input": "4\n2 4 1 2",
"output": "4"
},
{
"input": "4\n3 3 1 2",
"output": "4"
},
{
"input": "4\n2 3 4 1",
"output": "5"
},
{
"input": "4\n1 4 2 4",
"output": "5"
},
{
"input": "4\n3 1 3 3",
"output": "4"
},
{
"input": "4\n3 4 3 1",
"output": "5"
},
{
"input": "4\n1 4 4 3",
"output": "5"
},
{
"input": "4\n4 1 4 4",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "4\n2 2 3 2",
"output": "4"
},
{
"input": "4\n2 2 2 4",
"output": "4"
},
{
"input": "4\n2 2 3 3",
"output": "4"
},
{
"input": "4\n2 2 3 4",
"output": "5"
},
{
"input": "4\n2 4 4 2",
"output": "5"
},
{
"input": "4\n2 3 3 3",
"output": "4"
},
{
"input": "4\n2 4 3 3",
"output": "5"
},
{
"input": "4\n4 4 2 3",
"output": "5"
},
{
"input": "4\n4 4 4 2",
"output": "5"
},
{
"input": "4\n3 3 3 3",
"output": "4"
},
{
"input": "4\n3 3 3 4",
"output": "5"
},
{
"input": "4\n4 3 3 4",
"output": "5"
},
{
"input": "4\n4 4 3 4",
"output": "5"
},
{
"input": "4\n4 4 4 4",
"output": "5"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 3 3",
"output": "4"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8",
"output": "9"
},
{
"input": "4\n2 2 2 3",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100",
"output": "15"
},
{
"input": "7\n1 2 2 2 5 5 1",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "5\n1 1 1 1 10000",
"output": "3"
},
{
"input": "5\n1 1 1 1 2",
"output": "3"
},
{
"input": "7\n1 3 3 3 3 3 6",
"output": "5"
},
{
"input": "4\n1 1 1 3",
"output": "3"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 100",
"output": "3"
},
{
"input": "4\n1 1 2 2",
"output": "3"
},
{
"input": "5\n1 1 1 3 4",
"output": "4"
},
{
"input": "8\n1 1 1 1 2 2 3 40",
"output": "5"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "7\n1 2 2 2 2 2 4",
"output": "4"
},
{
"input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 3",
"output": "4"
},
{
"input": "4\n8 8 8 8",
"output": "5"
},
{
"input": "5\n5 6 6 6 7",
"output": "6"
}
] | 1,587,918,234 | 2,147,483,647 | Python 3 | OK | TESTS | 127 | 187 | 9,216,000 | t = int(input())
l=[]
l.extend( map(int, input().split()))
# print(l)
# for _ in range(t):
# l.append(int(input()))
l.sort()
ans=1
for i in range(len(l)):
if ans <= l[i]:
ans+=1
print(ans) | Title: Alyona and Mex
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=β€<=*b**i*<=β€<=*a**i* for every 1<=β€<=*i*<=β€<=*n*. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
Input Specification:
The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of elements in the Alyona's array.
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109)Β β the elements of the array.
Output Specification:
Print one positive integerΒ β the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
Demo Input:
['5\n1 3 3 3 6\n', '2\n2 1\n']
Demo Output:
['5\n', '3\n']
Note:
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | ```python
t = int(input())
l=[]
l.extend( map(int, input().split()))
# print(l)
# for _ in range(t):
# l.append(int(input()))
l.sort()
ans=1
for i in range(len(l)):
if ans <= l[i]:
ans+=1
print(ans)
``` | 3 | t = int(input())
l=[]
l.extend( map(int, input().split()))
# print(l)
# for | _ in range(t):
# l.append(int(input()))
l.sort()
ans=1
for i in range(len(l)):
|
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=β€<=*m*<=β€<=*n*<=β€<=100) β amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=β€<=*a**i*<=β€<=1000) β prices of the TV sets. | Output the only number β the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,646,324,931 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | k,m = map(int,input().split(" "))
l = list(map(int,input().split(" ")))
s = []
for i in range(m):
if(min(l)<0):
s.append(min(l))
l.remove(min(l))
else:
if(not s):
s.append(0)
break
if(sum(s)<0):
print(sum(s)*-1)
else:
print(sum(s)) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price β their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=β€<=*m*<=β€<=*n*<=β€<=100) β amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=β€<=*a**i*<=β€<=1000) β prices of the TV sets.
Output Specification:
Output the only number β the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
k,m = map(int,input().split(" "))
l = list(map(int,input().split(" ")))
s = []
for i in range(m):
if(min(l)<0):
s.append(min(l))
l.remove(min(l))
else:
if(not s):
s.append(0)
break
if(sum(s)<0):
print(sum(s)*-1)
else:
print(sum(s))
``` | 3.9845 | k,m = map(int,input().split(" "))
l = list(map(int,input().split(" ")))
s = []
for i in range(m):
if(min(l)<0):
s.append(min(l))
l.remove(min(l))
else:
if(not s):
s.append(0)
break
if(sum(s)<0):
print(sum | (s)*-1)
else:
print(sum(s)) |
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,136,800 | 2,147,483,647 | Python 3 | OK | TESTS | 168 | 46 | 0 | import math
n,k = map(int,input().split())
if k > n**2:
print(-1)
else:
m = math.ceil(math.sqrt(n**2-k))
gap = m**2 + k - n**2
matrix = []
for i in range(n):
if i <= n-m-1:
matrix.append(['1']*n)
else:
matrix.append(['1']*(n-m) + ['0']*m)
if gap != 0:
matrix[n-m][n-m] = '1'
gap -= 1
if gap % 2 == 1:
matrix[n-m+1][n-m+1] = '1'
gap -= 1
gap = gap//2
for x in range(n-m+1,n-m+1+gap):
matrix[n-m][x] = '1'
matrix[x][n-m] = '1'
for lst in matrix:
print(' '.join(lst)) | 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
import math
n,k = map(int,input().split())
if k > n**2:
print(-1)
else:
m = math.ceil(math.sqrt(n**2-k))
gap = m**2 + k - n**2
matrix = []
for i in range(n):
if i <= n-m-1:
matrix.append(['1']*n)
else:
matrix.append(['1']*(n-m) + ['0']*m)
if gap != 0:
matrix[n-m][n-m] = '1'
gap -= 1
if gap % 2 == 1:
matrix[n-m+1][n-m+1] = '1'
gap -= 1
gap = gap//2
for x in range(n-m+1,n-m+1+gap):
matrix[n-m][x] = '1'
matrix[x][n-m] = '1'
for lst in matrix:
print(' '.join(lst))
``` | 3 | import math
n,k = map(int,input().split())
if k > n**2:
print(-1)
else:
m = math.ceil(math.sqrt(n**2-k))
gap = m**2 + k - n**2
matrix = []
for i in range(n):
if i <= n-m-1:
matrix.append(['1']*n)
else:
matrix.append(['1']*(n-m) + ['0']*m)
if gap != 0:
matrix[n-m][n-m] = '1'
gap -= 1
if gap % 2 == 1:
matrix[n-m+1][n-m+1] = '1'
gap -= 1
gap = gap//2
for x in range(n-m | +1,n-m+1+gap):
matrix[n-m][x] = ' |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=β€<=*i*<=<<=*j*<=β€<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. | The first line of the input contains the single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances. | 0 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
"input": "2\n315 845\n-669 -762",
"output": "0"
},
{
"input": "3\n8911 7861\n-6888 7861\n8911 7861",
"output": "3"
},
{
"input": "2\n-1 1000000000\n0 -1",
"output": "0"
},
{
"input": "2\n1000000000 0\n-7 1",
"output": "0"
},
{
"input": "2\n1 4\n2 1",
"output": "0"
},
{
"input": "2\n1 0\n0 2333333",
"output": "0"
},
{
"input": "2\n2 1\n1 2",
"output": "0"
},
{
"input": "2\n1 1000000000\n2 -1000000000",
"output": "0"
},
{
"input": "2\n0 1000000000\n1 -7",
"output": "0"
},
{
"input": "2\n1 0\n0 19990213",
"output": "0"
}
] | 1,641,378,904 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 1,949 | 48,537,600 | from collections import defaultdict
n=int(input())
row=defaultdict(int)
col=defaultdict(int)
v=defaultdict(int)
ans=0
for _ in range(n):
a,b=map(int, input().split())
ans += row[a]
ans += col[b]
ans -= v[(a,b)]
row[a]+=1
col[b]+=1
v[(a,b)]+=1
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=β€<=*i*<=<<=*j*<=β€<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input Specification:
The first line of the input contains the single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109).
Some positions may coincide.
Output Specification:
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Demo Input:
['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n']
Demo Output:
['2\n', '11\n']
Note:
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1β-β7|β+β|1β-β5|β=β10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1,β1), (1,β5) and (7,β5), (1,β5) Doctor Manhattan and Daniel will calculate the same distances. | ```python
from collections import defaultdict
n=int(input())
row=defaultdict(int)
col=defaultdict(int)
v=defaultdict(int)
ans=0
for _ in range(n):
a,b=map(int, input().split())
ans += row[a]
ans += col[b]
ans -= v[(a,b)]
row[a]+=1
col[b]+=1
v[(a,b)]+=1
print(ans)
``` | 3 | from collections import defaultdict
n=int(input())
row=defaultdict(int)
col=defaultdict(int)
v=defaultdict(int)
ans=0
for _ in range(n):
| a,b=map(int, input().split())
ans += row[a]
ans += col[b]
ans -= v[( |
|
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 1,600,571,698 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 109 | 0 | n=int(input())-1
l=["Sheldon","Leonard","Penny","Rajesh","Howard"]
while n>4:
n=(n-5)//2
print(l[n])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input Specification:
The input data consist of a single integer *n* (1<=β€<=*n*<=β€<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output Specification:
Print the single line β the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Demo Input:
['1\n', '6\n', '1802\n']
Demo Output:
['Sheldon\n', 'Sheldon\n', 'Penny\n']
Note:
none | ```python
n=int(input())-1
l=["Sheldon","Leonard","Penny","Rajesh","Howard"]
while n>4:
n=(n-5)//2
print(l[n])
``` | 3.9455 | n=int(input())-1
l=["Sheldon","Leonard","Penny","Raj | esh","Howard"]
while n>4:
n=(n-5)// |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then β zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number β the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1"
},
{
"input": "FSFlNEelYY",
"output": "3"
},
{
"input": "lgtyasficu",
"output": "0"
},
{
"input": "WYKUDTDDBT",
"output": "0"
},
{
"input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd",
"output": "0"
},
{
"input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu",
"output": "43"
},
{
"input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR",
"output": "13"
},
{
"input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi",
"output": "27"
},
{
"input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn",
"output": "31"
}
] | 1,647,104,368 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 102,400 | mensagem = input()
acao = 0
for i in range(len(mensagem)):
if mensagem[i].isupper():
acao = acao+ 1
p = acao
for i in range(len(mensagem)):
if mensagem[i].isupper():
aux = -1
else:
aux = 1
p= p + aux
acao = min(acao,p)
print(acao) | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then β zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
Input Specification:
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Output Specification:
Print a single number β the least number of actions needed to make the message fancy.
Demo Input:
['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n']
Demo Output:
['5\n', '0\n', '0\n']
Note:
none | ```python
mensagem = input()
acao = 0
for i in range(len(mensagem)):
if mensagem[i].isupper():
acao = acao+ 1
p = acao
for i in range(len(mensagem)):
if mensagem[i].isupper():
aux = -1
else:
aux = 1
p= p + aux
acao = min(acao,p)
print(acao)
``` | 3 | mensagem = input()
acao = 0
for i in range(len(mensagem)):
if mensagem[i].isupper():
acao = acao+ 1
p = acao
for i in range(len(mensagem)):
if mensagem[i].isupper():
aux = -1
else:
aux = 1
p= | p + aux
acao = min(acao,p)
|
|
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=Γ<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=Γ<=2 square consisting of black pixels is formed. | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=β€<=*n*,<=*m*<=β€<=1000, 1<=β€<=*k*<=β€<=105)Β β the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=β€<=*i*<=β€<=*n*, 1<=β€<=*j*<=β€<=*m*), representing the row number and column number of the pixel that was painted during a move. | If Pasha loses, print the number of the move when the 2<=Γ<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=Γ<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 1,668,578,009 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 498 | 5,324,800 | n,m,k=map(int,input().split())
s=[[0 for x in range(m+2)]for y in range(n+2)]
for k in range(1,k+1):
i,j=map(int,input().split())
s[i][j]=1
if s[i][j-1]==s[i-1][j]==s[i-1][j-1]==1:
print(k)
break
elif s[i][j+1]==s[i-1][j]==s[i-1][j+1]==1:
print(k)
break
elif s[i][j+1]==s[i+1][j]==s[i+1][j+1]==1:
print(k)
break
elif s[i][j-1]==s[i+1][j]==s[i+1][j-1]==1:
print(k)
break
else:
print(0) | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=Γ<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=Γ<=2 square consisting of black pixels is formed.
Input Specification:
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=β€<=*n*,<=*m*<=β€<=1000, 1<=β€<=*k*<=β€<=105)Β β the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=β€<=*i*<=β€<=*n*, 1<=β€<=*j*<=β€<=*m*), representing the row number and column number of the pixel that was painted during a move.
Output Specification:
If Pasha loses, print the number of the move when the 2<=Γ<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=Γ<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
Demo Input:
['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n']
Demo Output:
['4\n', '5\n', '0\n']
Note:
none | ```python
n,m,k=map(int,input().split())
s=[[0 for x in range(m+2)]for y in range(n+2)]
for k in range(1,k+1):
i,j=map(int,input().split())
s[i][j]=1
if s[i][j-1]==s[i-1][j]==s[i-1][j-1]==1:
print(k)
break
elif s[i][j+1]==s[i-1][j]==s[i-1][j+1]==1:
print(k)
break
elif s[i][j+1]==s[i+1][j]==s[i+1][j+1]==1:
print(k)
break
elif s[i][j-1]==s[i+1][j]==s[i+1][j-1]==1:
print(k)
break
else:
print(0)
``` | 3 | n,m,k=map(int,input().split())
s=[[0 for x in range(m+2)]for y in range(n+2)]
for k in range(1,k+1):
i,j=map(int,input().split())
s[i][j]=1
| if s[i][j-1]==s[i-1][j]==s[i-1][ |
|
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days.
Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems.
The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice.
You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum.
For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$. | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them). | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice.
If there are many possible answers, you may print any of them. | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
},
{
"input": "3 2\n1 1 1",
"output": "2\n2 1"
},
{
"input": "4 2\n3 5 1 1",
"output": "8\n1 3"
},
{
"input": "5 3\n5 5 6 7 1",
"output": "18\n2 1 2"
},
{
"input": "6 4\n1 1 1 1 2 2",
"output": "6\n3 1 1 1"
},
{
"input": "5 3\n5 5 6 6 4",
"output": "17\n2 1 2"
},
{
"input": "16 15\n14 4 9 12 17 1 1 8 12 13 6 9 17 2 18 12",
"output": "154\n1 1 1 1 1 2 1 1 1 1 1 1 1 1 1"
},
{
"input": "1 1\n1996",
"output": "1996\n1"
},
{
"input": "5 3\n5 5 5 9 10",
"output": "24\n3 1 1"
},
{
"input": "18 15\n18 2 13 1 18 3 2 18 18 20 9 2 20 20 4 20 9 12",
"output": "204\n1 2 2 1 2 1 1 1 1 1 1 1 1 1 1"
},
{
"input": "5 3\n1 20 20 50 50",
"output": "120\n3 1 1"
},
{
"input": "8 3\n15 14 11 19 17 14 14 8",
"output": "51\n1 3 4"
},
{
"input": "5 2\n15 20 6 19 6",
"output": "39\n2 3"
},
{
"input": "6 3\n5 5 5 5 6 9",
"output": "20\n4 1 1"
},
{
"input": "5 3\n2 2 2 3 3",
"output": "8\n3 1 1"
},
{
"input": "7 3\n2 2 2 2 2 3 3",
"output": "8\n5 1 1"
},
{
"input": "6 5\n1 1 6 6 6 6",
"output": "25\n2 1 1 1 1"
},
{
"input": "8 4\n1 2 2 2 2 3 4 5",
"output": "14\n5 1 1 1"
},
{
"input": "6 4\n1 1 1 5 5 5",
"output": "16\n3 1 1 1"
},
{
"input": "6 3\n1 2 2 2 4 5",
"output": "11\n4 1 1"
},
{
"input": "18 6\n17 17 19 14 10 20 18 16 6 7 2 15 14 16 13 6 12 11",
"output": "107\n1 1 1 3 1 11"
},
{
"input": "6 3\n1 1 2 2 3 4",
"output": "9\n4 1 1"
},
{
"input": "8 3\n5 4 2 5 6 1 9 2",
"output": "20\n4 1 3"
}
] | 1,695,547,304 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 93 | 4,710,400 | def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
a_indexes = sorted(range(1, n + 1), key=lambda i: a[i - 1])
best = sorted(a_indexes[-k:])
print(sum((a[i - 1] for i in best)))
prev = 0
for i in best[:-1]:
print(i - prev, end=' ')
prev = i
print(n - prev)
main()
| Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days.
Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems.
The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice.
You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum.
For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$.
Input Specification:
The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) β the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) β difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them).
Output Specification:
In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice.
If there are many possible answers, you may print any of them.
Demo Input:
['8 3\n5 4 2 6 5 1 9 2\n', '5 1\n1 1 1 1 1\n', '4 2\n1 2000 2000 2\n']
Demo Output:
['20\n3 2 3', '1\n5\n', '4000\n2 2\n']
Note:
The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | ```python
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
a_indexes = sorted(range(1, n + 1), key=lambda i: a[i - 1])
best = sorted(a_indexes[-k:])
print(sum((a[i - 1] for i in best)))
prev = 0
for i in best[:-1]:
print(i - prev, end=' ')
prev = i
print(n - prev)
main()
``` | 3 | def main():
n, k = map(int, input().split())
a = list(map(int, input(). | split()))
a_indexes = sorted(range(1, n + 1), key=lambda |
|
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. | The first line contains an integer *n*Β (1<=β€<=*n*<=β€<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=β€<=*v**i*<=β€<=109) β costs of the stones.
The third line contains an integer *m*Β (1<=β€<=*m*<=β€<=105) β the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*;Β 1<=β€<=*type*<=β€<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. | Print *m* lines. Each line must contain an integer β the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2",
"output": "5\n7\n5\n5\n2\n7\n7\n13\n4"
},
{
"input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7",
"output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326"
},
{
"input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29",
"output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772"
},
{
"input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12",
"output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195"
},
{
"input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1",
"output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2"
},
{
"input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2",
"output": "6\n1\n6\n1\n5\n6\n1\n5"
},
{
"input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4",
"output": "22\n10\n10\n6\n12\n36\n6\n14\n16"
},
{
"input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4",
"output": "11\n11\n2\n10\n1\n3\n10\n12\n12"
},
{
"input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5",
"output": "8\n27\n1\n8\n26"
},
{
"input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8",
"output": "10\n2\n13\n10"
},
{
"input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5",
"output": "9\n24\n28"
},
{
"input": "1\n1\n2\n1 1 1\n2 1 1",
"output": "1\n1"
}
] | 1,648,814,515 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 1,170 | 10,035,200 | n = int(input())
v_list = list(map(int, input().split()))
m = int(input())
v_list_sorted = sorted(v_list)
prefix_sum = [[0,v_list[0]],[0,v_list_sorted[0]]]
for i in range(1, n):
sum_val = prefix_sum[0][i] + v_list[i]
prefix_sum[0].append(sum_val)
for i in range(1, n):
sum_val = prefix_sum[1][i] + v_list_sorted[i]
prefix_sum[1].append(sum_val)
for i in range(m):
type_question, l, r = map(int, input().split())
print(str(prefix_sum[type_question-1][r] - prefix_sum[type_question-1][l-1])) | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
Input Specification:
The first line contains an integer *n*Β (1<=β€<=*n*<=β€<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=β€<=*v**i*<=β€<=109) β costs of the stones.
The third line contains an integer *m*Β (1<=β€<=*m*<=β€<=105) β the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r*Β (1<=β€<=*l*<=β€<=*r*<=β€<=*n*;Β 1<=β€<=*type*<=β€<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Output Specification:
Print *m* lines. Each line must contain an integer β the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
Demo Input:
['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n']
Demo Output:
['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n']
Note:
Please note that the answers to the questions may overflow 32-bit integer type. | ```python
n = int(input())
v_list = list(map(int, input().split()))
m = int(input())
v_list_sorted = sorted(v_list)
prefix_sum = [[0,v_list[0]],[0,v_list_sorted[0]]]
for i in range(1, n):
sum_val = prefix_sum[0][i] + v_list[i]
prefix_sum[0].append(sum_val)
for i in range(1, n):
sum_val = prefix_sum[1][i] + v_list_sorted[i]
prefix_sum[1].append(sum_val)
for i in range(m):
type_question, l, r = map(int, input().split())
print(str(prefix_sum[type_question-1][r] - prefix_sum[type_question-1][l-1]))
``` | 3 | n = int(input())
v_list = list(map(int, input().split()))
m = int(input())
v_list_sorted = sorted(v_list)
prefix_sum = [[0,v_list[0]],[0,v_list_sorted[0]]]
for i in range(1, n):
| sum_val = prefix_sum[0][i] + v_list[i]
|
|
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=β€<=*t*0<=β€<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses. | The first line contains three space-separated integers *a*, *b* and *c* (1<=β€<=*a*,<=*b*,<=*c*<=β€<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds. | Print a single number β the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 Β· 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 Β· 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "2 1 4",
"output": "4"
},
{
"input": "5 1 5",
"output": "20"
},
{
"input": "2 1 2",
"output": "2"
},
{
"input": "60 16 1",
"output": "3"
},
{
"input": "64 12 8",
"output": "35"
},
{
"input": "66 38 4",
"output": "3"
},
{
"input": "70 32 1",
"output": "2"
},
{
"input": "24 12 12",
"output": "12"
},
{
"input": "24 19 9",
"output": "3"
},
{
"input": "244 87 4",
"output": "8"
},
{
"input": "305 203 421",
"output": "212"
},
{
"input": "888 777 1",
"output": "1"
},
{
"input": "888 777 1000",
"output": "143"
},
{
"input": "888 777 888",
"output": "127"
},
{
"input": "5 4 10",
"output": "3"
},
{
"input": "1000 1 1",
"output": "999"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "1000 999 1",
"output": "1"
},
{
"input": "1000 999 1000",
"output": "2"
},
{
"input": "945 812 917",
"output": "151"
},
{
"input": "993 992 991",
"output": "1"
},
{
"input": "17 7 10",
"output": "15"
},
{
"input": "17 10 7",
"output": "5"
},
{
"input": "500 300 300",
"output": "200"
},
{
"input": "196 169 144",
"output": "24"
},
{
"input": "7 3 200",
"output": "267"
},
{
"input": "9 3 300",
"output": "600"
},
{
"input": "561 31 917",
"output": "15678"
},
{
"input": "100 10 1",
"output": "9"
},
{
"input": "1000 100 10",
"output": "90"
},
{
"input": "18 14 10",
"output": "3"
},
{
"input": "93 74 831",
"output": "214"
},
{
"input": "960 935 994",
"output": "27"
},
{
"input": "894 1 999",
"output": "892107"
},
{
"input": "767 2 514",
"output": "196605"
},
{
"input": "765 123 45",
"output": "235"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "765 123 899",
"output": "4693"
},
{
"input": "759 10 258",
"output": "19325"
},
{
"input": "100 1 10",
"output": "990"
},
{
"input": "99 8 99",
"output": "1127"
},
{
"input": "27 26 1",
"output": "1"
}
] | 1,612,557,331 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | if __name__ == "__main__":
a, b, c = list(map(int, input().split()))
aux = (a*c)-(b*c)
t = int(aux/b) + (aux % b > 0)
print(t)
| Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=β€<=*t*0<=β€<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.
Input Specification:
The first line contains three space-separated integers *a*, *b* and *c* (1<=β€<=*a*,<=*b*,<=*c*<=β€<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds.
Output Specification:
Print a single number β the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
Demo Input:
['4 1 1\n', '10 3 2\n', '13 12 1\n']
Demo Output:
['3\n', '5\n', '1\n']
Note:
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 Β· 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 Β· 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | ```python
if __name__ == "__main__":
a, b, c = list(map(int, input().split()))
aux = (a*c)-(b*c)
t = int(aux/b) + (aux % b > 0)
print(t)
``` | 3 | if __name__ == "__main__":
a, b, c = list(map(int, input().split()))
aux = (a*c)-(b*c)
t = int(aux/b) + (aux % b > 0)
print | (t)
|
|
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,688,224,402 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n = int(input())
l = []
ct = 0
for i in range(n):
input_line = input()
values = input_line.split()
numbers = [int(value) for value in values]
l.append(numbers)
for i in range(len(l)):
if l[i][0] + 2 <= l[i][1]:
ct += 1
print(ct)
| 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
n = int(input())
l = []
ct = 0
for i in range(n):
input_line = input()
values = input_line.split()
numbers = [int(value) for value in values]
l.append(numbers)
for i in range(len(l)):
if l[i][0] + 2 <= l[i][1]:
ct += 1
print(ct)
``` | 3 | n = int(input())
l = []
ct = 0
for i in range(n):
input_line = input()
values = input_line.split()
numbers = [int(value) for value in values]
l.append(numbers)
for i in range(len(l)):
if l[i][0] + 2 <= l[i][1]:
ct += | 1
print(ct)
|
|
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow! | The first line contains an odd positive integer *n*Β β the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
{
"input": "11",
"output": "-1"
},
{
"input": "1435678543",
"output": "1435678534"
},
{
"input": "4250769",
"output": "9250764"
},
{
"input": "4052769",
"output": "9052764"
},
{
"input": "5685341",
"output": "5685314"
},
{
"input": "1111111111111111231",
"output": "1111111111111111132"
},
{
"input": "333333332379",
"output": "333333339372"
},
{
"input": "85",
"output": "58"
},
{
"input": "7700016673",
"output": "7730016670"
},
{
"input": "35451519805848712272404365322858764249299938505103",
"output": "35451519835848712272404365322858764249299938505100"
},
{
"input": "4314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123919",
"output": "9314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123914"
},
{
"input": "21",
"output": "12"
},
{
"input": "101",
"output": "110"
},
{
"input": "503147",
"output": "573140"
},
{
"input": "333333333333333333333",
"output": "-1"
},
{
"input": "55555555555555555555555",
"output": "-1"
},
{
"input": "99",
"output": "-1"
},
{
"input": "23759",
"output": "93752"
},
{
"input": "235749",
"output": "935742"
},
{
"input": "435729",
"output": "935724"
},
{
"input": "8623",
"output": "8632"
},
{
"input": "109",
"output": "190"
},
{
"input": "20000000000000000000001",
"output": "21000000000000000000000"
},
{
"input": "1001",
"output": "1100"
}
] | 1,693,689,013 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 171 | 12,185,600 | import sys, collections, bisect, heapq, functools, itertools, math
input = sys.stdin.readline
s = list(input().strip())
even = [[int(x), i] for i, x in enumerate(s) if ~int(x)&1]
if not even:
print(-1)
else:
for x, i in even:
if int(s[-1]) > x:
s[i], s[-1] = s[-1], s[i]
print(''.join(s))
quit()
s[even[-1][1]], s[-1] = s[-1], s[even[-1][1]]
print(''.join(s)) | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow!
Input Specification:
The first line contains an odd positive integer *n*Β β the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes.
Output Specification:
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
Demo Input:
['527\n', '4573\n', '1357997531\n']
Demo Output:
['572\n', '3574\n', '-1\n']
Note:
none | ```python
import sys, collections, bisect, heapq, functools, itertools, math
input = sys.stdin.readline
s = list(input().strip())
even = [[int(x), i] for i, x in enumerate(s) if ~int(x)&1]
if not even:
print(-1)
else:
for x, i in even:
if int(s[-1]) > x:
s[i], s[-1] = s[-1], s[i]
print(''.join(s))
quit()
s[even[-1][1]], s[-1] = s[-1], s[even[-1][1]]
print(''.join(s))
``` | 3 | import sys, collections, bisect, heapq, functools, itertools, math
input = sys.stdin.readline
s = list(input().strip())
even = [[int(x), i] for i, x in enumerate(s) if ~int(x)&1]
if not even:
print(-1)
else:
for x, i in even:
if int(s[-1]) > x:
s[i], s | [-1] = s[-1], s[i]
print(''.join(s))
quit()
|
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). | Print a single integer β the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2,β2,β2,β2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,700,024,159 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 264 | 13,721,600 | from bisect import *
n=int(input())
a=[0]+list(map(int,input().split()))
point=0
a.sort()
dp=[0]*(n+1)
dp[1]=a[1]
for i in range(2,n+1):
dp[i]=max(dp[i-1],a[i]*(bisect_right(a,a[i])-bisect_left(a,a[i]))+dp[bisect_left(a,a[i]-1)-1])
print(dp[n])
| Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=β€<=*n*<=β€<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105).
Output Specification:
Print a single integer β the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2,β2,β2,β2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
from bisect import *
n=int(input())
a=[0]+list(map(int,input().split()))
point=0
a.sort()
dp=[0]*(n+1)
dp[1]=a[1]
for i in range(2,n+1):
dp[i]=max(dp[i-1],a[i]*(bisect_right(a,a[i])-bisect_left(a,a[i]))+dp[bisect_left(a,a[i]-1)-1])
print(dp[n])
``` | 3 | from bisect import *
n=int(input())
a=[0]+list(map(int,input().split()))
point=0
a.sort()
dp=[0]*(n+1)
dp | [1]=a[1]
for i in range(2,n+1):
dp[i |
|
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=β€<=*y*<=β€<=9000) β the year number. | Print a single integer β the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,691,344,001 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | s = int(input()) + 1
while len(set(str(s))) < 4:
s += 1
print(s) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input Specification:
The single line contains integer *y* (1000<=β€<=*y*<=β€<=9000) β the year number.
Output Specification:
Print a single integer β the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
Demo Input:
['1987\n', '2013\n']
Demo Output:
['2013\n', '2014\n']
Note:
none | ```python
s = int(input()) + 1
while len(set(str(s))) < 4:
s += 1
print(s)
``` | 3 | s = int(input()) + 1
while len(set(str(s))) | < 4:
s += 1
print(s) |
|
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i.Β e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves. | The first line contains one integer $n$ ($1 \le n \le 1000$)Β β the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"output": "53"
},
{
"input": "1\n124",
"output": "124"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 1 1000",
"output": "1"
},
{
"input": "2\n322 322",
"output": "322"
},
{
"input": "3\n9 92 12",
"output": "12"
},
{
"input": "3\n1 2 2",
"output": "2"
}
] | 1,572,463,275 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 156 | 0 | # cf 984 A (700)
n = int(input())
A = list(map(int, input().split()))
# first = minimize last, second = maximize last
# first = take largest, second = take smallest
A.sort()
if len(A) % 2 == 1:
print(A[len(A) // 2])
else:
print(A[len(A) // 2 - 1])
#i, j = 0, len(A) - 1
#while j - i > 1:
# i += 1
# j -= 1
#print(A[i])
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i.Β e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves.
Input Specification:
The first line contains one integer $n$ ($1 \le n \le 1000$)Β β the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Output Specification:
Print one number that will be left on the board.
Demo Input:
['3\n2 1 3\n', '3\n2 2 2\n']
Demo Output:
['2', '2']
Note:
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | ```python
# cf 984 A (700)
n = int(input())
A = list(map(int, input().split()))
# first = minimize last, second = maximize last
# first = take largest, second = take smallest
A.sort()
if len(A) % 2 == 1:
print(A[len(A) // 2])
else:
print(A[len(A) // 2 - 1])
#i, j = 0, len(A) - 1
#while j - i > 1:
# i += 1
# j -= 1
#print(A[i])
``` | 3 | # cf 984 A (700)
n = int(input())
A = list(map(int, input().split()))
# first = minimize last, second = maximize last
# first = take largest, second = take smallest
A.sort()
if len(A) % 2 == 1:
print(A[len(A) // 2])
else:
print(A[len(A) | // 2 - 1])
#i, j = 0, len(A) - 1
#while |
|
90 | B | African Crossword | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. African Crossword | 2 | 256 | An African crossword is a rectangular table *n*<=Γ<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.
When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.
You are suggested to solve an African crossword and print the word encrypted there. | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
] | [
"abcd",
"codeforces"
] | none | 1,000 | [
{
"input": "3 3\ncba\nbcd\ncbc",
"output": "abcd"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf",
"output": "codeforces"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha",
"output": "ahhasusu"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz",
"output": "bcdeghjlmnprsuvwz"
},
{
"input": "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe",
"output": "b"
},
{
"input": "15 3\njhg\njkn\njui\nfth\noij\nyuf\nyfb\nugd\nhgd\noih\nhvc\nugg\nyvv\ntdg\nhgf",
"output": "hkniftjfbctd"
},
{
"input": "17 19\nbmzbmweyydiadtlcoue\ngmdbyfwurpwbpuvhifn\nuapwyndmhtqvkgkbhty\ntszotwflegsjzzszfwt\nzfpnscguemwrczqxyci\nvdqnkypnxnnpmuduhzn\noaquudhavrncwfwujpc\nmiggjmcmkkbnjfeodxk\ngjgwxtrxingiqquhuwq\nhdswxxrxuzzfhkplwun\nfagppcoildagktgdarv\neusjuqfistulgbglwmf\ngzrnyxryetwzhlnfewc\nzmnoozlqatugmdjwgzc\nfabbkoxyjxkatjmpprs\nwkdkobdagwdwxsufees\nrvncbszcepigpbzuzoo",
"output": "lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs"
},
{
"input": "1 1\na",
"output": "a"
},
{
"input": "2 2\nzx\nxz",
"output": "zxxz"
},
{
"input": "1 2\nfg",
"output": "fg"
},
{
"input": "2 1\nh\nj",
"output": "hj"
},
{
"input": "1 3\niji",
"output": "j"
},
{
"input": "3 1\nk\np\nk",
"output": "p"
},
{
"input": "2 3\nmhw\nbfq",
"output": "mhwbfq"
},
{
"input": "3 2\nxe\ner\nwb",
"output": "xeerwb"
},
{
"input": "3 7\nnutuvjg\ntgqutfn\nyfjeiot",
"output": "ntvjggqfnyfjeiot"
},
{
"input": "5 4\nuzvs\namfz\nwypl\nxizp\nfhmf",
"output": "uzvsamfzwyplxizphm"
},
{
"input": "8 9\ntjqrtgrem\nrwjcfuoey\nywrjgpzca\nwabzggojv\najqmmcclh\nozilebskd\nqmgnbmtcq\nwakptzkjr",
"output": "mrjcfuyyrjpzabzvalhozilebskdgnbtpzr"
},
{
"input": "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt",
"output": "elwtabvyokgmplabqbxlt"
},
{
"input": "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv",
"output": "eklgximpzgfvwcmrrqedoiqptdeiokuorv"
},
{
"input": "14 27\npzoshpvvjdpmwfoeojapmkxjrnk\nitoojpcorxjdxrwyewtmmlhjxhx\ndoyopbwusgsmephixzcilxpskxh\nygpvepeuxjbnezdrnjfwdhjwjka\nrfjlbypoalbtjwrpjxzenmeipfg\nkhjhrtktcnajrnbefhpavxxfnlx\nvwlwumqpfegjgvoezevqsolaqhh\npdrvrtzqsoujqfeitkqgtxwckrl\nxtepjflcxcrfomhqimhimnzfxzg\nwhkfkfvvjwkmwhfgeovwowshyhw\nolchgmhiehumivswgtfyhqfagbp\ntdudrkttpkryvaiepsijuejqvmq\nmuratfqqdbfpefmhjzercortroh\nwxkebkzchupxumfizftgqvuwgau",
"output": "zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva"
},
{
"input": "1 100\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu",
"output": "g"
},
{
"input": "2 100\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg",
"output": "rbe"
},
{
"input": "3 100\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo",
"output": "blkck"
},
{
"input": "100 1\na\nm\nn\nh\na\nx\nt\na\no\np\nj\nz\nr\nk\nq\nl\nb\nr\no\ni\ny\ni\np\ni\nt\nn\nd\nc\nz\np\nu\nn\nw\ny\ng\ns\nt\nm\nz\ne\nv\ng\ny\nj\nd\nz\ny\na\nn\nx\nk\nd\nq\nn\nv\ng\nk\ni\nk\nf\na\nb\nw\no\nu\nw\nk\nk\nb\nz\nu\ni\nu\nv\ng\nv\nx\ng\np\ni\nz\ns\nv\nq\ns\nb\nw\ne\np\nk\nt\np\nd\nr\ng\nd\nk\nm\nf\nd",
"output": "hlc"
},
{
"input": "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\nrp\nsz\noi\nec\npw\nhf\njm\nwu\nhq\nra\npv\ntc\ngv\nik\nux\ntz\nbf\nty\ndk\nwo\nor\nza\nkv\nqt\nfa\njy\nbk\nuv\ngk\ncz\nds\nie\noq\nmf\nxn\nql\nxs\nfb\niv\ncj\nkn\nns\nlg\nji\nha\naj\ndg\nfj\nut\nsg\nju\noc\nov\nhe\nnw\nbl\nlp\nbx\nnm\nyq\ncw\nov\nxk\npg\noh\npl\nuo\ngf\nul",
"output": "dvy"
},
{
"input": "100 3\nruy\nmye\njgp\nscn\nktq\nalx\nmvk\nlpm\nkry\norb\nmpu\nzcv\nlge\nkft\ndzp\ntfb\nhqz\nuur\nhry\nzjx\ncuo\nqqc\ntih\nenj\nvnp\nbwi\nzzh\nhkc\nwdr\nldh\nvel\nizj\nfhb\nqrn\nqpp\nvzs\nlhg\nkee\nlbq\nzhy\nwcl\nyaa\nton\nfly\nkyw\nept\ngwq\ncoe\nopd\neez\nnmx\nnjg\nwhy\nvel\nafq\nnbq\nulx\noxs\nbbo\nyhx\nfmz\nnrg\nnfm\njek\nbeu\ntya\nxgs\nsgg\nnkq\nbbv\nwkd\ntns\nfdt\neox\nobc\neab\nkkj\noub\ngji\nrht\nozv\nysk\nsbt\nflf\npbu\nlxb\npzs\nrzh\ncea\nkmi\nuea\nncc\nzng\nvkn\njhn\njqw\nlqc\nmbt\nlov\ngam",
"output": "tvdiixs"
}
] | 1,675,135,230 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 92 | 102,400 | from collections import Counter
m, n = map(int, input().split())
crossword = []
for _ in range(m):
crossword.append(input())
rowCount = []
for i in range(m):
rowCount.append(Counter(crossword[i]))
colCount = list(zip(*crossword))
for i in range(n):
colCount[i] = Counter(colCount[i])
word = ""
for row in range(m):
for col in range(n):
if rowCount[row][crossword[row][col]] == 1 and colCount[col][crossword[row][col]] == 1:
word += crossword[row][col]
print(word)
| Title: African Crossword
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
An African crossword is a rectangular table *n*<=Γ<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.
When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.
You are suggested to solve an African crossword and print the word encrypted there.
Input Specification:
The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Output Specification:
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
Demo Input:
['3 3\ncba\nbcd\ncbc\n', '5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n']
Demo Output:
['abcd', 'codeforces']
Note:
none | ```python
from collections import Counter
m, n = map(int, input().split())
crossword = []
for _ in range(m):
crossword.append(input())
rowCount = []
for i in range(m):
rowCount.append(Counter(crossword[i]))
colCount = list(zip(*crossword))
for i in range(n):
colCount[i] = Counter(colCount[i])
word = ""
for row in range(m):
for col in range(n):
if rowCount[row][crossword[row][col]] == 1 and colCount[col][crossword[row][col]] == 1:
word += crossword[row][col]
print(word)
``` | 3.976809 | from collections import Counter
m, n = map(int, input().split())
crossword = []
for _ in range(m):
crossword.append(input())
rowCount = []
for i in range(m):
rowCount.append(Counter(crossword[i]))
colCount | = list(zip(*crossword))
for i in range(n):
colCount[i] = Counter(colCount[i])
|
478 | A | Initial Bet | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size *b* of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins *b* in the initial bet. | The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 β the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=β€<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=β€<=100). | Print the only line containing a single positive integer *b* β the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity). | [
"2 5 4 0 4\n",
"4 5 9 2 1\n"
] | [
"3\n",
"-1\n"
] | In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to the second player. | 500 | [
{
"input": "2 5 4 0 4",
"output": "3"
},
{
"input": "4 5 9 2 1",
"output": "-1"
},
{
"input": "0 0 0 0 0",
"output": "-1"
},
{
"input": "1 2 1 2 3",
"output": "-1"
},
{
"input": "100 0 0 0 0",
"output": "20"
},
{
"input": "2 3 4 5 6",
"output": "4"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "0 1 2 3 4",
"output": "2"
},
{
"input": "100 100 100 100 100",
"output": "100"
},
{
"input": "93 100 99 90 98",
"output": "96"
},
{
"input": "99 99 99 99 99",
"output": "99"
},
{
"input": "99 98 98 99 100",
"output": "-1"
},
{
"input": "43 83 1 0 23",
"output": "30"
},
{
"input": "43 83 1 100 23",
"output": "50"
},
{
"input": "57 83 11 4 93",
"output": "-1"
},
{
"input": "87 38 19 33 100",
"output": "-1"
},
{
"input": "56 0 0 0 4",
"output": "12"
},
{
"input": "0 0 0 0 1",
"output": "-1"
},
{
"input": "99 100 100 100 100",
"output": "-1"
}
] | 1,664,590,169 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | a,b,c,d,e = map(int,input().split())
if (a+b+c+d+e)%5 == 0 and (a+b+c+d+e) >= 5:
print((a+b+c+d+e)//5)
else:
print(-1)
| Title: Initial Bet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size *b* of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins *b* in the initial bet.
Input Specification:
The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 β the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=β€<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=β€<=100).
Output Specification:
Print the only line containing a single positive integer *b* β the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity).
Demo Input:
['2 5 4 0 4\n', '4 5 9 2 1\n']
Demo Output:
['3\n', '-1\n']
Note:
In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to the second player. | ```python
a,b,c,d,e = map(int,input().split())
if (a+b+c+d+e)%5 == 0 and (a+b+c+d+e) >= 5:
print((a+b+c+d+e)//5)
else:
print(-1)
``` | 3 | a,b,c,d,e = map(int,input().split())
if (a | +b+c+d+e)%5 == 0 and (a+b+c+d+e) >= 5 |
|
576 | A | Vasya and Petya's Game | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | 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. | 500 | [
{
"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,596,218,296 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 140 | 20,172,800 | from math import *
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
n=int(input())
ans=[]
for i in range(2,n+1):
if(isPrime(i)==1):
ans.append(i)
k=i
while(k*i<=n):
k*=i
ans.append(k)
print(len(ans))
print(*ans)
| Title: Vasya and Petya's Game
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
from math import *
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
n=int(input())
ans=[]
for i in range(2,n+1):
if(isPrime(i)==1):
ans.append(i)
k=i
while(k*i<=n):
k*=i
ans.append(k)
print(len(ans))
print(*ans)
``` | 3 | from math import *
def isPrime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
n=int(input())
ans=[]
for i in range(2,n+1):
if(isPrime(i)==1):
ans.append(i | )
k=i
while(k*i<=n):
k*=i
ans.append(k)
|
|
534 | B | Covered Path | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"math"
] | null | null | The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters. | The first line contains two integers *v*1 and *v*2 (1<=β€<=*v*1,<=*v*2<=β€<=100) β the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=β€<=*t*<=β€<=100) β the time when the car moves along the segment in seconds, *d* (0<=β€<=*d*<=β€<=10) β the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that:
- the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*. | Print the maximum possible length of the path segment in meters. | [
"5 6\n4 2\n",
"10 10\n10 0\n"
] | [
"26",
"100"
] | In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5β+β7β+β8β+β6β=β26 meters.
In the second sample, as *d*β=β0, the car covers the whole segment at constant speed *v*β=β10. In *t*β=β10 seconds it covers the distance of 100 meters. | 1,000 | [
{
"input": "5 6\n4 2",
"output": "26"
},
{
"input": "10 10\n10 0",
"output": "100"
},
{
"input": "87 87\n2 10",
"output": "174"
},
{
"input": "1 11\n6 2",
"output": "36"
},
{
"input": "100 10\n10 10",
"output": "550"
},
{
"input": "1 1\n100 10",
"output": "24600"
},
{
"input": "1 1\n5 1",
"output": "9"
},
{
"input": "1 1\n5 2",
"output": "13"
},
{
"input": "100 100\n100 0",
"output": "10000"
},
{
"input": "100 100\n100 10",
"output": "34500"
},
{
"input": "1 100\n100 1",
"output": "5050"
},
{
"input": "1 100\n100 10",
"output": "29305"
},
{
"input": "100 1\n100 1",
"output": "5050"
},
{
"input": "100 1\n100 10",
"output": "29305"
},
{
"input": "1 10\n2 10",
"output": "11"
},
{
"input": "1 1\n2 1",
"output": "2"
},
{
"input": "1 1\n2 10",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "3"
},
{
"input": "1 2\n2 10",
"output": "3"
},
{
"input": "1 5\n3 2",
"output": "9"
},
{
"input": "2 1\n2 2",
"output": "3"
},
{
"input": "2 1\n2 10",
"output": "3"
},
{
"input": "1 11\n2 10",
"output": "12"
},
{
"input": "11 1\n2 10",
"output": "12"
},
{
"input": "1 1\n3 5",
"output": "8"
},
{
"input": "1 10\n3 5",
"output": "17"
},
{
"input": "1 21\n3 10",
"output": "33"
},
{
"input": "21 1\n3 10",
"output": "33"
},
{
"input": "100 100\n99 1",
"output": "12301"
},
{
"input": "100 100\n100 1",
"output": "12450"
},
{
"input": "99 99\n99 1",
"output": "12202"
},
{
"input": "99 99\n99 10",
"output": "33811"
},
{
"input": "1 100\n99 10",
"output": "28764"
},
{
"input": "13 31\n7 5",
"output": "182"
},
{
"input": "88 78\n8 5",
"output": "719"
},
{
"input": "34 48\n47 4",
"output": "4030"
},
{
"input": "91 29\n78 3",
"output": "8806"
},
{
"input": "90 81\n21 6",
"output": "2391"
},
{
"input": "95 89\n45 3",
"output": "5589"
},
{
"input": "48 54\n84 2",
"output": "7724"
},
{
"input": "72 31\n59 7",
"output": "8865"
},
{
"input": "51 13\n47 3",
"output": "2970"
},
{
"input": "97 91\n82 2",
"output": "10984"
},
{
"input": "71 71\n9 5",
"output": "719"
},
{
"input": "16 49\n40 3",
"output": "2350"
},
{
"input": "22 41\n68 4",
"output": "6608"
},
{
"input": "13 71\n72 6",
"output": "10444"
},
{
"input": "77 78\n46 3",
"output": "5083"
},
{
"input": "36 60\n54 2",
"output": "3924"
},
{
"input": "55 39\n93 2",
"output": "8571"
},
{
"input": "34 7\n48 6",
"output": "4266"
},
{
"input": "80 88\n79 3",
"output": "11193"
},
{
"input": "34 62\n15 4",
"output": "866"
},
{
"input": "81 40\n73 2",
"output": "6798"
},
{
"input": "13 38\n97 6",
"output": "16271"
},
{
"input": "84 87\n45 2",
"output": "4814"
},
{
"input": "42 65\n76 3",
"output": "8240"
},
{
"input": "55 6\n24 4",
"output": "1110"
},
{
"input": "41 16\n43 2",
"output": "2029"
},
{
"input": "99 93\n78 1",
"output": "8961"
},
{
"input": "10 7\n44 2",
"output": "1297"
},
{
"input": "72 54\n91 3",
"output": "11781"
},
{
"input": "48 34\n80 2",
"output": "6376"
},
{
"input": "92 85\n70 1",
"output": "7373"
}
] | 1,429,780,310 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 62 | 4,710,400 | i_speed, f_speed = input().split(" ")
time, transition = input().split(" ")
i_speed = int(i_speed)
f_speed = int(f_speed)
time = int(time)
transition = int(transition)
path = [ i_speed ] * time
for i in range( 1, len(path) ):
path[i] += transition*i
while path[i] > f_speed + transition*(len(path)-i-1):
path[i] -= 1
print(sum(path))
| Title: Covered Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters.
Input Specification:
The first line contains two integers *v*1 and *v*2 (1<=β€<=*v*1,<=*v*2<=β€<=100) β the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=β€<=*t*<=β€<=100) β the time when the car moves along the segment in seconds, *d* (0<=β€<=*d*<=β€<=10) β the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that:
- the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*.
Output Specification:
Print the maximum possible length of the path segment in meters.
Demo Input:
['5 6\n4 2\n', '10 10\n10 0\n']
Demo Output:
['26', '100']
Note:
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5β+β7β+β8β+β6β=β26 meters.
In the second sample, as *d*β=β0, the car covers the whole segment at constant speed *v*β=β10. In *t*β=β10 seconds it covers the distance of 100 meters. | ```python
i_speed, f_speed = input().split(" ")
time, transition = input().split(" ")
i_speed = int(i_speed)
f_speed = int(f_speed)
time = int(time)
transition = int(transition)
path = [ i_speed ] * time
for i in range( 1, len(path) ):
path[i] += transition*i
while path[i] > f_speed + transition*(len(path)-i-1):
path[i] -= 1
print(sum(path))
``` | 3 | i_speed, f_speed = input().split(" ")
time, transition = input().split(" ")
i_speed = int(i_speed)
f_speed = int(f_speed)
time = int(time)
transition = int(transition)
path = [ i_speed ] * time
for i in range( 1, len(path) ):
path[i] += transition*i
while path[i] > | f_speed + transition*(len(path)-i-1):
path[i] -= 1
print(sum(path))
|
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 31