contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B. | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "A>C\nA>B\nB<C",
"output": "BCA"
},
{
"input": "C<B\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nA>B\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nA<C",
"output": "ABC"
},
{
"input": "C<B\nB<A\nC>A",
"output": "Impossible"
},
{
"input": "B<C\nC<A\nA>B",
"output": "BCA"
},
{
"input": "A>B\nC<B\nC<A",
"output": "CBA"
},
{
"input": "B>A\nC>B\nA>C",
"output": "Impossible"
},
{
"input": "B<A\nC>B\nC>A",
"output": "BAC"
},
{
"input": "A<B\nC>B\nA<C",
"output": "ABC"
},
{
"input": "A<B\nC<A\nB<C",
"output": "Impossible"
},
{
"input": "A>C\nC<B\nB>A",
"output": "CAB"
},
{
"input": "C>A\nA<B\nB>C",
"output": "ACB"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "B>C\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA<B\nB>C",
"output": "ACB"
},
{
"input": "B>A\nA>C\nB>C",
"output": "CAB"
},
{
"input": "B<A\nA<C\nC<B",
"output": "Impossible"
},
{
"input": "A<C\nB>C\nA>B",
"output": "Impossible"
},
{
"input": "B>A\nC<A\nC>B",
"output": "Impossible"
},
{
"input": "A>C\nC>B\nB<A",
"output": "BCA"
},
{
"input": "B<C\nB<A\nA>C",
"output": "BCA"
},
{
"input": "A>B\nC>B\nA<C",
"output": "BAC"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA>B\nB>C",
"output": "Impossible"
},
{
"input": "B>A\nB>C\nA<C",
"output": "ACB"
},
{
"input": "B>C\nC<A\nB<A",
"output": "CBA"
},
{
"input": "C>A\nB>A\nB>C",
"output": "ACB"
},
{
"input": "B<A\nB>C\nA<C",
"output": "Impossible"
},
{
"input": "B<C\nA<B\nC>A",
"output": "ABC"
},
{
"input": "C<B\nB>A\nA>C",
"output": "CAB"
},
{
"input": "A>B\nC>A\nB<C",
"output": "BAC"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "B>C\nC>A\nA>B",
"output": "Impossible"
},
{
"input": "B<A\nB>C\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nC>A",
"output": "ABC"
},
{
"input": "A>C\nA>B\nB>C",
"output": "CBA"
},
{
"input": "B<C\nA>B\nA<C",
"output": "BAC"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "C>B\nA<B\nC<A",
"output": "Impossible"
},
{
"input": "A<C\nC<B\nA>B",
"output": "Impossible"
},
{
"input": "B>C\nA<B\nA<C",
"output": "ACB"
},
{
"input": "C>A\nA<B\nC>B",
"output": "ABC"
}
] | 1,513,199,340 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 5,632,000 | import operator
import sys
r1 = list(input())
r2 = list(input())
r3 = list(input())
if(r1==r2):
print("Impossible")
sys.exit()
if(r3==r2):
print("Impossible")
sys.exit()
if(r1==r3):
print("Impossible")
sys.exit()
order={"A":0,"B":0,"C":0}
ordered ={}
if(r1[1]=='<'):
order[r1[0]]-=1
order[r1[2]]+=1
ordered[r1[0]+r1[2]]=1
elif(r1[1]=='>'):
order[r1[2]]-=1
order[r1[0]]+=1
ordered[r1[0]+r1[2]]=1
if(r2[1]=='<'):
order[r2[0]]-=1
order[r2[2]]+=1
ordered[r2[0]+r2[2]]=1
elif(r2[1]=='>'):
order[r2[2]]-=1
order[r2[0]]+=1
ordered[r2[0]+r2[2]]=1
if(r3[1]=='<'):
order[r3[0]]-=1
order[r3[2]]+=1
ordered[r3[0]+r3[2]]=1
elif(r3[1]=='>'):
order[r3[2]]-=1
order[r3[0]]+=1
ordered[r3[0]+r3[2]]=1
sorted_x = sorted(order.items(), key=operator.itemgetter(1))
word =""
for i in sorted_x:
word = word + i[0]
for k in ordered.keys():
if(k[::-1] in ordered.keys()):
print("Impossible")
sys.exit()
print(word)
sys.exit()
| Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
Input Specification:
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.
Output Specification:
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
Demo Input:
['A>B\nC<B\nA>C\n', 'A<B\nB>C\nC>A\n']
Demo Output:
['CBA', 'ACB']
Note:
none | ```python
import operator
import sys
r1 = list(input())
r2 = list(input())
r3 = list(input())
if(r1==r2):
print("Impossible")
sys.exit()
if(r3==r2):
print("Impossible")
sys.exit()
if(r1==r3):
print("Impossible")
sys.exit()
order={"A":0,"B":0,"C":0}
ordered ={}
if(r1[1]=='<'):
order[r1[0]]-=1
order[r1[2]]+=1
ordered[r1[0]+r1[2]]=1
elif(r1[1]=='>'):
order[r1[2]]-=1
order[r1[0]]+=1
ordered[r1[0]+r1[2]]=1
if(r2[1]=='<'):
order[r2[0]]-=1
order[r2[2]]+=1
ordered[r2[0]+r2[2]]=1
elif(r2[1]=='>'):
order[r2[2]]-=1
order[r2[0]]+=1
ordered[r2[0]+r2[2]]=1
if(r3[1]=='<'):
order[r3[0]]-=1
order[r3[2]]+=1
ordered[r3[0]+r3[2]]=1
elif(r3[1]=='>'):
order[r3[2]]-=1
order[r3[0]]+=1
ordered[r3[0]+r3[2]]=1
sorted_x = sorted(order.items(), key=operator.itemgetter(1))
word =""
for i in sorted_x:
word = word + i[0]
for k in ordered.keys():
if(k[::-1] in ordered.keys()):
print("Impossible")
sys.exit()
print(word)
sys.exit()
``` | 0 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
"output": "1"
},
{
"input": "10 7\n1101111011",
"output": "2"
},
{
"input": "10 9\n1110000101",
"output": "1"
},
{
"input": "10 9\n1100000001",
"output": "1"
},
{
"input": "20 5\n11111111110111101001",
"output": "4"
},
{
"input": "20 11\n11100000111000011011",
"output": "2"
},
{
"input": "20 19\n10100000000000000001",
"output": "1"
},
{
"input": "50 13\n10011010100010100111010000010000000000010100000101",
"output": "5"
},
{
"input": "50 8\n11010100000011001100001100010001110000101100110011",
"output": "8"
},
{
"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111",
"output": "25"
},
{
"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "20"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111",
"output": "25"
},
{
"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111",
"output": "25"
},
{
"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111",
"output": "34"
},
{
"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111",
"output": "13"
},
{
"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111",
"output": "15"
},
{
"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111",
"output": "12"
},
{
"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111",
"output": "18"
},
{
"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001",
"output": "16"
},
{
"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101",
"output": "10"
},
{
"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111",
"output": "13"
},
{
"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001",
"output": "18"
},
{
"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011",
"output": "12"
},
{
"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001",
"output": "9"
},
{
"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101",
"output": "12"
},
{
"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001",
"output": "7"
},
{
"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001",
"output": "3"
},
{
"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001",
"output": "3"
},
{
"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001",
"output": "3"
},
{
"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "99"
},
{
"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111",
"output": "-1"
},
{
"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111",
"output": "33"
},
{
"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111",
"output": "-1"
},
{
"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111",
"output": "17"
},
{
"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111",
"output": "-1"
},
{
"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011",
"output": "14"
},
{
"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101",
"output": "11"
},
{
"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001",
"output": "-1"
},
{
"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111",
"output": "-1"
},
{
"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101",
"output": "13"
},
{
"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101",
"output": "9"
},
{
"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001",
"output": "-1"
},
{
"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001",
"output": "-1"
},
{
"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001",
"output": "-1"
},
{
"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001",
"output": "3"
},
{
"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "2"
},
{
"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "-1"
},
{
"input": "43 30\n1001000001111111010100100100110101011101101",
"output": "2"
},
{
"input": "7 1\n1111111",
"output": "6"
},
{
"input": "9 3\n101000001",
"output": "-1"
},
{
"input": "10 3\n1100000001",
"output": "-1"
},
{
"input": "8 2\n10000101",
"output": "-1"
},
{
"input": "2 1\n11",
"output": "1"
}
] | 1,603,292,179 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 307,200 | n, d = list(map(int, input().split(" ")))
s = input()
location = 0
jump_counter = 0
i = 0
while i < len(s):
i += d
if i >= len(s) - 1:
jump_counter += 1
print(jump_counter)
exit()
while not int(s[i]) and i > location:
i -= 1
if i == location:
print("-1")
exit()
else:
location = i
jump_counter += 1
print(jump_counter) | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*.
Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.
Input Specification:
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one.
Output Specification:
If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
Demo Input:
['8 4\n10010101\n', '4 2\n1001\n', '8 4\n11100101\n', '12 3\n101111100101\n']
Demo Output:
['2\n', '-1\n', '3\n', '4\n']
Note:
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two. | ```python
n, d = list(map(int, input().split(" ")))
s = input()
location = 0
jump_counter = 0
i = 0
while i < len(s):
i += d
if i >= len(s) - 1:
jump_counter += 1
print(jump_counter)
exit()
while not int(s[i]) and i > location:
i -= 1
if i == location:
print("-1")
exit()
else:
location = i
jump_counter += 1
print(jump_counter)
``` | 3 |
|
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold. | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9 16 25 36 49 64 81 100",
"output": "19"
},
{
"input": "10\n300 315 325 338 350 365 379 391 404 416",
"output": "23"
},
{
"input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112",
"output": "2"
},
{
"input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500",
"output": "310"
},
{
"input": "3\n159 282 405",
"output": "246"
},
{
"input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741",
"output": "241"
},
{
"input": "10\n218 300 388 448 535 629 680 740 836 925",
"output": "111"
},
{
"input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996",
"output": "20"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "901"
},
{
"input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978",
"output": "605"
},
{
"input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999",
"output": "803"
},
{
"input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932",
"output": "17"
},
{
"input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000",
"output": "54"
},
{
"input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000",
"output": "74"
}
] | 1,491,594,969 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 4,608,000 | n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
m = 10 ** 4
x = 0
for i in range(n - 2):
if c[i + 2] - c[i] < m:
m = c[i + 2] - c[i]
print(m) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.
Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.
Help Mike determine the minimum difficulty of the track after removing one hold.
Input Specification:
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output Specification:
Print a single number — the minimum difficulty of the track after removing a single hold.
Demo Input:
['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n']
Demo Output:
['5\n', '2\n', '4\n']
Note:
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4. | ```python
n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
m = 10 ** 4
x = 0
for i in range(n - 2):
if c[i + 2] - c[i] < m:
m = c[i + 2] - c[i]
print(m)
``` | 0 |
|
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3",
"output": "16"
},
{
"input": "10\n2 3 0 1 3 1 2 2 1 0",
"output": "3"
},
{
"input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n3 3",
"output": "0"
},
{
"input": "3\n3 3 3",
"output": "0"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "2\n0 2",
"output": "1"
},
{
"input": "10\n2 2 3 3 3 3 2 1 3 2",
"output": "2"
},
{
"input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0",
"output": "11"
},
{
"input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1",
"output": "4"
},
{
"input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2",
"output": "3"
},
{
"input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0",
"output": "12"
},
{
"input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3",
"output": "5"
},
{
"input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2",
"output": "4"
},
{
"input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1",
"output": "16"
},
{
"input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3",
"output": "5"
},
{
"input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3",
"output": "3"
},
{
"input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0",
"output": "22"
},
{
"input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2",
"output": "9"
},
{
"input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3",
"output": "2"
},
{
"input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0",
"output": "21"
},
{
"input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2",
"output": "11"
},
{
"input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2",
"output": "7"
},
{
"input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0",
"output": "28"
},
{
"input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1",
"output": "10"
},
{
"input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3",
"output": "8"
},
{
"input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2",
"output": "29"
},
{
"input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3",
"output": "8"
},
{
"input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0",
"output": "32"
},
{
"input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2",
"output": "16"
},
{
"input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3",
"output": "7"
},
{
"input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0",
"output": "40"
},
{
"input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2",
"output": "13"
},
{
"input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3",
"output": "7"
},
{
"input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0",
"output": "44"
},
{
"input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2",
"output": "15"
},
{
"input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3",
"output": "8"
},
{
"input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1",
"output": "35"
},
{
"input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3",
"output": "13"
},
{
"input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3",
"output": "6"
},
{
"input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1",
"output": "43"
},
{
"input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1",
"output": "16"
},
{
"input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1",
"output": "10"
},
{
"input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 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2 2 2",
"output": "50"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "49"
},
{
"input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "2\n0 3",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "1"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n3 0",
"output": "1"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0",
"output": "50"
}
] | 1,569,516,487 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 139 | 307,200 | n = int(input())
days = list(map(int, input().split()))
dp = [[999,999,999] for x in range(100)]
dp[0][0] = 1
if (days[0] == 1):
dp[0][1] = 0
elif (days[0] == 2):
dp[0][2] = 0
elif days[0] == 3:
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, n):
dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])
if (days[i] == 1):
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
elif days[i] == 2:
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
elif days[i] == 3:
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
print(min(dp[n-1][0], dp[n-1][1], dp[n-1][2]))
| Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Output Specification:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days.
Demo Input:
['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | ```python
n = int(input())
days = list(map(int, input().split()))
dp = [[999,999,999] for x in range(100)]
dp[0][0] = 1
if (days[0] == 1):
dp[0][1] = 0
elif (days[0] == 2):
dp[0][2] = 0
elif days[0] == 3:
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, n):
dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])
if (days[i] == 1):
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
elif days[i] == 2:
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
elif days[i] == 3:
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
print(min(dp[n-1][0], dp[n-1][1], dp[n-1][2]))
``` | 3 |
|
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club. | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
{
"input": "5 4\n1 4\n4 3\n4 5\n5 2",
"output": "2"
},
{
"input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11",
"output": "4"
},
{
"input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7",
"output": "2"
},
{
"input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6",
"output": "0"
},
{
"input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3",
"output": "0"
},
{
"input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5",
"output": "0"
},
{
"input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6",
"output": "1"
},
{
"input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4",
"output": "0"
},
{
"input": "95 0",
"output": "0"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39",
"output": "2"
},
{
"input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51",
"output": "3"
},
{
"input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41",
"output": "3"
},
{
"input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65",
"output": "5"
},
{
"input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7",
"output": "4"
},
{
"input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35",
"output": "4"
},
{
"input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65",
"output": "8"
},
{
"input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36",
"output": "4"
},
{
"input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70",
"output": "4"
},
{
"input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66",
"output": "3"
},
{
"input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27",
"output": "8"
},
{
"input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51",
"output": "4"
},
{
"input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75",
"output": "5"
},
{
"input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31",
"output": "3"
},
{
"input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35",
"output": "8"
},
{
"input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37",
"output": "3"
},
{
"input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41",
"output": "4"
},
{
"input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53",
"output": "5"
}
] | 1,638,915,562 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 186 | 0 |
def find_root_of_a(i, a):
while i != a[i]:
i = a[i]
return i
def connect_two_people(i, j, a):
root_of_a = find_root_of_a(i, a)
root_of_b = find_root_of_a(j, a)
if root_of_b == root_of_a:
pass
else:
a[root_of_a] = a[root_of_b]
def main_function():
n, m = [int(i) for i in input().split(" ")]
a = [i for i in range(n)]
database = []
hash_a = [[[], 0] for i in range(n + 1)]
counter = 0
for t in range(m):
b = [int(y) for y in input().split(" ")]
database.append(b)
hash_a[b[0]][0].append(b[1])
hash_a[b[0]][1] += 1
hash_a[b[1]][0].append(b[0])
hash_a[b[1]][1] += 1
while True:
is_found_one = False
for i in range(len(hash_a)):
if hash_a[i][1] == 1:
is_found_one = True
hash_a[i][1] -= 1
hash_a[hash_a[i][0][0]][1] -= 1
if not is_found_one:
break
else:
counter += 1
print(counter)
main_function()
| Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
Input Specification:
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Output Specification:
Print the single number — the number of groups of students that will be kicked out from the club.
Demo Input:
['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | ```python
def find_root_of_a(i, a):
while i != a[i]:
i = a[i]
return i
def connect_two_people(i, j, a):
root_of_a = find_root_of_a(i, a)
root_of_b = find_root_of_a(j, a)
if root_of_b == root_of_a:
pass
else:
a[root_of_a] = a[root_of_b]
def main_function():
n, m = [int(i) for i in input().split(" ")]
a = [i for i in range(n)]
database = []
hash_a = [[[], 0] for i in range(n + 1)]
counter = 0
for t in range(m):
b = [int(y) for y in input().split(" ")]
database.append(b)
hash_a[b[0]][0].append(b[1])
hash_a[b[0]][1] += 1
hash_a[b[1]][0].append(b[0])
hash_a[b[1]][1] += 1
while True:
is_found_one = False
for i in range(len(hash_a)):
if hash_a[i][1] == 1:
is_found_one = True
hash_a[i][1] -= 1
hash_a[hash_a[i][0][0]][1] -= 1
if not is_found_one:
break
else:
counter += 1
print(counter)
main_function()
``` | 0 |
|
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"output": "YES"
},
{
"input": "4363010 696782227 701145238",
"output": "YES"
},
{
"input": "9295078 2 6",
"output": "NO"
},
{
"input": "76079 281367 119938421",
"output": "YES"
},
{
"input": "93647 7 451664565",
"output": "YES"
},
{
"input": "5 18553 10908",
"output": "NO"
},
{
"input": "6 52 30",
"output": "NO"
},
{
"input": "6431 855039 352662",
"output": "NO"
},
{
"input": "749399100 103031711 761562532",
"output": "NO"
},
{
"input": "21 65767 55245",
"output": "NO"
},
{
"input": "4796601 66897 4860613",
"output": "NO"
},
{
"input": "8 6728951 860676",
"output": "NO"
},
{
"input": "914016 6 914019",
"output": "NO"
},
{
"input": "60686899 78474 60704617",
"output": "NO"
},
{
"input": "3 743604 201724",
"output": "NO"
},
{
"input": "571128 973448796 10",
"output": "NO"
},
{
"input": "688051712 67 51",
"output": "NO"
},
{
"input": "74619 213344 6432326",
"output": "NO"
},
{
"input": "6947541 698167 6",
"output": "NO"
},
{
"input": "83 6 6772861",
"output": "NO"
},
{
"input": "251132 67561 135026988",
"output": "NO"
},
{
"input": "8897216 734348516 743245732",
"output": "YES"
},
{
"input": "50 64536 153660266",
"output": "YES"
},
{
"input": "876884 55420 971613604",
"output": "YES"
},
{
"input": "0 6906451 366041903",
"output": "YES"
},
{
"input": "11750 8 446010134",
"output": "YES"
},
{
"input": "582692707 66997 925047377",
"output": "YES"
},
{
"input": "11 957526890 957526901",
"output": "YES"
},
{
"input": "556888 514614196 515171084",
"output": "YES"
},
{
"input": "6 328006 584834704",
"output": "YES"
},
{
"input": "4567998 4 204966403",
"output": "YES"
},
{
"input": "60 317278 109460971",
"output": "YES"
},
{
"input": "906385 342131991 685170368",
"output": "YES"
},
{
"input": "1 38 902410512",
"output": "YES"
},
{
"input": "29318 787017 587931018",
"output": "YES"
},
{
"input": "351416375 243431 368213115",
"output": "YES"
},
{
"input": "54 197366062 197366117",
"output": "YES"
},
{
"input": "586389 79039 850729874",
"output": "YES"
},
{
"input": "723634470 2814619 940360134",
"output": "YES"
},
{
"input": "0 2 0",
"output": "YES"
},
{
"input": "0 2 1",
"output": "NO"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "0 2 3",
"output": "YES"
},
{
"input": "0 2 1000000000",
"output": "YES"
},
{
"input": "0 10 23",
"output": "NO"
},
{
"input": "0 2 999999999",
"output": "YES"
},
{
"input": "10 5 11",
"output": "NO"
},
{
"input": "1 2 1000000000",
"output": "YES"
},
{
"input": "1 10 20",
"output": "NO"
},
{
"input": "1 2 999999937",
"output": "YES"
},
{
"input": "10 3 5",
"output": "NO"
},
{
"input": "3 2 5",
"output": "YES"
},
{
"input": "0 4 0",
"output": "YES"
},
{
"input": "0 215 403",
"output": "NO"
},
{
"input": "5 2 10",
"output": "YES"
},
{
"input": "0 2 900000000",
"output": "YES"
},
{
"input": "0 79 4000",
"output": "NO"
},
{
"input": "5 1000 1000",
"output": "NO"
},
{
"input": "1 5 103",
"output": "NO"
},
{
"input": "5 2 6",
"output": "NO"
},
{
"input": "120 2 1000000000",
"output": "YES"
},
{
"input": "2 2 1000000000",
"output": "YES"
},
{
"input": "5 5 13",
"output": "NO"
},
{
"input": "10 5 15",
"output": "YES"
},
{
"input": "11 2 0",
"output": "NO"
},
{
"input": "3 8 53",
"output": "NO"
},
{
"input": "2 2 4",
"output": "YES"
},
{
"input": "4 4 0",
"output": "NO"
},
{
"input": "1 2 3",
"output": "YES"
},
{
"input": "5 3 9",
"output": "YES"
},
{
"input": "5 6 19",
"output": "NO"
},
{
"input": "3 10 125",
"output": "NO"
},
{
"input": "5 3 8",
"output": "YES"
},
{
"input": "6 3 9",
"output": "YES"
},
{
"input": "0 3 5",
"output": "NO"
},
{
"input": "5 3 300000035",
"output": "YES"
},
{
"input": "5 2 7",
"output": "YES"
},
{
"input": "1 5 6",
"output": "YES"
},
{
"input": "4 2 6",
"output": "YES"
},
{
"input": "0 3 999999998",
"output": "NO"
},
{
"input": "0 10001 0",
"output": "YES"
},
{
"input": "6 5 3",
"output": "NO"
},
{
"input": "1 5 1000000000",
"output": "NO"
},
{
"input": "1 3 6",
"output": "NO"
},
{
"input": "3 3 1000000000",
"output": "YES"
},
{
"input": "3 3 4",
"output": "NO"
},
{
"input": "3 3 5",
"output": "NO"
},
{
"input": "3 3 0",
"output": "NO"
},
{
"input": "1 2 4",
"output": "YES"
},
{
"input": "5 5 10",
"output": "YES"
}
] | 1,477,789,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | t,s,x = map(int,input().split())
if x < t or x == t+1:
print('NO')
elif x == t :
print('YES')
else:
r = x % s
if r == t or r == t +1 :
print('YES')
else:
print('NO')
| Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time.
Input Specification:
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Output Specification:
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
Demo Input:
['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | ```python
t,s,x = map(int,input().split())
if x < t or x == t+1:
print('NO')
elif x == t :
print('YES')
else:
r = x % s
if r == t or r == t +1 :
print('YES')
else:
print('NO')
``` | 0 |
|
14 | C | Four Segments | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 3 0\n3 0 2 0\n2 0 0 0",
"output": "NO"
},
{
"input": "0 0 3 0\n0 0 0 3\n0 3 3 3\n3 3 3 0",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n0 1 1 1\n0 0 0 1",
"output": "YES"
},
{
"input": "0 0 1 0\n1 0 1 1\n1 1 1 0\n1 0 0 0",
"output": "NO"
},
{
"input": "0 0 1 1\n1 1 2 0\n2 0 1 -1\n1 -1 0 0",
"output": "NO"
},
{
"input": "0 0 0 10\n0 10 0 9\n0 9 0 8\n0 8 0 0",
"output": "NO"
},
{
"input": "0 0 4 0\n4 0 4 0\n4 0 0 0\n0 0 0 0",
"output": "NO"
},
{
"input": "0 0 0 2\n0 2 2 2\n0 0 2 2\n2 2 2 0",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 2 2\n0 2 0 0\n2 2 2 0",
"output": "NO"
},
{
"input": "13 13 13 13\n13 13 13 13\n13 13 13 13\n13 13 13 13",
"output": "NO"
},
{
"input": "0 0 2 0\n0 1 0 3\n0 4 3 4\n3 0 3 3",
"output": "NO"
},
{
"input": "1 1 1 1\n0 1 -1 1\n-1 1 1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 -1 0 1\n0 0 0 1\n0 -1 0 -1\n0 -1 0 -1",
"output": "NO"
},
{
"input": "0 0 -1 0\n-1 0 0 0\n-1 0 -1 0\n-1 0 -1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 0",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 1",
"output": "NO"
},
{
"input": "-1 1 -1 1\n0 1 1 1\n1 -1 -1 1\n-1 1 1 1",
"output": "NO"
},
{
"input": "-1 -1 -1 -1\n-1 0 -1 0\n-1 0 -1 0\n-1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n-2 2 1 2\n1 -2 -2 2\n-2 -2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -2 -1\n-2 -2 -2 -2\n-2 -1 -2 -2\n-2 1 -2 -1",
"output": "NO"
},
{
"input": "1 2 1 2\n1 -1 1 -1\n1 -1 1 -1\n1 -1 1 -1",
"output": "NO"
},
{
"input": "-2 0 -2 -1\n-2 2 -2 0\n-2 2 -2 2\n-2 0 -2 -1",
"output": "NO"
},
{
"input": "-1 1 -2 1\n0 -1 -1 1\n-2 1 -1 -1\n0 1 0 -1",
"output": "NO"
},
{
"input": "2 -1 -2 -1\n2 -1 2 -1\n2 -1 -2 -1\n2 -1 2 -1",
"output": "NO"
},
{
"input": "0 2 0 2\n0 2 0 1\n0 1 0 1\n0 2 0 1",
"output": "NO"
},
{
"input": "1 0 1 0\n1 0 1 0\n1 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "-1 1 2 1\n0 1 0 1\n0 1 2 1\n2 1 -1 1",
"output": "NO"
},
{
"input": "0 0 2 0\n0 0 2 0\n0 -2 0 0\n0 -2 0 0",
"output": "NO"
},
{
"input": "0 -3 0 -1\n1 -1 1 -1\n0 -1 1 -2\n0 -2 -2 -3",
"output": "NO"
},
{
"input": "-3 -2 -2 -2\n3 -2 3 -2\n-3 -2 -2 -2\n3 -2 3 -2",
"output": "NO"
},
{
"input": "1 2 -2 2\n-2 2 3 2\n1 2 -2 2\n-2 2 3 2",
"output": "NO"
},
{
"input": "0 -2 1 3\n1 3 1 3\n1 3 1 3\n1 3 1 -2",
"output": "NO"
},
{
"input": "0 -3 -2 -3\n0 1 0 -3\n0 1 0 -3\n0 1 0 -3",
"output": "NO"
},
{
"input": "1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3\n1 -3 1 -3",
"output": "NO"
},
{
"input": "-3 2 -2 1\n0 2 0 -3\n0 -3 -2 1\n0 1 -3 -3",
"output": "NO"
},
{
"input": "-3 3 2 3\n2 3 2 3\n-3 3 -3 3\n-3 3 2 3",
"output": "NO"
},
{
"input": "2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2\n2 -2 2 -2",
"output": "NO"
},
{
"input": "2 -1 0 -2\n-3 -2 -3 3\n2 -2 2 -2\n0 3 -3 -2",
"output": "NO"
},
{
"input": "1 -3 -1 1\n0 -2 1 -3\n1 1 0 1\n1 -3 0 1",
"output": "NO"
},
{
"input": "-2 4 -2 4\n-2 4 -2 -2\n-2 4 -2 -2\n-2 4 -2 -2",
"output": "NO"
},
{
"input": "3 1 3 1\n-3 1 3 1\n3 3 -3 1\n-3 1 3 1",
"output": "NO"
},
{
"input": "0 1 4 1\n0 1 4 1\n4 1 0 1\n0 -2 4 1",
"output": "NO"
},
{
"input": "0 -2 0 -1\n0 -1 0 -2\n0 -2 0 -2\n0 -2 0 -2",
"output": "NO"
},
{
"input": "-1 1 -1 1\n-1 1 -1 1\n-1 1 -1 3\n-3 1 -3 1",
"output": "NO"
},
{
"input": "578327678 518066351 578327678 498442467\n583129774 498442467 578327678 518066351\n583129774 518066351 578327678 518066351\n583129774 498442467 578327678 518066351",
"output": "NO"
},
{
"input": "-973576966 32484917 -973576966 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917\n-973576966 32484917 347173379 32484917",
"output": "NO"
},
{
"input": "572793036 194804279 572793036 -866298887\n572793036 461349977 -860420833 194804279\n572793036 461349977 572793036 -866298887\n-860420833 461349977 572793036 -866298887",
"output": "NO"
},
{
"input": "949753871 -467933239 -72251156 462207752\n949753871 462207752 425479768 -467933239\n425479768 462207752 425479768 -467933239\n949753871 -467933239 949753871 462207752",
"output": "NO"
},
{
"input": "1 -1 1 -1\n-1 -1 -1 -1\n1 0 -1 -1\n1 -1 -1 -1",
"output": "NO"
},
{
"input": "1 -1 1 -1\n1 0 1 0\n1 0 1 -1\n1 0 1 -1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1",
"output": "NO"
},
{
"input": "1 -1 1 0\n1 0 1 0\n0 0 0 -1\n1 -1 1 0",
"output": "NO"
},
{
"input": "0 0 2 2\n0 0 2 0\n2 2 2 2\n0 2 0 2",
"output": "NO"
},
{
"input": "-2 -1 -1 -1\n-2 -1 -1 -1\n-2 -1 -2 2\n-2 2 -1 2",
"output": "NO"
},
{
"input": "2 1 -1 0\n-1 0 2 1\n2 1 2 1\n-1 0 2 1",
"output": "NO"
},
{
"input": "1 -1 2 -1\n1 -2 2 -2\n1 -2 2 -2\n1 -2 2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1 2\n-1 -2 -1 -2\n-1 2 -1 2\n-1 -2 -1 -2",
"output": "NO"
},
{
"input": "2 0 2 -1\n2 -1 -1 0\n2 -1 -1 0\n2 -1 -1 0",
"output": "NO"
},
{
"input": "2 -3 1 3\n1 -3 1 3\n2 3 2 -3\n2 -3 2 -3",
"output": "NO"
},
{
"input": "130120899 550158649 130120899 831843953\n130120899 550158649 130120899 831843953\n130120899 550158649 434006978 831843953\n434006978 550158649 434006978 550158649",
"output": "NO"
},
{
"input": "-214484034 559719641 -214484034 559719641\n-214484034 559719641 -214484034 559719641\n-214484034 2764087 -214484034 559719641\n-214484034 2764087 734280017 2764087",
"output": "NO"
},
{
"input": "-966947426 664261857 -994206270 664261857\n-966947426 664261857 -994206270 664261857\n-966947426 789165019 -966947426 789165019\n-966947426 664261857 -966947426 789165019",
"output": "NO"
},
{
"input": "264411509 -329579381 264411509 -329579381\n-726758913 -329579381 264411509 357369289\n-726758913 -329579381 264411509 -329579381\n264411509 -329579381 264411509 -329579381",
"output": "NO"
},
{
"input": "-193720583 -547078093 -570748852 58725936\n-570748852 -547078093 -570748852 58725936\n-193720583 58725936 -570748852 -547078093\n-570748852 -547078093 -193720583 58725936",
"output": "NO"
},
{
"input": "-534094150 -333730697 120658438 -333730697\n-534094150 -333730697 120658438 869464313\n-534094150 -333730697 -534094150 -333730697\n-534094150 869464313 -534094150 -333730697",
"output": "NO"
},
{
"input": "-328545071 835751660 -345950135 835751660\n-345950135 243569491 -328545071 835751660\n-328545071 835751660 -345950135 243569491\n-328545071 243569491 -328545071 243569491",
"output": "NO"
},
{
"input": "-985236057 -809433993 -985236057 -225363622\n-484344733 -225363622 -484344733 -225363622\n-985236057 -225363622 -985236057 -809433993\n-484344733 -225363622 -484344733 -809433993",
"output": "NO"
},
{
"input": "774287068 919049158 774287068 919049158\n250033372 653817677 250033372 653817677\n250033372 919049158 774287068 653817677\n250033372 653817677 250033372 653817677",
"output": "NO"
},
{
"input": "15319063 -661389770 632904085 -661389770\n15319063 834266473 632904085 834266473\n15319063 834266473 15319063 -661389770\n632904085 -661389770 632904085 834266473",
"output": "YES"
},
{
"input": "157550209 -594704878 157550209 524666828\n671878188 -594704878 157550209 -594704878\n671878188 -594704878 671878188 524666828\n671878188 524666828 157550209 524666828",
"output": "YES"
},
{
"input": "-887135208 728202342 127569272 728202342\n127569272 728202342 127569272 -932260532\n-887135208 -932260532 -887135208 728202342\n127569272 -932260532 -887135208 -932260532",
"output": "YES"
},
{
"input": "-777411660 -392696120 -777411660 878250237\n461320023 878250237 -777411660 878250237\n461320023 878250237 461320023 -392696120\n461320023 -392696120 -777411660 -392696120",
"output": "YES"
},
{
"input": "-892785315 567101756 -892785315 212349618\n-403060667 212349618 -403060667 567101756\n-403060667 567101756 -892785315 567101756\n-892785315 212349618 -403060667 212349618",
"output": "YES"
},
{
"input": "-360046034 -871603961 -37695563 -871603961\n-37695563 664955871 -37695563 -871603961\n-360046034 664955871 -360046034 -871603961\n-360046034 664955871 -37695563 664955871",
"output": "YES"
},
{
"input": "375089524 -852468724 -952575952 -852468724\n-952575952 -852468724 -952575952 -883150295\n-952575952 -883150295 375089524 -883150295\n375089524 -852468724 375089524 -883150295",
"output": "YES"
},
{
"input": "851113265 -893293930 851113265 -444742025\n-864765585 -893293930 -864765585 -444742025\n-864765585 -893293930 851113265 -893293930\n-864765585 -444742025 851113265 -444742025",
"output": "YES"
},
{
"input": "-309306779 559081237 255096743 559081237\n-309306779 -359724178 255096743 -359724178\n255096743 -359724178 255096743 559081237\n-309306779 559081237 -309306779 -359724178",
"output": "YES"
},
{
"input": "542957347 -480242202 566995046 -480242202\n542957347 -480242202 542957347 -298569507\n566995046 -298569507 542957347 -298569507\n566995046 -298569507 566995046 -480242202",
"output": "YES"
},
{
"input": "724715871 -943657730 964573294 -943657730\n724715871 -943657730 724715871 -216459206\n964573294 -216459206 964573294 -943657730\n724715871 -216459206 964573294 -216459206",
"output": "YES"
},
{
"input": "-394306310 -279360055 -394306310 771835446\n-394306310 -279360055 -358661829 -279360055\n-358661829 771835446 -358661829 -279360055\n-358661829 771835446 -394306310 771835446",
"output": "YES"
},
{
"input": "-204472047 -894485730 -204472047 640004355\n960702643 -894485730 960702643 640004355\n960702643 -894485730 -204472047 -894485730\n-204472047 640004355 960702643 640004355",
"output": "YES"
},
{
"input": "747591 5158024 -837871358 5158024\n-837871358 -874026904 747591 -874026904\n747591 -874026904 747591 5158024\n-837871358 -874026904 -837871358 5158024",
"output": "YES"
},
{
"input": "-442585231 90863587 800882871 90863587\n800882871 288218107 800882871 90863587\n800882871 288218107 -442585231 288218107\n-442585231 90863587 -442585231 288218107",
"output": "YES"
},
{
"input": "-969490772 476931470 -969490772 929999730\n-426216863 929999730 -969490772 929999730\n-426216863 929999730 -426216863 476931470\n-969490772 476931470 -426216863 476931470",
"output": "YES"
},
{
"input": "-683046010 -125472203 -683046010 418507423\n817863270 418507423 817863270 -125472203\n817863270 418507423 -683046010 418507423\n817863270 -125472203 -683046010 -125472203",
"output": "YES"
},
{
"input": "231996287 974811621 -923122611 974811621\n-923122611 646880519 -923122611 974811621\n231996287 646880519 231996287 974811621\n-923122611 646880519 231996287 646880519",
"output": "YES"
},
{
"input": "-83429272 -350159212 -990378619 -350159212\n-990378619 -350159212 -990378619 247777831\n-83429272 -350159212 -83429272 247777831\n-990378619 247777831 -83429272 247777831",
"output": "YES"
},
{
"input": "-679599706 974881765 -679599706 -84192294\n-554774137 -84192294 -554774137 974881765\n-554774137 974881765 -679599706 974881765\n-554774137 -84192294 -679599706 -84192294",
"output": "YES"
},
{
"input": "-155221108 -190475340 -155221108 -819044368\n-155221108 -190475340 -155875856 -190475340\n-155875856 -190475340 -155875856 -819044368\n-155875856 -819044368 -155221108 -819044368",
"output": "YES"
},
{
"input": "377126871 -877660066 -633390329 -877660066\n377126871 -175686511 377126871 -877660066\n-633390329 -877660066 -633390329 -175686511\n-633390329 -175686511 377126871 -175686511",
"output": "YES"
},
{
"input": "919022298 897009314 77151365 897009314\n77151365 579795002 919022298 579795002\n77151365 579795002 77151365 897009314\n919022298 579795002 919022298 897009314",
"output": "YES"
},
{
"input": "146411776 -188986353 146411776 -808042296\n-381166510 -808042296 -381166510 -188986353\n146411776 -188986353 -381166510 -188986353\n146411776 -808042296 -381166510 -808042296",
"output": "YES"
},
{
"input": "438703475 871560515 571565350 871560515\n571565350 -204157747 438703475 -204157747\n438703475 -204157747 438703475 871560515\n571565350 -204157747 571565350 871560515",
"output": "YES"
},
{
"input": "0 0 0 0\n5 5 5 5\n5 0 5 5\n0 5 0 0",
"output": "NO"
},
{
"input": "0 1 1 2\n2 1 1 2\n1 0 0 1\n2 1 1 0",
"output": "NO"
},
{
"input": "-3 0 -3 3\n0 0 0 3\n3 3 -3 3\n3 0 -3 0",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 0 1\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n1 1 1 1",
"output": "NO"
},
{
"input": "0 0 1 0\n1 1 0 1\n0 0 1 0\n1 1 0 1",
"output": "NO"
},
{
"input": "0 0 0 1\n0 1 1 1\n1 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 0 0\n1 1 1 1\n0 1 1 0\n1 0 0 1",
"output": "NO"
},
{
"input": "0 0 1 0\n0 1 1 1\n0 0 1 0\n0 1 1 1",
"output": "NO"
}
] | 1,661,985,914 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | points = []
for _ in range(4):
p = input()
p = p.strip().split()
p = list(map(int, p))
if _ == 0:
points.append(p[0:2])
points.append(p[2:4])
else:
c1 = points.count(p[0:2])
c2 = points.count(p[2:4])
if c1 == 0:
points.append(p[0:2])
elif c2 == 0:
points.append(p[2:4])
if len(points) == 4:
print("YES")
else:
print("NO")
| Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.
Input Specification:
The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.
Output Specification:
Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».
Demo Input:
['1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n', '0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
points = []
for _ in range(4):
p = input()
p = p.strip().split()
p = list(map(int, p))
if _ == 0:
points.append(p[0:2])
points.append(p[2:4])
else:
c1 = points.count(p[0:2])
c2 = points.count(p[2:4])
if c1 == 0:
points.append(p[0:2])
elif c2 == 0:
points.append(p[2:4])
if len(points) == 4:
print("YES")
else:
print("NO")
``` | 0 |
762 | B | USB vs. PS/2 | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings",
"two pointers"
] | null | null | Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.
You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.
You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. | The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.
The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105) — the number of mouses in the price list.
The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109) — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. | Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy. | [
"2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n"
] | [
"3 14\n"
] | In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. | 0 | [
{
"input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2",
"output": "3 14"
},
{
"input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB",
"output": "8 2345344274"
},
{
"input": "3 0 3\n0",
"output": "0 0"
},
{
"input": "1 2 4\n12\n257866589 PS/2\n246883568 USB\n104396128 USB\n993389754 PS/2\n896419206 USB\n405836977 USB\n50415634 PS/2\n152940828 PS/2\n847270779 PS/2\n850467106 USB\n922287488 USB\n622484596 PS/2",
"output": "7 1840824320"
},
{
"input": "0 4 2\n12\n170189291 USB\n670118538 USB\n690872205 PS/2\n582606841 PS/2\n397508479 USB\n578814041 USB\n96734643 USB\n168371453 USB\n528445088 PS/2\n506017602 PS/2\n512143072 USB\n188740735 USB",
"output": "6 2573047832"
},
{
"input": "5 100 100\n29\n741703337 USB\n285817204 PS/2\n837154300 USB\n250820430 USB\n809146898 PS/2\n10478072 USB\n2833804 PS/2\n669657009 USB\n427708130 PS/2\n204319444 PS/2\n209882040 USB\n56937335 USB\n107442187 USB\n46188465 USB\n902978472 USB\n792812238 PS/2\n513787720 PS/2\n486353330 PS/2\n168930159 PS/2\n183624803 USB\n67302934 USB\n264291554 USB\n467936329 USB\n82111533 USB\n849018301 USB\n645374374 PS/2\n967926381 PS/2\n286289663 PS/2\n36760263 USB",
"output": "29 11375586709"
},
{
"input": "71 15 60\n24\n892757877 USB\n613048358 USB\n108150254 USB\n425313488 USB\n949441992 USB\n859461207 PS/2\n81440099 PS/2\n348819522 USB\n606267503 USB\n443620287 PS/2\n610038583 USB\n374259313 PS/2\n947207567 PS/2\n424889764 PS/2\n58345333 USB\n735796912 PS/2\n523115052 USB\n983709864 USB\n426463338 USB\n305759345 PS/2\n689127461 PS/2\n878781173 PS/2\n445036480 USB\n643765304 USB",
"output": "24 13374616076"
},
{
"input": "37 80 100\n31\n901706521 USB\n555265160 PS/2\n547038505 PS/2\n644436873 PS/2\n105558073 USB\n915082057 PS/2\n913113815 USB\n953413471 PS/2\n252912707 PS/2\n830344497 USB\n781593007 USB\n610659875 PS/2\n177755858 PS/2\n496444729 PS/2\n617569418 USB\n304908147 PS/2\n188649950 PS/2\n705737216 USB\n473915286 USB\n622994426 PS/2\n783873493 USB\n789927108 USB\n258311181 PS/2\n720083354 PS/2\n676406125 PS/2\n634885851 PS/2\n126814339 USB\n704693540 USB\n789707618 PS/2\n938873907 USB\n576166502 USB",
"output": "31 18598842609"
},
{
"input": "6 100 10\n11\n931138340 USB\n421397130 USB\n899599243 PS/2\n891033726 PS/2\n375251114 PS/2\n991976657 USB\n743116261 PS/2\n163085281 PS/2\n111524953 PS/2\n148832199 PS/2\n480084927 PS/2",
"output": "11 6157039831"
},
{
"input": "1 1 124\n1\n2 USB",
"output": "1 2"
},
{
"input": "1 1 1\n3\n3 USB\n3 PS/2\n3 PS/2",
"output": "3 9"
},
{
"input": "3 3 3\n6\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB\n3 USB",
"output": "6 18"
},
{
"input": "1 1 1\n0",
"output": "0 0"
},
{
"input": "1 1 1\n4\n9 USB\n1 PS/2\n5 USB\n6 PS/2",
"output": "3 12"
},
{
"input": "1 1 1\n1\n6 PS/2",
"output": "1 6"
},
{
"input": "1 3 1\n5\n1 PS/2\n8 USB\n8 PS/2\n8 PS/2\n1 PS/2",
"output": "5 26"
},
{
"input": "3 2 1\n6\n1 USB\n4 PS/2\n4 PS/2\n7 USB\n8 PS/2\n1 USB",
"output": "6 25"
},
{
"input": "1 1 1\n3\n10 USB\n6 USB\n6 USB",
"output": "2 12"
},
{
"input": "1 1 1\n3\n4 USB\n3 PS/2\n3 USB",
"output": "3 10"
},
{
"input": "1 1 1\n2\n6 PS/2\n5 USB",
"output": "2 11"
},
{
"input": "1 1 2\n5\n4 USB\n7 PS/2\n10 PS/2\n7 PS/2\n3 USB",
"output": "4 21"
},
{
"input": "1 4 4\n8\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n474310330 USB",
"output": "7 1621841331"
},
{
"input": "1 4 4\n9\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB",
"output": "8 2538599717"
},
{
"input": "1 4 4\n10\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB",
"output": "8 2414801876"
},
{
"input": "48810 78876 100000\n0",
"output": "0 0"
},
{
"input": "1 0 0\n1\n862644246 PS/2",
"output": "0 0"
},
{
"input": "2 6 0\n3\n380521935 USB\n261865233 USB\n744434239 USB",
"output": "2 642387168"
},
{
"input": "0 0 0\n1\n1 USB",
"output": "0 0"
},
{
"input": "0 0 0\n1\n2 USB",
"output": "0 0"
},
{
"input": "1 1 1\n1\n5 USB",
"output": "1 5"
},
{
"input": "1 1 1\n2\n2 USB\n5 USB",
"output": "2 7"
},
{
"input": "1 1 1\n2\n3 PS/2\n6 PS/2",
"output": "2 9"
},
{
"input": "2 1 1\n4\n5 USB\n5 PS/2\n3 PS/2\n7 PS/2",
"output": "3 13"
}
] | 1,651,835,753 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 2,000 | 103,731,200 | a, b, c = map(int, input().split())
n = int(input())
cnt = []
for i in range(n):
cnt.append(list(map(str, input().split())))
for i in range(n):
cnt[i][0] = int(cnt[i][0])
cnt = sorted(cnt, key = lambda x: int(x[0]))
res = 0
cur = 0
for i, j in cnt:
if j == 'USB':
if a != 0:
a -= 1
res += i
cur += 1
elif c != 0:
c -= 1
res += i
cur += 1
if j == 'PS/2':
if b != 0:
b -= 1
res += i
cur += 1
elif c != 0:
c -= 1
res += i
cur += 1
print(cur, res) | Title: USB vs. PS/2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.
You have found a price list of a certain computer shop. In it, for *m* mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.
You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.
Input Specification:
The first line contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.
The next line contains one integer *m* (0<=≤<=*m*<=≤<=3·105) — the number of mouses in the price list.
The next *m* lines each describe another mouse. The *i*-th line contains first integer *val**i* (1<=≤<=*val**i*<=≤<=109) — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
Output Specification:
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
Demo Input:
['2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n']
Demo Output:
['3 14\n']
Note:
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. | ```python
a, b, c = map(int, input().split())
n = int(input())
cnt = []
for i in range(n):
cnt.append(list(map(str, input().split())))
for i in range(n):
cnt[i][0] = int(cnt[i][0])
cnt = sorted(cnt, key = lambda x: int(x[0]))
res = 0
cur = 0
for i, j in cnt:
if j == 'USB':
if a != 0:
a -= 1
res += i
cur += 1
elif c != 0:
c -= 1
res += i
cur += 1
if j == 'PS/2':
if b != 0:
b -= 1
res += i
cur += 1
elif c != 0:
c -= 1
res += i
cur += 1
print(cur, res)
``` | 0 |
|
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 1\n1\n0\n0",
"output": "2"
},
{
"input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0",
"output": "25"
},
{
"input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 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",
"output": "4"
},
{
"input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1",
"output": "26"
},
{
"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "121"
},
{
"input": "1 2\n0 1",
"output": "1"
},
{
"input": "1 2\n1 0",
"output": "1"
},
{
"input": "1 2\n1 1",
"output": "0"
},
{
"input": "2 1\n1\n0",
"output": "1"
},
{
"input": "2 1\n0\n1",
"output": "1"
},
{
"input": "2 1\n1\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1",
"output": "16"
}
] | 1,479,636,562 | 3,862 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 6 | 1,000 | 6,553,600 | n, m = map(int, input().split())
k = 0
a = [[int(j) for j in input().split()] for i in range(n)]
for i in range(n):
for j in range(m):
if a[i][j] == 0:
for q in range(0, j):
if a[i][q] == 1:
k += 1
break
for q in range(j+1, m):
if a[i][q] == 1:
k += 1
break
for q in range(0, i):
if a[q][j] == 1:
k += 1
break
for q in range(i+1, n):
if a[q][j] == 1:
k += 1
break
print(k)
| Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
Input Specification:
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Output Specification:
Print one integer — the number of good positions for placing the spotlight.
Demo Input:
['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n']
Demo Output:
['9\n', '20\n']
Note:
In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | ```python
n, m = map(int, input().split())
k = 0
a = [[int(j) for j in input().split()] for i in range(n)]
for i in range(n):
for j in range(m):
if a[i][j] == 0:
for q in range(0, j):
if a[i][q] == 1:
k += 1
break
for q in range(j+1, m):
if a[i][q] == 1:
k += 1
break
for q in range(0, i):
if a[q][j] == 1:
k += 1
break
for q in range(i+1, n):
if a[q][j] == 1:
k += 1
break
print(k)
``` | 0 |
|
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input. | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"input": "4\n3\n5 6\n1 3\n1 5\n4 1",
"output": "NO"
},
{
"input": "2\n2\n3 1\n1 3",
"output": "YES"
},
{
"input": "3\n2\n1 4\n3 1\n4 6",
"output": "YES"
},
{
"input": "4\n3\n5 6\n1 5\n5 1\n1 5",
"output": "YES"
},
{
"input": "5\n1\n2 3\n5 3\n5 4\n5 1\n3 5",
"output": "NO"
},
{
"input": "10\n5\n1 3\n2 3\n6 5\n6 5\n4 5\n1 3\n1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"
},
{
"input": "2\n5\n6 3\n4 5",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 5",
"output": "NO"
},
{
"input": "2\n1\n3 2\n1 2",
"output": "NO"
},
{
"input": "2\n3\n5 1\n3 5",
"output": "NO"
},
{
"input": "2\n1\n2 3\n1 2",
"output": "NO"
},
{
"input": "2\n1\n2 3\n2 1",
"output": "NO"
},
{
"input": "3\n1\n4 5\n4 1\n4 5",
"output": "NO"
},
{
"input": "2\n4\n2 6\n5 4",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 2",
"output": "NO"
},
{
"input": "2\n3\n2 1\n3 5",
"output": "NO"
},
{
"input": "2\n3\n1 2\n3 1",
"output": "NO"
},
{
"input": "2\n3\n2 6\n5 3",
"output": "NO"
},
{
"input": "3\n3\n1 2\n3 2\n3 1",
"output": "NO"
},
{
"input": "3\n5\n3 1\n1 3\n2 3",
"output": "NO"
},
{
"input": "2\n6\n2 4\n6 5",
"output": "NO"
},
{
"input": "2\n6\n4 5\n6 5",
"output": "NO"
},
{
"input": "2\n6\n3 5\n3 6",
"output": "NO"
},
{
"input": "2\n4\n1 2\n4 5",
"output": "NO"
},
{
"input": "2\n3\n2 6\n3 1",
"output": "NO"
}
] | 1,580,852,949 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 218 | 307,200 | n = int(input())
x = int(input())
s = {x, 7-x}
print(('YES','NO')[any(s&set(map(int, input().split())) for _ in range(n))]) | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.
Output Specification:
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
Demo Input:
['3\n6\n3 2\n5 4\n2 4\n', '3\n3\n2 6\n4 1\n5 3\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
n = int(input())
x = int(input())
s = {x, 7-x}
print(('YES','NO')[any(s&set(map(int, input().split())) for _ in range(n))])
``` | 3 |
|
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,588,716,597 | 2,147,483,647 | Python 3 | OK | TESTS | 4 | 218 | 0 | #ROUNIAAUDI
files=open("input.txt","r")
t,t1=files.read().split()
print(t,t1)
files.close()
files2=open("output.txt","w")
if t=="front" and t1=="1":
files2.write("L")
elif t == "front" and t1 == "2":
files2.write("R")
elif t == "back" and t1 == "2":
files2.write("L")
elif t == "back" and t1 == "1":
files2.write("R")
files2.close()
| Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
Input Specification:
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Output Specification:
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
Demo Input:
['front\n1\n']
Demo Output:
['L\n']
Note:
none | ```python
#ROUNIAAUDI
files=open("input.txt","r")
t,t1=files.read().split()
print(t,t1)
files.close()
files2=open("output.txt","w")
if t=="front" and t1=="1":
files2.write("L")
elif t == "front" and t1 == "2":
files2.write("R")
elif t == "back" and t1 == "2":
files2.write("L")
elif t == "back" and t1 == "1":
files2.write("R")
files2.close()
``` | 3 |
|
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4",
"output": "-1"
},
{
"input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4",
"output": "-1"
},
{
"input": "1\n2 4",
"output": "0"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "2\n1 1\n3 3",
"output": "0"
},
{
"input": "2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1 1\n1 2",
"output": "-1"
},
{
"input": "5\n1 2\n6 6\n1 1\n3 3\n6 1",
"output": "1"
},
{
"input": "5\n5 4\n2 6\n6 2\n1 4\n6 2",
"output": "0"
},
{
"input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1",
"output": "0"
},
{
"input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5",
"output": "-1"
},
{
"input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1",
"output": "1"
},
{
"input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4",
"output": "-1"
},
{
"input": "20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3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2",
"output": "-1"
},
{
"input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2",
"output": "1"
},
{
"input": "1\n2 2",
"output": "0"
},
{
"input": "3\n2 4\n6 6\n3 3",
"output": "-1"
},
{
"input": "2\n3 6\n4 1",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n3 3",
"output": "-1"
},
{
"input": "3\n2 3\n1 1\n2 3",
"output": "1"
},
{
"input": "3\n2 2\n2 1\n1 2",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n1 1",
"output": "-1"
}
] | 1,665,667,607 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | # from lib2to3.pgen2.token import RPAR
# import math
# import sys
# t=True
# s=input()
# arr=[]
# arr[:0]=s
# print(arr)
# ans=0
ax=[]
ay=[]
for i in range(int(input())):
# n=int(input())
# n,c=map(int,input().split())
# st=input()
x,y=map(int,input().split())
# arr=list(map(int,input().split()))
ax.append(x)
ay.append(y)
# print(ax,ay)
evex=0
evey=0
oddx=0
oddy=0
for i in range(len(ax)):
if(ax[i]%2==0):
evex+=1
else:
oddx+=1
for i in range(len(ay)):
if(ay[i]%2==0):
evey+=1
else:
oddy+=1
if(oddx==0 and oddy==0):
print(0)
elif(evex==0 and evey==0):
print(0)
elif(oddx==0 and evex!=0 and oddy!=0 and evey!=0):
print(-1)
elif(oddx!=0 and evex==0 and oddy!=0 and evey!=0):
print(-1)
elif(oddx!=0 and evex!=0 and oddy==0 and evey!=0):
print(-1)
elif(oddx!=0 and evex!=0 and oddy!=0 and evey==0):
print(-1)
elif(oddy==1 and evex==1):
print(-1)
elif(oddx==1 and evey==1):
print(-1)
else:
print(min(oddx,evex))
| Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Output Specification:
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
Demo Input:
['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | ```python
# from lib2to3.pgen2.token import RPAR
# import math
# import sys
# t=True
# s=input()
# arr=[]
# arr[:0]=s
# print(arr)
# ans=0
ax=[]
ay=[]
for i in range(int(input())):
# n=int(input())
# n,c=map(int,input().split())
# st=input()
x,y=map(int,input().split())
# arr=list(map(int,input().split()))
ax.append(x)
ay.append(y)
# print(ax,ay)
evex=0
evey=0
oddx=0
oddy=0
for i in range(len(ax)):
if(ax[i]%2==0):
evex+=1
else:
oddx+=1
for i in range(len(ay)):
if(ay[i]%2==0):
evey+=1
else:
oddy+=1
if(oddx==0 and oddy==0):
print(0)
elif(evex==0 and evey==0):
print(0)
elif(oddx==0 and evex!=0 and oddy!=0 and evey!=0):
print(-1)
elif(oddx!=0 and evex==0 and oddy!=0 and evey!=0):
print(-1)
elif(oddx!=0 and evex!=0 and oddy==0 and evey!=0):
print(-1)
elif(oddx!=0 and evex!=0 and oddy!=0 and evey==0):
print(-1)
elif(oddy==1 and evex==1):
print(-1)
elif(oddx==1 and evey==1):
print(-1)
else:
print(min(oddx,evex))
``` | 0 |
|
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4"
},
{
"input": "7 13\n6 8 14 9 4 11 10",
"output": "2"
},
{
"input": "10 15\n10 9 1 1 5 10 5 3 7 2",
"output": "3"
},
{
"input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4",
"output": "6"
},
{
"input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19",
"output": "4"
},
{
"input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52",
"output": "3"
},
{
"input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708",
"output": "0"
},
{
"input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550",
"output": "1"
}
] | 1,670,348,996 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | # your code goes here
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
c = 0
for i in l:
if m-i>=0:
m-=i
c+=1
else:
break
print(c) | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Output Specification:
Print a single integer — the maximum number of books Valera can read.
Demo Input:
['4 5\n3 1 2 1\n', '3 3\n2 2 3\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
# your code goes here
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
c = 0
for i in l:
if m-i>=0:
m-=i
c+=1
else:
break
print(c)
``` | 0 |
|
23 | C | Oranges and Apples | PROGRAMMING | 2,500 | [
"constructive algorithms",
"sortings"
] | C. Oranges and Apples | 1 | 256 | In 2*N*<=-<=1 boxes there are apples and oranges. Your task is to choose *N* boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges. | The first input line contains one number *T* — amount of tests. The description of each test starts with a natural number *N* — amount of boxes. Each of the following 2*N*<=-<=1 lines contains numbers *a**i* and *o**i* — amount of apples and oranges in the *i*-th box (0<=≤<=*a**i*,<=*o**i*<=≤<=109). The sum of *N* in all the tests in the input doesn't exceed 105. All the input numbers are integer. | For each test output two lines. In the first line output YES, if it's possible to choose *N* boxes, or NO otherwise. If the answer is positive output in the second line *N* numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space. | [
"2\n2\n10 15\n5 7\n20 18\n1\n0 0\n"
] | [
"YES\n1 3\nYES\n1\n"
] | none | 0 | [
{
"input": "2\n2\n10 15\n5 7\n20 18\n1\n0 0",
"output": "YES\n3 1\nYES\n1"
}
] | 1,593,867,082 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 654 | 15,052,800 | import os,io
from sys import stdout
import collections
# import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**6)
# from functools import lru_cache
# @lru_cache(maxsize=None)
def primes(n):
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1, 1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i-1]
return arr
def divisors(n):
i = 1
result = []
while i*i <= n:
if n%i == 0:
if n/i == i:
result.append(i)
else:
result.append(i)
result.append(n/i)
i+=1
return result
def kadane(a,size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
# @lru_cache(maxsize=None)
def digitsSum(n):
if n == 0:
return 0
r = 0
while n > 0:
r += n % 10
n //= 10
return r
def print_grid(grid):
for line in grid:
print("".join(line))
# INPUTS --------------------------
# s = input().decode('utf-8').strip()
# n = int(input())
# l = list(map(int, input().split()))
# t = int(input())
# for _ in range(t):
# for _ in range(t):
t = int(input())
for _ in range(t):
n = int(input())
boxes = []
i = 0
for _ in range(2*n-1):
boxes.append(list(map(int, input().split()))+[i+1])
i+=1
boxes = sorted(boxes, key=itemgetter(0, 1))
even = boxes[::2]
odd = boxes[1::2]
oranges = int(math.ceil(sum([e[0] for e in boxes])/2))
apples = int(math.ceil(sum([e[1] for e in boxes])/2))
oeven = sum([e[0] for e in even])
aeven = sum([e[1] for e in even])
oodd = sum([e[0] for e in odd])
aodd = sum([e[1] for e in odd])
if oeven >= oranges and aeven >= apples:
print('YES')
res = []
for e in even:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
elif oodd >= oranges and aodd >= apples:
print('YES')
res = []
for e in odd:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
else:
print('NO')
| Title: Oranges and Apples
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
In 2*N*<=-<=1 boxes there are apples and oranges. Your task is to choose *N* boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input Specification:
The first input line contains one number *T* — amount of tests. The description of each test starts with a natural number *N* — amount of boxes. Each of the following 2*N*<=-<=1 lines contains numbers *a**i* and *o**i* — amount of apples and oranges in the *i*-th box (0<=≤<=*a**i*,<=*o**i*<=≤<=109). The sum of *N* in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output Specification:
For each test output two lines. In the first line output YES, if it's possible to choose *N* boxes, or NO otherwise. If the answer is positive output in the second line *N* numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Demo Input:
['2\n2\n10 15\n5 7\n20 18\n1\n0 0\n']
Demo Output:
['YES\n1 3\nYES\n1\n']
Note:
none | ```python
import os,io
from sys import stdout
import collections
# import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**6)
# from functools import lru_cache
# @lru_cache(maxsize=None)
def primes(n):
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1, 1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i-1]
return arr
def divisors(n):
i = 1
result = []
while i*i <= n:
if n%i == 0:
if n/i == i:
result.append(i)
else:
result.append(i)
result.append(n/i)
i+=1
return result
def kadane(a,size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
# @lru_cache(maxsize=None)
def digitsSum(n):
if n == 0:
return 0
r = 0
while n > 0:
r += n % 10
n //= 10
return r
def print_grid(grid):
for line in grid:
print("".join(line))
# INPUTS --------------------------
# s = input().decode('utf-8').strip()
# n = int(input())
# l = list(map(int, input().split()))
# t = int(input())
# for _ in range(t):
# for _ in range(t):
t = int(input())
for _ in range(t):
n = int(input())
boxes = []
i = 0
for _ in range(2*n-1):
boxes.append(list(map(int, input().split()))+[i+1])
i+=1
boxes = sorted(boxes, key=itemgetter(0, 1))
even = boxes[::2]
odd = boxes[1::2]
oranges = int(math.ceil(sum([e[0] for e in boxes])/2))
apples = int(math.ceil(sum([e[1] for e in boxes])/2))
oeven = sum([e[0] for e in even])
aeven = sum([e[1] for e in even])
oodd = sum([e[0] for e in odd])
aodd = sum([e[1] for e in odd])
if oeven >= oranges and aeven >= apples:
print('YES')
res = []
for e in even:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
elif oodd >= oranges and aodd >= apples:
print('YES')
res = []
for e in odd:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
else:
print('NO')
``` | 0 |
106 | A | Card Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Card Game | 2 | 256 | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.
The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.
A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.
You are given the trump suit and two different cards. Determine whether the first one beats the second one or not. | The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C"). | Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes). | [
"H\nQH 9S\n",
"S\n8D 6D\n",
"C\n7H AS\n"
] | [
"YES\n",
"YES",
"NO"
] | none | 500 | [
{
"input": "H\nQH 9S",
"output": "YES"
},
{
"input": "S\n8D 6D",
"output": "YES"
},
{
"input": "C\n7H AS",
"output": "NO"
},
{
"input": "C\nKC 9C",
"output": "YES"
},
{
"input": "D\n7D KD",
"output": "NO"
},
{
"input": "H\n7H KD",
"output": "YES"
},
{
"input": "D\nAS AH",
"output": "NO"
},
{
"input": "H\nKH KS",
"output": "YES"
},
{
"input": "C\n9H 6C",
"output": "NO"
},
{
"input": "C\n9H JC",
"output": "NO"
},
{
"input": "D\nTD JD",
"output": "NO"
},
{
"input": "H\n6S 7S",
"output": "NO"
},
{
"input": "D\n7S 8S",
"output": "NO"
},
{
"input": "S\n8H 9H",
"output": "NO"
},
{
"input": "C\n9D TD",
"output": "NO"
},
{
"input": "H\nTC JC",
"output": "NO"
},
{
"input": "C\nJH QH",
"output": "NO"
},
{
"input": "H\nQD KD",
"output": "NO"
},
{
"input": "D\nKS AS",
"output": "NO"
},
{
"input": "S\nAH 6H",
"output": "YES"
},
{
"input": "H\n7D 6D",
"output": "YES"
},
{
"input": "S\n8H 7H",
"output": "YES"
},
{
"input": "D\n9S 8S",
"output": "YES"
},
{
"input": "S\nTC 9C",
"output": "YES"
},
{
"input": "H\nJS TS",
"output": "YES"
},
{
"input": "S\nQD JD",
"output": "YES"
},
{
"input": "D\nKH QH",
"output": "YES"
},
{
"input": "H\nAD KD",
"output": "YES"
},
{
"input": "H\nQS QD",
"output": "NO"
},
{
"input": "C\nTS TH",
"output": "NO"
},
{
"input": "C\n6C 6D",
"output": "YES"
},
{
"input": "H\n8H 8D",
"output": "YES"
},
{
"input": "S\n7D 7S",
"output": "NO"
},
{
"input": "H\nJC JH",
"output": "NO"
},
{
"input": "H\n8H 9C",
"output": "YES"
},
{
"input": "D\n9D 6S",
"output": "YES"
},
{
"input": "C\nJC AH",
"output": "YES"
},
{
"input": "S\nAS KD",
"output": "YES"
},
{
"input": "S\n7S JS",
"output": "NO"
},
{
"input": "H\nTH 8H",
"output": "YES"
},
{
"input": "S\n7S QS",
"output": "NO"
},
{
"input": "C\nKC QC",
"output": "YES"
},
{
"input": "S\nAD 9S",
"output": "NO"
},
{
"input": "D\n7H 8D",
"output": "NO"
},
{
"input": "H\nJC 9H",
"output": "NO"
},
{
"input": "C\n7S AC",
"output": "NO"
},
{
"input": "C\n8C 7C",
"output": "YES"
},
{
"input": "H\n9D 8S",
"output": "NO"
},
{
"input": "D\nAC KS",
"output": "NO"
},
{
"input": "H\n8C QH",
"output": "NO"
},
{
"input": "S\n7S TS",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\nKS QS",
"output": "YES"
},
{
"input": "H\nAC QC",
"output": "YES"
},
{
"input": "S\n9H 8D",
"output": "NO"
},
{
"input": "S\nTS JS",
"output": "NO"
},
{
"input": "S\n8H 7C",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\n7S QS",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\nTS KS",
"output": "NO"
},
{
"input": "C\nTH KH",
"output": "NO"
},
{
"input": "H\n9C 6D",
"output": "NO"
},
{
"input": "H\n9C 8D",
"output": "NO"
},
{
"input": "H\nTH AH",
"output": "NO"
},
{
"input": "H\nTH JH",
"output": "NO"
},
{
"input": "H\nQS 9C",
"output": "NO"
},
{
"input": "H\nKC AC",
"output": "NO"
},
{
"input": "H\nAH KH",
"output": "YES"
},
{
"input": "H\nKS QS",
"output": "YES"
},
{
"input": "C\nAD KS",
"output": "NO"
},
{
"input": "H\nQS 9C",
"output": "NO"
},
{
"input": "H\n9D 7S",
"output": "NO"
},
{
"input": "D\n6D 9S",
"output": "YES"
},
{
"input": "H\nAH KH",
"output": "YES"
},
{
"input": "H\nKC AC",
"output": "NO"
},
{
"input": "D\n8S 6C",
"output": "NO"
},
{
"input": "S\nAC KC",
"output": "YES"
}
] | 1,609,044,113 | 2,147,483,647 | Python 3 | OK | TESTS | 78 | 218 | 0 | t = str(input())
s1, s2 = map(str,input().split())
temp = "6789TJQKA"
if s1[1] == s2[1]:
print("YES" if temp.find(s1[0]) > temp.find(s2[0]) else "NO")
else:
print("YES" if s1[1] == t else "NO") | Title: Card Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.
The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.
A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.
You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.
Input Specification:
The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").
Output Specification:
Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).
Demo Input:
['H\nQH 9S\n', 'S\n8D 6D\n', 'C\n7H AS\n']
Demo Output:
['YES\n', 'YES', 'NO']
Note:
none | ```python
t = str(input())
s1, s2 = map(str,input().split())
temp = "6789TJQKA"
if s1[1] == s2[1]:
print("YES" if temp.find(s1[0]) > temp.find(s2[0]) else "NO")
else:
print("YES" if s1[1] == t else "NO")
``` | 3.9455 |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,515,135,513 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,529,600 | n,k=map(int,input().split())
maxi=0
ans=0
index=1
for i in range(1,10):
x=n*i
c=10
count=0
while x%c==0:
count+=1
x/=c
if count>maxi:
maxi=count
index=i
if k>maxi:
ans=n*index*(10**(k-maxi))
else:
ans=n*index
print(ans)
| Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Output Specification:
Print the *k*-rounding of *n*.
Demo Input:
['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n']
Demo Output:
['30000\n', '10000\n', '38101\n', '12345678900000000\n']
Note:
none | ```python
n,k=map(int,input().split())
maxi=0
ans=0
index=1
for i in range(1,10):
x=n*i
c=10
count=0
while x%c==0:
count+=1
x/=c
if count>maxi:
maxi=count
index=i
if k>maxi:
ans=n*index*(10**(k-maxi))
else:
ans=n*index
print(ans)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,570,727,508 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | s = input()
a = []
countered = 0
for alpha in s:
if alpha not in a:
a.append(alpha)
if alpha == 'l':
countered += 1
elif alpha == 'l' and countered <2:
a.append(alpha)
countered += 1
for alpha in a:
check = False
if alpha in 'hello':
check = True
elif 'hello' in ''.join(a):
check = True
break
if check:
print("YES")
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
a = []
countered = 0
for alpha in s:
if alpha not in a:
a.append(alpha)
if alpha == 'l':
countered += 1
elif alpha == 'l' and countered <2:
a.append(alpha)
countered += 1
for alpha in a:
check = False
if alpha in 'hello':
check = True
elif 'hello' in ''.join(a):
check = True
break
if check:
print("YES")
else:
print('NO')
``` | 0 |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000",
"output": "1"
},
{
"input": "12345 67890123456789123457",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158",
"output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158"
},
{
"input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751",
"output": "1"
},
{
"input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794",
"output": "1"
},
{
"input": "10000 1000000000",
"output": "1"
},
{
"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "11210171722243 65715435710585778347",
"output": "1"
},
{
"input": "2921881079263974825226940825843 767693191032295360887755303860323261471",
"output": "1"
},
{
"input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085",
"output": "1"
},
{
"input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424",
"output": "1"
},
{
"input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614",
"output": "1"
},
{
"input": "15943150466658398903 15943150466658398903",
"output": "15943150466658398903"
},
{
"input": "410470228200245407491525399055972 410470228200245407491525399055972",
"output": "410470228200245407491525399055972"
},
{
"input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307",
"output": "51894705655711504622197349350106792045098781545973899451307"
},
{
"input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410",
"output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410"
},
{
"input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535",
"output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535"
},
{
"input": "1 2000000000",
"output": "1"
},
{
"input": "13 1928834874",
"output": "1"
},
{
"input": "87 2938984237482934238",
"output": "1"
},
{
"input": "213 413",
"output": "1"
},
{
"input": "3 4",
"output": "1"
}
] | 1,631,319,928 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 77 | 6,758,400 | if __name__ == '__main__':
numA, numB = input().split()
if numA == numB:
print(numA)
else:
print("1")
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output Specification:
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
Demo Input:
['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n']
Demo Output:
['1\n', '61803398874989484820458683436563811772030917980576\n']
Note:
none | ```python
if __name__ == '__main__':
numA, numB = input().split()
if numA == numB:
print(numA)
else:
print("1")
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,673,522,951 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | count = int(input())
toprint = ""
for x in range(count):
word = input()
if len(word)>10:
num = len(word)-2
ans = word[0] + str(num) + word[len(word)-1]
else:
ans = word
if x==0:
toprint += ans
else:
toprint += "\n" + ans
print(toprint) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
count = int(input())
toprint = ""
for x in range(count):
word = input()
if len(word)>10:
num = len(word)-2
ans = word[0] + str(num) + word[len(word)-1]
else:
ans = word
if x==0:
toprint += ans
else:
toprint += "\n" + ans
print(toprint)
``` | 3.977 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,665,044,943 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
a = [0,0,0]
for i in range(n):
x,y,z = map(int,input().split())
a[0] += x
a[1] += y
a[2] += z
if any(a):
print("NO")
else:
print("YES") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
a = [0,0,0]
for i in range(n):
x,y,z = map(int,input().split())
a[0] += x
a[1] += y
a[2] += z
if any(a):
print("NO")
else:
print("YES")
``` | 3.977 |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10000",
"output": "10800100"
},
{
"input": "2333",
"output": "310060"
},
{
"input": "9139",
"output": "10134010"
},
{
"input": "9859",
"output": "10422001"
},
{
"input": "5987",
"output": "2221201"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "46"
},
{
"input": "5",
"output": "55"
},
{
"input": "7",
"output": "73"
},
{
"input": "9",
"output": "91"
},
{
"input": "10",
"output": "109"
},
{
"input": "15",
"output": "154"
},
{
"input": "51",
"output": "613"
},
{
"input": "99",
"output": "1414"
},
{
"input": "138",
"output": "2224"
},
{
"input": "233",
"output": "5050"
},
{
"input": "666",
"output": "27100"
},
{
"input": "1234",
"output": "110206"
},
{
"input": "3567",
"output": "1033003"
},
{
"input": "4445",
"output": "1221301"
},
{
"input": "5689",
"output": "2114002"
},
{
"input": "6666",
"output": "3102004"
},
{
"input": "7777",
"output": "5300200"
},
{
"input": "8888",
"output": "10110061"
},
{
"input": "9411",
"output": "10214200"
},
{
"input": "5539",
"output": "2101114"
},
{
"input": "6259",
"output": "2511100"
},
{
"input": "2387",
"output": "312220"
},
{
"input": "8515",
"output": "10030114"
}
] | 1,647,459,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | k=int(input())
print(19+(9*(k-1))+9*(k//10)) | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
Output Specification:
A single number, denoting the $k$-th smallest perfect integer.
Demo Input:
['1\n', '2\n']
Demo Output:
['19\n', '28\n']
Note:
The first perfect integer is $19$ and the second one is $28$. | ```python
k=int(input())
print(19+(9*(k-1))+9*(k//10))
``` | 0 |
|
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C"
},
{
"input": "15",
"output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C"
},
{
"input": "100",
"output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C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C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1",
"output": "1\nC"
}
] | 1,567,607,918 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | #print(" ".join(map(str, r)))
n = int(input())
a = []
a = [[0] * n for i in range(n)]
for i in range(len(a)):
for j in range(len(a[i])):
if i % 2 == 0:
if j % 2 == 0:
a[i][j] = "C"
else:
a[i][j] = "."
else:
if j % 2 !=0:
a[i][j] = "C"
else:
a[i][j] = "."
count = 0
for z in a:
for u in z:
if u == "C":
count+=1
print (count)
for e in a:
print(" ".join(map(str, e)))
| Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any.
Demo Input:
['2\n']
Demo Output:
['2\nC.\n.C\n']
Note:
none | ```python
#print(" ".join(map(str, r)))
n = int(input())
a = []
a = [[0] * n for i in range(n)]
for i in range(len(a)):
for j in range(len(a[i])):
if i % 2 == 0:
if j % 2 == 0:
a[i][j] = "C"
else:
a[i][j] = "."
else:
if j % 2 !=0:
a[i][j] = "C"
else:
a[i][j] = "."
count = 0
for z in a:
for u in z:
if u == "C":
count+=1
print (count)
for e in a:
print(" ".join(map(str, e)))
``` | 0 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,622,058,182 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 0 | n = int(input())
l = list(map(int,input().split()))
odd = even = 0
for i in range(len(l)):
if(l[i]%2!=0):
odd+=1
else:
even+=1
if(odd%2==0):
print(even)
else:
print(odd) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n = int(input())
l = list(map(int,input().split()))
odd = even = 0
for i in range(len(l)):
if(l[i]%2!=0):
odd+=1
else:
even+=1
if(odd%2==0):
print(even)
else:
print(odd)
``` | 3 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,685,799,439 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 312 | 13,824,000 | from fractions import Fraction
arr = list(map(int, input().split()))
arr.sort()
x = 7 - arr[1]
y = Fraction(x/6)
if x == 1:
print("1/1")
elif x == 0:
print("0/1")
else:
print(y) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
from fractions import Fraction
arr = list(map(int, input().split()))
arr.sort()
x = 7 - arr[1]
y = Fraction(x/6)
if x == 1:
print("1/1")
elif x == 0:
print("0/1")
else:
print(y)
``` | 0 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,622,522,132 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Jun 1 12:33:33 2021
@author: nagan
"""
n, m, z = map(int, input().split())
print(z // (n * m)) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 1 12:33:33 2021
@author: nagan
"""
n, m, z = map(int, input().split())
print(z // (n * m))
``` | 0 |
|
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match. | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
},
{
"input": "4 5 4 5",
"output": "0.833333333333"
},
{
"input": "466 701 95 721",
"output": "0.937693791148"
},
{
"input": "268 470 444 885",
"output": "0.725614009325"
},
{
"input": "632 916 713 821",
"output": "0.719292895126"
},
{
"input": "269 656 918 992",
"output": "0.428937461623"
},
{
"input": "71 657 187 695",
"output": "0.310488463257"
},
{
"input": "435 852 973 978",
"output": "0.511844133157"
},
{
"input": "518 816 243 359",
"output": "0.719734031025"
},
{
"input": "882 962 311 811",
"output": "0.966386645447"
},
{
"input": "684 774 580 736",
"output": "0.906051574446"
},
{
"input": "486 868 929 999",
"output": "0.577723252958"
},
{
"input": "132 359 996 998",
"output": "0.368154532345"
},
{
"input": "933 977 266 450",
"output": "0.972879407907"
},
{
"input": "298 833 615 872",
"output": "0.441270817024"
},
{
"input": "34 554 14 958",
"output": "0.817324099167"
},
{
"input": "836 934 800 905",
"output": "0.906105535462"
},
{
"input": "482 815 69 509",
"output": "0.914365577772"
},
{
"input": "284 423 137 521",
"output": "0.885974839378"
},
{
"input": "648 881 486 703",
"output": "0.800911421248"
},
{
"input": "450 885 755 836",
"output": "0.533901011176"
},
{
"input": "533 773 823 998",
"output": "0.729222130525"
},
{
"input": "897 957 92 898",
"output": "0.993193806364"
},
{
"input": "699 925 441 928",
"output": "0.866816866175"
},
{
"input": "64 704 148 603",
"output": "0.289486317811"
},
{
"input": "719 735 626 990",
"output": "0.986124079764"
},
{
"input": "1 1000 1 1000",
"output": "0.500250125063"
}
] | 1,609,133,642 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 0 | a, b, c, d = map(int, input().split())
m = a / b
n = 1 - (1 - a / b) * (1 - c / d)
print(round(m / n, 6)) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match.
Input Specification:
A single line contains four integers .
Output Specification:
Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['1 2 1 2\n']
Demo Output:
['0.666666666667']
Note:
none | ```python
a, b, c, d = map(int, input().split())
m = a / b
n = 1 - (1 - a / b) * (1 - c / d)
print(round(m / n, 6))
``` | 3 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,697,856,774 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 0 | a = input().split("+")
a.sort()
c = ""
for i in a:
c =c+"+"+ i
print(c[1:]) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
a = input().split("+")
a.sort()
c = ""
for i in a:
c =c+"+"+ i
print(c[1:])
``` | 3 |
|
18 | D | Seller Bob | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | 0 | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1",
"output": "2147483646"
},
{
"input": "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819",
"output": "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054..."
},
{
"input": "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304",
"output": "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648"
},
{
"input": "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257",
"output": "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273..."
},
{
"input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165",
"output": "0"
},
{
"input": "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312",
"output": "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933..."
},
{
"input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838",
"output": "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779..."
},
{
"input": "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157",
"output": "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144"
},
{
"input": "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549",
"output": "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096"
},
{
"input": "1\nsell 2000",
"output": "0"
},
{
"input": "1\nwin 2000",
"output": "0"
},
{
"input": "2\nwin 2000\nsell 2000",
"output": "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..."
}
] | 1,553,430,869 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 248 | 409,600 | N = int(input())
winsell = (N)*[0]
pow = (2001)*[-1];
ans = int(0)
for i in range(0,N):
S, x = input().split()
x = int(x)
if S == "win":
winsell[i] = x
else:
pow[x] = i;
winsell[i] = -x
for i in range(2000,-1,-1):
if pow[i]!=-1:
b = bool(0)
for j in range(pow[i],-1,-1):
if winsell[j] != 2001:
if winsell[j] == i:
b = 1
ans+=2**i
for k in range(j,pow[i]+1):
winsell[k]=2001
else:
b = 1
if b == 1:
break
print(ans)
# Sun Mar 24 2019 15:34:27 GMT+0300 (MSK)
| Title: Seller Bob
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally.
Input Specification:
The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000).
Output Specification:
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
Demo Input:
['7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n', '3\nwin 5\nsell 6\nsell 4\n']
Demo Output:
['1056\n', '0\n']
Note:
none | ```python
N = int(input())
winsell = (N)*[0]
pow = (2001)*[-1];
ans = int(0)
for i in range(0,N):
S, x = input().split()
x = int(x)
if S == "win":
winsell[i] = x
else:
pow[x] = i;
winsell[i] = -x
for i in range(2000,-1,-1):
if pow[i]!=-1:
b = bool(0)
for j in range(pow[i],-1,-1):
if winsell[j] != 2001:
if winsell[j] == i:
b = 1
ans+=2**i
for k in range(j,pow[i]+1):
winsell[k]=2001
else:
b = 1
if b == 1:
break
print(ans)
# Sun Mar 24 2019 15:34:27 GMT+0300 (MSK)
``` | 0 |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "20\n5 3 7 2 1 6 4",
"output": "6"
},
{
"input": "10\n5 1 1 1 1 1 5",
"output": "6"
},
{
"input": "50\n10 1 10 1 10 1 10",
"output": "1"
},
{
"input": "77\n11 11 11 11 11 11 10",
"output": "1"
},
{
"input": "1\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n100 100 100 100 100 100 100",
"output": "3"
},
{
"input": "999\n10 20 10 20 30 20 10",
"output": "3"
},
{
"input": "433\n109 58 77 10 39 125 15",
"output": "7"
},
{
"input": "1\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n1 0 1 0 1 0 1",
"output": "1"
},
{
"input": "997\n1 1 0 0 1 0 1",
"output": "1"
},
{
"input": "1000\n1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1000\n1000 1000 1000 1000 1000 1000 1000",
"output": "1"
},
{
"input": "1000\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "1000\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "1000\n1 0 0 1 0 0 1",
"output": "1"
},
{
"input": "509\n105 23 98 0 7 0 155",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2\n1 1 0 0 0 0 0",
"output": "2"
},
{
"input": "1\n0 0 0 0 0 1 0",
"output": "6"
},
{
"input": "10\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 6 0",
"output": "6"
},
{
"input": "3\n0 1 0 0 0 0 0",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "28\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "100\n5 5 5 5 5 5 5",
"output": "6"
},
{
"input": "4\n1 0 0 0 0 0 1",
"output": "7"
},
{
"input": "2\n0 0 0 0 0 0 1",
"output": "7"
},
{
"input": "7\n0 0 0 0 0 0 7",
"output": "7"
},
{
"input": "7\n2 1 1 1 1 1 0",
"output": "6"
},
{
"input": "2\n0 0 1 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1 0",
"output": "6"
},
{
"input": "5\n1 1 1 0 0 1 1",
"output": "7"
},
{
"input": "100\n10 20 30 10 10 10 10",
"output": "7"
},
{
"input": "1\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "70\n10 10 10 10 10 10 10",
"output": "7"
},
{
"input": "22\n1 2 3 4 5 6 10",
"output": "7"
},
{
"input": "5\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "2\n0 0 0 1 0 0 0",
"output": "4"
},
{
"input": "6\n1 0 0 0 0 0 2",
"output": "7"
},
{
"input": "10\n1 2 2 1 2 1 1",
"output": "7"
},
{
"input": "5\n0 0 0 0 0 0 10",
"output": "7"
},
{
"input": "4\n0 1 1 0 0 0 0",
"output": "3"
},
{
"input": "100\n0 0 0 0 0 1 0",
"output": "6"
}
] | 1,664,876,683 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 92 | 0 | t=int(input())
l=list(map(int,input().split()))
check=0
x=0
while check<t:
for i in range(len(l)):
if check<t:
check+=l[i]
x=i
print(x+1)
| Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.
Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.
Input Specification:
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.
Output Specification:
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Demo Input:
['100\n15 20 20 15 10 30 45\n', '2\n1 0 0 0 0 0 0\n']
Demo Output:
['6\n', '1\n']
Note:
Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book. | ```python
t=int(input())
l=list(map(int,input().split()))
check=0
x=0
while check<t:
for i in range(len(l)):
if check<t:
check+=l[i]
x=i
print(x+1)
``` | 3 |
|
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "0"
},
{
"input": "6\n2 6 3 8 7 2",
"output": "5\n2 5\n3 0\n6 0\n7 0\n8 0"
},
{
"input": "7\n2 1 2 1 2 1 2",
"output": "2\n1 2\n2 2"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "1\n1 1"
},
{
"input": "9\n2 3 3 3 2 1 2 3 2",
"output": "1\n1 0"
},
{
"input": "10\n3 1 1 1 1 3 1 2 2 1",
"output": "2\n2 1\n3 5"
},
{
"input": "12\n10 9 8 7 7 8 9 10 10 9 8 7",
"output": "0"
}
] | 1,623,474,406 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def myf(x):
return x[0]
n = int(input())
a = [int(i) for i in input().split()]
b = list(set(a))
l = len(b)
# print(l)
st = [[0 for i in range(2)] for i in range(l)]
c=0
for i in range(l):
z = a.count(b[i])
flag = True
if z >= 2:
p = a.index(b[i])
q = a.index(b[i], p+1)
m = q-p
p = q
for j in range(z-2):
q = a.index(b[i], p+1)
if q-p != m:
flag = False
break
if flag == True:
st[c][0] = b[i]
st[c][1] = m
c += 1
else:
st[c][0] = 0
st[c][1] = 0
c += 1
else:
st[c][0] = b[i]
st[c][1] = 0
c += 1
st.sort(key=myf)
for i in range(l):
if st[i][0] != 0:
print(st[i][0], st[i][1])
if st[0][0]==0 and st[l-1][0]==0:
print(0)
| Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | ```python
def myf(x):
return x[0]
n = int(input())
a = [int(i) for i in input().split()]
b = list(set(a))
l = len(b)
# print(l)
st = [[0 for i in range(2)] for i in range(l)]
c=0
for i in range(l):
z = a.count(b[i])
flag = True
if z >= 2:
p = a.index(b[i])
q = a.index(b[i], p+1)
m = q-p
p = q
for j in range(z-2):
q = a.index(b[i], p+1)
if q-p != m:
flag = False
break
if flag == True:
st[c][0] = b[i]
st[c][1] = m
c += 1
else:
st[c][0] = 0
st[c][1] = 0
c += 1
else:
st[c][0] = b[i]
st[c][1] = 0
c += 1
st.sort(key=myf)
for i in range(l):
if st[i][0] != 0:
print(st[i][0], st[i][1])
if st[0][0]==0 and st[l-1][0]==0:
print(0)
``` | 0 |
|
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\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",
"output": "1"
},
{
"input": "2\n10000000 10000000",
"output": "1"
},
{
"input": "5\n100000000 100000001 100000000 100000001 100000000",
"output": "2"
},
{
"input": "9\n4 3 4 3 4 1 3 3 1",
"output": "3"
},
{
"input": "3\n10000000 1000000000 10000000",
"output": "2"
},
{
"input": "12\n5 6 6 5 6 1 9 9 9 9 9 1",
"output": "6"
},
{
"input": "5\n5 5 1 2 1",
"output": "2"
},
{
"input": "5\n2 2 1 3 1",
"output": "2"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "3\n100000005 1000000000 100000005",
"output": "2"
},
{
"input": "5\n1 2 2 2 1",
"output": "4"
},
{
"input": "3\n10000 1000000 10000",
"output": "2"
},
{
"input": "3\n999999999 999999998 999999998",
"output": "1"
},
{
"input": "6\n2 1 1 2 3 4",
"output": "1"
},
{
"input": "4\n1000000000 900000000 900000000 1000000000",
"output": "1"
},
{
"input": "5\n7 7 2 7 2",
"output": "2"
},
{
"input": "6\n10 10 1 20 20 1",
"output": "3"
},
{
"input": "2\n999999999 999999999",
"output": "1"
},
{
"input": "10\n100000 100000 1 2 3 4 5 6 7 1",
"output": "7"
},
{
"input": "10\n3 3 1 2 2 1 10 10 10 10",
"output": "3"
},
{
"input": "5\n900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n3 3 2 5 2",
"output": "2"
},
{
"input": "2\n100000000 100000000",
"output": "1"
},
{
"input": "10\n10 15 10 2 54 54 54 54 2 10",
"output": "5"
},
{
"input": "2\n999999 999999",
"output": "1"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n1000000000 100000000 1000000000 1000000000 100000000",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "2"
},
{
"input": "5\n1 3 2 3 1",
"output": "4"
},
{
"input": "5\n2 2 1 4 1",
"output": "2"
},
{
"input": "6\n1 2 2 2 2 1",
"output": "5"
},
{
"input": "7\n3 7 6 7 6 7 3",
"output": "6"
},
{
"input": "8\n1 2 2 2 2 1 2 2",
"output": "5"
},
{
"input": "10\n2 2 2 3 3 1 3 3 3 1",
"output": "4"
},
{
"input": "2\n88888888 88888888",
"output": "1"
},
{
"input": "3\n100000000 100000000 100000000",
"output": "1"
},
{
"input": "10\n1 3 2 4 5 5 4 3 2 1",
"output": "9"
},
{
"input": "5\n2 2 1 2 1",
"output": "2"
},
{
"input": "6\n900000005 900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n41 41 1 41 1",
"output": "2"
},
{
"input": "6\n5 5 1 3 3 1",
"output": "3"
},
{
"input": "8\n1 2 2 2 1 2 2 2",
"output": "4"
},
{
"input": "7\n6 6 6 6 1 8 1",
"output": "2"
},
{
"input": "3\n999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n5 5 4 10 4",
"output": "2"
},
{
"input": "11\n2 2 3 4 1 5 3 4 2 5 1",
"output": "6"
},
{
"input": "5\n3 5 4 5 3",
"output": "4"
},
{
"input": "6\n6 6 6 6 1 1",
"output": "1"
},
{
"input": "7\n11 1 3 2 3 1 11",
"output": "4"
},
{
"input": "5\n3 3 1 2 1",
"output": "2"
},
{
"input": "5\n4 4 2 5 2",
"output": "2"
},
{
"input": "4\n10000099 10000567 10000099 10000234",
"output": "2"
},
{
"input": "4\n100000009 100000011 100000012 100000009",
"output": "3"
},
{
"input": "2\n1000000 1000000",
"output": "1"
},
{
"input": "2\n10000010 10000010",
"output": "1"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "8\n2 6 2 8 1 9 8 1",
"output": "3"
},
{
"input": "5\n7 7 1 8 1",
"output": "2"
},
{
"input": "7\n1 3 2 3 2 3 1",
"output": "6"
},
{
"input": "7\n2 3 2 1 3 4 1",
"output": "3"
},
{
"input": "5\n1000000000 999999999 1000000000 1000000000 999999999",
"output": "3"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n5 5 3 5 3",
"output": "2"
},
{
"input": "6\n2 3 3 3 3 2",
"output": "5"
},
{
"input": "4\n1 1 2 2",
"output": "1"
},
{
"input": "5\n1 1 2 2 2",
"output": "1"
},
{
"input": "6\n2 1 1 2 2 2",
"output": "1"
},
{
"input": "5\n1000000000 1000000000 100000000 1000000000 100000000",
"output": "2"
},
{
"input": "7\n2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "8\n2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "10\n2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "11\n2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "12\n2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "13\n2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1000000000 100000000 100000000 1000000000",
"output": "1"
},
{
"input": "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1 2 3 1",
"output": "3"
},
{
"input": "8\n5 5 5 5 3 5 5 3",
"output": "3"
},
{
"input": "7\n2 3 2 1 4 4 1",
"output": "3"
},
{
"input": "6\n3 3 1 2 4 1",
"output": "3"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "5\n3 3 2 8 2",
"output": "2"
},
{
"input": "5\n1 2 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 1 2",
"output": "2"
},
{
"input": "5\n3 1 1 3 2",
"output": "1"
},
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "4\n2 2 1 1",
"output": "1"
},
{
"input": "5\n1 2 2 1 2",
"output": "3"
},
{
"input": "7\n2 1 2 1 1 2 1",
"output": "1"
},
{
"input": "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "85\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1",
"output": "84"
},
{
"input": "5\n1000000000 1000000000 999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n2 1 2 2 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n1 2 1 1",
"output": "1"
},
{
"input": "6\n1 3 4 2 4 1",
"output": "5"
},
{
"input": "9\n2 2 5 1 6 8 7 9 1",
"output": "5"
},
{
"input": "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999",
"output": "6"
},
{
"input": "7\n3 3 1 2 4 1 2",
"output": "3"
},
{
"input": "7\n3 3 1 2 3 4 1",
"output": "4"
},
{
"input": "8\n10 5 10 1 10 10 10 1",
"output": "4"
}
] | 1,568,357,352 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | if __name__ == "__main__":
n = int(input())
nums = [int(a) for a in input().strip().split()]
min_num = min(nums)
pre_index = -1
ans = 1e5 + 1
for index in range(n):
if nums[index] == min_num:
if pre_index == -1:
pre_index = index
else:
ans = min(ans, index - pre_index)
print(str(ans - 1))
| Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
Input Specification:
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Output Specification:
Print the only number — distance between two nearest minimums in the array.
Demo Input:
['2\n3 3\n', '3\n5 6 5\n', '9\n2 1 3 5 4 1 2 3 1\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
none | ```python
if __name__ == "__main__":
n = int(input())
nums = [int(a) for a in input().strip().split()]
min_num = min(nums)
pre_index = -1
ans = 1e5 + 1
for index in range(n):
if nums[index] == min_num:
if pre_index == -1:
pre_index = index
else:
ans = min(ans, index - pre_index)
print(str(ans - 1))
``` | 0 |
|
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:
- Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=><=*h**i*<=+<=1.
Compute the minimal time (in seconds) required to eat all nuts. | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,604,354,894 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import com.sun.jdi.ArrayReference;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int n = fs.nextInt();
int[] a = fs.readArray(n);
int ans = a[n-1] + n;
for (int i = n-1; i>0; i--) {
if (a[i] >= a[i-1]) {
ans += 1;
} else {
ans += a[i];
ans += a[i-1];
}
}
System.out.println(ans);
}
public static boolean inArray(ArrayList<Integer> a, int n) {
for (int i = 0; i<a.size(); i++) {
if (a.get(i) == n) return true;
}
return false;
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:
- Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=><=*h**i*<=+<=1.
Compute the minimal time (in seconds) required to eat all nuts.
Input Specification:
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Output Specification:
Print a single integer — the minimal time required to eat all nuts in seconds.
Demo Input:
['2\n1\n2\n', '5\n2\n1\n2\n1\n1\n']
Demo Output:
['5\n', '14\n']
Note:
none | ```python
import com.sun.jdi.ArrayReference;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int n = fs.nextInt();
int[] a = fs.readArray(n);
int ans = a[n-1] + n;
for (int i = n-1; i>0; i--) {
if (a[i] >= a[i-1]) {
ans += 1;
} else {
ans += a[i];
ans += a[i-1];
}
}
System.out.println(ans);
}
public static boolean inArray(ArrayList<Integer> a, int n) {
for (int i = 0; i<a.size(); i++) {
if (a.get(i) == n) return true;
}
return false;
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
``` | -1 |
|
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100",
"output": "14247"
},
{
"input": "1000000000 1000000000",
"output": "4444444444"
},
{
"input": "77 77",
"output": "77"
},
{
"input": "69 788",
"output": "452195"
},
{
"input": "474 747",
"output": "202794"
},
{
"input": "4 77777",
"output": "4070145675"
},
{
"input": "1 1000000",
"output": "1394675359387"
},
{
"input": "47 744447",
"output": "381286992761"
},
{
"input": "47444 1000000000",
"output": "1394672348253941136"
},
{
"input": "48 854888",
"output": "749733199853"
},
{
"input": "854444 985555",
"output": "582719941728"
},
{
"input": "774744 774747",
"output": "3098985"
},
{
"input": "654 987654",
"output": "1339803940266"
},
{
"input": "477777 1000000000",
"output": "1394672167300009765"
},
{
"input": "77777 777777777",
"output": "407018021649898097"
},
{
"input": "963 85555574",
"output": "7526978888069560"
},
{
"input": "47 7444",
"output": "38125896"
},
{
"input": "1 1000000000",
"output": "1394672350065645019"
},
{
"input": "474 999888555",
"output": "1394177038954402791"
},
{
"input": "777 1000000000",
"output": "1394672350065239125"
},
{
"input": "7 777777774",
"output": "407018023386632646"
},
{
"input": "369 852",
"output": "606732"
},
{
"input": "47 47",
"output": "47"
},
{
"input": "747 748",
"output": "1521"
},
{
"input": "77777440 77777444",
"output": "388887220"
},
{
"input": "987545885 999875584",
"output": "54798666661186800"
},
{
"input": "2 777777776",
"output": "407018024942188226"
},
{
"input": "1 1",
"output": "4"
},
{
"input": "1 2",
"output": "8"
},
{
"input": "999999999 1000000000",
"output": "8888888888"
},
{
"input": "777777777 1000000000",
"output": "987654325123456789"
},
{
"input": "777777778 1000000000",
"output": "987654324345679012"
},
{
"input": "5 6",
"output": "14"
},
{
"input": "49 49",
"output": "74"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "3 4",
"output": "8"
}
] | 1,688,753,767 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 0 | def is_lucky(n):
while n > 0:
if n % 10 != 4 and n % 10 != 7:
return False
n //= 10
return True
def next_lucky(n):
i = n + 1
while not is_lucky(i):
i += 1
return i
l, r = map(int, input().split())
ans = 0
for i in range(l, r+1):
if is_lucky(i):
ans += i
else:
ans += next_lucky(i)
print(ans)
| Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
Input Specification:
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
Output Specification:
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2 7\n', '7 7\n']
Demo Output:
['33\n', '7\n']
Note:
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | ```python
def is_lucky(n):
while n > 0:
if n % 10 != 4 and n % 10 != 7:
return False
n //= 10
return True
def next_lucky(n):
i = n + 1
while not is_lucky(i):
i += 1
return i
l, r = map(int, input().split())
ans = 0
for i in range(l, r+1):
if is_lucky(i):
ans += i
else:
ans += next_lucky(i)
print(ans)
``` | 0 |
|
578 | B | "Or" Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy"
] | null | null | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output the maximum value of a bitwise OR of sequence elements after performing operations. | [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n"
] | [
"3\n",
"79\n"
] | For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | 500 | [
{
"input": "3 1 2\n1 1 1",
"output": "3"
},
{
"input": "4 2 3\n1 2 4 8",
"output": "79"
},
{
"input": "2 1 2\n12 9",
"output": "30"
},
{
"input": "2 1 2\n12 7",
"output": "31"
},
{
"input": "3 1 3\n3 2 0",
"output": "11"
},
{
"input": "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1073741825000000000"
},
{
"input": "1 2 3\n612635770",
"output": "5513721930"
},
{
"input": "3 2 5\n0 2 3",
"output": "75"
},
{
"input": "2 1 8\n18 17",
"output": "154"
},
{
"input": "5 10 8\n0 0 0 0 0",
"output": "0"
},
{
"input": "1 1 2\n1",
"output": "2"
},
{
"input": "1 1 2\n0",
"output": "0"
},
{
"input": "3 2 6\n724148075 828984987 810015532",
"output": "29996605423"
},
{
"input": "3 1 2\n17 18 4",
"output": "54"
},
{
"input": "3 1 2\n4 17 18",
"output": "54"
},
{
"input": "2 2 2\n60 59",
"output": "252"
},
{
"input": "2 2 2\n9 10",
"output": "46"
},
{
"input": "3 1 2\n10 12 5",
"output": "31"
},
{
"input": "3 1 2\n20 17 8",
"output": "62"
},
{
"input": "3 1 2\n5 12 10",
"output": "31"
},
{
"input": "3 1 8\n10 17 18",
"output": "155"
},
{
"input": "3 1 2\n17 20 28",
"output": "62"
},
{
"input": "5 1 3\n1 5 13 8 16",
"output": "63"
}
] | 1,653,107,120 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import sys
input = lambda : sys.stdin.readline().strip()
a , k , x = list(map(int,input().split()))
b = sorted(list(map(int,input().split())))
b[-1] = b[-1] * (x ** k)
count = b[0]
for i in range(1,a):
count |= b[i]
print(count) | Title: "Or" Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally.
Input Specification:
The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output Specification:
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Demo Input:
['3 1 2\n1 1 1\n', '4 2 3\n1 2 4 8\n']
Demo Output:
['3\n', '79\n']
Note:
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | ```python
import sys
input = lambda : sys.stdin.readline().strip()
a , k , x = list(map(int,input().split()))
b = sorted(list(map(int,input().split())))
b[-1] = b[-1] * (x ** k)
count = b[0]
for i in range(1,a):
count |= b[i]
print(count)
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,693,122,838 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input()) # Read the number of force vectors
total_force = [0, 0, 0] # Initialize the total force as (0, 0, 0)
# Read and accumulate the force vectors
for _ in range(n):
x, y, z = map(int, input().split())
total_force[0] += x
total_force[1] += y
total_force[2] += z
# Check if the total force is (0, 0, 0) and print the result
if total_force == [0, 0, 0]:
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input()) # Read the number of force vectors
total_force = [0, 0, 0] # Initialize the total force as (0, 0, 0)
# Read and accumulate the force vectors
for _ in range(n):
x, y, z = map(int, input().split())
total_force[0] += x
total_force[1] += y
total_force[2] += z
# Check if the total force is (0, 0, 0) and print the result
if total_force == [0, 0, 0]:
print("YES")
else:
print("NO")
``` | 3.977 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,647,018,876 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 46 | 124 | 0 | n=int(input())
l=[]
for i in range(n):
l.append(list(map(int,input().split())))
s=[]
sum=0
for j in range(len(l[0])):
for i in range(n):
sum=sum+l[i][j]
s.append(sum)
sum=0
if s[0]==s[1] and s[1]==s[2]:
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
l=[]
for i in range(n):
l.append(list(map(int,input().split())))
s=[]
sum=0
for j in range(len(l[0])):
for i in range(n):
sum=sum+l[i][j]
s.append(sum)
sum=0
if s[0]==s[1] and s[1]==s[2]:
print("YES")
else:
print("NO")
``` | 0 |
915 | B | Browser | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.
Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab *i*, then she can move it to the tab *max*(*i*<=-<=1,<=*a*) or to the tab *min*(*i*<=+<=1,<=*b*)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab *i*, she can close all the tabs with indices from segment [*a*,<=*i*<=-<=1] or from segment [*i*<=+<=1,<=*b*]). In the aforementioned expressions *a* and *b* denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then *a*<==<=3, *b*<==<=6.
What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from *l* to *r* inclusive opened? | The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened. | Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*]. | [
"6 3 2 4\n",
"6 3 1 3\n",
"5 2 1 5\n"
] | [
"5\n",
"1\n",
"0\n"
] | In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current position of the cursor.
In the third test Luba doesn't need to do anything. | 0 | [
{
"input": "6 3 2 4",
"output": "5"
},
{
"input": "6 3 1 3",
"output": "1"
},
{
"input": "5 2 1 5",
"output": "0"
},
{
"input": "100 1 1 99",
"output": "99"
},
{
"input": "100 50 1 99",
"output": "50"
},
{
"input": "100 99 1 99",
"output": "1"
},
{
"input": "100 100 1 99",
"output": "2"
},
{
"input": "100 50 2 100",
"output": "49"
},
{
"input": "100 1 100 100",
"output": "100"
},
{
"input": "100 50 50 50",
"output": "2"
},
{
"input": "6 4 2 5",
"output": "6"
},
{
"input": "100 5 2 50",
"output": "53"
},
{
"input": "10 7 3 9",
"output": "10"
},
{
"input": "7 4 2 5",
"output": "6"
},
{
"input": "43 16 2 18",
"output": "20"
},
{
"input": "100 50 2 51",
"output": "52"
},
{
"input": "6 5 2 4",
"output": "5"
},
{
"input": "10 5 2 7",
"output": "9"
},
{
"input": "10 10 2 9",
"output": "10"
},
{
"input": "10 7 3 7",
"output": "6"
},
{
"input": "64 64 8 44",
"output": "58"
},
{
"input": "5 4 2 4",
"output": "4"
},
{
"input": "6 6 3 5",
"output": "5"
},
{
"input": "10 6 2 7",
"output": "8"
},
{
"input": "8 6 2 7",
"output": "8"
},
{
"input": "7 5 2 4",
"output": "5"
},
{
"input": "7 5 2 6",
"output": "7"
},
{
"input": "100 50 49 99",
"output": "53"
},
{
"input": "100 50 2 99",
"output": "147"
},
{
"input": "10 9 2 9",
"output": "9"
},
{
"input": "10 10 7 9",
"output": "5"
},
{
"input": "8 4 2 7",
"output": "9"
},
{
"input": "100 50 2 2",
"output": "50"
},
{
"input": "10 4 3 7",
"output": "7"
},
{
"input": "6 3 2 5",
"output": "6"
},
{
"input": "53 17 13 18",
"output": "8"
},
{
"input": "10 6 3 6",
"output": "5"
},
{
"input": "9 8 2 5",
"output": "8"
},
{
"input": "100 50 2 3",
"output": "50"
},
{
"input": "10 7 2 9",
"output": "11"
},
{
"input": "6 1 2 5",
"output": "6"
},
{
"input": "7 6 2 4",
"output": "6"
},
{
"input": "26 12 2 4",
"output": "12"
},
{
"input": "10 8 3 7",
"output": "7"
},
{
"input": "100 97 3 98",
"output": "98"
},
{
"input": "6 2 2 4",
"output": "4"
},
{
"input": "9 2 4 6",
"output": "6"
},
{
"input": "6 6 2 4",
"output": "6"
},
{
"input": "50 2 25 49",
"output": "49"
},
{
"input": "5 5 2 3",
"output": "5"
},
{
"input": "49 11 2 17",
"output": "23"
},
{
"input": "10 3 2 9",
"output": "10"
},
{
"input": "10 6 3 7",
"output": "7"
},
{
"input": "6 1 5 5",
"output": "6"
},
{
"input": "5 5 3 4",
"output": "4"
},
{
"input": "10 2 5 6",
"output": "6"
},
{
"input": "7 7 3 4",
"output": "6"
},
{
"input": "7 3 2 3",
"output": "3"
},
{
"input": "5 1 2 4",
"output": "5"
},
{
"input": "100 53 2 99",
"output": "145"
},
{
"input": "10 2 4 7",
"output": "7"
},
{
"input": "5 2 1 4",
"output": "3"
},
{
"input": "100 65 41 84",
"output": "64"
},
{
"input": "33 20 7 17",
"output": "15"
},
{
"input": "7 2 3 6",
"output": "6"
},
{
"input": "77 64 10 65",
"output": "58"
},
{
"input": "6 1 3 4",
"output": "5"
},
{
"input": "6 4 2 4",
"output": "4"
},
{
"input": "11 8 2 10",
"output": "12"
},
{
"input": "7 1 3 6",
"output": "7"
},
{
"input": "100 50 2 50",
"output": "50"
},
{
"input": "50 49 5 8",
"output": "46"
},
{
"input": "15 1 10 13",
"output": "14"
},
{
"input": "13 9 5 11",
"output": "10"
},
{
"input": "20 3 5 8",
"output": "7"
},
{
"input": "10 5 2 3",
"output": "5"
},
{
"input": "7 1 3 5",
"output": "6"
},
{
"input": "7 2 3 4",
"output": "4"
},
{
"input": "10 5 2 5",
"output": "5"
},
{
"input": "8 5 2 6",
"output": "7"
},
{
"input": "8 5 3 6",
"output": "6"
},
{
"input": "9 6 3 7",
"output": "7"
},
{
"input": "50 46 34 37",
"output": "14"
},
{
"input": "10 7 2 8",
"output": "9"
},
{
"input": "8 3 1 4",
"output": "2"
},
{
"input": "100 3 10 20",
"output": "19"
},
{
"input": "6 2 1 5",
"output": "4"
},
{
"input": "12 11 5 10",
"output": "8"
},
{
"input": "98 97 72 83",
"output": "27"
},
{
"input": "100 5 3 98",
"output": "99"
},
{
"input": "8 5 2 7",
"output": "9"
},
{
"input": "10 10 4 6",
"output": "8"
},
{
"input": "10 4 2 5",
"output": "6"
},
{
"input": "3 3 2 3",
"output": "2"
},
{
"input": "75 30 6 33",
"output": "32"
},
{
"input": "4 3 2 3",
"output": "3"
},
{
"input": "2 2 1 1",
"output": "2"
},
{
"input": "2 2 1 2",
"output": "0"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "20 9 7 17",
"output": "14"
},
{
"input": "10 2 3 7",
"output": "7"
},
{
"input": "100 40 30 80",
"output": "62"
},
{
"input": "10 6 2 3",
"output": "6"
},
{
"input": "7 3 2 5",
"output": "6"
},
{
"input": "10 6 2 9",
"output": "12"
},
{
"input": "23 20 19 22",
"output": "6"
},
{
"input": "100 100 1 1",
"output": "100"
},
{
"input": "10 2 5 9",
"output": "9"
},
{
"input": "9 7 2 8",
"output": "9"
},
{
"input": "100 50 50 100",
"output": "1"
},
{
"input": "3 1 2 2",
"output": "3"
},
{
"input": "16 13 2 15",
"output": "17"
},
{
"input": "9 8 2 6",
"output": "8"
},
{
"input": "43 22 9 24",
"output": "19"
},
{
"input": "5 4 2 3",
"output": "4"
},
{
"input": "82 72 66 75",
"output": "14"
},
{
"input": "7 4 5 6",
"output": "4"
},
{
"input": "100 50 51 51",
"output": "3"
},
{
"input": "6 5 2 6",
"output": "4"
},
{
"input": "4 4 2 2",
"output": "4"
},
{
"input": "4 3 2 4",
"output": "2"
},
{
"input": "2 2 2 2",
"output": "1"
},
{
"input": "6 1 2 4",
"output": "5"
},
{
"input": "2 1 1 1",
"output": "1"
},
{
"input": "4 2 2 3",
"output": "3"
},
{
"input": "2 1 1 2",
"output": "0"
},
{
"input": "5 4 1 2",
"output": "3"
},
{
"input": "100 100 2 99",
"output": "100"
},
{
"input": "10 6 3 4",
"output": "5"
},
{
"input": "100 74 30 60",
"output": "46"
},
{
"input": "4 1 2 3",
"output": "4"
},
{
"input": "100 50 3 79",
"output": "107"
},
{
"input": "10 6 2 8",
"output": "10"
},
{
"input": "100 51 23 33",
"output": "30"
},
{
"input": "3 1 2 3",
"output": "2"
},
{
"input": "29 13 14 23",
"output": "12"
},
{
"input": "6 5 2 5",
"output": "5"
},
{
"input": "10 2 3 5",
"output": "5"
},
{
"input": "9 3 1 6",
"output": "4"
},
{
"input": "45 33 23 37",
"output": "20"
},
{
"input": "100 99 1 98",
"output": "2"
},
{
"input": "100 79 29 68",
"output": "52"
},
{
"input": "7 7 6 6",
"output": "3"
},
{
"input": "100 4 30 60",
"output": "58"
},
{
"input": "100 33 50 50",
"output": "19"
},
{
"input": "50 2 34 37",
"output": "37"
},
{
"input": "100 70 2 99",
"output": "128"
},
{
"input": "6 6 4 4",
"output": "4"
},
{
"input": "41 24 14 19",
"output": "12"
},
{
"input": "100 54 52 55",
"output": "6"
},
{
"input": "10 5 3 6",
"output": "6"
},
{
"input": "6 5 4 6",
"output": "2"
},
{
"input": "10 9 2 3",
"output": "9"
},
{
"input": "6 4 2 3",
"output": "4"
},
{
"input": "100 68 5 49",
"output": "65"
},
{
"input": "8 4 3 6",
"output": "6"
},
{
"input": "9 3 2 8",
"output": "9"
},
{
"input": "100 50 1 1",
"output": "50"
},
{
"input": "10 9 5 9",
"output": "6"
},
{
"input": "62 54 2 54",
"output": "54"
},
{
"input": "100 54 30 60",
"output": "38"
},
{
"input": "6 6 6 6",
"output": "1"
},
{
"input": "10 2 2 9",
"output": "9"
},
{
"input": "50 3 23 25",
"output": "24"
},
{
"input": "24 1 5 18",
"output": "19"
},
{
"input": "43 35 23 34",
"output": "14"
},
{
"input": "50 46 23 26",
"output": "25"
},
{
"input": "10 8 5 9",
"output": "7"
},
{
"input": "6 2 2 5",
"output": "5"
},
{
"input": "43 1 13 41",
"output": "42"
},
{
"input": "13 2 1 5",
"output": "4"
},
{
"input": "6 3 3 5",
"output": "4"
},
{
"input": "14 10 4 12",
"output": "12"
},
{
"input": "5 1 4 4",
"output": "5"
},
{
"input": "3 3 1 1",
"output": "3"
},
{
"input": "17 17 12 14",
"output": "7"
},
{
"input": "20 15 6 7",
"output": "11"
},
{
"input": "86 36 8 70",
"output": "92"
},
{
"input": "100 69 39 58",
"output": "32"
},
{
"input": "3 3 2 2",
"output": "3"
},
{
"input": "3 2 1 1",
"output": "2"
},
{
"input": "9 7 3 8",
"output": "8"
},
{
"input": "4 4 2 3",
"output": "4"
},
{
"input": "100 4 2 5",
"output": "6"
},
{
"input": "100 65 5 13",
"output": "62"
},
{
"input": "3 2 2 3",
"output": "1"
},
{
"input": "44 38 20 28",
"output": "20"
},
{
"input": "100 65 58 60",
"output": "9"
},
{
"input": "16 12 8 13",
"output": "8"
},
{
"input": "11 8 4 9",
"output": "8"
},
{
"input": "20 9 2 10",
"output": "11"
},
{
"input": "5 5 4 5",
"output": "2"
},
{
"input": "100 99 1 50",
"output": "50"
},
{
"input": "6 5 3 5",
"output": "4"
},
{
"input": "50 29 7 48",
"output": "62"
},
{
"input": "26 11 1 24",
"output": "14"
},
{
"input": "5 2 3 4",
"output": "4"
},
{
"input": "100 1 2 3",
"output": "4"
},
{
"input": "100 60 27 56",
"output": "35"
},
{
"input": "6 4 2 6",
"output": "3"
},
{
"input": "8 7 3 5",
"output": "6"
},
{
"input": "4 1 3 3",
"output": "4"
},
{
"input": "12 9 2 10",
"output": "11"
},
{
"input": "100 25 9 19",
"output": "18"
},
{
"input": "10 7 3 8",
"output": "8"
},
{
"input": "7 3 2 6",
"output": "7"
},
{
"input": "100 39 4 40",
"output": "39"
},
{
"input": "100 51 2 99",
"output": "147"
},
{
"input": "15 6 4 10",
"output": "10"
},
{
"input": "10 4 4 9",
"output": "7"
},
{
"input": "6 4 3 4",
"output": "3"
},
{
"input": "14 7 4 12",
"output": "13"
},
{
"input": "4 4 1 2",
"output": "3"
},
{
"input": "6 5 2 3",
"output": "5"
},
{
"input": "12 12 5 5",
"output": "9"
},
{
"input": "10 5 3 5",
"output": "4"
},
{
"input": "8 6 2 2",
"output": "6"
},
{
"input": "8 7 2 7",
"output": "7"
},
{
"input": "100 33 5 60",
"output": "84"
},
{
"input": "100 32 5 60",
"output": "84"
},
{
"input": "79 5 3 5",
"output": "4"
},
{
"input": "85 85 85 85",
"output": "1"
},
{
"input": "69 69 69 69",
"output": "1"
},
{
"input": "7 5 3 6",
"output": "6"
},
{
"input": "7 4 2 6",
"output": "8"
},
{
"input": "2 1 2 2",
"output": "2"
},
{
"input": "100 2 1 90",
"output": "89"
},
{
"input": "100 89 11 90",
"output": "82"
},
{
"input": "10 1 2 8",
"output": "9"
}
] | 1,517,396,034 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 5,632,000 | from math import *
n,pos,l,r=map(int,input().split(' '))
a,b=1,1
if l==1:
a=0
if r==n:
b=0
if (a,b)==(0,0):
print(0)
elif b==0:
print((abs(pos-l)+1))
elif a==0:
print((abs(pos-r)+1))
else:
print((abs(pos-l)+1)+(r-l+1))
| Title: Browser
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba is surfing the Internet. She currently has *n* opened tabs in her browser, indexed from 1 to *n* from left to right. The mouse cursor is currently located at the *pos*-th tab. Luba needs to use the tabs with indices from *l* to *r* (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.
Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab *i*, then she can move it to the tab *max*(*i*<=-<=1,<=*a*) or to the tab *min*(*i*<=+<=1,<=*b*)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab *i*, she can close all the tabs with indices from segment [*a*,<=*i*<=-<=1] or from segment [*i*<=+<=1,<=*b*]). In the aforementioned expressions *a* and *b* denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then *a*<==<=3, *b*<==<=6.
What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from *l* to *r* inclusive opened?
Input Specification:
The only line of input contains four integer numbers *n*, *pos*, *l*, *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*pos*<=≤<=*n*, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.
Output Specification:
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [*l*,<=*r*].
Demo Input:
['6 3 2 4\n', '6 3 1 3\n', '5 2 1 5\n']
Demo Output:
['5\n', '1\n', '0\n']
Note:
In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current position of the cursor.
In the third test Luba doesn't need to do anything. | ```python
from math import *
n,pos,l,r=map(int,input().split(' '))
a,b=1,1
if l==1:
a=0
if r==n:
b=0
if (a,b)==(0,0):
print(0)
elif b==0:
print((abs(pos-l)+1))
elif a==0:
print((abs(pos-r)+1))
else:
print((abs(pos-l)+1)+(r-l+1))
``` | 0 |
|
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem! | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*. | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzx\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy"
},
{
"input": "q\nz",
"output": "r"
},
{
"input": "pnzcl\npnzdf",
"output": "pnzcm"
},
{
"input": "vklldrxnfgyorgfpfezvhbouyzzzzz\nvklldrxnfgyorgfpfezvhbouzaaadv",
"output": "vklldrxnfgyorgfpfezvhbouzaaaaa"
},
{
"input": "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr",
"output": "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "exoudpymnspkocwszzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nexoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabml",
"output": "exoudpymnspkocwtaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "anarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubil\nanarzvsklmwvovozwnmhklkpcseeogdgauoppmzrukynbjjoxytuvsiecuzfquxnowewebhtuoxepocyeamqfrblpwqiokbcubim",
"output": "No such string"
},
{
"input": "uqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjllzzz\nuqyugulumzwlxsjnxxkutzqayskrbjoaaekbhckjryhjjlmaaa",
"output": "No such string"
},
{
"input": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdacbzzzzzzzzzzzzzz\nesfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaatf",
"output": "esfaeyxpblcrriizhnhfrxnbopqvhwtetgjqavlqdlxexaifgvkqfwzneibhxxdaccaaaaaaaaaaaaaa"
},
{
"input": "oisjtilteipnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\noisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "oisjtilteipoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "svpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimgzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nsvpoxbsudndfnnpugbouawegyxgtmvqzbewxpcwhopdbwscimhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No such string"
},
{
"input": "ddzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ndeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaao",
"output": "deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavdzz\nxqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdavilj",
"output": "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczdaveaa"
},
{
"input": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfoq\npoflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawujg",
"output": "poflpxucohdobeisxfsnkbdzwizjjhgngufssqhmfgmydmmrnuminrvxxamoebhczlwsfefdtnchaisfxkfcovxmvppxnrfawfor"
},
{
"input": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjnzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nvonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "vonggnmokmvmguwtobkxoqgxkuxtyjmxrygyliohlhwxuxjmlkqcfuxboxjoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "bqycw\nquhod",
"output": "bqycx"
},
{
"input": "hceslswecf\nnmxshuymaa",
"output": "hceslswecg"
},
{
"input": "awqtzslxowuaefe\nvujscakjpvxviki",
"output": "awqtzslxowuaeff"
},
{
"input": "lerlcnaogdravnogfogcyoxgi\nojrbithvjdqtempegvqxmgmmw",
"output": "lerlcnaogdravnogfogcyoxgj"
},
{
"input": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxv\noevvkhujmhagaholrmsatdjjyfmyblvgetpnxgjcilugjsncjs",
"output": "jbrhvicytqaivheqeourrlosvnsujsxdinryyawgalidsaufxw"
},
{
"input": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzww\nspvgaswympzlscnumemgiznngnxqgccbubmxgqmaakbnyngkxlxjjsafricchhpecdjgxw",
"output": "jrpogrcuhqdpmyzpuabuhaptlxaeiqjxhqkmuzsjbhqxvdtoocrkusaeasqdwlunomwzwx"
},
{
"input": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcf\nohhhhkujfpjbgouebtmmbzizuhuumvrsqfniwpmxdtzhyiaivdyxhywnqzagicydixjtvbqbevhbqttu",
"output": "mzmhjmfxaxaplzjmjkbyadeweltagyyuzpvrmnyvirjpdmebxyzjvdoezhnayfrvtnccryhkvhcvakcg"
},
{
"input": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndl\nuvuqvyrnhtyubpevizhjxdvmpueittksrnosmfuuzbimnqussasdjufrthrgjbyzomauaxbvwferfvtmydmwmjaoxg",
"output": "cdmwmzutsicpzhcokbbhwktqbomozxvvjlhwdgtiledgurxsfreisgczdwgupzxmjnfyjxcpdwzkggludkcmgppndm"
},
{
"input": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyay\nqibcfxdfovoejutaeetbbwrgexdrvqywwmhipxgfrvhzovxkfawpfnpjvlhkyahessodqcclangxefcaixysqijnitevwmpalkzd",
"output": "dpnmrwpbgzvcmrcodwgvvfwpyagdwlngmhrazyvalszhruprxzmwltftxmujfyrrnwzvphgqlcphreumqkytswxziugburwrlyaz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "No such string"
},
{
"input": "phdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmun\nphdvmuwqmvzyurtnshitcypuzbhpceovkibzbhhjwxkdtvqmbpoumeoiztxtvkvsjrlnhowsdmgftuiulzebdigmuo",
"output": "No such string"
},
{
"input": "hrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzoog\nhrsantdquixzjyjtqytcmnflnyehzbibkbgkqffgqpkgeuqmbmxzhbjwsnfkizvbcyoghyvnxxjavoahlqjxomtsouzooh",
"output": "No such string"
},
{
"input": "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywm",
"output": "No such string"
},
{
"input": "yijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowmk\nyijdysvzfcnaedvnecswgoylhzgguxecmucepgstjbdkbjyfdlxxxejkrrxfiuwjpdmdhhqhlqeqzjwudtdryrfkpwfxdjlkowml",
"output": "No such string"
},
{
"input": "a\nb",
"output": "No such string"
},
{
"input": "x\nz",
"output": "y"
},
{
"input": "a\nz",
"output": "b"
},
{
"input": "y\nz",
"output": "No such string"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "No such string"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
},
{
"input": "yzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyz"
},
{
"input": "aaa\naac",
"output": "aab"
},
{
"input": "aaa\naab",
"output": "No such string"
},
{
"input": "zzx\nzzz",
"output": "zzy"
},
{
"input": "zzy\nzzz",
"output": "No such string"
},
{
"input": "aba\naca",
"output": "abb"
},
{
"input": "aaa\nbbb",
"output": "aab"
},
{
"input": "azzz\ncaaa",
"output": "baaa"
}
] | 1,642,311,066 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 93 | 0 | s=input()
t=input()
a=[]
b=[]
for i in s:
a.append(i)
for i in t:
b.append(i)
if len(s)==s.count('z'):
ans='a'*(len(s)+1)
if ans!=t:
print(ans)
else:
print("No such string")
else:
pos=-1
for i in range(len(s)-1,-1,-1):
if a[i]!='z':
pos=i
break
val=ord(a[pos])+1
a[pos]=chr(val)
for i in range(pos+1,len(s)):
a[i]='a'
if a!=b:
print(*a,sep="")
elif a==b:
print("No such string")
| Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*.
Let's help Vitaly solve this easy problem!
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*.
Output Specification:
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
Demo Input:
['a\nc\n', 'aaa\nzzz\n', 'abcdefg\nabcdefh\n']
Demo Output:
['b\n', 'kkk\n', 'No such string\n']
Note:
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ... *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | ```python
s=input()
t=input()
a=[]
b=[]
for i in s:
a.append(i)
for i in t:
b.append(i)
if len(s)==s.count('z'):
ans='a'*(len(s)+1)
if ans!=t:
print(ans)
else:
print("No such string")
else:
pos=-1
for i in range(len(s)-1,-1,-1):
if a[i]!='z':
pos=i
break
val=ord(a[pos])+1
a[pos]=chr(val)
for i in range(pos+1,len(s)):
a[i]='a'
if a!=b:
print(*a,sep="")
elif a==b:
print("No such string")
``` | 3 |
|
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,687,938,577 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | x = int(input())
if x % 4 == 0 or x % 7 == 0 or '4' in str(x) or '7' in str(x):
print("YES")
else:
print("NO") | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
x = int(input())
if x % 4 == 0 or x % 7 == 0 or '4' in str(x) or '7' in str(x):
print("YES")
else:
print("NO")
``` | 0 |
|
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct. | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 2147483648\n2 1",
"output": "2"
},
{
"input": "3 2\n1 3 2",
"output": "3 "
},
{
"input": "3 3\n1 2 3",
"output": "3 "
},
{
"input": "5 2\n2 1 3 4 5",
"output": "5 "
},
{
"input": "10 2\n7 10 5 8 9 3 4 6 1 2",
"output": "10 "
},
{
"input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98",
"output": "70 "
},
{
"input": "4 10\n2 1 3 4",
"output": "4"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "10 "
},
{
"input": "10 2\n10 9 8 7 6 5 4 3 2 1",
"output": "10 "
},
{
"input": "4 1000000000000\n3 4 1 2",
"output": "4"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "91 "
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "100 "
},
{
"input": "2 1000000000000\n1 2",
"output": "2"
},
{
"input": "5 2\n1 4 3 5 2",
"output": "4 "
},
{
"input": "5 2\n1 3 2 4 5",
"output": "3 "
},
{
"input": "4 1000000000000\n3 1 2 4",
"output": "4"
},
{
"input": "4 2\n1 3 2 4",
"output": "3 "
},
{
"input": "10 3\n8 1 9 2 3 10 4 5 6 7",
"output": "9 "
},
{
"input": "5 2\n2 1 4 3 5",
"output": "4 "
},
{
"input": "3 4294967297\n2 1 3",
"output": "3"
},
{
"input": "4 4294967297\n3 2 1 4",
"output": "4"
},
{
"input": "5 4294967298\n3 2 1 4 5",
"output": "5"
},
{
"input": "10 4\n5 4 7 1 2 9 3 6 8 10",
"output": "9 "
},
{
"input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11",
"output": "11"
}
] | 1,521,486,067 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 78 | 7,065,600 | IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
n, k = IL()
a = IL()
ans = 0
score = 0
for i in range(n-1):
if a[0] > a[1]:
score += 1
else:
score = 1
if score == k:
ans = a[0]
break
p1, p2 = a[:2]
a.pop(0)
a[0] = max(p1, p2)
a.append(min(p1, p2))
if ans==0:
ans = max(a)
print(ans) | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
Input Specification:
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output Specification:
Output a single integer — power of the winner.
Demo Input:
['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n']
Demo Output:
['2 ', '3 ', '6 ', '2\n']
Note:
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | ```python
IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
n, k = IL()
a = IL()
ans = 0
score = 0
for i in range(n-1):
if a[0] > a[1]:
score += 1
else:
score = 1
if score == k:
ans = a[0]
break
p1, p2 = a[:2]
a.pop(0)
a[0] = max(p1, p2)
a.append(min(p1, p2))
if ans==0:
ans = max(a)
print(ans)
``` | 3 |
|
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4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n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\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}
] | 1,693,232,811 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
a1=0
b1=0
for i in range(n):
a,b=map(int,input().split())
a1+=a
b1+=b
if a1>b1:
print('Mishka')
elif a1<b1:
print('Chris')
else:
print('Friendship is magic!^^') | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
n=int(input())
a1=0
b1=0
for i in range(n):
a,b=map(int,input().split())
a1+=a
b1+=b
if a1>b1:
print('Mishka')
elif a1<b1:
print('Chris')
else:
print('Friendship is magic!^^')
``` | 0 |
|
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.
As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (*n*<=-<=1) friends. Determine if Sereja's friends can play the game so that nobody loses. | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"output": "NO"
},
{
"input": "5 16\n3 3 2 7 9",
"output": "YES"
},
{
"input": "6 38\n9 10 3 8 10 6",
"output": "YES"
},
{
"input": "7 12\n4 4 5 2 2 4 9",
"output": "NO"
},
{
"input": "8 15\n8 10 4 2 10 9 7 6",
"output": "NO"
},
{
"input": "9 22\n1 3 5 9 7 6 1 10 1",
"output": "NO"
},
{
"input": "10 30\n9 10 4 5 5 7 1 7 7 2",
"output": "NO"
},
{
"input": "38 83\n9 9 3 10 2 4 6 10 9 5 1 8 7 4 7 2 6 5 3 1 10 8 4 8 3 7 1 2 7 6 8 6 5 2 3 1 1 2",
"output": "NO"
},
{
"input": "84 212\n6 2 3 1 2 7 5 1 7 2 9 10 9 5 2 5 4 10 9 9 1 9 8 8 9 4 9 4 8 2 1 8 4 5 10 7 6 2 1 10 10 7 9 4 5 9 5 10 10 3 6 6 4 4 4 8 5 4 9 1 9 9 1 7 9 2 10 9 10 8 3 3 9 3 9 10 1 8 9 2 6 9 7 2",
"output": "NO"
},
{
"input": "8 50\n8 8 8 4 4 6 10 10",
"output": "YES"
},
{
"input": "7 24\n1 4 9 1 2 3 6",
"output": "YES"
},
{
"input": "47 262\n3 7 6 4 10 3 5 7 2 9 3 2 2 10 8 7 3 10 6 3 1 1 4 10 2 9 2 10 6 4 3 6 3 6 9 7 8 8 3 3 10 5 2 10 7 10 9",
"output": "YES"
},
{
"input": "42 227\n3 6 1 9 4 10 4 10 7 8 10 10 8 7 10 4 6 8 7 7 6 9 3 6 5 5 2 7 2 7 4 4 6 6 4 3 9 3 6 4 7 2",
"output": "NO"
},
{
"input": "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 1 4 5 1 1 6 4 2 1 7 8 6 1 1 5 6 5 10 6 7 5",
"output": "NO"
},
{
"input": "94 279\n2 5 9 5 10 3 1 8 1 7 1 8 1 6 7 8 4 9 5 10 3 7 6 8 8 5 6 8 10 9 4 1 3 3 4 7 8 2 6 6 5 1 3 7 1 7 2 2 2 8 4 1 1 5 9 4 1 2 3 10 1 4 9 9 6 8 8 1 9 10 4 1 8 5 8 9 4 8 2 1 1 9 4 5 6 1 2 5 6 7 3 1 4 6",
"output": "NO"
},
{
"input": "58 70\n8 2 10 2 7 3 8 3 8 7 6 2 4 10 10 6 10 3 7 6 4 3 5 5 5 3 8 10 3 4 8 4 2 6 8 9 6 9 4 3 5 2 2 6 10 6 2 1 7 5 6 4 1 9 10 2 4 5",
"output": "NO"
},
{
"input": "6 14\n3 9 2 1 4 2",
"output": "YES"
},
{
"input": "78 400\n5 9 3 4 7 4 1 4 6 3 9 1 8 3 3 6 10 2 1 9 6 1 8 10 1 6 4 5 2 1 5 9 6 10 3 6 5 2 4 10 6 9 3 8 10 7 2 8 8 2 10 1 4 5 2 8 6 4 4 3 5 2 3 10 1 9 8 5 6 7 9 1 8 8 5 4 2 4",
"output": "YES"
},
{
"input": "41 181\n5 3 10 4 2 5 9 3 1 6 6 10 4 3 9 8 5 9 2 5 4 6 6 3 7 9 10 3 10 6 10 5 6 1 6 9 9 1 2 4 3",
"output": "NO"
},
{
"input": "2 4\n4 4",
"output": "YES"
},
{
"input": "29 71\n4 8 9 4 8 10 4 10 2 9 3 9 1 2 9 5 9 7 1 10 4 1 1 9 8 7 4 6 7",
"output": "NO"
},
{
"input": "49 272\n4 10 8 7 5 6 9 7 2 6 6 2 10 7 5 6 5 3 6 4 3 7 9 3 7 7 4 10 5 6 7 3 6 4 6 7 7 2 5 5 7 3 7 9 3 6 6 2 1",
"output": "YES"
},
{
"input": "91 486\n1 3 5 4 4 7 3 9 3 4 5 4 5 4 7 9 5 8 4 10 9 1 1 9 9 1 6 2 5 4 7 4 10 3 2 10 9 3 4 5 1 3 4 2 10 9 10 9 10 2 4 6 2 5 3 6 4 9 10 3 9 8 1 2 5 9 2 10 4 6 10 8 10 9 1 2 5 8 6 6 6 1 10 3 9 3 5 6 1 5 5",
"output": "YES"
},
{
"input": "80 78\n1 9 4 9 8 3 7 10 4 9 2 1 4 4 9 5 9 1 2 6 5 2 4 8 4 6 9 6 7 10 1 9 10 4 7 1 7 10 8 9 10 5 2 6 7 7 7 7 7 8 2 5 1 7 2 3 2 5 10 6 3 4 5 2 6 3 4 2 7 9 9 3 8 8 2 3 7 1 5 10",
"output": "NO"
},
{
"input": "53 245\n5 6 9 9 2 3 2 5 10 9 3 5 6 3 10 10 9 4 9 7 10 9 7 7 3 4 9 3 7 3 8 6 8 9 3 8 9 1 3 1 9 10 3 9 3 1 6 6 3 8 7 8 9",
"output": "NO"
},
{
"input": "50 271\n6 9 10 1 1 1 8 3 6 6 3 2 5 9 7 5 7 9 10 9 4 6 6 2 6 6 9 5 1 6 5 8 3 2 5 10 10 1 4 1 4 6 1 8 7 8 9 4 7 5",
"output": "YES"
},
{
"input": "38 214\n5 8 4 5 1 9 9 2 6 3 4 3 5 7 7 7 3 10 1 5 10 4 2 2 10 10 6 6 6 7 1 6 10 5 7 4 5 10",
"output": "YES"
},
{
"input": "100 1\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "100 100\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "100 989\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "100 990\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "YES"
},
{
"input": "100 1000\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "YES"
},
{
"input": "2 1\n1 1",
"output": "YES"
},
{
"input": "2 1\n2 2",
"output": "NO"
},
{
"input": "2 1000\n1 1",
"output": "YES"
},
{
"input": "10 89\n10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "10 44\n1 10 2 3 4 5 6 7 8 9",
"output": "NO"
}
] | 1,587,486,136 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 140 | 0 | def canWin(c, arr):
return sum(arr) - max(arr) <= c
n, c = map(int, input().split())
nums = list(map(int, input().split()))
print("YES" if canWin(c, nums) else "NO") | Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.
As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (*n*<=-<=1) friends. Determine if Sereja's friends can play the game so that nobody loses.
Input Specification:
The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug.
Output Specification:
In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.
Demo Input:
['3 4\n1 1 1\n', '3 4\n3 1 3\n', '3 4\n4 4 4\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
def canWin(c, arr):
return sum(arr) - max(arr) <= c
n, c = map(int, input().split())
nums = list(map(int, input().split()))
print("YES" if canWin(c, nums) else "NO")
``` | 3 |
|
796 | D | Police Stations | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"dp",
"graphs",
"shortest paths",
"trees"
] | null | null | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most *d* kilometers along the roads.
There are *n* cities in the country, numbered from 1 to *n*, connected only by exactly *n*<=-<=1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has *k* police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city.
However, Zane feels like having as many as *n*<=-<=1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible.
Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads. | The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — each denoting the city each police station is located in.
The *i*-th of the following *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities directly connected by the road with index *i*.
It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within *d* kilometers. | In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down.
In the second line, print *s* distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | [
"6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n"
] | [
"1\n5\n",
"2\n4 5 "
] | In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | 1,500 | [
{
"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "1\n3 "
},
{
"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6",
"output": "2\n4 5 "
},
{
"input": "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "0"
},
{
"input": "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11",
"output": "0"
},
{
"input": "2 1 1\n1\n1 2",
"output": "0"
}
] | 1,649,911,847 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 75,878,400 | from collections import deque
if __name__ == '__main__':
n,k,d = map(int, input().split())
polices = [int(i) for i in input().split()]
adj = [[] for i in range (n+1)]
for i in range (n-1):
u,v = map(int, input().split())
adj[u].append((v,i+1))
adj[v].append((u,i+1))
used = [False]*(n+1)
edges = set()
q = deque()
for police in polices:
q.append(police)
used[police] = True
while len(q)>0:
node = q.popleft()
for child, i in adj[node]:
if not used[child]:
used[child] = True
q.append(child)
edges.add(i)
print(n-1-len(edges))
ans = []
for i in range (n-1):
if i+1 not in edges:
ans.append(i+1)
print(*ans)
| Title: Police Stations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most *d* kilometers along the roads.
There are *n* cities in the country, numbered from 1 to *n*, connected only by exactly *n*<=-<=1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has *k* police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city.
However, Zane feels like having as many as *n*<=-<=1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible.
Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads.
Input Specification:
The first line contains three integers *n*, *k*, and *d* (2<=≤<=*n*<=≤<=3·105, 1<=≤<=*k*<=≤<=3·105, 0<=≤<=*d*<=≤<=*n*<=-<=1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains *k* integers *p*1,<=*p*2,<=...,<=*p**k* (1<=≤<=*p**i*<=≤<=*n*) — each denoting the city each police station is located in.
The *i*-th of the following *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities directly connected by the road with index *i*.
It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within *d* kilometers.
Output Specification:
In the first line, print one integer *s* that denotes the maximum number of roads that can be shut down.
In the second line, print *s* distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them.
Demo Input:
['6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n', '6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n']
Demo Output:
['1\n5\n', '2\n4 5 ']
Note:
In the first sample, if you shut down road 5, all cities can still reach a police station within *k* = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | ```python
from collections import deque
if __name__ == '__main__':
n,k,d = map(int, input().split())
polices = [int(i) for i in input().split()]
adj = [[] for i in range (n+1)]
for i in range (n-1):
u,v = map(int, input().split())
adj[u].append((v,i+1))
adj[v].append((u,i+1))
used = [False]*(n+1)
edges = set()
q = deque()
for police in polices:
q.append(police)
used[police] = True
while len(q)>0:
node = q.popleft()
for child, i in adj[node]:
if not used[child]:
used[child] = True
q.append(child)
edges.add(i)
print(n-1-len(edges))
ans = []
for i in range (n-1):
if i+1 not in edges:
ans.append(i+1)
print(*ans)
``` | 0 |
|
518 | C | Anya and Smartphone | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen contains *k* icons. The icons from the first to the *k*-th one are located on the first screen, from the (*k*<=+<=1)-th to the 2*k*-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen *t*, Anya needs to make the following gestures: first she scrolls to the required screen number *t*, by making *t*<=-<=1 gestures (if the icon is on the screen *t*), and then make another gesture — press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to *n*. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times. | The first line of the input contains three numbers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains *n* integers, permutation *a*1,<=*a*2,<=...,<=*a**n* — the initial order of icons from left to right in the menu (from the first to the last one), *a**i* — is the id of the application, whose icon goes *i*-th in the menu. Each integer from 1 to *n* occurs exactly once among *a**i*.
The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m*(1<=≤<=*b**i*<=≤<=*n*) — the ids of the launched applications in the planned order. One application may be launched multiple times. | Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order. | [
"8 3 3\n1 2 3 4 5 6 7 8\n7 8 1\n",
"5 4 2\n3 1 5 2 4\n4 4 4 4\n"
] | [
"7\n",
"8\n"
] | In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | 1,500 | [
{
"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1",
"output": "7"
},
{
"input": "5 4 2\n3 1 5 2 4\n4 4 4 4",
"output": "8"
},
{
"input": "10 10 3\n1 2 3 4 5 6 7 8 9 10\n2 3 4 5 6 7 8 9 10 1",
"output": "25"
},
{
"input": "10 12 3\n6 1 2 9 3 10 8 5 7 4\n3 9 9 4 8 2 3 8 10 8 3 4",
"output": "29"
},
{
"input": "16 12 8\n6 11 12 5 1 10 16 3 13 15 9 4 8 2 14 7\n6 13 8 12 8 15 12 16 8 11 3 16",
"output": "18"
},
{
"input": "4 3 5\n3 1 4 2\n4 2 4",
"output": "3"
},
{
"input": "4 2 15\n2 4 3 1\n1 2",
"output": "2"
},
{
"input": "71 96 75634\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71\n27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26 27 26",
"output": "96"
},
{
"input": "71 81 2149\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 28 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71\n29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29 28 29",
"output": "81"
}
] | 1,583,345,788 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 421 | 19,865,600 | import sys
input = sys.stdin.readline
from collections import defaultdict
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x-1, a))
b = list(map(int, input().split()))
b = list(map(lambda x: x-1, b))
page = [-1]*n
pos = [-1]*n
d = defaultdict(int)
for i in range(n):
page[a[i]] = i//k
pos[a[i]] = i%k
d[i//k*10**6+i%k] = a[i]
ans = 0
for bi in b:
ans += page[bi]+1
if page[bi]==0 and pos[bi]==0:
continue
page1 = page[bi]
pos1 = pos[bi]
if pos1==0:
page2 = page1-1
pos2 = k-1
else:
page2 = page1
pos2 = pos1-1
ci = d[page2*10**6+pos2]
page[bi] = page2
pos[bi] = pos2
page[ci] = page1
pos[ci] = pos1
d[page1*10**6+pos1] = ci
d[page2*10**6+pos2] = bi
print(ans) | Title: Anya and Smartphone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen contains *k* icons. The icons from the first to the *k*-th one are located on the first screen, from the (*k*<=+<=1)-th to the 2*k*-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen *t*, Anya needs to make the following gestures: first she scrolls to the required screen number *t*, by making *t*<=-<=1 gestures (if the icon is on the screen *t*), and then make another gesture — press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to *n*. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
Input Specification:
The first line of the input contains three numbers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains *n* integers, permutation *a*1,<=*a*2,<=...,<=*a**n* — the initial order of icons from left to right in the menu (from the first to the last one), *a**i* — is the id of the application, whose icon goes *i*-th in the menu. Each integer from 1 to *n* occurs exactly once among *a**i*.
The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m*(1<=≤<=*b**i*<=≤<=*n*) — the ids of the launched applications in the planned order. One application may be launched multiple times.
Output Specification:
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
Demo Input:
['8 3 3\n1 2 3 4 5 6 7 8\n7 8 1\n', '5 4 2\n3 1 5 2 4\n4 4 4 4\n']
Demo Output:
['7\n', '8\n']
Note:
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures. | ```python
import sys
input = sys.stdin.readline
from collections import defaultdict
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x-1, a))
b = list(map(int, input().split()))
b = list(map(lambda x: x-1, b))
page = [-1]*n
pos = [-1]*n
d = defaultdict(int)
for i in range(n):
page[a[i]] = i//k
pos[a[i]] = i%k
d[i//k*10**6+i%k] = a[i]
ans = 0
for bi in b:
ans += page[bi]+1
if page[bi]==0 and pos[bi]==0:
continue
page1 = page[bi]
pos1 = pos[bi]
if pos1==0:
page2 = page1-1
pos2 = k-1
else:
page2 = page1
pos2 = pos1-1
ci = d[page2*10**6+pos2]
page[bi] = page2
pos[bi] = pos2
page[ci] = page1
pos[ci] = pos1
d[page1*10**6+pos1] = ci
d[page2*10**6+pos2] = bi
print(ans)
``` | 3 |
|
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them. | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
{
"input": "1 1000000000",
"output": "NO"
},
{
"input": "999999999 1000000000",
"output": "NO"
},
{
"input": "1 2",
"output": "YES\n2\n1 2 "
},
{
"input": "1 536870912",
"output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 "
},
{
"input": "11111 11111111",
"output": "YES\n4\n11111 111111 1111111 11111111 "
},
{
"input": "59139 946224",
"output": "YES\n5\n59139 118278 236556 473112 946224 "
},
{
"input": "9859 19718",
"output": "YES\n2\n9859 19718 "
},
{
"input": "25987 51974222",
"output": "YES\n5\n25987 259871 2598711 25987111 51974222 "
},
{
"input": "9411 188222222",
"output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 "
},
{
"input": "25539 510782222",
"output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 "
},
{
"input": "76259 610072",
"output": "YES\n4\n76259 152518 305036 610072 "
},
{
"input": "92387 184774",
"output": "YES\n2\n92387 184774 "
},
{
"input": "8515 85151111",
"output": "YES\n5\n8515 85151 851511 8515111 85151111 "
},
{
"input": "91939 9193911",
"output": "YES\n3\n91939 919391 9193911 "
},
{
"input": "30518 610361",
"output": "YES\n3\n30518 61036 610361 "
},
{
"input": "46646 373168844",
"output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 "
},
{
"input": "30070 300701",
"output": "YES\n2\n30070 300701 "
},
{
"input": "13494 1079528",
"output": "YES\n5\n13494 134941 269882 539764 1079528 "
},
{
"input": "96918 775344422",
"output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 "
},
{
"input": "13046 260921",
"output": "YES\n3\n13046 26092 260921 "
},
{
"input": "29174 5834811",
"output": "YES\n4\n29174 58348 583481 5834811 "
},
{
"input": "79894 319576421",
"output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 "
},
{
"input": "96022 1920442",
"output": "YES\n3\n96022 960221 1920442 "
},
{
"input": "79446 6355681",
"output": "YES\n5\n79446 158892 317784 635568 6355681 "
},
{
"input": "5440 27853056",
"output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 "
},
{
"input": "250000000 705032705",
"output": "NO"
},
{
"input": "17 35",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
}
] | 1,618,144,702 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 140 | 4,915,200 | def get_user_input():
user_input = input().split()
x = int(user_input[0])
n = int(user_input[1])
return x, n
def is_valid(x, n):
return x <= n
results = []
def transformation(x, n, seq, i):
if x == n:
results.append((i, seq))
else:
value_append = (10 * x) + 1
value_double = 2 * x
if is_valid(value_append, n):
transformation(value_append, n, [*seq, str(value_append)], i + 1)
if is_valid(value_double, n):
transformation(value_double, n, [*seq, str(value_double)], i + 1)
x, n = get_user_input()
transformation(x, n, [str(x)], 1)
if len(results) > 0:
print("YES")
for result in results:
print(result[0])
print(" ".join(result[1]))
else:
print("NO")
| Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
Input Specification:
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
Output Specification:
If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them.
Demo Input:
['2 162\n', '4 42\n', '100 40021\n']
Demo Output:
['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n']
Note:
none | ```python
def get_user_input():
user_input = input().split()
x = int(user_input[0])
n = int(user_input[1])
return x, n
def is_valid(x, n):
return x <= n
results = []
def transformation(x, n, seq, i):
if x == n:
results.append((i, seq))
else:
value_append = (10 * x) + 1
value_double = 2 * x
if is_valid(value_append, n):
transformation(value_append, n, [*seq, str(value_append)], i + 1)
if is_valid(value_double, n):
transformation(value_double, n, [*seq, str(value_double)], i + 1)
x, n = get_user_input()
transformation(x, n, [str(x)], 1)
if len(results) > 0:
print("YES")
for result in results:
print(result[0])
print(" ".join(result[1]))
else:
print("NO")
``` | 3 |
|
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,596,261,005 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 6,963,200 | n=int(input())
list=[int(i) for i in input().split()]
list.sort()
if(n%2):
print(list[int(n/2)])
else:
print(list[int(n/2)-1]) | 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
n=int(input())
list=[int(i) for i in input().split()]
list.sort()
if(n%2):
print(list[int(n/2)])
else:
print(list[int(n/2)-1])
``` | 3 |
|
222 | A | Shooshuns and Sequence | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence.
The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. | Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. | [
"3 2\n3 1 1\n",
"3 1\n3 1 1\n"
] | [
"1\n",
"-1\n"
] | In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1. | 500 | [
{
"input": "3 2\n3 1 1",
"output": "1"
},
{
"input": "3 1\n3 1 1",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "-1"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "4 3\n1 2 3 4",
"output": "-1"
},
{
"input": "5 3\n2 1 1 1 1",
"output": "1"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10 1\n1 2 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 1\n2 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 2\n2 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 2\n1 2 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "10 3\n3 2 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "-1"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "19"
}
] | 1,612,468,238 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n, k = map(int, list(input().split()))
print(n, k)
s = list(input().split())
print(s)
op = k-1
for i in range(k-1, n):
if s[i]!=s[k-1]:
op = -1
break
print(op) | Title: Shooshuns and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence.
The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
Input Specification:
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Output Specification:
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
Demo Input:
['3 2\n3 1 1\n', '3 1\n3 1 1\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1. | ```python
n, k = map(int, list(input().split()))
print(n, k)
s = list(input().split())
print(s)
op = k-1
for i in range(k-1, n):
if s[i]!=s[k-1]:
op = -1
break
print(op)
``` | 0 |
|
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits. | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471"
},
{
"input": "45154",
"output": "22578"
},
{
"input": "60324",
"output": "30163"
},
{
"input": "91840",
"output": "45921"
},
{
"input": "41909",
"output": "20955"
},
{
"input": "58288",
"output": "29145"
},
{
"input": "91641",
"output": "45821"
},
{
"input": "62258",
"output": "31130"
},
{
"input": "79811",
"output": "39906"
},
{
"input": "88740",
"output": "44371"
},
{
"input": "12351",
"output": "6176"
},
{
"input": "1960",
"output": "981"
},
{
"input": "29239",
"output": "14620"
},
{
"input": "85801",
"output": "42901"
},
{
"input": "43255",
"output": "21628"
},
{
"input": "13439",
"output": "6720"
},
{
"input": "35668",
"output": "17835"
},
{
"input": "19122",
"output": "9562"
},
{
"input": "60169",
"output": "30085"
},
{
"input": "50588",
"output": "25295"
},
{
"input": "2467",
"output": "1234"
},
{
"input": "39315",
"output": "19658"
},
{
"input": "29950",
"output": "14976"
},
{
"input": "17286",
"output": "8644"
},
{
"input": "7359066",
"output": "3679534"
},
{
"input": "1016391",
"output": "508196"
},
{
"input": "7928871",
"output": "3964436"
},
{
"input": "3968891",
"output": "1984446"
},
{
"input": "2636452",
"output": "1318227"
},
{
"input": "5076901",
"output": "2538451"
},
{
"input": "9870265",
"output": "4935133"
},
{
"input": "2453786",
"output": "1226894"
},
{
"input": "7263670",
"output": "3631836"
},
{
"input": "1890845",
"output": "945423"
},
{
"input": "574128507",
"output": "287064254"
},
{
"input": "648476655",
"output": "324238328"
},
{
"input": "97349542",
"output": "48674772"
},
{
"input": "716489761",
"output": "358244881"
},
{
"input": "858771038",
"output": "429385520"
},
{
"input": "520778784",
"output": "260389393"
},
{
"input": "439004204",
"output": "219502103"
},
{
"input": "589992198",
"output": "294996100"
},
{
"input": "371106544",
"output": "185553273"
},
{
"input": "894241590",
"output": "447120796"
},
{
"input": "123957268",
"output": "61978635"
},
{
"input": "234149297",
"output": "117074649"
},
{
"input": "789954052",
"output": "394977027"
},
{
"input": "667978920",
"output": "333989461"
},
{
"input": "154647261",
"output": "77323631"
},
{
"input": "751453521",
"output": "375726761"
},
{
"input": "848862308",
"output": "424431155"
},
{
"input": "323926781",
"output": "161963391"
},
{
"input": "576768825",
"output": "288384413"
},
{
"input": "31293802",
"output": "15646902"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000000000",
"output": "500000001"
},
{
"input": "3",
"output": "2"
}
] | 1,596,390,006 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 156 | 20,172,800 | # import sys;sys.stdin = open("in.txt", "r");sys.stdout = open("out.txt", "w")
print(int(input())//2 + 1) | Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits.
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output Specification:
Output one integer — the answer to the problem.
Demo Input:
['7\n', '8\n', '9\n']
Demo Output:
['4\n', '5\n', '5\n']
Note:
In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | ```python
# import sys;sys.stdin = open("in.txt", "r");sys.stdout = open("out.txt", "w")
print(int(input())//2 + 1)
``` | 3 |
|
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200",
"output": "YES"
},
{
"input": "2\n100 200",
"output": "NO"
},
{
"input": "2\n200 100",
"output": "NO"
},
{
"input": "3\n100 100 100",
"output": "NO"
},
{
"input": "3\n200 200 200",
"output": "NO"
},
{
"input": "3\n200 100 200",
"output": "NO"
},
{
"input": "4\n100 100 100 100",
"output": "YES"
},
{
"input": "4\n200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100",
"output": "YES"
},
{
"input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100",
"output": "NO"
},
{
"input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100",
"output": "YES"
},
{
"input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200",
"output": "YES"
},
{
"input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200",
"output": "YES"
},
{
"input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200",
"output": "NO"
},
{
"input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100",
"output": "YES"
},
{
"input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100",
"output": "YES"
},
{
"input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100",
"output": "NO"
},
{
"input": "5\n200 200 200 200 200",
"output": "NO"
},
{
"input": "9\n100 100 100 200 100 100 200 100 200",
"output": "YES"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "7\n200 200 200 100 200 200 200",
"output": "NO"
},
{
"input": "4\n100 100 200 200",
"output": "YES"
},
{
"input": "6\n100 100 100 200 200 200",
"output": "NO"
},
{
"input": "4\n200 100 100 200",
"output": "YES"
},
{
"input": "5\n100 100 100 100 200",
"output": "YES"
}
] | 1,665,174,366 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | L=list(map(int,input().split()))
N=list(map(int,input().split()))
a=0
b=0
for i in (L[0]):
if N[i]==100:
a=+1
if a%2==0:
print('YES')
else:
print('NO')
| Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
Output Specification:
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Demo Input:
['3\n100 200 100\n', '4\n100 100 100 200\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | ```python
L=list(map(int,input().split()))
N=list(map(int,input().split()))
a=0
b=0
for i in (L[0]):
if N[i]==100:
a=+1
if a%2==0:
print('YES')
else:
print('NO')
``` | -1 |
|
120 | F | Spiders | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"trees"
] | null | null | One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan.
A spider consists of *k* beads tied together by *k*<=-<=1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads.
Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features.
After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible.
The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture. | The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to *n**i*. | Print a single number — the length of the required construction. | [
"1\n3 1 2 2 3\n",
"2\n3 1 2 1 3\n4 1 2 2 3 2 4\n",
"2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n"
] | [
"2\n",
"4\n",
"7\n"
] | none | 0 | [
{
"input": "1\n3 1 2 2 3",
"output": "2"
},
{
"input": "2\n3 1 2 1 3\n4 1 2 2 3 2 4",
"output": "4"
},
{
"input": "2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5",
"output": "7"
},
{
"input": "3\n3 1 2 2 3\n5 2 5 5 3 3 4 5 1\n9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3",
"output": "10"
},
{
"input": "7\n2 2 1\n4 1 4 2 3 1 2\n3 3 1 3 2\n5 1 4 3 5 1 2 1 3\n6 4 5 1 3 4 2 3 6 5 1\n7 1 3 3 6 7 4 7 1 5 2 3 5\n10 6 8 2 6 6 3 2 7 2 4 6 10 3 1 6 5 6 9",
"output": "23"
},
{
"input": "10\n3 1 2 1 3\n3 1 2 1 3\n7 1 2 1 3 3 4 7 5 1 6 5 1\n2 1 2\n4 4 3 3 1 4 2\n3 3 1 3 2\n5 4 2 5 1 3 5 3 4\n6 1 6 2 4 6 2 4 3 5 1\n7 2 4 4 6 7 3 3 1 3 5 2 7\n10 3 5 5 6 1 9 5 2 7 8 8 1 6 10 4 3 4 7",
"output": "36"
},
{
"input": "7\n4 2 3 4 1 2 4\n4 4 3 2 1 3 2\n3 2 1 2 3\n5 5 4 1 5 1 2 2 3\n6 1 3 4 5 2 6 3 2 1 4\n7 6 4 4 7 6 2 6 3 3 1 6 5\n10 8 10 4 8 5 9 5 6 3 4 3 1 5 3 4 7 1 2",
"output": "26"
},
{
"input": "7\n2 1 2\n4 4 1 1 2 4 3\n3 3 2 2 1\n5 4 1 1 5 4 3 1 2\n6 4 2 3 1 3 4 3 5 3 6\n8 7 4 6 2 6 7 4 5 4 1 1 3 6 8\n10 4 1 8 9 7 8 2 4 8 6 6 5 2 7 8 3 7 10",
"output": "23"
},
{
"input": "3\n4 3 2 3 1 1 4\n4 3 1 2 4 3 2\n4 1 4 2 1 4 3",
"output": "9"
},
{
"input": "3\n10 7 3 10 9 7 10 4 7 8 6 8 2 4 8 8 5 5 1\n12 10 3 11 4 11 9 12 1 10 12 8 7 8 11 6 5 10 6 10 2 6 8\n13 3 7 10 4 3 8 3 1 8 5 4 12 9 2 8 6 10 9 1 10 10 11 4 13",
"output": "18"
},
{
"input": "4\n5 3 2 3 5 4 1 4 3\n6 6 4 1 2 2 3 2 6 6 5\n7 6 1 6 4 4 5 1 7 4 3 2 6\n8 2 1 6 8 4 5 8 3 4 7 4 2 2 6",
"output": "15"
},
{
"input": "2\n10 8 1 6 7 10 8 7 5 3 4 5 3 9 2 6 9 2 10\n10 9 7 6 1 8 10 6 4 8 3 9 2 3 5 8 9 3 6",
"output": "14"
},
{
"input": "6\n3 1 3 1 2\n3 2 1 3 2\n5 2 5 5 1 2 3 2 4\n4 2 3 2 4 1 2\n5 2 3 2 1 3 5 2 4\n5 3 5 2 3 5 1 4 2",
"output": "16"
},
{
"input": "1\n50 4 37 49 41 40 10 23 14 35 3 39 46 40 8 11 35 32 17 3 7 25 47 17 27 49 1 28 9 6 38 41 29 22 13 38 16 4 48 4 21 13 23 49 30 35 44 25 34 25 18 31 50 21 6 32 19 19 28 22 42 39 25 22 26 21 40 21 33 21 39 14 43 3 15 17 2 19 12 26 24 28 5 22 11 4 20 10 45 48 36 4 22 4 32 4 31 39 49",
"output": "10"
},
{
"input": "4\n10 9 5 9 7 7 6 7 2 1 4 9 1 7 3 2 10 3 8\n10 9 10 2 5 3 6 5 7 9 3 9 1 9 2 2 8 2 4\n10 5 3 2 5 1 6 6 8 3 9 3 10 5 1 8 4 3 7\n10 7 6 3 1 8 10 2 3 2 7 5 9 10 5 1 4 2 8",
"output": "23"
}
] | 1,650,452,793 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 404 | 10,137,600 | import abc
import itertools
import math
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
def solve():
def bfs(g, s):
used = [-1 for i in range(len(g))]
used[s] = 0
q = [s]
it = 0
while it < len(q):
f = q[it]
it += 1
for u in g[f]:
if used[u] == -1:
used[u] = used[f] + 1
q.append(u)
return max(used)
f = open("input.txt", "r")
n = int(f.readline())
res = 0
for i in range(n):
k, *a = map(int, f.readline().split())
g = [[] for i in range(k)]
for j in range(k - 1):
v, u = a[j * 2] - 1, a[j * 2 + 1] - 1
g[v].append(u)
g[u].append(v)
mx = 0
for i in range(k):
mx = max(mx, bfs(g, i))
res += mx
f.close()
f = open("output.txt", "w")
f.write(str(res))
f.close()
if __name__ == '__main__':
multi_test = 0
if multi_test == 1:
t = int(sys.stdin.readline())
for _ in range(t):
solve()
else:
solve()
| Title: Spiders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan.
A spider consists of *k* beads tied together by *k*<=-<=1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads.
Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features.
After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible.
The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture.
Input Specification:
The first input file line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n**i* (2<=≤<=*n**i*<=≤<=100) — the number of beads, then *n**i*<=-<=1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to *n**i*.
Output Specification:
Print a single number — the length of the required construction.
Demo Input:
['1\n3 1 2 2 3\n', '2\n3 1 2 1 3\n4 1 2 2 3 2 4\n', '2\n5 1 2 2 3 3 4 3 5\n7 3 4 1 2 2 4 4 6 2 7 6 5\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
none | ```python
import abc
import itertools
import math
from math import gcd as gcd
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
def solve():
def bfs(g, s):
used = [-1 for i in range(len(g))]
used[s] = 0
q = [s]
it = 0
while it < len(q):
f = q[it]
it += 1
for u in g[f]:
if used[u] == -1:
used[u] = used[f] + 1
q.append(u)
return max(used)
f = open("input.txt", "r")
n = int(f.readline())
res = 0
for i in range(n):
k, *a = map(int, f.readline().split())
g = [[] for i in range(k)]
for j in range(k - 1):
v, u = a[j * 2] - 1, a[j * 2 + 1] - 1
g[v].append(u)
g[u].append(v)
mx = 0
for i in range(k):
mx = max(mx, bfs(g, i))
res += mx
f.close()
f = open("output.txt", "w")
f.write(str(res))
f.close()
if __name__ == '__main__':
multi_test = 0
if multi_test == 1:
t = int(sys.stdin.readline())
for _ in range(t):
solve()
else:
solve()
``` | 3 |
|
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,665,670,623 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 184 | 1,843,200 | import math
def sum_digit(n):
sum = 0
for i in n:
sum += int(i)
return str(sum)
n = input()
result = 0
while (len(n) > 1):
n = sum_digit(n)
# print(n)
result += 1
print(result)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
import math
def sum_digit(n):
sum = 0
for i in n:
sum += int(i)
return str(sum)
n = input()
result = 0
while (len(n) > 1):
n = sum_digit(n)
# print(n)
result += 1
print(result)
``` | 3.950683 |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,457,882,450 | 12,050 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 12 | 3,000 | 1,126,400 | n = int(input())
a=list()
for i in range(n):
temp=input()
if temp in a:
a.remove(temp)
a.append(temp)
else:
a.append(temp)
lena=len(a)-1
for i in range(lena+1):
print(a[lena-i]) | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n = int(input())
a=list()
for i in range(n):
temp=input()
if temp in a:
a.remove(temp)
a.append(temp)
else:
a.append(temp)
lena=len(a)-1
for i in range(lena+1):
print(a[lena-i])
``` | 0 |
|
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,585,072,607 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 | n,m=map(int,input().split());p=0
a=sorted(list(map(int,input().split())))
for i in range(m):
if a[i]>=0:break
else:p=p+abs(a[i])
print(p) | 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
n,m=map(int,input().split());p=0
a=sorted(list(map(int,input().split())))
for i in range(m):
if a[i]>=0:break
else:p=p+abs(a[i])
print(p)
``` | 3.93 |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5.
In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9. | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116",
"output": "254"
},
{
"input": "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64",
"output": "128"
},
{
"input": "1\n1000000000\n1000000000",
"output": "2000000000"
},
{
"input": "1\n0\n0",
"output": "0"
},
{
"input": "2\n7 16\n16 7",
"output": "46"
},
{
"input": "4\n6 0 0 0\n0 0 0 1",
"output": "7"
},
{
"input": "8\n1 2 4 8 16 32 64 128\n1 2 4 8 16 32 64 128",
"output": "510"
},
{
"input": "1\n2\n3",
"output": "5"
},
{
"input": "1\n4\n3",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "2"
}
] | 1,660,206,010 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 187 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxx = 0
for i in range(n):
res1 = 0
res2 = 0
for j in range(i, n):
res1 |= a[j]
res2 |= b[j]
maxx = max(maxx, res1 + res2)
print(maxx)
| Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109).
Output Specification:
Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*.
Demo Input:
['5\n1 2 4 3 2\n2 3 3 12 1\n', '10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n']
Demo Output:
['22', '46']
Note:
Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *f*(*a*, 2, 4) + *f*(*b*, 2, 4) = (2 *OR* 4 *OR* 3) + (3 *OR* 3 *OR* 12) = 7 + 15 = 22. Other ways to get maximum value is to choose *l* = 1 and *r* = 4, *l* = 1 and *r* = 5, *l* = 2 and *r* = 4, *l* = 2 and *r* = 5, *l* = 3 and *r* = 4, or *l* = 3 and *r* = 5.
In the second sample, the maximum value is obtained for *l* = 1 and *r* = 9. | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
maxx = 0
for i in range(n):
res1 = 0
res2 = 0
for j in range(i, n):
res1 |= a[j]
res2 |= b[j]
maxx = max(maxx, res1 + res2)
print(maxx)
``` | 3 |
|
856 | E | Satellites | PROGRAMMING | 3,100 | [] | null | null | Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.
The planet is at the very edge of the universe, so its form is half of a circle. Its radius is *r*, the ends of its diameter are points *A* and *B*. The line *AB* is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of *AB* segment, *OX* axis coincides with line *AB*, the planet is completely in *y*<=><=0 half-plane.
The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate *y*<=><=0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points *A* and *B*. Let us call this area the satellite coverage area.
The picture below shows coordinate system and coverage area of a satellite.
When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types:
1. 1 x y — launch the new satellite and put it to the point (*x*,<=*y*). Satellites never move and stay at the point they were launched. Let us assign the number *i* to the *i*-th satellite in order of launching, starting from one. 1. 2 i — remove satellite number *i*. 1. 3 i j — make an attempt to create a communication channel between satellites *i* and *j*. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites *i* and *j*. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate *y*<=><=0.
For each attempt to create a communication channel you must find out whether it is possible.
Sample test has the following satellites locations: | The first line of input data contains integers *r* and *n* — radius of the planet and the number of events (1<=≤<=*r*<=≤<=109, 1<=≤<=*n*<=≤<=5·105).
Each of the following *n* lines describe events in the specified format.
Satellite coordinates are integer, the satisfy the following constraints |*x*|<=≤<=109, 0<=<<=*y*<=≤<=109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than *r*.
It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality *i*<=≠<=*j* is satisfied. | For each event of type 3 print «YES» on a separate line, if it is possible to create a communication channel, or «NO» if it is impossible. | [
"5 8\n1 -5 8\n1 -4 8\n1 -3 8\n1 2 7\n3 1 3\n2 2\n3 1 3\n3 3 4\n"
] | [
"NO\nYES\nYES\n"
] | none | 0 | [] | 1,690,505,303 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690505302.9599776")# 1690505302.9599986 | Title: Satellites
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.
The planet is at the very edge of the universe, so its form is half of a circle. Its radius is *r*, the ends of its diameter are points *A* and *B*. The line *AB* is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of *AB* segment, *OX* axis coincides with line *AB*, the planet is completely in *y*<=><=0 half-plane.
The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate *y*<=><=0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points *A* and *B*. Let us call this area the satellite coverage area.
The picture below shows coordinate system and coverage area of a satellite.
When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types:
1. 1 x y — launch the new satellite and put it to the point (*x*,<=*y*). Satellites never move and stay at the point they were launched. Let us assign the number *i* to the *i*-th satellite in order of launching, starting from one. 1. 2 i — remove satellite number *i*. 1. 3 i j — make an attempt to create a communication channel between satellites *i* and *j*. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites *i* and *j*. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate *y*<=><=0.
For each attempt to create a communication channel you must find out whether it is possible.
Sample test has the following satellites locations:
Input Specification:
The first line of input data contains integers *r* and *n* — radius of the planet and the number of events (1<=≤<=*r*<=≤<=109, 1<=≤<=*n*<=≤<=5·105).
Each of the following *n* lines describe events in the specified format.
Satellite coordinates are integer, the satisfy the following constraints |*x*|<=≤<=109, 0<=<<=*y*<=≤<=109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than *r*.
It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality *i*<=≠<=*j* is satisfied.
Output Specification:
For each event of type 3 print «YES» on a separate line, if it is possible to create a communication channel, or «NO» if it is impossible.
Demo Input:
['5 8\n1 -5 8\n1 -4 8\n1 -3 8\n1 2 7\n3 1 3\n2 2\n3 1 3\n3 3 4\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
none | ```python
print("_RANDOM_GUESS_1690505302.9599776")# 1690505302.9599986
``` | 0 |
|
903 | C | Boxes Packing | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. | Print the minimum possible number of visible boxes. | [
"3\n1 2 3\n",
"4\n4 2 4 3\n"
] | [
"1\n",
"2\n"
] | In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | 0 | [
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "4\n4 2 4 3",
"output": "2"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58",
"output": "10"
},
{
"input": "10\n86 89 89 86 86 89 86 86 89 89",
"output": "5"
},
{
"input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360",
"output": "14"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n131",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "11"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "8"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
}
] | 1,665,035,030 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 62 | 1,843,200 | '''
probably I am not getting the box packing rules
'''
if __name__ == "__main__":
n=int(input())
nums=[int(i) for i in input().split()]
freq_hashmap={}
for num in nums:
freq_hashmap[num]=freq_hashmap.get(num,0)+1
print(max(freq_hashmap.values())) | Title: Boxes Packing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*.
Mishka can put a box *i* into another box *j* if the following conditions are met:
- *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=<<=*a**j*).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.
Help Mishka to determine the minimum possible number of visible boxes!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Output Specification:
Print the minimum possible number of visible boxes.
Demo Input:
['3\n1 2 3\n', '4\n4 2 4 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example it is possible to put box 1 into box 2, and 2 into 3.
In the second example Mishka can put box 2 into box 3, and box 4 into box 1. | ```python
'''
probably I am not getting the box packing rules
'''
if __name__ == "__main__":
n=int(input())
nums=[int(i) for i in input().split()]
freq_hashmap={}
for num in nums:
freq_hashmap[num]=freq_hashmap.get(num,0)+1
print(max(freq_hashmap.values()))
``` | 3 |
|
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work. | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "52870"
},
{
"input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245",
"output": "46995"
},
{
"input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434",
"output": "85540"
},
{
"input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357",
"output": "67147"
},
{
"input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422",
"output": "85876"
},
{
"input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282",
"output": "38570"
},
{
"input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431",
"output": "11134"
},
{
"input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424",
"output": "59043"
},
{
"input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369",
"output": "53608"
},
{
"input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438",
"output": "84067"
},
{
"input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439",
"output": "79844"
},
{
"input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437",
"output": "82686"
},
{
"input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437",
"output": "92356"
},
{
"input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434",
"output": "107490"
},
{
"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401",
"output": "25258"
},
{
"input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419",
"output": "23992"
}
] | 1,572,279,435 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 186 | 0 | n,p1,p2,p3,t1,t2 = map(int,input().split())
aktivnosti = []
for i in range(n):
l,r = map(int,input().split())
aktivnosti.append((l,r))
otvet = 0
for i in range(n):
vremya_raboty = aktivnosti[i][1] - aktivnosti[i][0]
otvet = otvet + vremya_raboty * p1
if i == n - 1:
break
pereryv = aktivnosti[i+1][0] - aktivnosti[i][1]
vremeni_v_pl = min(t1,pereryv)
otvet = otvet + vremeni_v_pl * p1
vremeni_v_p2 = min(t2,max(0,pereryv - t1))
otvet = otvet + vremeni_v_p2l * p2
vremeni_v_p3 = max(0,pereryv - t1 - t2)
otvet = otvet + vremeni_v_p3 * p3
print(otvet) | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
Input Specification:
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work.
Output Specification:
Output the answer to the problem.
Demo Input:
['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n']
Demo Output:
['30', '570']
Note:
none | ```python
n,p1,p2,p3,t1,t2 = map(int,input().split())
aktivnosti = []
for i in range(n):
l,r = map(int,input().split())
aktivnosti.append((l,r))
otvet = 0
for i in range(n):
vremya_raboty = aktivnosti[i][1] - aktivnosti[i][0]
otvet = otvet + vremya_raboty * p1
if i == n - 1:
break
pereryv = aktivnosti[i+1][0] - aktivnosti[i][1]
vremeni_v_pl = min(t1,pereryv)
otvet = otvet + vremeni_v_pl * p1
vremeni_v_p2 = min(t2,max(0,pereryv - t1))
otvet = otvet + vremeni_v_p2l * p2
vremeni_v_p3 = max(0,pereryv - t1 - t2)
otvet = otvet + vremeni_v_p3 * p3
print(otvet)
``` | -1 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{
"input": "6\n5083 3289 7708 5362 9031 7458",
"output": "5 7708"
},
{
"input": "7\n9038 6222 3392 1706 3778 1807 2657",
"output": "1 6222"
},
{
"input": "8\n7062 2194 4481 3864 7470 1814 8091 733",
"output": "7 7470"
},
{
"input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408",
"output": "3 7906"
},
{
"input": "2\n3458 1504",
"output": "1 1504"
},
{
"input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991",
"output": "39 9752"
},
{
"input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602",
"output": "86 9806"
},
{
"input": "2\n2 1",
"output": "1 1"
},
{
"input": "2\n1 2",
"output": "2 1"
},
{
"input": "3\n10 20 30",
"output": "3 20"
},
{
"input": "3\n10 30 20",
"output": "2 20"
},
{
"input": "3\n20 10 30",
"output": "3 20"
},
{
"input": "3\n20 30 10",
"output": "2 20"
},
{
"input": "3\n30 10 20",
"output": "1 20"
},
{
"input": "3\n30 20 10",
"output": "1 20"
},
{
"input": "2\n1 10000",
"output": "2 1"
},
{
"input": "2\n10000 999",
"output": "1 999"
},
{
"input": "3\n3 4 1",
"output": "2 3"
},
{
"input": "6\n1 2 24 6 5 7",
"output": "3 7"
}
] | 1,635,495,531 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 61 | 4,505,600 | p = int(input())
str_price = str(input())
list_price = list(map(lambda x: int(x), str_price.split()))
winner = list_price.index(max(list_price)) + 1
val = sorted(list_price)[-2]
print(winner, val) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
Output Specification:
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
Demo Input:
['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n']
Demo Output:
['2 5\n', '1 8\n', '6 9\n']
Note:
none | ```python
p = int(input())
str_price = str(input())
list_price = list(map(lambda x: int(x), str_price.split()))
winner = list_price.index(max(list_price)) + 1
val = sorted(list_price)[-2]
print(winner, val)
``` | 3 |
|
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$. | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,635,234,924 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 29,388,800 | def insert(b,i):
b.insert(i+1,b[i]+1)
on=[]
on.append(b[0])
for j in range(1,n,2):
on.append(b[j+1]-b[j])
if len(a)%2==0:
on.append(M-a[-1])
global t_on
t_on.append(sum(on))
b.pop(i+1)
n,M=map(int,input().split())
a=list(map(int,input().split()))
on=[]
on.append(a[0])
t_on=[]
for i in range(1,n-1,2):
on.append(a[i+1]-a[i])
if len(a)%2==0:
on.append(M-a[-1])
t_on.append(sum(on))
for i in range(0,n,2):
insert(a,i)
print(max(t_on)) | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | ```python
def insert(b,i):
b.insert(i+1,b[i]+1)
on=[]
on.append(b[0])
for j in range(1,n,2):
on.append(b[j+1]-b[j])
if len(a)%2==0:
on.append(M-a[-1])
global t_on
t_on.append(sum(on))
b.pop(i+1)
n,M=map(int,input().split())
a=list(map(int,input().split()))
on=[]
on.append(a[0])
t_on=[]
for i in range(1,n-1,2):
on.append(a[i+1]-a[i])
if len(a)%2==0:
on.append(M-a[-1])
t_on.append(sum(on))
for i in range(0,n,2):
insert(a,i)
print(max(t_on))
``` | 0 |
|
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"input": "1000000000",
"output": "1\n999999932"
},
{
"input": "999999979",
"output": "2\n999999899\n999999908"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "1\n5"
},
{
"input": "11",
"output": "1\n10"
},
{
"input": "39",
"output": "1\n33"
},
{
"input": "66",
"output": "1\n60"
},
{
"input": "75",
"output": "0"
},
{
"input": "100",
"output": "1\n86"
},
{
"input": "101",
"output": "2\n91\n100"
},
{
"input": "2014",
"output": "2\n1988\n2006"
},
{
"input": "999999994",
"output": "0"
}
] | 1,556,726,542 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | x=int(input())
n=x
l=1
s=[]
while 1:
m=n+sum([int(k) for k in str(n)])
# print(m)
if m==x:
s.append(n)
if n==(x-81):
l=0
break
else:
# print(n)
n-=1
continue
print(len(s))
if len(s)!=0:
for n in s:
print(n) | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system.
Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order.
Demo Input:
['21\n', '20\n']
Demo Output:
['1\n15\n', '0\n']
Note:
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | ```python
x=int(input())
n=x
l=1
s=[]
while 1:
m=n+sum([int(k) for k in str(n)])
# print(m)
if m==x:
s.append(n)
if n==(x-81):
l=0
break
else:
# print(n)
n-=1
continue
print(len(s))
if len(s)!=0:
for n in s:
print(n)
``` | -1 |
|
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},
{
"input": "lwzjp\ninjit",
"output": "-1"
},
{
"input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm",
"output": "eodnlemiicdedmkcgavqbnqmm"
},
{
"input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs",
"output": "-1"
},
{
"input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf",
"output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf"
},
{
"input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen",
"output": "-1"
},
{
"input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb",
"output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb"
},
{
"input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym",
"output": "-1"
},
{
"input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib",
"output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib"
},
{
"input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew",
"output": "-1"
},
{
"input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv",
"output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv"
},
{
"input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns",
"output": "-1"
},
{
"input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf",
"output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf"
},
{
"input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp",
"output": "-1"
},
{
"input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp",
"output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp"
},
{
"input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej",
"output": "-1"
},
{
"input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe",
"output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe"
},
{
"input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang",
"output": "-1"
},
{
"input": "ftfr\nftfr",
"output": "ftfr"
},
{
"input": "ftr\nftr",
"output": "ftr"
},
{
"input": "shftr\nshftr",
"output": "shftr"
},
{
"input": "vkvkkv\nvkvkkv",
"output": "vkvkkv"
},
{
"input": "ftrd\nftrd",
"output": "ftrd"
},
{
"input": "fztr\nfztr",
"output": "fztr"
},
{
"input": "frtr\nfrtr",
"output": "frtr"
},
{
"input": "shdftr\nshdftr",
"output": "shdftr"
},
{
"input": "zzz\nzzz",
"output": "zzz"
},
{
"input": "shtr\nshtr",
"output": "shtr"
},
{
"input": "aaaaa\nzzzzz",
"output": "-1"
},
{
"input": "efr\nefr",
"output": "efr"
}
] | 1,648,380,611 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | a,b=list(input()),list(input());t=''
for x,y in zip(a,b):
if x>=y:t+=y
else:t=-1;break
print(t)
| Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
Input Specification:
The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
Output Specification:
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
Demo Input:
['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n']
Demo Output:
['ba\n', 'xiyez\n', '-1\n']
Note:
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | ```python
a,b=list(input()),list(input());t=''
for x,y in zip(a,b):
if x>=y:t+=y
else:t=-1;break
print(t)
``` | 3 |
|
895 | B | XK Segments | PROGRAMMING | 1,700 | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*.
In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1). | The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print one integer — the answer to the problem. | [
"4 2 1\n1 3 5 7\n",
"4 2 0\n5 3 1 7\n",
"5 3 1\n3 3 3 3 3\n"
] | [
"3\n",
"4\n",
"25\n"
] | In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25. | 1,000 | [
{
"input": "4 2 1\n1 3 5 7",
"output": "3"
},
{
"input": "4 2 0\n5 3 1 7",
"output": "4"
},
{
"input": "5 3 1\n3 3 3 3 3",
"output": "25"
},
{
"input": "5 3 4\n24 13 1 24 24",
"output": "4"
},
{
"input": "4 2 2\n1 3 5 7",
"output": "2"
},
{
"input": "5 1 0\n10 12 14 20 30",
"output": "0"
},
{
"input": "7 3 1\n3 3 6 9 12 15 18",
"output": "9"
},
{
"input": "2 5 0\n3 4",
"output": "3"
},
{
"input": "3 5 0\n4 4 4",
"output": "9"
},
{
"input": "3 6 0\n3 4 5",
"output": "6"
},
{
"input": "10 2 1\n2 2 2 2 2 2 2 1 2 1",
"output": "80"
},
{
"input": "100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 1 2 2 1 1 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 2 1 1 2 2 2 1",
"output": "5200"
},
{
"input": "1 13 1\n13",
"output": "1"
},
{
"input": "2 1 1000000000\n1 1000000000",
"output": "1"
},
{
"input": "2 1000000000 1\n1 1000000000",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "5 1000000000 1\n1000000000 1 1 1 1",
"output": "5"
},
{
"input": "2 1000 1000000\n1 1000000000",
"output": "1"
},
{
"input": "6 2 10\n1 1 1 20 20 20",
"output": "9"
},
{
"input": "1 1000000000 1\n1000000000",
"output": "1"
},
{
"input": "4 65536 65536\n1 2 3 4",
"output": "0"
},
{
"input": "1 600000000 1\n500000000",
"output": "0"
},
{
"input": "5 3 2\n2 3 4 5 8",
"output": "2"
}
] | 1,690,486,621 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690486621.4073868")# 1690486621.4074066 | Title: XK Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*.
In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1).
Input Specification:
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Output Specification:
Print one integer — the answer to the problem.
Demo Input:
['4 2 1\n1 3 5 7\n', '4 2 0\n5 3 1 7\n', '5 3 1\n3 3 3 3 3\n']
Demo Output:
['3\n', '4\n', '25\n']
Note:
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25. | ```python
print("_RANDOM_GUESS_1690486621.4073868")# 1690486621.4074066
``` | 0 |
|
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away.
Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting.
Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$. | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies. | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total.
Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times.
In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time. | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
"input": "100 33 100 100",
"output": "100"
},
{
"input": "1000000000 1000000000 1000000000 1000",
"output": "1000000000"
},
{
"input": "1000000000 32428 1000000000 1000",
"output": "1000000000"
},
{
"input": "1000000000 324934 1000 1000",
"output": "4000"
},
{
"input": "1000000000000000000 32400093004 10000000 1000",
"output": "40000000"
},
{
"input": "885 2 160 842",
"output": "504"
},
{
"input": "216 137 202 208",
"output": "202"
},
{
"input": "72 66 28 9",
"output": "28"
},
{
"input": "294 4 13 8",
"output": "80"
},
{
"input": "9 2 2 3",
"output": "4"
},
{
"input": "31 3 2 8",
"output": "10"
},
{
"input": "104 2 5 11",
"output": "50"
},
{
"input": "1000000000000000000 1000000000000000000 1000 1000",
"output": "1000"
},
{
"input": "1000000000000000000 100000000000000000 1 1000",
"output": "10"
},
{
"input": "23925738098196565 23925738098196565 23925738098196565 1000",
"output": "23925738098196565"
},
{
"input": "576460752303423488 576460752303423488 351082447248993993 1000",
"output": "351082447248993993"
},
{
"input": "962768465676381898 72057594037927936 586039918340257175 256",
"output": "586039918340257175"
},
{
"input": "1000000000000000000 1000000000000000000 10 1000",
"output": "10"
},
{
"input": "23925738098196565 23925738098196565 1 1000",
"output": "1"
},
{
"input": "1000000000000000000 1000000000000000000 1 1000",
"output": "1"
}
] | 1,524,680,013 | 2,313 | Python 3 | OK | TESTS | 25 | 93 | 7,065,600 | n, k, m, d = map(int, input().split())
res = 0
for a in range(1, d + 1):
x = n // (a * k - k + 1)
x = min(x, m)
res = max(res, x * a)
print(res) | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away.
Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting.
Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$.
Input Specification:
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Output Specification:
Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$.
Demo Input:
['20 4 5 2\n', '30 9 4 1\n']
Demo Output:
['8\n', '4\n']
Note:
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total.
Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times.
In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time. | ```python
n, k, m, d = map(int, input().split())
res = 0
for a in range(1, d + 1):
x = n // (a * k - k + 1)
x = min(x, m)
res = max(res, x * a)
print(res)
``` | 3 |
|
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3"
},
{
"input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2",
"output": "7\n7"
},
{
"input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1",
"output": "7"
},
{
"input": "2 2\n8 4\n1\n1",
"output": "2\n2"
},
{
"input": "1 5\n5\n1\n1\n1\n1\n1",
"output": "1\n1\n1\n1\n1"
},
{
"input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4",
"output": "1\n4\n3\n2\n3\n1\n1"
},
{
"input": "4 3\n9 1 7 1\n1\n4\n2",
"output": "3\n1\n2"
},
{
"input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7",
"output": "4\n3\n2"
},
{
"input": "1 1\n1\n1",
"output": "1"
}
] | 1,668,965,612 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
"""for i in range(m):
b = int(input())
ay = a[b-1:]
print(len(set(ay)))"""
rev = a[::-1]
setindex = 1
iwc = [len(a)+1]
for i in range(len(rev)):
if len(set(rev[:i])) > setindex:
k = len(a) - (i - 1)
iwc.append(k)
setindex += 1
iwc.append(-1)
for j in range(m):
b =int(input())
k = 0
while iwc[k] > b and b < iwc[k+1]:
k+=1
print(k + 2) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.?
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Output Specification:
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
Demo Input:
['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n']
Demo Output:
['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n']
Note:
none | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
"""for i in range(m):
b = int(input())
ay = a[b-1:]
print(len(set(ay)))"""
rev = a[::-1]
setindex = 1
iwc = [len(a)+1]
for i in range(len(rev)):
if len(set(rev[:i])) > setindex:
k = len(a) - (i - 1)
iwc.append(k)
setindex += 1
iwc.append(-1)
for j in range(m):
b =int(input())
k = 0
while iwc[k] > b and b < iwc[k+1]:
k+=1
print(k + 2)
``` | 0 |
|
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX",
"output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbCh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EjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ"
},
{
"input": "P",
"output": "P"
},
{
"input": "Xyzzy",
"output": "Xyzzy"
},
{
"input": "Zzz",
"output": "Zzz"
},
{
"input": "Zp",
"output": "Zp"
}
] | 1,697,303,046 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 154 | 0 | l=input()
print(l[0].capitalize()+l[1:])
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input Specification:
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output Specification:
Output the given word after capitalization.
Demo Input:
['ApPLe\n', 'konjac\n']
Demo Output:
['ApPLe\n', 'Konjac\n']
Note:
none | ```python
l=input()
print(l[0].capitalize()+l[1:])
``` | 3 |
|
371 | B | Fox Dividing Cheese | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal. | The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109). | If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0. | [
"15 20\n",
"14 8\n",
"6 6\n"
] | [
"3\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "15 20",
"output": "3"
},
{
"input": "14 8",
"output": "-1"
},
{
"input": "6 6",
"output": "0"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1024",
"output": "10"
},
{
"input": "1024 729",
"output": "16"
},
{
"input": "1024 1048576",
"output": "10"
},
{
"input": "36 30",
"output": "3"
},
{
"input": "100 10",
"output": "2"
},
{
"input": "21 35",
"output": "2"
},
{
"input": "9900 7128",
"output": "5"
},
{
"input": "7920 9900",
"output": "3"
},
{
"input": "576000 972000",
"output": "7"
},
{
"input": "691200 583200",
"output": "8"
},
{
"input": "607500 506250",
"output": "3"
},
{
"input": "881280 765000",
"output": "9"
},
{
"input": "800000 729000",
"output": "13"
},
{
"input": "792000 792000",
"output": "0"
},
{
"input": "513600 513600",
"output": "0"
},
{
"input": "847500 610200",
"output": "5"
},
{
"input": "522784320 784176480",
"output": "2"
},
{
"input": "689147136 861433920",
"output": "3"
},
{
"input": "720212000 864254400",
"output": "3"
},
{
"input": "673067520 807681024",
"output": "3"
},
{
"input": "919536000 993098880",
"output": "5"
},
{
"input": "648293430 540244525",
"output": "3"
},
{
"input": "537814642 537814642",
"output": "0"
},
{
"input": "100000007 800000011",
"output": "-1"
},
{
"input": "900000011 800000011",
"output": "-1"
},
{
"input": "900000011 999900017",
"output": "-1"
},
{
"input": "536870912 387420489",
"output": "47"
},
{
"input": "820125000 874800000",
"output": "6"
},
{
"input": "864000000 607500000",
"output": "9"
},
{
"input": "609120000 913680000",
"output": "2"
},
{
"input": "509607936 306110016",
"output": "24"
},
{
"input": "445906944 528482304",
"output": "8"
},
{
"input": "119144448 423624704",
"output": "7"
},
{
"input": "1 1000000000",
"output": "18"
},
{
"input": "1000000000 1",
"output": "18"
},
{
"input": "1000000000 2",
"output": "17"
},
{
"input": "2 1000000000",
"output": "17"
},
{
"input": "5 1000000000",
"output": "17"
},
{
"input": "1000000000 5",
"output": "17"
},
{
"input": "3 1000000000",
"output": "19"
},
{
"input": "1000000000 3",
"output": "19"
},
{
"input": "1000000000 7",
"output": "-1"
},
{
"input": "2208870 122715",
"output": "3"
},
{
"input": "4812500 7577955",
"output": "16"
},
{
"input": "3303936 3097440",
"output": "6"
},
{
"input": "55404 147744",
"output": "4"
},
{
"input": "10332160 476643528",
"output": "19"
},
{
"input": "21751200 43502400",
"output": "1"
},
{
"input": "19500000 140400000",
"output": "5"
},
{
"input": "1 22",
"output": "-1"
}
] | 1,626,254,073 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 93 | 20,172,800 | a, b = map(int, input().split())
oper = 0
while a != b:
if a > b:
for i in [2,3,5]:
if a % i == 0:
a //= i
oper += 1
break
else:
print(-1)
exit()
if b > a:
for i in [2,3,5]:
if b % i == 0:
b //= i
oper += 1
break
else:
print(-1)
exit()
print(oper) | Title: Fox Dividing Cheese
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two little greedy bears have found two pieces of cheese in the forest of weight *a* and *b* grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
Input Specification:
The first line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=109).
Output Specification:
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
Demo Input:
['15 20\n', '14 8\n', '6 6\n']
Demo Output:
['3\n', '-1\n', '0\n']
Note:
none | ```python
a, b = map(int, input().split())
oper = 0
while a != b:
if a > b:
for i in [2,3,5]:
if a % i == 0:
a //= i
oper += 1
break
else:
print(-1)
exit()
if b > a:
for i in [2,3,5]:
if b % i == 0:
b //= i
oper += 1
break
else:
print(-1)
exit()
print(oper)
``` | 0 |
|
989 | B | A Tide of Riverscape | PROGRAMMING | 1,200 | [
"constructive algorithms",
"strings"
] | null | null | "Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$. | The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character. | Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)). | [
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] | [
"1000100010\n",
"1001101000\n",
"No\n"
] | In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | 1,000 | [
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"input": "17 10\n..1.100..1..0.100",
"output": "00101000010000100"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "3 1\n.0.",
"output": "001"
},
{
"input": "3 1\n00.",
"output": "001"
},
{
"input": "3 2\n0..",
"output": "001"
},
{
"input": "3 2\n0.0",
"output": "No"
},
{
"input": "3 2\n1..",
"output": "100"
},
{
"input": "3 2\n.1.",
"output": "011"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "3 3\n1..",
"output": "No"
},
{
"input": "3 3\n.00",
"output": "No"
},
{
"input": "5 3\n0.000",
"output": "01000"
},
{
"input": "10 6\n10010.1001",
"output": "No"
},
{
"input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.",
"output": "000001000011001000010001000111000110000000010000110010000100010001110001101"
},
{
"input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001",
"output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001"
},
{
"input": "5 4\n.101.",
"output": "01011"
},
{
"input": "4 2\n101.",
"output": "1011"
},
{
"input": "5 4\n.1011",
"output": "01011"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "5 3\n00.11",
"output": "00011"
},
{
"input": "10 8\n1111.00000",
"output": "1111000000"
},
{
"input": "10 3\n11111111.1",
"output": "1111111101"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "6 4\n11..10",
"output": "110010"
},
{
"input": "4 2\n.111",
"output": "0111"
},
{
"input": "3 2\n01.",
"output": "011"
},
{
"input": "5 4\n10.00",
"output": "10000"
},
{
"input": "10 9\n1........0",
"output": "1000000000"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "8 4\n111111..",
"output": "11111100"
},
{
"input": "3 2\n0.1",
"output": "001"
},
{
"input": "4 1\n111.",
"output": "1110"
},
{
"input": "3 1\n01.",
"output": "010"
},
{
"input": "10 7\n000....111",
"output": "0000000111"
}
] | 1,528,974,549 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 93 | 0 | n,p=map(int,input().split())
s=input()
ans=s.replace('.','0')
if all(ans[i]==ans[i+p] for i in range(n-p)):
i=0
while i<n and s[i]!='.': i+=1
if i+p<n:
ans=ans[:i]+'1'+ans[i+1:]
print(ans)
exit()
i=n-1
while i>=0 and s[i]!='.':i-=1
if i-p>=0:
ans=ans[:i]+'1'+ans[i+1:]
print(ans)
exit()
print("No")
else:
print(ans)
| Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
Input Specification:
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
Output Specification:
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Demo Input:
['10 7\n1.0.1.0.1.\n', '10 6\n1.0.1.1000\n', '10 9\n1........1\n']
Demo Output:
['1000100010\n', '1001101000\n', 'No\n']
Note:
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | ```python
n,p=map(int,input().split())
s=input()
ans=s.replace('.','0')
if all(ans[i]==ans[i+p] for i in range(n-p)):
i=0
while i<n and s[i]!='.': i+=1
if i+p<n:
ans=ans[:i]+'1'+ans[i+1:]
print(ans)
exit()
i=n-1
while i>=0 and s[i]!='.':i-=1
if i-p>=0:
ans=ans[:i]+'1'+ans[i+1:]
print(ans)
exit()
print("No")
else:
print(ans)
``` | 3 |
|
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,677,934,622 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | n = int(input())
if (n%2 == 0):
print("4", n-4)
else:
print("9", n-9)
| Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
n = int(input())
if (n%2 == 0):
print("4", n-4)
else:
print("9", n-9)
``` | 3 |
|
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment. | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 100000",
"output": "Yes"
},
{
"input": "1 99989",
"output": "No"
},
{
"input": "512 2",
"output": "Yes"
},
{
"input": "100 24",
"output": "No"
},
{
"input": "1 100000",
"output": "No"
},
{
"input": "100000 1",
"output": "Yes"
},
{
"input": "3 99929",
"output": "No"
},
{
"input": "99961 99971",
"output": "No"
},
{
"input": "1 65536",
"output": "Yes"
},
{
"input": "4 65536",
"output": "Yes"
},
{
"input": "3 65536",
"output": "Yes"
},
{
"input": "32768 65536",
"output": "Yes"
},
{
"input": "65535 65536",
"output": "Yes"
},
{
"input": "1 65535",
"output": "No"
},
{
"input": "98812 100000",
"output": "No"
},
{
"input": "10 5",
"output": "Yes"
},
{
"input": "6 8",
"output": "Yes"
}
] | 1,687,185,245 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 62 | 0 | import sys
#sys.setrecursionlimit(10**7)
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Functions ---- ############
def Factory():
def power_of_2(num):
p = 1
while num % (2**p) == 0:
p += 1
return p - 1
a , m = invr()
if m == 1 or m == 2 :
print("Yes")
return
power_of_2_m = power_of_2(m)
power_of_2_a = power_of_2(a)
t1 = int(m/(2**power_of_2_m))
t2 = int(a/(2**power_of_2_a))
if t2 % t1 != 0:
print("No")
else:
if power_of_2_a <= power_of_2_m:
print("Yes")
else:
print("No")
return
Factory() | Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment.
Input Specification:
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Output Specification:
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Demo Input:
['1 5\n', '3 6\n']
Demo Output:
['No\n', 'Yes\n']
Note:
none | ```python
import sys
#sys.setrecursionlimit(10**7)
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Functions ---- ############
def Factory():
def power_of_2(num):
p = 1
while num % (2**p) == 0:
p += 1
return p - 1
a , m = invr()
if m == 1 or m == 2 :
print("Yes")
return
power_of_2_m = power_of_2(m)
power_of_2_a = power_of_2(a)
t1 = int(m/(2**power_of_2_m))
t2 = int(a/(2**power_of_2_a))
if t2 % t1 != 0:
print("No")
else:
if power_of_2_a <= power_of_2_m:
print("Yes")
else:
print("No")
return
Factory()
``` | 0 |
|
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
},
{
"input": "2\n8 2",
"output": "1 1"
},
{
"input": "3\n6 8 4",
"output": "1 2"
},
{
"input": "4\n4 3 2 8",
"output": "3 1"
},
{
"input": "5\n1 9 8 2 7",
"output": "2 3"
},
{
"input": "6\n1 4 7 3 2 1",
"output": "3 3"
},
{
"input": "11\n7 9 1 8 7 1 7 1 4 8 1",
"output": "4 7"
},
{
"input": "12\n4 2 7 1 9 5 6 2 7 8 5 7",
"output": "7 5"
},
{
"input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "7 6"
}
] | 1,600,670,314 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 310 | 409,600 | from sys import stdin,stdout
from collections import Counter
from collections import defaultdict
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda: list(map(int, stdin.readline().split()))
ei = lambda: map(int, stdin.readline().split())
ip = lambda: int(stdin.readline().strip())
n = ip()
li = ai()
i = 0
j = n-1
alice = 0
bob = 0
alice_time = bob_time = 0
while i <= j:
if (alice_time == bob_time) and i==j:
alice_time += li[i]
i += 1
alice += 1
elif i==j:
MIN = min(alice_time,bob_time)
if MIN == alice_time:
alice += 1
i += 1
else:
bob += 1
j -= 1
else:
alice_time += li[i]
bob_time += li[j]
i += 1
j -= 1
alice += 1
bob += 1
print(alice,bob) | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Output Specification:
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
Demo Input:
['5\n2 9 8 2 7\n']
Demo Output:
['2 3\n']
Note:
none | ```python
from sys import stdin,stdout
from collections import Counter
from collections import defaultdict
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda: list(map(int, stdin.readline().split()))
ei = lambda: map(int, stdin.readline().split())
ip = lambda: int(stdin.readline().strip())
n = ip()
li = ai()
i = 0
j = n-1
alice = 0
bob = 0
alice_time = bob_time = 0
while i <= j:
if (alice_time == bob_time) and i==j:
alice_time += li[i]
i += 1
alice += 1
elif i==j:
MIN = min(alice_time,bob_time)
if MIN == alice_time:
alice += 1
i += 1
else:
bob += 1
j -= 1
else:
alice_time += li[i]
bob_time += li[j]
i += 1
j -= 1
alice += 1
bob += 1
print(alice,bob)
``` | 0 |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,629,035,209 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 14,028,800 | n, b, d= map(int, input().split())
oranges=list(map(int, input().split()))
ts=0
empty=0
for i in range(n):
orange=oranges[i]
if(orange>b):
continue
ts+=orange
if ts>d:
empty+=1
ts=ts-d
print(empty)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
n, b, d= map(int, input().split())
oranges=list(map(int, input().split()))
ts=0
empty=0
for i in range(n):
orange=oranges[i]
if(orange>b):
continue
ts+=orange
if ts>d:
empty+=1
ts=ts-d
print(empty)
``` | 0 |
|
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"output": "2"
},
{
"input": "2 2\n0 4\n7 4",
"output": "4"
},
{
"input": "4 1\n-12 1\n-14 1\n4 1\n-11 1",
"output": "5"
},
{
"input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1",
"output": "2"
},
{
"input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6",
"output": "6"
},
{
"input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9",
"output": "35"
},
{
"input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34",
"output": "16"
},
{
"input": "3 501\n827 327\n-85 480\n-999 343",
"output": "6"
},
{
"input": "2 999\n-999 471\n530 588",
"output": "4"
},
{
"input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31",
"output": "30"
},
{
"input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3",
"output": "16"
},
{
"input": "4 512\n-997 354\n-568 216\n-234 221\n603 403",
"output": "4"
},
{
"input": "3 966\n988 5\n15 2\n-992 79",
"output": "6"
},
{
"input": "2 1000\n-995 201\n206 194",
"output": "4"
},
{
"input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2",
"output": "9"
},
{
"input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1",
"output": "43"
},
{
"input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7",
"output": "96"
},
{
"input": "1 1000\n0 1000",
"output": "2"
}
] | 1,663,262,870 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | n, t = map(int, input().split())
l = []
for i in range(n):
l.append([int(j) for j in input().split()])
f = []
for m in l:
f.append([m[0]-m[1]/2, m[0]+m[1]/2])
k = 2
for i in range(n-1):
if abs(f[i][-1] - f[i+1][0]) > t:
k += 2
elif abs(f[i][-1] - f[i+1][0]) == t:
k += 1
else:
continue
print(k) | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
Input Specification:
The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000).
Output Specification:
Output the amount of possible positions of the new house.
Demo Input:
['2 2\n0 4\n6 2\n', '2 2\n0 4\n5 2\n', '2 3\n0 4\n5 2\n']
Demo Output:
['4\n', '3\n', '2\n']
Note:
It is possible for the *x*-coordinate of the new house to have non-integer value. | ```python
n, t = map(int, input().split())
l = []
for i in range(n):
l.append([int(j) for j in input().split()])
f = []
for m in l:
f.append([m[0]-m[1]/2, m[0]+m[1]/2])
k = 2
for i in range(n-1):
if abs(f[i][-1] - f[i+1][0]) > t:
k += 2
elif abs(f[i][-1] - f[i+1][0]) == t:
k += 1
else:
continue
print(k)
``` | 0 |
928 | B | Chat | PROGRAMMING | 1,400 | [
"*special",
"dp"
] | null | null | There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to *n* where *n* is the total number of messages in the chat.
Each message might contain a link to an earlier message which it is a reply to. When opening a message *x* or getting a link to it, the dialogue is shown in such a way that *k* previous messages, message *x* and *k* next messages are visible (with respect to message *x*). In case there are less than *k* messages somewhere, they are yet all shown.
Digging deep into your message history, you always read all visible messages and then go by the link in the current message *x* (if there is one) and continue reading in the same manner.
Determine the number of messages you'll read if your start from message number *t* for all *t* from 1 to *n*. Calculate these numbers independently. If you start with message *x*, the initial configuration is *x* itself, *k* previous and *k* next messages. Messages read multiple times are considered as one. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*i*), where *a**i* denotes the *i*-th message link destination or zero, if there's no link from *i*. All messages are listed in chronological order. It's guaranteed that the link from message *x* goes to message with number strictly less than *x*. | Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible. | [
"6 0\n0 1 1 2 3 2\n",
"10 1\n0 1 0 3 4 5 2 3 7 0\n",
"2 2\n0 1\n"
] | [
"1 2 2 3 3 3 \n",
"2 3 3 4 5 6 6 6 8 2 \n",
"2 2 \n"
] | Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6. | 1,250 | [
{
"input": "6 0\n0 1 1 2 3 2",
"output": "1 2 2 3 3 3 "
},
{
"input": "10 1\n0 1 0 3 4 5 2 3 7 0",
"output": "2 3 3 4 5 6 6 6 8 2 "
},
{
"input": "2 2\n0 1",
"output": "2 2 "
},
{
"input": "1 1\n0",
"output": "1 "
},
{
"input": "5 2\n0 1 2 3 1",
"output": "3 4 5 5 5 "
},
{
"input": "30 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 0 0 0 0 0 2 1 0",
"output": "2 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 3 3 3 3 3 6 3 3 3 3 3 6 5 2 "
},
{
"input": "100 5\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33 46 26 31 0 21 57 57 31 63 63 25 59 65 56 68 0 30 55 55 0 70 43 59 49 59 79 66 74 0 11 65 0 80 63 0 84 73 49 73 81 0 86 76 98",
"output": "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 11 11 23 22 15 23 24 28 29 30 31 11 11 11 13 11 14 38 18 33 11 11 34 13 22 23 24 17 28 19 42 29 44 11 11 33 40 27 36 11 49 53 42 22 11 34 58 59 22 61 62 41 31 65 60 34 11 24 22 22 11 67 28 33 22 33 36 73 32 11 27 72 11 31 70 11 40 35 22 35 43 9 35 18 35 "
},
{
"input": "2 2\n0 0",
"output": "2 2 "
},
{
"input": "2 1\n0 0",
"output": "2 2 "
},
{
"input": "2 1\n0 1",
"output": "2 2 "
},
{
"input": "2 0\n0 0",
"output": "1 1 "
},
{
"input": "2 0\n0 1",
"output": "1 2 "
},
{
"input": "3 0\n0 0 0",
"output": "1 1 1 "
},
{
"input": "3 0\n0 0 1",
"output": "1 1 2 "
},
{
"input": "3 0\n0 0 2",
"output": "1 1 2 "
},
{
"input": "3 0\n0 1 0",
"output": "1 2 1 "
},
{
"input": "3 0\n0 1 1",
"output": "1 2 2 "
},
{
"input": "3 0\n0 1 2",
"output": "1 2 3 "
},
{
"input": "3 1\n0 0 0",
"output": "2 3 2 "
},
{
"input": "3 1\n0 0 1",
"output": "2 3 3 "
},
{
"input": "3 1\n0 0 2",
"output": "2 3 3 "
},
{
"input": "3 1\n0 1 0",
"output": "2 3 2 "
},
{
"input": "3 1\n0 1 1",
"output": "2 3 3 "
},
{
"input": "3 1\n0 1 2",
"output": "2 3 3 "
},
{
"input": "3 2\n0 0 0",
"output": "3 3 3 "
},
{
"input": "3 2\n0 0 1",
"output": "3 3 3 "
},
{
"input": "3 2\n0 0 2",
"output": "3 3 3 "
},
{
"input": "3 2\n0 1 0",
"output": "3 3 3 "
},
{
"input": "3 2\n0 1 1",
"output": "3 3 3 "
},
{
"input": "3 2\n0 1 2",
"output": "3 3 3 "
},
{
"input": "3 3\n0 0 0",
"output": "3 3 3 "
},
{
"input": "3 3\n0 0 1",
"output": "3 3 3 "
},
{
"input": "3 3\n0 0 2",
"output": "3 3 3 "
},
{
"input": "3 3\n0 1 0",
"output": "3 3 3 "
},
{
"input": "3 3\n0 1 1",
"output": "3 3 3 "
},
{
"input": "3 3\n0 1 2",
"output": "3 3 3 "
},
{
"input": "10 3\n0 0 0 0 0 0 0 4 0 4",
"output": "4 5 6 7 7 7 7 10 5 10 "
},
{
"input": "20 2\n0 0 0 0 2 1 0 3 0 1 1 11 0 10 0 0 9 17 9 0",
"output": "3 4 5 5 7 8 5 10 5 8 8 9 5 12 5 5 10 11 9 3 "
},
{
"input": "40 0\n0 1 2 3 4 5 0 0 0 0 0 11 12 0 14 10 0 16 15 0 19 21 22 0 23 25 25 24 24 29 29 0 0 31 0 35 31 36 34 29",
"output": "1 2 3 4 5 6 1 1 1 1 1 2 3 1 2 2 1 3 3 1 4 5 6 1 7 8 8 2 2 3 3 1 1 4 1 2 4 3 5 3 "
}
] | 1,519,561,850 | 75,350 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 9 | 1,000 | 138,240,000 | n,k=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for i in range(n):
x=set()
y=set()
for j in range(i-k,i+k+1):
if j>=0 and j<n: x.add(j)
if b[i]!=0:
y=a[b[i]-1]
x.update(y)
a.append(x)
for i in a: print(len(i),'',end='') | Title: Chat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to *n* where *n* is the total number of messages in the chat.
Each message might contain a link to an earlier message which it is a reply to. When opening a message *x* or getting a link to it, the dialogue is shown in such a way that *k* previous messages, message *x* and *k* next messages are visible (with respect to message *x*). In case there are less than *k* messages somewhere, they are yet all shown.
Digging deep into your message history, you always read all visible messages and then go by the link in the current message *x* (if there is one) and continue reading in the same manner.
Determine the number of messages you'll read if your start from message number *t* for all *t* from 1 to *n*. Calculate these numbers independently. If you start with message *x*, the initial configuration is *x* itself, *k* previous and *k* next messages. Messages read multiple times are considered as one.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*i*), where *a**i* denotes the *i*-th message link destination or zero, if there's no link from *i*. All messages are listed in chronological order. It's guaranteed that the link from message *x* goes to message with number strictly less than *x*.
Output Specification:
Print *n* integers with *i*-th denoting the number of distinct messages you can read starting from message *i* and traversing the links while possible.
Demo Input:
['6 0\n0 1 1 2 3 2\n', '10 1\n0 1 0 3 4 5 2 3 7 0\n', '2 2\n0 1\n']
Demo Output:
['1 2 2 3 3 3 \n', '2 3 3 4 5 6 6 6 8 2 \n', '2 2 \n']
Note:
Consider *i* = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case *i* = 6 gives you messages 5, 6, 7 since *k* = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6. | ```python
n,k=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for i in range(n):
x=set()
y=set()
for j in range(i-k,i+k+1):
if j>=0 and j<n: x.add(j)
if b[i]!=0:
y=a[b[i]-1]
x.update(y)
a.append(x)
for i in a: print(len(i),'',end='')
``` | 0 |
|
976 | C | Nested Segments | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment. | Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1. | [
"5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"3\n1 5\n2 6\n6 20\n"
] | [
"2 1\n",
"-1 -1\n"
] | In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | 0 | [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9",
"output": "2 1"
},
{
"input": "3\n1 5\n2 6\n6 20",
"output": "-1 -1"
},
{
"input": "1\n1 1000000000",
"output": "-1 -1"
},
{
"input": "2\n1 1000000000\n1 1000000000",
"output": "2 1"
},
{
"input": "2\n1 1000000000\n500000000 500000000",
"output": "2 1"
},
{
"input": "2\n1 10\n2 10",
"output": "2 1"
},
{
"input": "2\n10 20\n10 11",
"output": "2 1"
},
{
"input": "3\n1 10\n10 20\n9 11",
"output": "-1 -1"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "3 2"
},
{
"input": "4\n1 10\n2 11\n3 10000000\n3 100000000",
"output": "3 4"
},
{
"input": "2\n3 7\n3 9",
"output": "1 2"
},
{
"input": "3\n1 2\n2 3\n1 2",
"output": "3 1"
},
{
"input": "3\n5 6\n4 7\n3 8",
"output": "2 3"
},
{
"input": "3\n2 9\n1 7\n2 8",
"output": "3 1"
},
{
"input": "2\n1 4\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n4 4",
"output": "1 2"
},
{
"input": "3\n1 2\n1 3\n67 1234567",
"output": "1 2"
},
{
"input": "2\n1 1\n1 1",
"output": "2 1"
},
{
"input": "3\n1 5\n4 7\n3 9",
"output": "2 3"
},
{
"input": "2\n1 1\n1 10",
"output": "1 2"
},
{
"input": "2\n1 2\n1 3",
"output": "1 2"
},
{
"input": "2\n1 10\n1 11",
"output": "1 2"
},
{
"input": "2\n1 1\n1 2",
"output": "1 2"
},
{
"input": "2\n2 3\n2 4",
"output": "1 2"
},
{
"input": "2\n1 3\n3 3",
"output": "2 1"
},
{
"input": "3\n1 10\n11 13\n12 12",
"output": "3 2"
},
{
"input": "2\n2 10\n1 10",
"output": "1 2"
},
{
"input": "3\n1 3\n4 5\n4 4",
"output": "3 2"
},
{
"input": "5\n1 1\n2 6\n3 5\n10 15\n20 25",
"output": "3 2"
},
{
"input": "3\n1 1000\n1001 1007\n1002 1007",
"output": "3 2"
},
{
"input": "3\n1 3\n2 5\n3 4",
"output": "3 2"
},
{
"input": "3\n1 10\n2 11\n3 11",
"output": "3 2"
},
{
"input": "2\n2000000 999999999\n1000000 1000000000",
"output": "1 2"
},
{
"input": "3\n2 10\n11 12\n4 5",
"output": "3 1"
},
{
"input": "2\n1 10\n1 19",
"output": "1 2"
},
{
"input": "4\n1 3\n100 102\n108 110\n1 3",
"output": "4 1"
},
{
"input": "3\n1 3\n5 9\n5 6",
"output": "3 2"
},
{
"input": "3\n1 3\n3 4\n3 5",
"output": "2 3"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "2 3"
},
{
"input": "4\n2 3\n1 4\n100 200\n1000 2000",
"output": "1 2"
},
{
"input": "3\n1 1\n2 100\n3 99",
"output": "3 2"
},
{
"input": "3\n1 2\n1 3\n12 1234",
"output": "1 2"
},
{
"input": "3\n1 4\n2 6\n3 5",
"output": "3 2"
},
{
"input": "3\n1 10\n2 12\n1 9",
"output": "3 1"
},
{
"input": "2\n1 3\n1 5",
"output": "1 2"
},
{
"input": "3\n1 2\n2 5\n2 3",
"output": "3 2"
},
{
"input": "4\n1 3\n1 4\n5 10\n11 13",
"output": "1 2"
},
{
"input": "4\n7 15\n6 9\n9 10\n10 11",
"output": "3 1"
},
{
"input": "4\n2 3\n100 200\n1000 2000\n1 4",
"output": "1 4"
},
{
"input": "3\n10 20\n5 9\n11 19",
"output": "3 1"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10",
"output": "6 7"
},
{
"input": "2\n1 4\n1 7",
"output": "1 2"
},
{
"input": "3\n1 11\n2 12\n2 13",
"output": "2 3"
},
{
"input": "2\n1 4\n1 8",
"output": "1 2"
},
{
"input": "2\n2 5\n1 5",
"output": "1 2"
},
{
"input": "2\n2 9\n1 10",
"output": "1 2"
},
{
"input": "3\n2 4\n2 4\n1 3",
"output": "2 1"
},
{
"input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60",
"output": "3 4"
},
{
"input": "2\n1 3\n1 7",
"output": "1 2"
},
{
"input": "5\n4 6\n7 60\n80 90\n4 5\n8 80",
"output": "4 1"
},
{
"input": "2\n1 3\n1 4",
"output": "1 2"
},
{
"input": "3\n2 9\n1 7\n2 9",
"output": "3 1"
},
{
"input": "2\n1 4\n1 6",
"output": "1 2"
},
{
"input": "3\n4 4\n2 3\n4 5",
"output": "1 3"
},
{
"input": "2\n1 5\n1 7",
"output": "1 2"
},
{
"input": "2\n1 2\n1 4",
"output": "1 2"
},
{
"input": "4\n1 1\n2 2\n5 10\n2 4",
"output": "2 4"
},
{
"input": "3\n11 12\n11 15\n43 45",
"output": "1 2"
},
{
"input": "3\n2 3\n2 4\n2 5",
"output": "2 3"
},
{
"input": "2\n2 3\n2 5",
"output": "1 2"
},
{
"input": "3\n1 3\n1 4\n1 5",
"output": "2 3"
},
{
"input": "3\n1 1\n1 2\n1 3",
"output": "2 3"
},
{
"input": "2\n2 3\n1 3",
"output": "1 2"
},
{
"input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109",
"output": "11 5"
},
{
"input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11",
"output": "1 8"
},
{
"input": "4\n1 10\n12 15\n1 3\n17 18",
"output": "3 1"
},
{
"input": "3\n1 5\n1 10\n1 20",
"output": "2 3"
},
{
"input": "3\n1 1000\n1001 1003\n1 1",
"output": "3 1"
},
{
"input": "3\n1 10\n2 11\n2 11",
"output": "3 2"
},
{
"input": "2\n1 1\n1 3",
"output": "1 2"
},
{
"input": "2\n1 5\n1 6",
"output": "1 2"
},
{
"input": "3\n1 5\n3 6\n1 4",
"output": "3 1"
},
{
"input": "4\n2 8\n1 3\n2 9\n1 2",
"output": "4 2"
},
{
"input": "3\n3 6\n1 3\n3 9",
"output": "1 3"
},
{
"input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111",
"output": "1 5"
},
{
"input": "4\n1 2\n4 4\n3 3\n2 3",
"output": "3 4"
},
{
"input": "4\n1 1\n4 5\n7 9\n1 1",
"output": "4 1"
},
{
"input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281",
"output": "2 6"
},
{
"input": "2\n10 13\n10 14",
"output": "1 2"
},
{
"input": "5\n2 4\n3 6\n4 5\n222 333\n111 444",
"output": "3 2"
},
{
"input": "3\n1 2\n4 5\n1 1",
"output": "3 1"
},
{
"input": "2\n2 100\n1 100",
"output": "1 2"
},
{
"input": "3\n1 10\n9 20\n3 5",
"output": "3 1"
},
{
"input": "2\n1 9\n1 10",
"output": "1 2"
},
{
"input": "3\n1 2\n1 4\n1 6",
"output": "2 3"
}
] | 1,593,092,233 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | import sys
n=int(sys.stdin.readline())
ls=[]
for i in range(n):
u,v=map(int, sys.stdin.readline().split())
ls.append((u,v))
#ls.sort(key=lambda x:(x[0],x[1]))
ls.sort(key=lambda x: (x[0],-1*x[1]))
max_r=ls[0][1]
ind=0
for i in range(1,n):
if ls[i][1]<max_r:
print(i+1,ind+1)
exit()
if ls[i][1]>max_r:
max_r=ls[i][1]
ind=i
print(-1, -1) | Title: Nested Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* of one-dimensional segments numbered 1 through *n*. Your task is to find two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*.
Segment [*l*1,<=*r*1] lies within segment [*l*2,<=*r*2] iff *l*1<=≥<=*l*2 and *r*1<=≤<=*r*2.
Print indices *i* and *j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of segments.
Each of the next *n* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the *i*-th segment.
Output Specification:
Print two distinct indices *i* and *j* such that segment *a**i* lies within segment *a**j*. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
Demo Input:
['5\n1 10\n2 9\n3 9\n2 3\n2 9\n', '3\n1 5\n2 6\n6 20\n']
Demo Output:
['2 1\n', '-1 -1\n']
Note:
In the first example the following pairs are considered correct:
- (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; - (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; - (5, 2), (2, 5) — match exactly. | ```python
import sys
n=int(sys.stdin.readline())
ls=[]
for i in range(n):
u,v=map(int, sys.stdin.readline().split())
ls.append((u,v))
#ls.sort(key=lambda x:(x[0],x[1]))
ls.sort(key=lambda x: (x[0],-1*x[1]))
max_r=ls[0][1]
ind=0
for i in range(1,n):
if ls[i][1]<max_r:
print(i+1,ind+1)
exit()
if ls[i][1]>max_r:
max_r=ls[i][1]
ind=i
print(-1, -1)
``` | 0 |
|
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period. | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6",
"output": "3"
},
{
"input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32",
"output": "6"
},
{
"input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30",
"output": "10"
},
{
"input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20",
"output": "8"
},
{
"input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49",
"output": "1"
},
{
"input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16",
"output": "5"
},
{
"input": "2\n0 24\n1 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "1\n1 5",
"output": "1"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "3"
},
{
"input": "1\n5 0",
"output": "1"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "5"
},
{
"input": "1\n10 10",
"output": "1"
},
{
"input": "1\n8 0",
"output": "1"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "10"
},
{
"input": "2\n0 0\n0 1",
"output": "1"
},
{
"input": "2\n8 5\n8 5",
"output": "2"
}
] | 1,623,385,799 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 409,600 | a = int (input ())
kassa = []
proverka = []
for i in range (a):
n = input ()
proverka.append (n)
for i in range (len (proverka)):
kassa.append (proverka.count (proverka[i]))
print (max (kassa))
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output Specification:
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
Demo Input:
['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | ```python
a = int (input ())
kassa = []
proverka = []
for i in range (a):
n = input ()
proverka.append (n)
for i in range (len (proverka)):
kassa.append (proverka.count (proverka[i]))
print (max (kassa))
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,633,352,633 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 6,758,400 | S = list(input())
q = list(input())
if s.reversed() == q:
print ('YES')
else:
print('NO') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
S = list(input())
q = list(input())
if s.reversed() == q:
print ('YES')
else:
print('NO')
``` | -1 |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,697,566,125 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | # Read the input string
remix = input()
# Split the remix string by "WUB" to get a list of words
words = remix.split("WUB")
# Filter out any empty strings from the list
words = [word for word in words if word]
# Join the words to restore the initial song
initial_song = " ".join(words)
# Print the initial song
print(initial_song)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
# Read the input string
remix = input()
# Split the remix string by "WUB" to get a list of words
words = remix.split("WUB")
# Filter out any empty strings from the list
words = [word for word in words if word]
# Join the words to restore the initial song
initial_song = " ".join(words)
# Print the initial song
print(initial_song)
``` | 3 |
|
161 | D | Distance in Tree | PROGRAMMING | 1,800 | [
"dfs and similar",
"dp",
"trees"
] | null | null | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of exactly *k* between them. Note that pairs (*v*, *u*) and (*u*, *v*) are considered to be the same pair. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* are the vertices connected by the *i*-th edge. All given edges are different. | Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 2\n1 2\n2 3\n3 4\n2 5\n",
"5 3\n1 2\n2 3\n3 4\n4 5\n"
] | [
"4\n",
"2\n"
] | In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | 2,000 | [
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "4"
},
{
"input": "5 3\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "9"
},
{
"input": "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "10"
},
{
"input": "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "8"
},
{
"input": "50 3\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n16 15\n17 16\n18 17\n19 18\n20 19\n21 20\n22 21\n23 22\n24 23\n25 24\n26 25\n27 26\n28 27\n29 28\n30 29\n31 30\n32 31\n33 32\n34 33\n35 34\n36 35\n37 36\n38 37\n39 38\n40 39\n41 40\n42 41\n43 42\n44 43\n45 44\n46 45\n47 46\n48 47\n49 48\n50 49",
"output": "47"
},
{
"input": "50 4\n2 1\n3 1\n4 2\n5 2\n6 3\n7 3\n8 4\n9 4\n10 5\n11 5\n12 6\n13 6\n14 7\n15 7\n16 8\n17 8\n18 9\n19 9\n20 10\n21 10\n22 11\n23 11\n24 12\n25 12\n26 13\n27 13\n28 14\n29 14\n30 15\n31 15\n32 16\n33 16\n34 17\n35 17\n36 18\n37 18\n38 19\n39 19\n40 20\n41 20\n42 21\n43 21\n44 22\n45 22\n46 23\n47 23\n48 24\n49 24\n50 25",
"output": "124"
},
{
"input": "50 5\n2 1\n3 1\n4 2\n5 2\n6 4\n7 4\n8 6\n9 6\n10 8\n11 8\n12 10\n13 10\n14 12\n15 12\n16 14\n17 14\n18 16\n19 16\n20 18\n21 18\n22 20\n23 20\n24 22\n25 22\n26 24\n27 24\n28 26\n29 26\n30 28\n31 28\n32 30\n33 30\n34 32\n35 32\n36 34\n37 34\n38 36\n39 36\n40 38\n41 38\n42 40\n43 40\n44 42\n45 42\n46 44\n47 44\n48 46\n49 46\n50 48",
"output": "84"
},
{
"input": "10 20\n2 1\n3 2\n4 1\n5 3\n6 4\n7 1\n8 2\n9 7\n10 2",
"output": "0"
}
] | 1,642,236,947 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 16 | 1,340 | 14,028,800 | ans = 0
def dfs(node, par):
global ans
counter = [0]*(k+1)
counter[0] = 1
for i in adj[node]:
if i == par:
continue
tmp = dfs(i, node)
# print(tmp)
for i in range(k+1):
ans += tmp[i]*counter[k-i]
for i in range(k+1):
counter[i]+=tmp[i]
# print(node, counter)
for i in range(k, 0, -1):
counter[i] = counter[i-1]
counter[0] = 0
return counter
n,k = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n-1):
x,y = map(int, input().split())
adj[x-1].append(y-1)
adj[y-1].append(x-1)
dfs(0, -1)
print(ans) | Title: Distance in Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of exactly *k* between them. Note that pairs (*v*, *u*) and (*u*, *v*) are considered to be the same pair.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* are the vertices connected by the *i*-th edge. All given edges are different.
Output Specification:
Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['5 2\n1 2\n2 3\n3 4\n2 5\n', '5 3\n1 2\n2 3\n3 4\n4 5\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | ```python
ans = 0
def dfs(node, par):
global ans
counter = [0]*(k+1)
counter[0] = 1
for i in adj[node]:
if i == par:
continue
tmp = dfs(i, node)
# print(tmp)
for i in range(k+1):
ans += tmp[i]*counter[k-i]
for i in range(k+1):
counter[i]+=tmp[i]
# print(node, counter)
for i in range(k, 0, -1):
counter[i] = counter[i-1]
counter[0] = 0
return counter
n,k = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n-1):
x,y = map(int, input().split())
adj[x-1].append(y-1)
adj[y-1].append(x-1)
dfs(0, -1)
print(ans)
``` | -1 |
|
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
To understand the problem better please read the notes to the test samples. | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
"output": "Yes"
},
{
"input": "+",
"output": "No"
},
{
"input": "-+",
"output": "No"
},
{
"input": "--",
"output": "Yes"
},
{
"input": "+++",
"output": "No"
},
{
"input": "--+",
"output": "No"
},
{
"input": "++--++",
"output": "Yes"
},
{
"input": "+-++-+",
"output": "Yes"
},
{
"input": "+-+--+",
"output": "No"
},
{
"input": "--++-+",
"output": "No"
},
{
"input": "-+-+--",
"output": "No"
},
{
"input": "+-+++-",
"output": "No"
},
{
"input": "-+-+-+",
"output": "No"
},
{
"input": "-++-+--++--+-++-",
"output": "Yes"
},
{
"input": "+-----+-++---+------+++-++++",
"output": "No"
},
{
"input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-",
"output": "No"
},
{
"input": "-+-----++++--++-+-++",
"output": "Yes"
},
{
"input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+",
"output": "Yes"
},
{
"input": "-+-+-++-+-+-",
"output": "Yes"
},
{
"input": "-+-++-+-",
"output": "Yes"
},
{
"input": "-+-++-+-+-",
"output": "No"
},
{
"input": "++-+-+-+-+--+",
"output": "No"
},
{
"input": "+++---",
"output": "No"
},
{
"input": "+-+-+-+-+--+-+-+-+-++--++--+",
"output": "Yes"
},
{
"input": "+-+-++",
"output": "No"
},
{
"input": "-++--+--+++-+-+-+-+-",
"output": "No"
},
{
"input": "+---+-+-",
"output": "No"
},
{
"input": "+-+--+-+",
"output": "Yes"
},
{
"input": "+++---+++---",
"output": "No"
},
{
"input": "-+++++",
"output": "No"
},
{
"input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-",
"output": "Yes"
},
{
"input": "-+++--",
"output": "No"
},
{
"input": "+---+",
"output": "No"
},
{
"input": "-++",
"output": "No"
},
{
"input": "-+--+-",
"output": "Yes"
},
{
"input": "+---++--++",
"output": "No"
},
{
"input": "+++-",
"output": "No"
},
{
"input": "--+++",
"output": "No"
},
{
"input": "++-+",
"output": "No"
}
] | 1,579,946,898 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 280 | 5,017,600 | a = input()
stack = []
for i in a:
if not stack:
stack.append(i)
elif stack and stack[-1]==i:
stack.pop()
else:
stack.append(i)
if stack:
print('No')
else:
print('Yes') | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
To understand the problem better please read the notes to the test samples.
Input Specification:
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Output Specification:
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
Demo Input:
['-++-\n', '+-\n', '++\n', '-\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n', 'No\n']
Note:
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | ```python
a = input()
stack = []
for i in a:
if not stack:
stack.append(i)
elif stack and stack[-1]==i:
stack.pop()
else:
stack.append(i)
if stack:
print('No')
else:
print('Yes')
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] | [
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] | First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | 0 | [
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes"
},
{
"input": "1\n2 3",
"output": "No"
},
{
"input": "1\n1062961 1031",
"output": "Yes"
},
{
"input": "1\n6 12",
"output": "No"
},
{
"input": "1\n3 1",
"output": "No"
},
{
"input": "1\n3 10",
"output": "No"
},
{
"input": "1\n31159 970883281",
"output": "Yes"
},
{
"input": "1\n9907 98148649",
"output": "Yes"
},
{
"input": "1\n16 8",
"output": "No"
},
{
"input": "1\n90 72",
"output": "No"
}
] | 1,660,383,221 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | import math
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
t = a*b
l, r = 1, 1000000
ans = 'No'
while l <= r:
m = (l+r)//2
if m ** 3 == t:
ans = 'Yes'
break
elif m**3 < t:
l = m+1
else:
r = m-1
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input Specification:
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
Output Specification:
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n']
Demo Output:
['Yes\nYes\nYes\nNo\nNo\nYes\n']
Note:
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | ```python
import math
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
t = a*b
l, r = 1, 1000000
ans = 'No'
while l <= r:
m = (l+r)//2
if m ** 3 == t:
ans = 'Yes'
break
elif m**3 < t:
l = m+1
else:
r = m-1
print(ans)
``` | 0 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,693,837,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 31 | 0 | l = list(map(int, input().split()))
d = {}
for v in l: d[v] = d.get(v, 0) + 1
if len(d) > 3: answer = "Alien"
else:
if len(d) == 1: answer = "Elephant"
elif len(d) == 2:
if all(lambda x: x % 2 == 0 for v in d.values()): answer = "Elephant"
else: answer = "Bear"
else: answer = "Bear"
print(answer)
| Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
l = list(map(int, input().split()))
d = {}
for v in l: d[v] = d.get(v, 0) + 1
if len(d) > 3: answer = "Alien"
else:
if len(d) == 1: answer = "Elephant"
elif len(d) == 2:
if all(lambda x: x % 2 == 0 for v in d.values()): answer = "Elephant"
else: answer = "Bear"
else: answer = "Bear"
print(answer)
``` | 0 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,641,684,640 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 46 | 216 | 0 | n=int(input())
number=input()
while True:
if '1' in number or '2' in number or '3' in number or '5' in number or '6' in number or '8' in number or '9' in number or '0' in number:
print('NO')
break
number = [int(i) for i in number]
if sum(number[0:n//2])==sum(number[n//2:]):
print('YES')
break
else:
print('NO')
break | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
n=int(input())
number=input()
while True:
if '1' in number or '2' in number or '3' in number or '5' in number or '6' in number or '8' in number or '9' in number or '0' in number:
print('NO')
break
number = [int(i) for i in number]
if sum(number[0:n//2])==sum(number[n//2:]):
print('YES')
break
else:
print('NO')
break
``` | 3 |
|
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,695,552,712 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | # Read the year
y = int(input())
# Function to check if a year has distinct digits
def has_distinct_digits(year):
return len(set(str(year))) == 4
# Start iterating from y+1
next_year = y + 1
while not has_distinct_digits(next_year):
next_year += 1
# Output the minimum year with distinct digits
print(next_year)
| 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
# Read the year
y = int(input())
# Function to check if a year has distinct digits
def has_distinct_digits(year):
return len(set(str(year))) == 4
# Start iterating from y+1
next_year = y + 1
while not has_distinct_digits(next_year):
next_year += 1
# Output the minimum year with distinct digits
print(next_year)
``` | 3 |
|
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*?
Please help Kolya answer this question. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES"
},
{
"input": "999999987",
"output": "YES"
},
{
"input": "27406117",
"output": "NO"
},
{
"input": "27404883",
"output": "NO"
},
{
"input": "27403649",
"output": "NO"
},
{
"input": "27402415",
"output": "NO"
},
{
"input": "27401181",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999244",
"output": "YES"
},
{
"input": "999129999",
"output": "YES"
},
{
"input": "17159199",
"output": "NO"
},
{
"input": "13606913",
"output": "NO"
},
{
"input": "14841529",
"output": "NO"
},
{
"input": "915968473",
"output": "YES"
},
{
"input": "980698615",
"output": "YES"
},
{
"input": "912331505",
"output": "YES"
},
{
"input": "917261049",
"output": "YES"
},
{
"input": "999999997",
"output": "YES"
},
{
"input": "12345",
"output": "NO"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1359257",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "1234567",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "123456",
"output": "YES"
},
{
"input": "2592590",
"output": "YES"
},
{
"input": "999999998",
"output": "YES"
},
{
"input": "1356789",
"output": "NO"
},
{
"input": "12345670",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "1480800",
"output": "YES"
},
{
"input": "908000000",
"output": "YES"
},
{
"input": "3000",
"output": "NO"
},
{
"input": "1235801",
"output": "YES"
},
{
"input": "991919191",
"output": "YES"
},
{
"input": "25613715",
"output": "YES"
},
{
"input": "13580237",
"output": "YES"
},
{
"input": "14814804",
"output": "YES"
},
{
"input": "11403961",
"output": "YES"
},
{
"input": "999999989",
"output": "YES"
},
{
"input": "1237035",
"output": "YES"
},
{
"input": "81134231",
"output": "YES"
},
{
"input": "1236",
"output": "NO"
},
{
"input": "1359250",
"output": "YES"
},
{
"input": "100",
"output": "NO"
},
{
"input": "987654321",
"output": "YES"
},
{
"input": "122222",
"output": "NO"
},
{
"input": "123458",
"output": "NO"
},
{
"input": "20987639",
"output": "YES"
},
{
"input": "999973333",
"output": "YES"
},
{
"input": "253082",
"output": "YES"
},
{
"input": "1235",
"output": "NO"
},
{
"input": "803219200",
"output": "YES"
},
{
"input": "100000000",
"output": "YES"
},
{
"input": "1485181",
"output": "YES"
}
] | 1,508,678,579 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,529,600 | a = int(input().strip())
i,j,k = round(a/1234567*1000,0),round(a/123456*100,0),int(a/1234)
if i == j and j == k:
a -= (a//1234567)*1234567
a -= (a//123456)*123456
a -= (a//1234)*1234
if(a==0):
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*?
Please help Kolya answer this question.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score.
Output Specification:
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
Demo Input:
['1359257\n', '17851817\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | ```python
a = int(input().strip())
i,j,k = round(a/1234567*1000,0),round(a/123456*100,0),int(a/1234)
if i == j and j == k:
a -= (a//1234567)*1234567
a -= (a//123456)*123456
a -= (a//1234)*1234
if(a==0):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output": "12"
},
{
"input": "4 5\n5 2 6 4\n8 9 1 3 7",
"output": "12"
},
{
"input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1",
"output": "1"
},
{
"input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6",
"output": "1"
},
{
"input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9",
"output": "1"
},
{
"input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n8\n9",
"output": "89"
},
{
"input": "1 1\n9\n8",
"output": "89"
},
{
"input": "1 1\n1\n2",
"output": "12"
},
{
"input": "1 1\n2\n1",
"output": "12"
},
{
"input": "1 1\n9\n9",
"output": "9"
},
{
"input": "1 1\n1\n1",
"output": "1"
},
{
"input": "4 5\n3 2 4 5\n1 6 5 9 8",
"output": "5"
},
{
"input": "3 2\n4 5 6\n1 5",
"output": "5"
},
{
"input": "5 4\n1 3 5 6 7\n2 4 3 9",
"output": "3"
},
{
"input": "5 5\n1 3 5 7 9\n2 4 6 8 9",
"output": "9"
},
{
"input": "2 2\n1 8\n2 8",
"output": "8"
},
{
"input": "5 5\n5 6 7 8 9\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6",
"output": "2"
},
{
"input": "2 2\n1 5\n2 5",
"output": "5"
},
{
"input": "4 4\n1 3 5 8\n2 4 6 8",
"output": "8"
},
{
"input": "3 3\n1 5 3\n2 5 7",
"output": "5"
},
{
"input": "3 3\n3 6 8\n2 6 9",
"output": "6"
},
{
"input": "2 2\n1 4\n2 4",
"output": "4"
},
{
"input": "5 3\n3 4 5 6 7\n1 5 9",
"output": "5"
},
{
"input": "4 4\n1 2 3 4\n2 5 6 7",
"output": "2"
},
{
"input": "5 5\n1 2 3 4 5\n9 2 1 7 5",
"output": "1"
},
{
"input": "2 2\n1 3\n2 3",
"output": "3"
},
{
"input": "3 3\n3 2 1\n3 2 1",
"output": "1"
},
{
"input": "3 3\n1 3 5\n2 3 6",
"output": "3"
},
{
"input": "3 3\n5 6 7\n5 6 7",
"output": "5"
},
{
"input": "1 2\n5\n2 5",
"output": "5"
},
{
"input": "3 3\n2 4 9\n7 8 9",
"output": "9"
},
{
"input": "3 3\n1 2 4\n3 4 5",
"output": "4"
},
{
"input": "3 2\n1 4 9\n2 4",
"output": "4"
},
{
"input": "3 3\n3 5 6\n1 5 9",
"output": "5"
},
{
"input": "3 2\n1 2 4\n3 4",
"output": "4"
},
{
"input": "2 4\n8 9\n1 2 3 9",
"output": "9"
},
{
"input": "1 2\n9\n8 9",
"output": "9"
},
{
"input": "3 2\n1 2 4\n4 2",
"output": "2"
},
{
"input": "2 3\n4 5\n1 3 5",
"output": "5"
},
{
"input": "3 2\n1 2 3\n2 3",
"output": "2"
},
{
"input": "4 3\n1 3 5 9\n2 8 9",
"output": "9"
},
{
"input": "2 2\n1 9\n9 2",
"output": "9"
}
] | 1,605,014,202 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 139 | 0 | a, b = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
m = min(arr)
n = min(brr)
if m == n:
print(m)
else:
if m < n:
print(m, n, sep='')
else:
print(n, m, sep='') | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Output Specification:
Print the smallest pretty integer.
Demo Input:
['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n']
Demo Output:
['25\n', '1\n']
Note:
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | ```python
a, b = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
m = min(arr)
n = min(brr)
if m == n:
print(m)
else:
if m < n:
print(m, n, sep='')
else:
print(n, m, sep='')
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,653,549,274 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | m, n ,o = map(int, input().split())
x = 0
y = 0
if m%o == 0:
x = m/o
else:
x = m//o + 1
if n%o == 0:
y = n/o
else:
y = n//o + 1
print(x*y) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
m, n ,o = map(int, input().split())
x = 0
y = 0
if m%o == 0:
x = m/o
else:
x = m//o + 1
if n%o == 0:
y = n/o
else:
y = n//o + 1
print(x*y)
``` | 0 |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding. | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16",
"output": "50"
},
{
"input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75",
"output": "7"
},
{
"input": "8 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "3 8\n4 3 2",
"output": "2"
},
{
"input": "3 8\n2 4 2",
"output": "2"
},
{
"input": "3 6\n1 3 2",
"output": "2"
},
{
"input": "3 6\n3 2 5",
"output": "2"
},
{
"input": "3 8\n4 2 1",
"output": "2"
},
{
"input": "5 6\n2 3 5 1 2",
"output": "2"
},
{
"input": "2 6\n5 3",
"output": "2"
},
{
"input": "4 12\n6 4 3 1",
"output": "2"
},
{
"input": "3 18\n1 9 6",
"output": "2"
},
{
"input": "3 9\n3 2 1",
"output": "3"
},
{
"input": "3 6\n5 3 2",
"output": "2"
},
{
"input": "2 10\n5 2",
"output": "2"
},
{
"input": "2 18\n6 3",
"output": "3"
},
{
"input": "4 12\n1 2 12 3",
"output": "1"
},
{
"input": "3 7\n3 2 1",
"output": "7"
},
{
"input": "3 6\n3 2 1",
"output": "2"
},
{
"input": "5 10\n5 4 3 2 1",
"output": "2"
},
{
"input": "5 16\n8 4 2 1 7",
"output": "2"
},
{
"input": "6 7\n6 5 4 3 7 1",
"output": "1"
},
{
"input": "2 6\n3 2",
"output": "2"
},
{
"input": "2 4\n4 1",
"output": "1"
},
{
"input": "6 8\n2 4 1 3 5 7",
"output": "2"
},
{
"input": "6 8\n6 5 4 3 2 1",
"output": "2"
},
{
"input": "6 15\n5 2 3 6 4 3",
"output": "3"
},
{
"input": "4 8\n2 4 8 1",
"output": "1"
},
{
"input": "2 5\n5 1",
"output": "1"
},
{
"input": "4 18\n3 1 1 2",
"output": "6"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "3 10\n2 10 5",
"output": "1"
},
{
"input": "5 12\n12 4 4 4 3",
"output": "1"
},
{
"input": "3 6\n6 3 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 18\n1 9 3",
"output": "2"
},
{
"input": "3 8\n7 2 4",
"output": "2"
},
{
"input": "2 100\n99 1",
"output": "100"
},
{
"input": "4 12\n1 3 4 2",
"output": "3"
},
{
"input": "3 6\n2 3 1",
"output": "2"
},
{
"input": "4 6\n3 2 5 12",
"output": "2"
},
{
"input": "4 97\n97 1 50 10",
"output": "1"
},
{
"input": "3 12\n1 12 2",
"output": "1"
},
{
"input": "4 12\n1 4 3 2",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 19\n7 1 1",
"output": "19"
},
{
"input": "5 12\n12 4 3 4 4",
"output": "1"
},
{
"input": "3 8\n8 4 2",
"output": "1"
},
{
"input": "3 3\n3 2 1",
"output": "1"
},
{
"input": "5 6\n3 2 4 2 2",
"output": "2"
},
{
"input": "2 16\n8 4",
"output": "2"
},
{
"input": "3 6\n10 2 3",
"output": "2"
},
{
"input": "5 3\n2 4 5 3 6",
"output": "1"
},
{
"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66",
"output": "1"
},
{
"input": "3 12\n3 12 2",
"output": "1"
},
{
"input": "5 25\n24 5 15 25 23",
"output": "1"
},
{
"input": "2 4\n8 1",
"output": "4"
},
{
"input": "4 100\n2 50 4 1",
"output": "2"
},
{
"input": "3 28\n7 14 1",
"output": "2"
},
{
"input": "4 8\n2 8 4 1",
"output": "1"
},
{
"input": "4 6\n6 1 2 3",
"output": "1"
},
{
"input": "2 12\n4 3",
"output": "3"
},
{
"input": "4 12\n1 2 4 3",
"output": "3"
},
{
"input": "5 12\n2 3 12 6 4",
"output": "1"
},
{
"input": "4 4\n1 2 2 4",
"output": "1"
},
{
"input": "3 6\n2 3 2",
"output": "2"
},
{
"input": "4 21\n21 20 21 2",
"output": "1"
},
{
"input": "3 8\n3 4 2",
"output": "2"
},
{
"input": "1 25\n25",
"output": "1"
},
{
"input": "99 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "1"
},
{
"input": "98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98",
"output": "1"
},
{
"input": "79 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79",
"output": "1"
},
{
"input": "4 32\n1 1 1 1",
"output": "32"
},
{
"input": "1 100\n1",
"output": "100"
},
{
"input": "2 100\n7 1",
"output": "100"
},
{
"input": "7 24\n1 3 6 4 5 2 7",
"output": "4"
},
{
"input": "6 87\n1 2 8 4 5 7",
"output": "87"
},
{
"input": "1 88\n1",
"output": "88"
},
{
"input": "1 89\n1",
"output": "89"
}
] | 1,654,667,414 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 46 | 0 | n,k=map(int, input().split())
a=list(map(int, input().split()))
x=0
for i in range(n):
if k%a[i]==0 and a[i]>x:
x=a[i]
print(k//x)
| Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input Specification:
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output Specification:
Print one integer number — the minimum number of hours required to water the garden.
Demo Input:
['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n']
Demo Output:
['2\n', '7\n']
Note:
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | ```python
n,k=map(int, input().split())
a=list(map(int, input().split()))
x=0
for i in range(n):
if k%a[i]==0 and a[i]>x:
x=a[i]
print(k//x)
``` | 3 |
|
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 1 -1",
"output": "100"
},
{
"input": "100 54 100",
"output": "54"
},
{
"input": "100 37 -100",
"output": "37"
},
{
"input": "99 41 0",
"output": "41"
},
{
"input": "97 37 -92",
"output": "42"
},
{
"input": "99 38 59",
"output": "97"
},
{
"input": "35 34 1",
"output": "35"
},
{
"input": "48 1 -1",
"output": "48"
},
{
"input": "87 65 -76",
"output": "76"
},
{
"input": "76 26 29",
"output": "55"
},
{
"input": "100 65 0",
"output": "65"
},
{
"input": "2 1 100",
"output": "1"
},
{
"input": "3 2 -100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "1 1 -100",
"output": "1"
},
{
"input": "3 1 -100",
"output": "3"
},
{
"input": "4 3 -100",
"output": "3"
},
{
"input": "3 2 -12",
"output": "2"
},
{
"input": "2 2 -100",
"output": "2"
},
{
"input": "3 2 -90",
"output": "2"
},
{
"input": "6 2 -10",
"output": "4"
},
{
"input": "3 3 -100",
"output": "2"
},
{
"input": "5 2 4",
"output": "1"
},
{
"input": "6 4 5",
"output": "3"
},
{
"input": "3 2 -6",
"output": "2"
},
{
"input": "5 1 -99",
"output": "2"
},
{
"input": "6 2 5",
"output": "1"
},
{
"input": "10 1 -100",
"output": "1"
},
{
"input": "2 2 1",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "2"
},
{
"input": "17 17 2",
"output": "2"
},
{
"input": "6 6 1",
"output": "1"
},
{
"input": "5 3 -2",
"output": "1"
},
{
"input": "6 2 -100",
"output": "4"
},
{
"input": "5 3 -100",
"output": "3"
},
{
"input": "5 4 3",
"output": "2"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "5 5 2",
"output": "2"
},
{
"input": "3 2 5",
"output": "1"
},
{
"input": "5 5 -1",
"output": "4"
},
{
"input": "5 3 3",
"output": "1"
},
{
"input": "4 2 3",
"output": "1"
},
{
"input": "88 76 74",
"output": "62"
}
] | 1,564,452,450 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 0 | n,a,b=map(int,input().split())
print(((a+b)%n+n-1)%n+1) | Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input Specification:
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Output Specification:
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
Demo Input:
['6 2 -5\n', '5 1 3\n', '3 2 7\n']
Demo Output:
['3\n', '4\n', '3\n']
Note:
The first example is illustrated by the picture in the statements. | ```python
n,a,b=map(int,input().split())
print(((a+b)%n+n-1)%n+1)
``` | 3 |
|
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n0 1 1",
"output": "YES"
},
{
"input": "3\n0 1 0",
"output": "NO"
},
{
"input": "2\n0 1",
"output": "YES"
},
{
"input": "2\n1 0",
"output": "YES"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "10\n1 0 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5\n1 1 1 1 0",
"output": "YES"
},
{
"input": "4\n1 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 0 0",
"output": "NO"
},
{
"input": "10\n0 0 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "94\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",
"output": "NO"
},
{
"input": "64\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",
"output": "NO"
},
{
"input": "34\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",
"output": "NO"
},
{
"input": "35\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",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "10\n1 1 0 1 1 1 0 1 1 1",
"output": "NO"
}
] | 1,540,393,846 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 108 | 0 | buttons = int(input())
fastened = str(input())
number_buttons = int(buttons)
array_fastened = fastened.split()
array_fastened = array_fastened[0:number_buttons]
x = 0
for i in range(len(array_fastened)):
if int(array_fastened[i]) == 1:
x += 1
if ((x > 1 and x == len(array_fastened) - 1) or (x == 1 and len(array_fastened))) == 1:
print('YES')
else:
print('NO') | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
Output Specification:
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Demo Input:
['3\n1 0 1\n', '3\n1 0 0\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
buttons = int(input())
fastened = str(input())
number_buttons = int(buttons)
array_fastened = fastened.split()
array_fastened = array_fastened[0:number_buttons]
x = 0
for i in range(len(array_fastened)):
if int(array_fastened[i]) == 1:
x += 1
if ((x > 1 and x == len(array_fastened) - 1) or (x == 1 and len(array_fastened))) == 1:
print('YES')
else:
print('NO')
``` | 0 |
|
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description. | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k",
"output": "1\na k"
},
{
"input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha",
"output": "2\n123abc 1A2B3C\n1 Misha"
},
{
"input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e",
"output": "3\nM G\n1 R\nS e"
},
{
"input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV",
"output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV"
},
{
"input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSE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nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ",
"output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ"
}
] | 1,651,058,657 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a = int(input())
b = {}
for c in range(a):
d,e = input().split()
if d not in b:
b[e] = d
else:
b[e] = b[d]
b.pop(d)
print(b)
for i in b:
print(b[i], i)
| Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
Input Specification:
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
Output Specification:
In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
Demo Input:
['5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n']
Demo Output:
['3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n']
Note:
none | ```python
a = int(input())
b = {}
for c in range(a):
d,e = input().split()
if d not in b:
b[e] = d
else:
b[e] = b[d]
b.pop(d)
print(b)
for i in b:
print(b[i], i)
``` | 0 |
|
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
},
{
"input": "e1\nf2",
"output": "1\nRU"
},
{
"input": "g4\nd2",
"output": "3\nLD\nLD\nL"
},
{
"input": "a8\nb2",
"output": "6\nRD\nD\nD\nD\nD\nD"
},
{
"input": "d4\nh2",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "c5\na2",
"output": "3\nLD\nLD\nD"
},
{
"input": "h5\nf8",
"output": "3\nLU\nLU\nU"
},
{
"input": "e6\nb6",
"output": "3\nL\nL\nL"
},
{
"input": "a6\ng4",
"output": "6\nRD\nRD\nR\nR\nR\nR"
},
{
"input": "f7\nc2",
"output": "5\nLD\nLD\nLD\nD\nD"
},
{
"input": "b7\nh8",
"output": "6\nRU\nR\nR\nR\nR\nR"
},
{
"input": "g7\nd6",
"output": "3\nLD\nL\nL"
},
{
"input": "c8\na3",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "h8\nf1",
"output": "7\nLD\nLD\nD\nD\nD\nD\nD"
},
{
"input": "d1\nb7",
"output": "6\nLU\nLU\nU\nU\nU\nU"
},
{
"input": "a7\ne5",
"output": "4\nRD\nRD\nR\nR"
},
{
"input": "d6\nb1",
"output": "5\nLD\nLD\nD\nD\nD"
},
{
"input": "f5\ng5",
"output": "1\nR"
},
{
"input": "h4\nd1",
"output": "4\nLD\nLD\nLD\nL"
},
{
"input": "b3\na5",
"output": "2\nLU\nU"
},
{
"input": "d2\nf1",
"output": "2\nRD\nR"
},
{
"input": "f1\nc5",
"output": "4\nLU\nLU\nLU\nU"
},
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "c7\ne5",
"output": "2\nRD\nRD"
},
{
"input": "e7\nb1",
"output": "6\nLD\nLD\nLD\nD\nD\nD"
},
{
"input": "g8\na8",
"output": "6\nL\nL\nL\nL\nL\nL"
},
{
"input": "g6\nf2",
"output": "4\nLD\nD\nD\nD"
},
{
"input": "g4\nc4",
"output": "4\nL\nL\nL\nL"
},
{
"input": "g2\na6",
"output": "6\nLU\nLU\nLU\nLU\nL\nL"
},
{
"input": "f8\nf8",
"output": "0"
},
{
"input": "f5\nd2",
"output": "3\nLD\nLD\nD"
}
] | 1,581,149,348 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 307,200 | # -*-coding:utf-8-*-
a, b = input(), input()
m, n = (ord(a[i]) - ord(b[i]) for i in range(2))
p = max(abs(m), abs(n))
print(p)
while m != 0 and n != 0:
r = ''
if m < 0:
r = 'R'
m += 1
elif m < 0:
r = 'L'
m -= 1
if n < 0:
r += 'U'
n += 1
elif n > 0:
r += 'D'
n -= 1
print(r)
| Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this.
In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Input Specification:
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
Output Specification:
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
Demo Input:
['a8\nh1\n']
Demo Output:
['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n']
Note:
none | ```python
# -*-coding:utf-8-*-
a, b = input(), input()
m, n = (ord(a[i]) - ord(b[i]) for i in range(2))
p = max(abs(m), abs(n))
print(p)
while m != 0 and n != 0:
r = ''
if m < 0:
r = 'R'
m += 1
elif m < 0:
r = 'L'
m -= 1
if n < 0:
r += 'U'
n += 1
elif n > 0:
r += 'D'
n -= 1
print(r)
``` | 0 |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 27 4 2",
"output": "yes\n1 5"
},
{
"input": "9\n6 78 63 59 28 24 8 96 99",
"output": "yes\n2 7"
},
{
"input": "6\n19517752 43452931 112792556 68417469 779722934 921694415",
"output": "yes\n3 4"
},
{
"input": "6\n169793171 335736854 449917902 513287332 811627074 938727967",
"output": "yes\n1 1"
},
{
"input": "6\n509329 173849943 297546987 591032670 796346199 914588283",
"output": "yes\n1 1"
},
{
"input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100",
"output": "yes\n1 11"
},
{
"input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100",
"output": "yes\n25 37"
},
{
"input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "yes\n3 22"
},
{
"input": "2\n404928771 698395106",
"output": "yes\n1 1"
},
{
"input": "2\n699573624 308238132",
"output": "yes\n1 2"
},
{
"input": "5\n75531609 242194958 437796493 433259361 942142185",
"output": "yes\n3 4"
},
{
"input": "5\n226959376 840957605 833410429 273566427 872976052",
"output": "yes\n2 4"
},
{
"input": "5\n373362086 994096202 767275079 734424844 515504383",
"output": "yes\n2 5"
},
{
"input": "5\n866379155 593548704 259097686 216134784 879911740",
"output": "yes\n1 4"
},
{
"input": "5\n738083041 719956102 420866851 307749161 257917459",
"output": "yes\n1 5"
},
{
"input": "5\n90786760 107075352 139104198 424911569 858427981",
"output": "yes\n1 1"
},
{
"input": "6\n41533825 525419745 636375901 636653266 879043107 967434399",
"output": "yes\n1 1"
},
{
"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907",
"output": "yes\n20 35"
},
{
"input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165",
"output": "no"
},
{
"input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471",
"output": "no"
},
{
"input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655",
"output": "yes\n1 1"
},
{
"input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992",
"output": "no"
},
{
"input": "4\n1 4 2 3",
"output": "no"
},
{
"input": "6\n1 2 5 4 3 6",
"output": "yes\n3 5"
},
{
"input": "1\n1",
"output": "yes\n1 1"
},
{
"input": "6\n1 5 3 4 2 6",
"output": "no"
},
{
"input": "4\n3 4 1 2",
"output": "no"
},
{
"input": "5\n2 5 4 3 1",
"output": "no"
},
{
"input": "4\n2 1 4 3",
"output": "no"
},
{
"input": "6\n2 1 4 3 5 6",
"output": "no"
}
] | 1,676,269,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
d=list(map(int,input().split()))
b=[]
l=d[0]
t=0
g=0
k=0
r=d[n-1]
for i in range(n-1):
if d[i]>d[i+1]:
g=1
if g==1:
for i in range(1,n-1):
if l<d[i]:
l=d[i]
else:
l=i-1
break
print(l)
for i in range(n-1,1,-1):
if r>d[i-1]:
r=d[i-1]
else:
r=i
break
print(r)
for i in range(r,l-1,-1):
b.append(d[i])
for i in range(l,r+1):
d[i]=b[k]
k=k+1
for i in range(n-1):
if d[i]>d[i+1]:
t=1
print("no")
break
if t==0:
print("yes")
print(l+1,r+1)
else:
print("yes")
print(1,1)
| Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Output Specification:
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
Demo Input:
['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n']
Demo Output:
['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n']
Note:
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | ```python
n=int(input())
d=list(map(int,input().split()))
b=[]
l=d[0]
t=0
g=0
k=0
r=d[n-1]
for i in range(n-1):
if d[i]>d[i+1]:
g=1
if g==1:
for i in range(1,n-1):
if l<d[i]:
l=d[i]
else:
l=i-1
break
print(l)
for i in range(n-1,1,-1):
if r>d[i-1]:
r=d[i-1]
else:
r=i
break
print(r)
for i in range(r,l-1,-1):
b.append(d[i])
for i in range(l,r+1):
d[i]=b[k]
k=k+1
for i in range(n-1):
if d[i]>d[i+1]:
t=1
print("no")
break
if t==0:
print("yes")
print(l+1,r+1)
else:
print("yes")
print(1,1)
``` | 0 |
|
315 | B | Sereja and Array | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*.
Help Sereja, complete all his operations. | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*). | For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. | [
"10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n"
] | [
"2\n9\n11\n20\n30\n40\n39\n"
] | none | 1,000 | [
{
"input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9",
"output": "2\n9\n11\n20\n30\n40\n39"
},
{
"input": "1 3\n1\n1 1 2\n2 1\n3 1",
"output": "3"
},
{
"input": "1 1\n1\n3 1",
"output": "1"
},
{
"input": "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539",
"output": "862810900"
},
{
"input": "6 5\n545129895 918519812 2334334 565540665 484519712 904102869\n3 3\n1 2 641196860\n2 779\n2 3036\n3 1",
"output": "2334334\n545133710"
},
{
"input": "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119",
"output": "780579549"
},
{
"input": "4 4\n529316834 995684640 949078705 317773978\n3 3\n3 1\n2 6271\n1 1 856879574",
"output": "949078705\n529316834"
},
{
"input": "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946",
"output": "695181967"
}
] | 1,604,392,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 307,200 | n,m = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
s=0
for i in range(m):
inp = list(map(int, input().strip().split(' ')))
if inp[0]==3:
print(lst[inp[1]-1]+s)
elif inp[0]==1:
lst[inp[1]-1]=inp[2]
elif inp[0]==2:
s+=inp[1]
| Title: Sereja and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms:
1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*.
Help Sereja, complete all his operations.
Input Specification:
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array.
Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*).
Output Specification:
For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input.
Demo Input:
['10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n']
Demo Output:
['2\n9\n11\n20\n30\n40\n39\n']
Note:
none | ```python
n,m = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
s=0
for i in range(m):
inp = list(map(int, input().strip().split(' ')))
if inp[0]==3:
print(lst[inp[1]-1]+s)
elif inp[0]==1:
lst[inp[1]-1]=inp[2]
elif inp[0]==2:
s+=inp[1]
``` | 0 |
|
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese. | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"input": "n",
"output": "YES"
},
{
"input": "necnei",
"output": "NO"
},
{
"input": "nternn",
"output": "NO"
},
{
"input": "aucunuohja",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "b",
"output": "NO"
},
{
"input": "nn",
"output": "YES"
},
{
"input": "nnnzaaa",
"output": "YES"
},
{
"input": "zn",
"output": "NO"
},
{
"input": "ab",
"output": "NO"
},
{
"input": "aaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaab",
"output": "NO"
},
{
"input": "aaaaaaaaan",
"output": "YES"
},
{
"input": "baaaaaaaaa",
"output": "YES"
},
{
"input": "naaaaaaaaa",
"output": "YES"
},
{
"input": "nbaaaaaaaa",
"output": "YES"
},
{
"input": "bbaaaaaaaa",
"output": "NO"
},
{
"input": "bnaaaaaaaa",
"output": "NO"
},
{
"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu",
"output": "YES"
},
{
"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino",
"output": "NO"
},
{
"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul",
"output": "NO"
},
{
"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu",
"output": "YES"
},
{
"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo",
"output": "NO"
},
{
"input": "y",
"output": "NO"
},
{
"input": "by",
"output": "NO"
},
{
"input": "yy",
"output": "NO"
},
{
"input": "nbn",
"output": "NO"
},
{
"input": "nz",
"output": "NO"
},
{
"input": "king",
"output": "NO"
},
{
"input": "g",
"output": "NO"
},
{
"input": "az",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "yn",
"output": "NO"
},
{
"input": "aeo",
"output": "YES"
},
{
"input": "nb",
"output": "NO"
},
{
"input": "npn",
"output": "NO"
},
{
"input": "kini",
"output": "YES"
},
{
"input": "pya",
"output": "NO"
},
{
"input": "m",
"output": "NO"
},
{
"input": "p",
"output": "NO"
},
{
"input": "aaaaaaaak",
"output": "NO"
},
{
"input": "aab",
"output": "NO"
},
{
"input": "d",
"output": "NO"
},
{
"input": "at",
"output": "NO"
},
{
"input": "aaaaaak",
"output": "NO"
},
{
"input": "aaz",
"output": "NO"
},
{
"input": "aaab",
"output": "NO"
},
{
"input": "s",
"output": "NO"
},
{
"input": "nzzen",
"output": "NO"
},
{
"input": "aeionnhhhn",
"output": "NO"
},
{
"input": "h",
"output": "NO"
},
{
"input": "ny",
"output": "NO"
}
] | 1,636,799,175 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 46 | 4,505,600 | a=input()
c=0
if a[-1] in 'aeioun':
for i in range(0,len(a)-1):
if a[i] not in 'aeioun':
if a[i+1] not in 'aeiou':
print('NO')
c=c+1
break
else:
print('NO')
c=c+1
if c==0:
print('YES') | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese.
Input Specification:
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Output Specification:
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
Demo Input:
['sumimasen\n', 'ninja\n', 'codeforces\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | ```python
a=input()
c=0
if a[-1] in 'aeioun':
for i in range(0,len(a)-1):
if a[i] not in 'aeioun':
if a[i+1] not in 'aeiou':
print('NO')
c=c+1
break
else:
print('NO')
c=c+1
if c==0:
print('YES')
``` | 3 |
|
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day.
Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time.
Help Mister B to calculate how many days he needed to finish the book. | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished in 15 days. | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
"output": "999"
},
{
"input": "1000 1 1 1000 0",
"output": "1000"
},
{
"input": "737 41 74 12 11",
"output": "13"
},
{
"input": "1000 1000 1000 0 999",
"output": "1"
},
{
"input": "765 12 105 5 7",
"output": "17"
},
{
"input": "15 2 2 1000 0",
"output": "8"
},
{
"input": "1000 1 1000 1000 0",
"output": "2"
},
{
"input": "20 3 7 1 2",
"output": "6"
},
{
"input": "1000 500 500 1000 499",
"output": "501"
},
{
"input": "1 1000 1000 1000 0",
"output": "1"
},
{
"input": "1000 2 1000 56 0",
"output": "7"
},
{
"input": "1000 2 1000 802 0",
"output": "3"
},
{
"input": "16 1 8 2 0",
"output": "4"
},
{
"input": "20 6 10 2 2",
"output": "3"
},
{
"input": "8 2 12 4 1",
"output": "3"
},
{
"input": "8 6 13 2 5",
"output": "2"
},
{
"input": "70 4 20 87 0",
"output": "5"
},
{
"input": "97 8 13 234 5",
"output": "13"
},
{
"input": "16 4 23 8 3",
"output": "3"
},
{
"input": "65 7 22 7 4",
"output": "5"
},
{
"input": "93 10 18 11 7",
"output": "9"
},
{
"input": "86 13 19 15 9",
"output": "9"
},
{
"input": "333 17 50 10 16",
"output": "12"
},
{
"input": "881 16 55 10 12",
"output": "23"
},
{
"input": "528 11 84 3 9",
"output": "19"
},
{
"input": "896 2 184 8 1",
"output": "16"
},
{
"input": "236 10 930 9 8",
"output": "8"
},
{
"input": "784 1 550 14 0",
"output": "12"
},
{
"input": "506 1 10 4 0",
"output": "53"
},
{
"input": "460 1 3 2 0",
"output": "154"
},
{
"input": "701 1 3 1 0",
"output": "235"
},
{
"input": "100 49 50 1000 2",
"output": "3"
},
{
"input": "100 1 100 100 0",
"output": "2"
},
{
"input": "12 1 4 2 0",
"output": "4"
},
{
"input": "22 10 12 0 0",
"output": "3"
},
{
"input": "20 10 15 1 4",
"output": "3"
},
{
"input": "1000 5 10 1 4",
"output": "169"
},
{
"input": "1000 1 1000 1 0",
"output": "45"
},
{
"input": "4 1 2 2 0",
"output": "3"
},
{
"input": "1 5 5 1 1",
"output": "1"
},
{
"input": "19 10 11 0 2",
"output": "3"
},
{
"input": "1 2 3 0 0",
"output": "1"
},
{
"input": "10 1 4 10 0",
"output": "4"
},
{
"input": "20 3 100 1 1",
"output": "5"
},
{
"input": "1000 5 9 5 0",
"output": "112"
},
{
"input": "1 11 12 0 10",
"output": "1"
},
{
"input": "1 1 1 1 0",
"output": "1"
},
{
"input": "1000 1 20 1 0",
"output": "60"
},
{
"input": "9 1 4 2 0",
"output": "4"
},
{
"input": "129 2 3 4 0",
"output": "44"
},
{
"input": "4 2 2 0 1",
"output": "3"
},
{
"input": "1000 1 10 100 0",
"output": "101"
},
{
"input": "100 1 100 1 0",
"output": "14"
},
{
"input": "8 3 4 2 0",
"output": "3"
},
{
"input": "20 1 6 4 0",
"output": "5"
},
{
"input": "8 2 4 2 0",
"output": "3"
},
{
"input": "11 5 6 7 2",
"output": "3"
},
{
"input": "100 120 130 120 0",
"output": "1"
},
{
"input": "7 1 4 1 0",
"output": "4"
},
{
"input": "5 3 10 0 2",
"output": "3"
},
{
"input": "5 2 2 0 0",
"output": "3"
},
{
"input": "1000 10 1000 10 0",
"output": "14"
},
{
"input": "25 3 50 4 2",
"output": "4"
},
{
"input": "9 10 10 10 9",
"output": "1"
},
{
"input": "17 10 12 6 5",
"output": "2"
},
{
"input": "15 5 10 3 0",
"output": "3"
},
{
"input": "8 3 5 1 0",
"output": "3"
},
{
"input": "19 1 12 5 0",
"output": "4"
},
{
"input": "1000 10 1000 1 0",
"output": "37"
},
{
"input": "100 1 2 1000 0",
"output": "51"
},
{
"input": "20 10 11 1000 9",
"output": "6"
},
{
"input": "16 2 100 1 1",
"output": "5"
},
{
"input": "18 10 13 2 5",
"output": "3"
},
{
"input": "12 3 5 3 1",
"output": "4"
},
{
"input": "17 3 11 2 0",
"output": "4"
},
{
"input": "4 2 100 1 1",
"output": "2"
},
{
"input": "7 4 5 2 3",
"output": "3"
},
{
"input": "100 1 2 2 0",
"output": "51"
},
{
"input": "50 4 5 5 0",
"output": "11"
},
{
"input": "1 2 2 0 1",
"output": "1"
},
{
"input": "1000 2 3 10 1",
"output": "500"
},
{
"input": "500 10 500 1000 0",
"output": "2"
},
{
"input": "1000 4 12 1 0",
"output": "87"
},
{
"input": "18 10 13 1 5",
"output": "3"
},
{
"input": "7 3 6 2 2",
"output": "3"
},
{
"input": "15 5 100 1 2",
"output": "4"
},
{
"input": "100 1 10 1 0",
"output": "15"
},
{
"input": "8 2 7 5 1",
"output": "2"
},
{
"input": "11 2 4 1 1",
"output": "5"
},
{
"input": "1000 500 900 100 300",
"output": "3"
},
{
"input": "7 1 2 5 0",
"output": "4"
},
{
"input": "7 3 5 3 2",
"output": "3"
},
{
"input": "7 3 10 2 1",
"output": "2"
},
{
"input": "1000 501 510 1 499",
"output": "50"
},
{
"input": "1000 1 1000 2 0",
"output": "32"
},
{
"input": "1 5 5 0 0",
"output": "1"
},
{
"input": "18 10 15 1 5",
"output": "3"
},
{
"input": "100 4 1000 1 2",
"output": "13"
},
{
"input": "20 2 40 1 1",
"output": "6"
},
{
"input": "1 11 1000 100 1",
"output": "1"
},
{
"input": "6 4 4 1 2",
"output": "2"
},
{
"input": "8 3 5 3 1",
"output": "3"
},
{
"input": "10 5 7 1 2",
"output": "3"
},
{
"input": "400 100 198 1 99",
"output": "25"
},
{
"input": "3 1 2 5 0",
"output": "2"
}
] | 1,695,713,631 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | c, vo, v1, a, l = map(int, input().split())
c -= vo
days = max(0, (c + l) // (v1 - l)) + 1
remaining_c = c - (days - 1) * (v1 - l)
if remaining_c > 0:
extra_days = (remaining_c + vo - 1) // vo
days += extra_days
print(days)
| Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day.
Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time.
Help Mister B to calculate how many days he needed to finish the book.
Input Specification:
First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.
Output Specification:
Print one integer — the number of days Mister B needed to finish the book.
Demo Input:
['5 5 10 5 4\n', '12 4 12 4 1\n', '15 1 100 0 0\n']
Demo Output:
['1\n', '3\n', '15\n']
Note:
In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished in 15 days. | ```python
c, vo, v1, a, l = map(int, input().split())
c -= vo
days = max(0, (c + l) // (v1 - l)) + 1
remaining_c = c - (days - 1) * (v1 - l)
if remaining_c > 0:
extra_days = (remaining_c + vo - 1) // vo
days += extra_days
print(days)
``` | 0 |
|
919 | F | A Game With Numbers | PROGRAMMING | 2,600 | [
"games",
"graphs",
"shortest paths"
] | null | null | Imagine that Alice is playing a card game with her friend Bob. They both have exactly $8$ cards and there is an integer on each card, ranging from $0$ to $4$. In each round, Alice or Bob in turns choose two cards from different players, let them be $a$ and $b$, where $a$ is the number on the player's card, and $b$ is the number on the opponent's card. It is necessary that $a \cdot b \ne 0$. Then they calculate $c = (a + b) \bmod 5$ and replace the number $a$ with $c$. The player who ends up with numbers on all $8$ cards being $0$, wins.
Now Alice wants to know who wins in some situations. She will give you her cards' numbers, Bob's cards' numbers and the person playing the first round. Your task is to determine who wins if both of them choose the best operation in their rounds. | The first line contains one positive integer $T$ ($1 \leq T \leq 100\,000$), denoting the number of situations you need to consider.
The following lines describe those $T$ situations. For each situation:
- The first line contains a non-negative integer $f$ ($0 \leq f \leq 1$), where $f = 0$ means that Alice plays first and $f = 1$ means Bob plays first. - The second line contains $8$ non-negative integers $a_1, a_2, \ldots, a_8$ ($0 \leq a_i \leq 4$), describing Alice's cards. - The third line contains $8$ non-negative integers $b_1, b_2, \ldots, b_8$ ($0 \leq b_i \leq 4$), describing Bob's cards.
We guarantee that if $f=0$, we have $\sum_{i=1}^{8}a_i \ne 0$. Also when $f=1$, $\sum_{i=1}^{8}b_i \ne 0$ holds. | Output $T$ lines. For each situation, determine who wins. Output
- "Alice" (without quotes) if Alice wins. - "Bob" (without quotes) if Bob wins. - "Deal" (without quotes) if it gets into a deal, i.e. no one wins. | [
"4\n1\n0 0 0 0 0 0 0 0\n1 2 3 4 1 2 3 4\n1\n0 0 0 1 0 0 0 0\n0 0 0 0 4 0 0 0\n0\n1 0 0 0 0 0 0 0\n0 0 0 4 0 0 2 0\n1\n1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1\n"
] | [
"Alice\nBob\nAlice\nDeal\n"
] | In the first situation, Alice has all her numbers $0$. So she wins immediately.
In the second situation, Bob picks the numbers $4$ and $1$. Because we have $(4 + 1) \bmod 5 = 0$, Bob wins after this operation.
In the third situation, Alice picks the numbers $1$ and $4$. She wins after this operation.
In the fourth situation, we can prove that it falls into a loop. | 2,500 | [
{
"input": "4\n1\n0 0 0 0 0 0 0 0\n1 2 3 4 1 2 3 4\n1\n0 0 0 1 0 0 0 0\n0 0 0 0 4 0 0 0\n0\n1 0 0 0 0 0 0 0\n0 0 0 4 0 0 2 0\n1\n1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1",
"output": "Alice\nBob\nAlice\nDeal"
},
{
"input": "1\n0\n0 2 2 0 1 2 1 2\n1 2 4 3 2 1 1 0",
"output": "Alice"
}
] | 1,631,749,582 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 3,649 | 34,918,400 | # My Solution for CF 919/F.
import sys
import itertools
from collections import deque
t = int(input())
hand_size = 8
num_values = 5
res = 1
for x in range(hand_size + 1, hand_size + num_values):
res *= x
for x in range(1, num_values):
res //= x
# res = (handsize + numvalues - 1) choose (handsize)
counts = [0] * res * 5
# Precompute the possible winning/losing locations.
# First, generate the possible hand values, and turn them into integers.
m = {}
for i, v in enumerate(itertools.combinations(range(hand_size + num_values - 1), num_values - 1)):
prev = -1
ind = 0
for x in v:
counts[i * 5 + ind] = x - prev - 1
prev = x
ind += 1
counts[i * 5 + ind] = hand_size + num_values - prev - 2
m[tuple(counts[i*5:i*5+5])] = i
# 0 = DEAL
# 1 = WIN
# -1 = LOSE
CURRENT_STATUS = [0] * (res * res)
DEG = [0] * (res * res)
# Now, any vertex is just two numbers, ranging from 0 to res-1.
# We assume for a particular node that it is my turn.
# Then in the recursion we simply invert at each opportunity.
decided_queue = deque()
win_index = m[(hand_size, 0, 0, 0, 0)]
for i in range(res):
if i != win_index:
decided_queue.append(win_index * res + i)
CURRENT_STATUS[win_index * res + i] = 1
decided_queue.append(i * res + win_index)
CURRENT_STATUS[i * res + win_index] = -1
for i in range(res * res):
id1 = i // res
id2 = i % res
# What choices can I make as id1?
n_options_l = 0
for x in range(1, 5):
if counts[id1 * 5 + x] > 0:
n_options_l += 1
n_options_r = 0
for x in range(1, 5):
if counts[id2 * 5 + x] > 0:
n_options_r += 1
DEG[i] = n_options_l * n_options_r
p = [False] * (res * res)
parent = [-1] * (res * res)
while len(decided_queue) > 0:
index = decided_queue.pop()
if p[index]:
raise ValueError("Cycle bad.")
p[index] = True
# Check all possible inroads to this state.
# Which of the cards could've p2 just made?
id1 = index // res
id2 = index % res
for x in range(5):
if counts[id2 * 5 + x] > 0:
# We could've made this card.
# But what would the card have been / what of my cards should they have picked?
for y in range(1, 5):
if counts[id1 * 5 + y] > 0:
# They could've picked this card.
# x = y + z mod 5. So z = x - y mod 5.
z = (x - y) % 5
if z == 0:
continue
n_count = [counts[id2 * 5 + i] for i in range(5)]
n_count[x] -= 1
n_count[z] += 1
old_id2 = m[tuple(n_count)]
# Remember to flip
old_index = old_id2 * res + id1
if CURRENT_STATUS[old_index] == 0:
DEG[old_index] -= 1
if CURRENT_STATUS[index] == -1:
# If the other player is winning here, they can move here to win.
CURRENT_STATUS[old_index] = 1
decided_queue.append(old_index)
parent[old_index] = index
else:
if DEG[old_index] == 0:
# We've tried every edge and all of them are winning for me, so losing for the person above.
CURRENT_STATUS[old_index] = -1
decided_queue.append(old_index)
parent[old_index] = index
for case in range(t):
f = int(input())
alice_hand = tuple(map(int, input().split()))
c = [0] * num_values
for h in alice_hand:
c[h] += 1
alice = m[tuple(c)]
bob_hand = tuple(map(int, input().split()))
c = [0] * num_values
for h in bob_hand:
c[h] += 1
bob = m[tuple(c)]
if f == 0:
index = alice * res + bob
if CURRENT_STATUS[index] == 0:
print("Deal")
elif CURRENT_STATUS[index] == 1:
print("Alice")
else:
print("Bob")
else:
index = bob * res + alice
if CURRENT_STATUS[index] == 0:
print("Deal")
elif CURRENT_STATUS[index] == 1:
print("Bob")
else:
print("Alice")
| Title: A Game With Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that Alice is playing a card game with her friend Bob. They both have exactly $8$ cards and there is an integer on each card, ranging from $0$ to $4$. In each round, Alice or Bob in turns choose two cards from different players, let them be $a$ and $b$, where $a$ is the number on the player's card, and $b$ is the number on the opponent's card. It is necessary that $a \cdot b \ne 0$. Then they calculate $c = (a + b) \bmod 5$ and replace the number $a$ with $c$. The player who ends up with numbers on all $8$ cards being $0$, wins.
Now Alice wants to know who wins in some situations. She will give you her cards' numbers, Bob's cards' numbers and the person playing the first round. Your task is to determine who wins if both of them choose the best operation in their rounds.
Input Specification:
The first line contains one positive integer $T$ ($1 \leq T \leq 100\,000$), denoting the number of situations you need to consider.
The following lines describe those $T$ situations. For each situation:
- The first line contains a non-negative integer $f$ ($0 \leq f \leq 1$), where $f = 0$ means that Alice plays first and $f = 1$ means Bob plays first. - The second line contains $8$ non-negative integers $a_1, a_2, \ldots, a_8$ ($0 \leq a_i \leq 4$), describing Alice's cards. - The third line contains $8$ non-negative integers $b_1, b_2, \ldots, b_8$ ($0 \leq b_i \leq 4$), describing Bob's cards.
We guarantee that if $f=0$, we have $\sum_{i=1}^{8}a_i \ne 0$. Also when $f=1$, $\sum_{i=1}^{8}b_i \ne 0$ holds.
Output Specification:
Output $T$ lines. For each situation, determine who wins. Output
- "Alice" (without quotes) if Alice wins. - "Bob" (without quotes) if Bob wins. - "Deal" (without quotes) if it gets into a deal, i.e. no one wins.
Demo Input:
['4\n1\n0 0 0 0 0 0 0 0\n1 2 3 4 1 2 3 4\n1\n0 0 0 1 0 0 0 0\n0 0 0 0 4 0 0 0\n0\n1 0 0 0 0 0 0 0\n0 0 0 4 0 0 2 0\n1\n1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1\n']
Demo Output:
['Alice\nBob\nAlice\nDeal\n']
Note:
In the first situation, Alice has all her numbers $0$. So she wins immediately.
In the second situation, Bob picks the numbers $4$ and $1$. Because we have $(4 + 1) \bmod 5 = 0$, Bob wins after this operation.
In the third situation, Alice picks the numbers $1$ and $4$. She wins after this operation.
In the fourth situation, we can prove that it falls into a loop. | ```python
# My Solution for CF 919/F.
import sys
import itertools
from collections import deque
t = int(input())
hand_size = 8
num_values = 5
res = 1
for x in range(hand_size + 1, hand_size + num_values):
res *= x
for x in range(1, num_values):
res //= x
# res = (handsize + numvalues - 1) choose (handsize)
counts = [0] * res * 5
# Precompute the possible winning/losing locations.
# First, generate the possible hand values, and turn them into integers.
m = {}
for i, v in enumerate(itertools.combinations(range(hand_size + num_values - 1), num_values - 1)):
prev = -1
ind = 0
for x in v:
counts[i * 5 + ind] = x - prev - 1
prev = x
ind += 1
counts[i * 5 + ind] = hand_size + num_values - prev - 2
m[tuple(counts[i*5:i*5+5])] = i
# 0 = DEAL
# 1 = WIN
# -1 = LOSE
CURRENT_STATUS = [0] * (res * res)
DEG = [0] * (res * res)
# Now, any vertex is just two numbers, ranging from 0 to res-1.
# We assume for a particular node that it is my turn.
# Then in the recursion we simply invert at each opportunity.
decided_queue = deque()
win_index = m[(hand_size, 0, 0, 0, 0)]
for i in range(res):
if i != win_index:
decided_queue.append(win_index * res + i)
CURRENT_STATUS[win_index * res + i] = 1
decided_queue.append(i * res + win_index)
CURRENT_STATUS[i * res + win_index] = -1
for i in range(res * res):
id1 = i // res
id2 = i % res
# What choices can I make as id1?
n_options_l = 0
for x in range(1, 5):
if counts[id1 * 5 + x] > 0:
n_options_l += 1
n_options_r = 0
for x in range(1, 5):
if counts[id2 * 5 + x] > 0:
n_options_r += 1
DEG[i] = n_options_l * n_options_r
p = [False] * (res * res)
parent = [-1] * (res * res)
while len(decided_queue) > 0:
index = decided_queue.pop()
if p[index]:
raise ValueError("Cycle bad.")
p[index] = True
# Check all possible inroads to this state.
# Which of the cards could've p2 just made?
id1 = index // res
id2 = index % res
for x in range(5):
if counts[id2 * 5 + x] > 0:
# We could've made this card.
# But what would the card have been / what of my cards should they have picked?
for y in range(1, 5):
if counts[id1 * 5 + y] > 0:
# They could've picked this card.
# x = y + z mod 5. So z = x - y mod 5.
z = (x - y) % 5
if z == 0:
continue
n_count = [counts[id2 * 5 + i] for i in range(5)]
n_count[x] -= 1
n_count[z] += 1
old_id2 = m[tuple(n_count)]
# Remember to flip
old_index = old_id2 * res + id1
if CURRENT_STATUS[old_index] == 0:
DEG[old_index] -= 1
if CURRENT_STATUS[index] == -1:
# If the other player is winning here, they can move here to win.
CURRENT_STATUS[old_index] = 1
decided_queue.append(old_index)
parent[old_index] = index
else:
if DEG[old_index] == 0:
# We've tried every edge and all of them are winning for me, so losing for the person above.
CURRENT_STATUS[old_index] = -1
decided_queue.append(old_index)
parent[old_index] = index
for case in range(t):
f = int(input())
alice_hand = tuple(map(int, input().split()))
c = [0] * num_values
for h in alice_hand:
c[h] += 1
alice = m[tuple(c)]
bob_hand = tuple(map(int, input().split()))
c = [0] * num_values
for h in bob_hand:
c[h] += 1
bob = m[tuple(c)]
if f == 0:
index = alice * res + bob
if CURRENT_STATUS[index] == 0:
print("Deal")
elif CURRENT_STATUS[index] == 1:
print("Alice")
else:
print("Bob")
else:
index = bob * res + alice
if CURRENT_STATUS[index] == 0:
print("Deal")
elif CURRENT_STATUS[index] == 1:
print("Bob")
else:
print("Alice")
``` | 3 |
|
573 | A | Bear and Poker | PROGRAMMING | 1,300 | [
"implementation",
"math",
"number theory"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 500 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,678,018,013 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | user_input = int(input())
user_value = list(map(int, input().split()))
for i in range(0,len(user_value)):
while user_value[i] % 2 == 0:
user_value[i] /= 2
while user_value[i] % 3 == 0:
user_value[i] /= 3
if i >0 and user_value[i] != user_value[i-1]:
print("no")
else:
print("Yes")
| Title: Bear and Poker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
user_input = int(input())
user_value = list(map(int, input().split()))
for i in range(0,len(user_value)):
while user_value[i] % 2 == 0:
user_value[i] /= 2
while user_value[i] % 3 == 0:
user_value[i] /= 3
if i >0 and user_value[i] != user_value[i-1]:
print("no")
else:
print("Yes")
``` | 0 |
|
6 | E | Exposition | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dsu",
"trees",
"two pointers"
] | E. Exposition | 1 | 64 | There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters.
The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. | The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters. | In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters.
In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. | [
"3 3\n14 12 10\n",
"2 0\n10 10\n",
"4 5\n8 19 10 13\n"
] | [
"2 2\n1 2\n2 3\n",
"2 1\n1 2\n",
"2 1\n3 4\n"
] | none | 0 | [
{
"input": "3 3\n14 12 10",
"output": "2 2\n1 2\n2 3"
},
{
"input": "2 0\n10 10",
"output": "2 1\n1 2"
},
{
"input": "4 5\n8 19 10 13",
"output": "2 1\n3 4"
},
{
"input": "1 1\n1",
"output": "1 1\n1 1"
},
{
"input": "2 10\n35 45",
"output": "2 1\n1 2"
},
{
"input": "4 8\n89 33 54 75",
"output": "1 4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "5 1\n9 6 8 7 5",
"output": "2 1\n3 4"
},
{
"input": "3 3\n3 8 6",
"output": "2 1\n2 3"
},
{
"input": "4 1000000\n100001 1 200001 300001",
"output": "4 1\n1 4"
},
{
"input": "4 1000\n11497 9999 10730 12280",
"output": "2 1\n2 3"
},
{
"input": "3 0\n1000000 1000000 1000000",
"output": "3 1\n1 3"
},
{
"input": "4 50\n165 182 157 132",
"output": "4 1\n1 4"
},
{
"input": "5 173\n350 250 200 300 400",
"output": "4 1\n1 4"
},
{
"input": "4 0\n1 1 1 1",
"output": "4 1\n1 4"
},
{
"input": "2 1000000\n1 1000000",
"output": "2 1\n1 2"
},
{
"input": "7 14\n28 28 29 35 25 29 28",
"output": "7 1\n1 7"
},
{
"input": "10 163\n7541 2535 5883 5775 2821 5962 4489 5548 2852 4595",
"output": "2 1\n3 4"
},
{
"input": "15 793\n98580 27440 3719 73977 34819 64092 89939 75329 72884 66502 17464 73662 6666 47984 45348",
"output": "1 15\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"
},
{
"input": "28 543\n1921 1700 1363 2580 2693 3144 2269 908 3863 3750 2151 3039 1581 3395 1133 1804 1464 2040 2372 2475 1240 800 3521 3270 2815 1026 3625 2930",
"output": "3 1\n18 20"
},
{
"input": "55 1000\n2612 1306 4300 1790 3173 9493 7209 7763 8563 4534 7466 1281 4483 6863 3787 7292 3957 8775 7221 4016 5743 6556 2070 2119 4795 9094 1913 2077 8786 4520 1865 2357 7871 3288 8231 5808 9383 9820 9974 3056 5343 2169 5177 6299 5805 8132 9315 6747 5226 3531 1206 4073 8290 1423 6720",
"output": "3 1\n37 39"
}
] | 1,459,789,005 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,017,600 | n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
from collections import deque
D = deque()
S = deque()
a = 0
b = 0
position = []
maximum = 1
minimum = 1000000
for i in range(n):
D.append(h[i])
if h[i] >= maximum:
maximum = h[i]
if maximum-minimum>k:
minimun = maximum
for j in range(len(D)):
if maximum-D[-1]>k:
break
else:
S.appendleft(D.pop())
if S[0]<minimum:
minimum = S[0]
D = S
S = deque()
if h[i] <= minimum:
minimum = h[i]
if maximum-minimum>k:
maximum = minimum
for j in range(len(D)):
if D[-1]-minimum>k:
break
else:
S.appendleft(D.pop())
if S[0]>maximum:
maximum = S[0]
D = S
S = deque()
print(D,maximum,minimum)
if a < len(D):
a = len(D)
b = 1
position = [[str(i+2-a),str(i+1)]]
elif a == len(D):
b += 1
position.append([str(i+2-a),str(i+1)])
print(a,b)
for i in range(b):
print(' '.join(position[i]))
| Title: Exposition
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters.
The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.
Input Specification:
The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters.
Output Specification:
In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters.
In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.
Demo Input:
['3 3\n14 12 10\n', '2 0\n10 10\n', '4 5\n8 19 10 13\n']
Demo Output:
['2 2\n1 2\n2 3\n', '2 1\n1 2\n', '2 1\n3 4\n']
Note:
none | ```python
n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
from collections import deque
D = deque()
S = deque()
a = 0
b = 0
position = []
maximum = 1
minimum = 1000000
for i in range(n):
D.append(h[i])
if h[i] >= maximum:
maximum = h[i]
if maximum-minimum>k:
minimun = maximum
for j in range(len(D)):
if maximum-D[-1]>k:
break
else:
S.appendleft(D.pop())
if S[0]<minimum:
minimum = S[0]
D = S
S = deque()
if h[i] <= minimum:
minimum = h[i]
if maximum-minimum>k:
maximum = minimum
for j in range(len(D)):
if D[-1]-minimum>k:
break
else:
S.appendleft(D.pop())
if S[0]>maximum:
maximum = S[0]
D = S
S = deque()
print(D,maximum,minimum)
if a < len(D):
a = len(D)
b = 1
position = [[str(i+2-a),str(i+1)]]
elif a == len(D):
b += 1
position.append([str(i+2-a),str(i+1)])
print(a,b)
for i in range(b):
print(' '.join(position[i]))
``` | 0 |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.
Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side. | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1.
If there are several possible answers, output any of them. | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
{
"input": "7",
"output": "7\n7 5 3 1 6 4 2 "
},
{
"input": "8",
"output": "8\n7 5 3 1 8 6 4 2 "
},
{
"input": "9",
"output": "9\n9 7 5 3 1 8 6 4 2 "
},
{
"input": "10",
"output": "10\n9 7 5 3 1 10 8 6 4 2 "
},
{
"input": "13",
"output": "13\n13 11 9 7 5 3 1 12 10 8 6 4 2 "
},
{
"input": "16",
"output": "16\n15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 "
},
{
"input": "25",
"output": "25\n25 23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "29",
"output": "29\n29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "120",
"output": "120\n119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "128",
"output": "128\n127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "216",
"output": "216\n215 213 211 209 207 205 203 201 199 197 195 193 191 189 187 185 183 181 179 177 175 173 171 169 167 165 163 161 159 157 155 153 151 149 147 145 143 141 139 137 135 133 131 129 127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 216 214 212 210 208 206 204 202 200 198 196 194 192 190 188 186 184 182 180 178 176 174 172 170 168 166 164 162 160 158 156 154 1..."
},
{
"input": "729",
"output": "729\n729 727 725 723 721 719 717 715 713 711 709 707 705 703 701 699 697 695 693 691 689 687 685 683 681 679 677 675 673 671 669 667 665 663 661 659 657 655 653 651 649 647 645 643 641 639 637 635 633 631 629 627 625 623 621 619 617 615 613 611 609 607 605 603 601 599 597 595 593 591 589 587 585 583 581 579 577 575 573 571 569 567 565 563 561 559 557 555 553 551 549 547 545 543 541 539 537 535 533 531 529 527 525 523 521 519 517 515 513 511 509 507 505 503 501 499 497 495 493 491 489 487 485 483 481 479 47..."
},
{
"input": "1111",
"output": "1111\n1111 1109 1107 1105 1103 1101 1099 1097 1095 1093 1091 1089 1087 1085 1083 1081 1079 1077 1075 1073 1071 1069 1067 1065 1063 1061 1059 1057 1055 1053 1051 1049 1047 1045 1043 1041 1039 1037 1035 1033 1031 1029 1027 1025 1023 1021 1019 1017 1015 1013 1011 1009 1007 1005 1003 1001 999 997 995 993 991 989 987 985 983 981 979 977 975 973 971 969 967 965 963 961 959 957 955 953 951 949 947 945 943 941 939 937 935 933 931 929 927 925 923 921 919 917 915 913 911 909 907 905 903 901 899 897 895 893 891 889 8..."
},
{
"input": "1597",
"output": "1597\n1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 1575 1573 1571 1569 1567 1565 1563 1561 1559 1557 1555 1553 1551 1549 1547 1545 1543 1541 1539 1537 1535 1533 1531 1529 1527 1525 1523 1521 1519 1517 1515 1513 1511 1509 1507 1505 1503 1501 1499 1497 1495 1493 1491 1489 1487 1485 1483 1481 1479 1477 1475 1473 1471 1469 1467 1465 1463 1461 1459 1457 1455 1453 1451 1449 1447 1445 1443 1441 1439 1437 1435 1433 1431 1429 1427 1425 1423 1421 1419 1417 1415 1413 1411 1409 1407 1405 1403 1401 1399 1397 ..."
},
{
"input": "1777",
"output": "1777\n1777 1775 1773 1771 1769 1767 1765 1763 1761 1759 1757 1755 1753 1751 1749 1747 1745 1743 1741 1739 1737 1735 1733 1731 1729 1727 1725 1723 1721 1719 1717 1715 1713 1711 1709 1707 1705 1703 1701 1699 1697 1695 1693 1691 1689 1687 1685 1683 1681 1679 1677 1675 1673 1671 1669 1667 1665 1663 1661 1659 1657 1655 1653 1651 1649 1647 1645 1643 1641 1639 1637 1635 1633 1631 1629 1627 1625 1623 1621 1619 1617 1615 1613 1611 1609 1607 1605 1603 1601 1599 1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 ..."
},
{
"input": "2048",
"output": "2048\n2047 2045 2043 2041 2039 2037 2035 2033 2031 2029 2027 2025 2023 2021 2019 2017 2015 2013 2011 2009 2007 2005 2003 2001 1999 1997 1995 1993 1991 1989 1987 1985 1983 1981 1979 1977 1975 1973 1971 1969 1967 1965 1963 1961 1959 1957 1955 1953 1951 1949 1947 1945 1943 1941 1939 1937 1935 1933 1931 1929 1927 1925 1923 1921 1919 1917 1915 1913 1911 1909 1907 1905 1903 1901 1899 1897 1895 1893 1891 1889 1887 1885 1883 1881 1879 1877 1875 1873 1871 1869 1867 1865 1863 1861 1859 1857 1855 1853 1851 1849 1847 ..."
},
{
"input": "2999",
"output": "2999\n2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 2799 ..."
},
{
"input": "3001",
"output": "3001\n3001 2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 ..."
},
{
"input": "4181",
"output": "4181\n4181 4179 4177 4175 4173 4171 4169 4167 4165 4163 4161 4159 4157 4155 4153 4151 4149 4147 4145 4143 4141 4139 4137 4135 4133 4131 4129 4127 4125 4123 4121 4119 4117 4115 4113 4111 4109 4107 4105 4103 4101 4099 4097 4095 4093 4091 4089 4087 4085 4083 4081 4079 4077 4075 4073 4071 4069 4067 4065 4063 4061 4059 4057 4055 4053 4051 4049 4047 4045 4043 4041 4039 4037 4035 4033 4031 4029 4027 4025 4023 4021 4019 4017 4015 4013 4011 4009 4007 4005 4003 4001 3999 3997 3995 3993 3991 3989 3987 3985 3983 3981 ..."
},
{
"input": "4990",
"output": "4990\n4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 4789 ..."
},
{
"input": "4991",
"output": "4991\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..."
},
{
"input": "4992",
"output": "4992\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..."
},
{
"input": "4993",
"output": "4993\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..."
},
{
"input": "4994",
"output": "4994\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..."
},
{
"input": "4995",
"output": "4995\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..."
},
{
"input": "4996",
"output": "4996\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..."
},
{
"input": "4997",
"output": "4997\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..."
},
{
"input": "4998",
"output": "4998\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..."
},
{
"input": "4999",
"output": "4999\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..."
},
{
"input": "5000",
"output": "5000\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..."
}
] | 1,477,562,599 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 921,600 | import functools
n=int(input())
if n==1 or n==2:
print(1)
print(1)
exit(0)
elif n==3:
print(2)
print(1,3)
exit(0)
odds=list(filter(lambda x:True if x%2==1 else False, range(1,n+1)))
evens=list(filter(lambda x:True if x%2==0 else False, range(1,n+1)))
odds.reverse()
evens.reverse()
od=' '.join(map(str,odds))
ev=' '.join(map(str,evens))
print(n)
print(od+" "+ev) | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.
Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam.
Output Specification:
In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=≠<=1 for all *i* from 1 to *k*<=-<=1.
If there are several possible answers, output any of them.
Demo Input:
['6', '3\n']
Demo Output:
['6\n1 5 3 6 2 4', '2\n1 3']
Note:
none | ```python
import functools
n=int(input())
if n==1 or n==2:
print(1)
print(1)
exit(0)
elif n==3:
print(2)
print(1,3)
exit(0)
odds=list(filter(lambda x:True if x%2==1 else False, range(1,n+1)))
evens=list(filter(lambda x:True if x%2==0 else False, range(1,n+1)))
odds.reverse()
evens.reverse()
od=' '.join(map(str,odds))
ev=' '.join(map(str,evens))
print(n)
print(od+" "+ev)
``` | 3 |
|
39 | D | Cubical Planet | PROGRAMMING | 1,100 | [
"math"
] | D. Cubical Planet | 2 | 64 | You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube. | The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. | Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". | [
"0 0 0\n0 1 0\n",
"1 1 0\n0 1 0\n",
"0 0 0\n1 1 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "0 0 0\n1 0 0",
"output": "YES"
},
{
"input": "0 0 0\n0 1 0",
"output": "YES"
},
{
"input": "0 0 0\n1 1 0",
"output": "YES"
},
{
"input": "0 0 0\n0 0 1",
"output": "YES"
},
{
"input": "0 0 0\n1 0 1",
"output": "YES"
},
{
"input": "0 0 0\n0 1 1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1",
"output": "NO"
},
{
"input": "1 0 0\n0 0 0",
"output": "YES"
},
{
"input": "1 0 0\n0 1 0",
"output": "YES"
},
{
"input": "1 0 0\n1 1 0",
"output": "YES"
},
{
"input": "1 0 0\n0 0 1",
"output": "YES"
},
{
"input": "1 0 0\n1 0 1",
"output": "YES"
},
{
"input": "1 0 0\n0 1 1",
"output": "NO"
},
{
"input": "1 0 0\n1 1 1",
"output": "YES"
},
{
"input": "0 1 0\n0 0 0",
"output": "YES"
},
{
"input": "0 1 0\n1 0 0",
"output": "YES"
},
{
"input": "0 1 0\n1 1 0",
"output": "YES"
},
{
"input": "0 1 0\n0 0 1",
"output": "YES"
},
{
"input": "0 1 0\n1 0 1",
"output": "NO"
},
{
"input": "0 1 0\n0 1 1",
"output": "YES"
},
{
"input": "0 1 0\n1 1 1",
"output": "YES"
},
{
"input": "1 1 0\n0 0 0",
"output": "YES"
},
{
"input": "1 1 0\n1 0 0",
"output": "YES"
},
{
"input": "1 1 0\n0 1 0",
"output": "YES"
},
{
"input": "1 1 0\n0 0 1",
"output": "NO"
},
{
"input": "1 1 0\n1 0 1",
"output": "YES"
},
{
"input": "1 1 0\n0 1 1",
"output": "YES"
},
{
"input": "1 1 0\n1 1 1",
"output": "YES"
},
{
"input": "0 0 1\n0 0 0",
"output": "YES"
},
{
"input": "0 0 1\n1 0 0",
"output": "YES"
},
{
"input": "0 0 1\n0 1 0",
"output": "YES"
},
{
"input": "0 0 1\n1 1 0",
"output": "NO"
},
{
"input": "0 0 1\n1 0 1",
"output": "YES"
},
{
"input": "0 0 1\n0 1 1",
"output": "YES"
},
{
"input": "0 0 1\n1 1 1",
"output": "YES"
},
{
"input": "1 0 1\n0 0 0",
"output": "YES"
},
{
"input": "1 0 1\n1 0 0",
"output": "YES"
},
{
"input": "1 0 1\n0 1 0",
"output": "NO"
},
{
"input": "1 0 1\n1 1 0",
"output": "YES"
},
{
"input": "1 0 1\n0 0 1",
"output": "YES"
},
{
"input": "1 0 1\n0 1 1",
"output": "YES"
},
{
"input": "1 0 1\n1 1 1",
"output": "YES"
},
{
"input": "0 1 1\n0 0 0",
"output": "YES"
},
{
"input": "0 1 1\n1 0 0",
"output": "NO"
},
{
"input": "0 1 1\n0 1 0",
"output": "YES"
},
{
"input": "0 1 1\n1 1 0",
"output": "YES"
},
{
"input": "0 1 1\n0 0 1",
"output": "YES"
},
{
"input": "0 1 1\n1 0 1",
"output": "YES"
},
{
"input": "0 1 1\n1 1 1",
"output": "YES"
},
{
"input": "1 1 1\n0 0 0",
"output": "NO"
},
{
"input": "1 1 1\n1 0 0",
"output": "YES"
},
{
"input": "1 1 1\n0 1 0",
"output": "YES"
},
{
"input": "1 1 1\n1 1 0",
"output": "YES"
},
{
"input": "1 1 1\n0 0 1",
"output": "YES"
},
{
"input": "1 1 1\n1 0 1",
"output": "YES"
},
{
"input": "1 1 1\n0 1 1",
"output": "YES"
}
] | 1,523,603,745 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 186 | 7,372,800 | # from dust i have come dust i will be
'''
if the coordinates lie in the same plane then yes
'''
a,b,c=map(int,input().split())
x,y,z=map(int,input().split())
x=a-x
y=b-y
z=c-z
dist=x**2+y**2+z**2
if dist==3:
print('NO')
else:
print('YES') | Title: Cubical Planet
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.
Input Specification:
The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.
Output Specification:
Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".
Demo Input:
['0 0 0\n0 1 0\n', '1 1 0\n0 1 0\n', '0 0 0\n1 1 1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
# from dust i have come dust i will be
'''
if the coordinates lie in the same plane then yes
'''
a,b,c=map(int,input().split())
x,y,z=map(int,input().split())
x=a-x
y=b-y
z=c-z
dist=x**2+y**2+z**2
if dist==3:
print('NO')
else:
print('YES')
``` | 3.898568 |