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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,634,155,577 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | a, b, c=map(int,input().split())
d, e, f=map(int,input().split())
g, h, i=map(int,input().split())
A,B,C=1, 1, 1
D,E,F=1,1,1
G,H,I=1, 1, 1
if a+b+d==0:
A=1
elif (a+b+d)%2!=0:
A=0
else:
A=1
if a+b+c+e==0:
B=1
elif (a+b+c+e)%2!=0:
B=0
else:
B=1
if b+c+f==0:
C=1
elif (b+c+f)%2!=0:
C=0
else:
C=1
if a+d+e+g==0:
D=1
elif (a+d+e+g)%2!=0:
D=0
else:
D=1
if b+d+e+f+h==0:
E=1
elif (b+d+e+f+h)%2!=0:
E=0
else:
E=1
if c+e+f+i==0:
F=1
elif (c+e+f+i)%2!=0:
F=0
else:
F=1
if d+g+h==0:
G=1
elif (d+g+h)%2!=0:
G=0
else:
G=1
if e+g+h+i==0:
H=1
elif (e+g+h+i)%2!=0:
H=0
else:
H=1
if f+h+i==0:
I=1
elif (f+h+i)%2!=0:
I=0
else:
I=1
print(str(A)+str(B)+str(C))
print(str(D)+str(E)+str(F))
print(str(G)+str(H)+str(I)) | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
a, b, c=map(int,input().split())
d, e, f=map(int,input().split())
g, h, i=map(int,input().split())
A,B,C=1, 1, 1
D,E,F=1,1,1
G,H,I=1, 1, 1
if a+b+d==0:
A=1
elif (a+b+d)%2!=0:
A=0
else:
A=1
if a+b+c+e==0:
B=1
elif (a+b+c+e)%2!=0:
B=0
else:
B=1
if b+c+f==0:
C=1
elif (b+c+f)%2!=0:
C=0
else:
C=1
if a+d+e+g==0:
D=1
elif (a+d+e+g)%2!=0:
D=0
else:
D=1
if b+d+e+f+h==0:
E=1
elif (b+d+e+f+h)%2!=0:
E=0
else:
E=1
if c+e+f+i==0:
F=1
elif (c+e+f+i)%2!=0:
F=0
else:
F=1
if d+g+h==0:
G=1
elif (d+g+h)%2!=0:
G=0
else:
G=1
if e+g+h+i==0:
H=1
elif (e+g+h+i)%2!=0:
H=0
else:
H=1
if f+h+i==0:
I=1
elif (f+h+i)%2!=0:
I=0
else:
I=1
print(str(A)+str(B)+str(C))
print(str(D)+str(E)+str(F))
print(str(G)+str(H)+str(I))
``` | 3 |
|
125 | A | Measuring Lengths in Baden | PROGRAMMING | 1,400 | [
"math"
] | null | null | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.
Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch. | The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000). | Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches. | [
"42\n",
"5\n"
] | [
"1 2\n",
"0 2\n"
] | none | 1,000 | [
{
"input": "42",
"output": "1 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "24",
"output": "0 8"
},
{
"input": "1",
"output": "0 0"
},
{
"input": "2",
"output": "0 1"
},
{
"input": "3",
"output": "0 1"
},
{
"input": "4",
"output": "0 1"
},
{
"input": "8",
"output": "0 3"
},
{
"input": "10",
"output": "0 3"
},
{
"input": "12",
"output": "0 4"
},
{
"input": "13",
"output": "0 4"
},
{
"input": "100",
"output": "2 9"
},
{
"input": "120",
"output": "3 4"
},
{
"input": "199",
"output": "5 6"
},
{
"input": "501",
"output": "13 11"
},
{
"input": "1000",
"output": "27 9"
},
{
"input": "1233",
"output": "34 3"
},
{
"input": "9876",
"output": "274 4"
},
{
"input": "9999",
"output": "277 9"
},
{
"input": "10000",
"output": "277 9"
},
{
"input": "35",
"output": "1 0"
},
{
"input": "71",
"output": "2 0"
}
] | 1,549,653,969 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | from math import ceil
n = int(input())
print(str(n//36)+' '+str(ceil((n%36)/3))) | Title: Measuring Lengths in Baden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches.
Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=10000).
Output Specification:
Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches.
Demo Input:
['42\n', '5\n']
Demo Output:
['1 2\n', '0 2\n']
Note:
none | ```python
from math import ceil
n = int(input())
print(str(n//36)+' '+str(ceil((n%36)/3)))
``` | 0 |
|
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "YES"
},
{
"input": "qxolmbkkt\naovlajmlf",
"output": "NO"
},
{
"input": "b\ng",
"output": "NO"
},
{
"input": "ab\naba",
"output": "NO"
},
{
"input": "ba\na",
"output": "NO"
},
{
"input": "a\nab",
"output": "NO"
},
{
"input": "a\naa",
"output": "NO"
},
{
"input": "a\nz",
"output": "NO"
},
{
"input": "aabb\nbbaa",
"output": "NO"
},
{
"input": "ab\nbd",
"output": "NO"
},
{
"input": "bac\ndae",
"output": "NO"
},
{
"input": "abc\nakl",
"output": "NO"
},
{
"input": "cb\naa",
"output": "NO"
},
{
"input": "abaab\naabba",
"output": "NO"
},
{
"input": "aab\naaa",
"output": "NO"
},
{
"input": "abcde\nedcba",
"output": "NO"
},
{
"input": "abab\nbaba",
"output": "NO"
},
{
"input": "ab\nbac",
"output": "NO"
},
{
"input": "abcd\naqcb",
"output": "NO"
},
{
"input": "abc\nbad",
"output": "NO"
},
{
"input": "ab\nca",
"output": "NO"
},
{
"input": "abc\nab",
"output": "NO"
},
{
"input": "ab\nbae",
"output": "NO"
},
{
"input": "aaaabcccca\naaaadccccb",
"output": "NO"
},
{
"input": "acaa\nabca",
"output": "NO"
},
{
"input": "aba\naab",
"output": "YES"
},
{
"input": "ah\nla",
"output": "NO"
},
{
"input": "aab\naa",
"output": "NO"
},
{
"input": "abab\nabcd",
"output": "NO"
},
{
"input": "ed\nab",
"output": "NO"
}
] | 1,633,450,779 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 248 | 24,371,200 | s1=str(input())
s2=str(input())
l_1=[]
l_2=[]
l_1[:0]=s1
l_2[:0]=s2
p_1=sorted(l_1)
p_2=sorted(l_2)
if(len(l_1)!=len(l_2)):
print("NO")
else:
flag=False
for i in range (0,len(l_1)):
if(p_1[i]!=p_2[i]):
print("NO")
flag=True
break
if(flag==False):
for i in range(0, len(l_1)):
if (l_1[i] != l_2[i]):
p = l_1[i]
q = l_2.index(p)
if l_1[q] == l_2[i]:
l_2[i] = p
l_2[q] = l_1[q]
break
else:
print("NO")
flag=True
break
if (flag==False):
for i in range(0, len(l_1)):
if (l_1[i] != l_2[i]):
print("NO")
flag = True
break
if(flag==False):
print("YES")
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
Input Specification:
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Output Specification:
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
Demo Input:
['ab\nba\n', 'aa\nab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | ```python
s1=str(input())
s2=str(input())
l_1=[]
l_2=[]
l_1[:0]=s1
l_2[:0]=s2
p_1=sorted(l_1)
p_2=sorted(l_2)
if(len(l_1)!=len(l_2)):
print("NO")
else:
flag=False
for i in range (0,len(l_1)):
if(p_1[i]!=p_2[i]):
print("NO")
flag=True
break
if(flag==False):
for i in range(0, len(l_1)):
if (l_1[i] != l_2[i]):
p = l_1[i]
q = l_2.index(p)
if l_1[q] == l_2[i]:
l_2[i] = p
l_2[q] = l_1[q]
break
else:
print("NO")
flag=True
break
if (flag==False):
for i in range(0, len(l_1)):
if (l_1[i] != l_2[i]):
print("NO")
flag = True
break
if(flag==False):
print("YES")
``` | 0 |
|
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors. | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors. | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,609,230,572 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 15,052,800 |
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
#for tt in range(INT()):
def Binary_Search(arr , n , x):
l , r = 0 , n-1
while l <= r :
mid = l + (r - l )//2
if arr[mid] == x :
return mid+1
elif arr[mid] > x :
r = mid - 1
else:
l = mid + 1
return r + 1
n , q = MAP()
a = LIST()
b = LIST()
ps = [0]*n
ps[0] = a[0]
for i in range(1 , n ):
ps[i] = ps[i-1] + a[i]
sm = 0
for i in range(q):
sm += b[i]
if sm >= ps[-1]:
print(n)
sm = 0
else:
z = (Binary_Search(ps , n , sm))
print(n - z)
| Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | ```python
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
#for tt in range(INT()):
def Binary_Search(arr , n , x):
l , r = 0 , n-1
while l <= r :
mid = l + (r - l )//2
if arr[mid] == x :
return mid+1
elif arr[mid] > x :
r = mid - 1
else:
l = mid + 1
return r + 1
n , q = MAP()
a = LIST()
b = LIST()
ps = [0]*n
ps[0] = a[0]
for i in range(1 , n ):
ps[i] = ps[i-1] + a[i]
sm = 0
for i in range(q):
sm += b[i]
if sm >= ps[-1]:
print(n)
sm = 0
else:
z = (Binary_Search(ps , n , sm))
print(n - z)
``` | 0 |
|
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
},
{
"input": "9",
"output": "12870"
},
{
"input": "10",
"output": "48620"
},
{
"input": "8",
"output": "3432"
}
] | 1,634,078,323 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 61 | 0 | n=int(input())
a=[1,1,1,1,1,1,1,1,1,1,1]
for _ in range(1,n):
for i in range(1,n):
a[i]=a[i]+a[i-1]
print(max(a)) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
n=int(input())
a=[1,1,1,1,1,1,1,1,1,1,1]
for _ in range(1,n):
for i in range(1,n):
a[i]=a[i]+a[i-1]
print(max(a))
``` | 3 |
|
687 | B | Remainders Game | PROGRAMMING | 1,800 | [
"chinese remainder theorem",
"math",
"number theory"
] | null | null | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000). | Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise. | [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | 1,000 | [
{
"input": "4 5\n2 3 5 12",
"output": "Yes"
},
{
"input": "2 7\n2 3",
"output": "No"
},
{
"input": "1 6\n8",
"output": "No"
},
{
"input": "2 3\n9 4",
"output": "Yes"
},
{
"input": "4 16\n19 16 13 9",
"output": "Yes"
},
{
"input": "5 10\n5 16 19 9 17",
"output": "Yes"
},
{
"input": "11 95\n31 49 8 139 169 121 71 17 43 29 125",
"output": "No"
},
{
"input": "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17",
"output": "No"
},
{
"input": "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71",
"output": "No"
},
{
"input": "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71",
"output": "Yes"
},
{
"input": "2 4\n2 2",
"output": "No"
},
{
"input": "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619",
"output": "No"
},
{
"input": "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766",
"output": "No"
},
{
"input": "1 994619\n216000",
"output": "No"
},
{
"input": "1 651040\n911250",
"output": "No"
},
{
"input": "1 620622\n60060",
"output": "No"
},
{
"input": "1 1\n559872",
"output": "Yes"
},
{
"input": "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967",
"output": "No"
},
{
"input": "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426",
"output": "No"
},
{
"input": "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630",
"output": "No"
},
{
"input": "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043",
"output": "No"
},
{
"input": "1 216000\n648000",
"output": "Yes"
},
{
"input": "2 8\n4 4",
"output": "No"
},
{
"input": "3 8\n4 4 4",
"output": "No"
},
{
"input": "2 8\n2 4",
"output": "No"
},
{
"input": "3 12\n2 2 3",
"output": "No"
},
{
"input": "10 4\n2 2 2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "10 1024\n1 2 4 8 16 32 64 128 256 512",
"output": "No"
},
{
"input": "3 24\n2 2 3",
"output": "No"
},
{
"input": "1 8\n2",
"output": "No"
},
{
"input": "2 9\n3 3",
"output": "No"
},
{
"input": "3 4\n2 2 2",
"output": "No"
},
{
"input": "3 4\n1 2 2",
"output": "No"
},
{
"input": "1 4\n2",
"output": "No"
},
{
"input": "1 100003\n2",
"output": "No"
},
{
"input": "1 2\n12",
"output": "Yes"
},
{
"input": "2 988027\n989018 995006",
"output": "Yes"
},
{
"input": "3 9\n3 3 3",
"output": "No"
},
{
"input": "1 49\n7",
"output": "No"
},
{
"input": "2 600000\n200000 300000",
"output": "Yes"
},
{
"input": "3 8\n2 2 2",
"output": "No"
},
{
"input": "7 510510\n524288 531441 390625 823543 161051 371293 83521",
"output": "Yes"
},
{
"input": "2 30\n6 10",
"output": "Yes"
},
{
"input": "2 27000\n5400 4500",
"output": "Yes"
},
{
"input": "3 8\n1 2 4",
"output": "No"
},
{
"input": "4 16\n2 2 2 2",
"output": "No"
},
{
"input": "2 16\n4 8",
"output": "No"
},
{
"input": "2 8\n4 2",
"output": "No"
},
{
"input": "3 4\n2 2 3",
"output": "No"
},
{
"input": "1 8\n4",
"output": "No"
},
{
"input": "1 999983\n2",
"output": "No"
},
{
"input": "3 16\n2 4 8",
"output": "No"
},
{
"input": "2 216\n12 18",
"output": "No"
},
{
"input": "2 16\n8 8",
"output": "No"
},
{
"input": "2 36\n18 12",
"output": "Yes"
},
{
"input": "2 36\n12 18",
"output": "Yes"
},
{
"input": "2 1000000\n1000000 1000000",
"output": "Yes"
},
{
"input": "3 20\n2 2 5",
"output": "No"
},
{
"input": "1 2\n6",
"output": "Yes"
},
{
"input": "4 4\n2 3 6 5",
"output": "No"
},
{
"input": "1 2\n1",
"output": "No"
},
{
"input": "1 6\n6",
"output": "Yes"
},
{
"input": "2 16\n4 4",
"output": "No"
},
{
"input": "2 3779\n1 2",
"output": "No"
},
{
"input": "2 8\n4 12",
"output": "No"
},
{
"input": "2 24\n4 6",
"output": "No"
},
{
"input": "1 1\n5",
"output": "Yes"
},
{
"input": "10 255255\n1000000 700000 300000 110000 130000 170000 190000 230000 290000 310000",
"output": "Yes"
},
{
"input": "2 1000\n500 2",
"output": "No"
},
{
"input": "4 8\n2 2 2 2",
"output": "No"
},
{
"input": "1 666013\n1",
"output": "No"
},
{
"input": "1 999983\n1",
"output": "No"
},
{
"input": "1 125\n5",
"output": "No"
},
{
"input": "2 32\n4 8",
"output": "No"
},
{
"input": "3 32\n2 4 8",
"output": "No"
},
{
"input": "3 8\n2 4 11",
"output": "No"
},
{
"input": "1 32\n2",
"output": "No"
},
{
"input": "4 4\n2 2 2 2",
"output": "No"
},
{
"input": "8 32\n2 2 2 2 2 2 2 2",
"output": "No"
},
{
"input": "3 24\n2 4 3",
"output": "No"
},
{
"input": "2 4\n2 6",
"output": "No"
},
{
"input": "2 24\n6 4",
"output": "No"
},
{
"input": "1 20998\n2",
"output": "No"
},
{
"input": "1 1\n1",
"output": "Yes"
},
{
"input": "2 20998\n2 10499",
"output": "Yes"
},
{
"input": "1 5\n1",
"output": "No"
},
{
"input": "2 25\n5 5",
"output": "No"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "Yes"
},
{
"input": "3 12\n2 3 6",
"output": "No"
},
{
"input": "1 1\n3",
"output": "Yes"
},
{
"input": "2 16\n8 4",
"output": "No"
},
{
"input": "40 10\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "No"
}
] | 1,578,304,435 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 0 | def gcd(a, b):
if(a < b):
a, b = b, a
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return (a // gcd(a, b)) * b;
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 1
for x in a:
c = lcm(x, c)
if(gcd(k, c) == 1):
print("No")
else:
print("Yes")
| Title: Remainders Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer *x* and *k*, and tells Arya *k* but not *x*. Arya have to find the value . There are *n* ancient numbers *c*1,<=*c*2,<=...,<=*c**n* and Pari has to tell Arya if Arya wants. Given *k* and the ancient values, tell us if Arya has a winning strategy independent of value of *x* or not. Formally, is it true that Arya can understand the value for any positive integer *x*?
Note, that means the remainder of *x* after dividing it by *y*.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<= *k*<=≤<=1<=000<=000) — the number of ancient integers and value *k* that is chosen by Pari.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=1<=000<=000).
Output Specification:
Print "Yes" (without quotes) if Arya has a winning strategy independent of value of *x*, or "No" (without quotes) otherwise.
Demo Input:
['4 5\n2 3 5 12\n', '2 7\n2 3\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample, Arya can understand <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d170efffcde0907ee6bcf32de21051bce0677a2c.png" style="max-width: 100.0%;max-height: 100.0%;"/> because 5 is one of the ancient numbers.
In the second sample, Arya can't be sure what <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/57b5f6a96f5db073270dd3ed4266c69299ec701d.png" style="max-width: 100.0%;max-height: 100.0%;"/> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7. | ```python
def gcd(a, b):
if(a < b):
a, b = b, a
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return (a // gcd(a, b)) * b;
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 1
for x in a:
c = lcm(x, c)
if(gcd(k, c) == 1):
print("No")
else:
print("Yes")
``` | 0 |
|
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends. | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters. | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 1 1 1 1",
"output": "6.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 2 2 2 2",
"output": "12.0000000000"
},
{
"input": "4 1\n3 3 3 3 4 4 4 4",
"output": "1.0000000000"
},
{
"input": "2 19\n3 3 5 5",
"output": "15.0000000000"
},
{
"input": "3 31\n3 3 3 5 5 5",
"output": "22.5000000000"
},
{
"input": "5 15\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "5 14\n2 3 4 1 2 4 5 3 5 10",
"output": "14.0000000000"
},
{
"input": "5 16\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "1 100\n1 200",
"output": "3.0000000000"
},
{
"input": "1 1\n1 1",
"output": "1.0000000000"
},
{
"input": "2 1000000000\n1 1 1 100",
"output": "3.0000000000"
},
{
"input": "4 30\n3 3 3 3 4 5 6 7",
"output": "24.0000000000"
},
{
"input": "2 100\n1 1 1 10",
"output": "3.0000000000"
},
{
"input": "3 18\n1 1 1 1 1 5",
"output": "4.5000000000"
}
] | 1,445,594,686 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 327 | 17,305,600 | from sys import stdin
from sys import exit
live = True
if not live: stdin = open('data.in', 'r')
n, w = list(map(int, stdin.readline().strip().split()))
cups = list(map(int, stdin.readline().strip().split()))
maxx = w / (3 * n)
cups = sorted(cups, reverse = True)
for it in range(n):
maxx = min(maxx, cups[it] / 2)
for it in range(n, 2 * n):
maxx = min(maxx, cups[it])
print(3 * n * maxx)
if not live: stdin.close() | Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
Input Specification:
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
Output Specification:
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['2 4\n1 1 1 1\n', '3 18\n4 4 4 2 2 2\n', '1 5\n2 3\n']
Demo Output:
['3', '18', '4.5']
Note:
Pasha also has candies that he is going to give to girls but that is another task... | ```python
from sys import stdin
from sys import exit
live = True
if not live: stdin = open('data.in', 'r')
n, w = list(map(int, stdin.readline().strip().split()))
cups = list(map(int, stdin.readline().strip().split()))
maxx = w / (3 * n)
cups = sorted(cups, reverse = True)
for it in range(n):
maxx = min(maxx, cups[it] / 2)
for it in range(n, 2 * n):
maxx = min(maxx, cups[it])
print(3 * n * maxx)
if not live: stdin.close()
``` | 3 |
|
33 | A | What is for dinner? | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | A. What is for dinner? | 2 | 256 | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth. | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | [
"4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"2 2 13\n1 13\n2 12\n"
] | [
"11\n",
"13\n"
] | none | 500 | [
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3",
"output": "11"
},
{
"input": "2 2 13\n1 13\n2 12",
"output": "13"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3",
"output": "8"
},
{
"input": "1 1 0\n1 3",
"output": "0"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16",
"output": "5"
},
{
"input": "4 2 8\n1 9\n1 10\n1 4\n2 6",
"output": "8"
},
{
"input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0",
"output": "8"
},
{
"input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7",
"output": "180"
},
{
"input": "1 1 1000000\n1 1000000",
"output": "1000000"
},
{
"input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278",
"output": "4136"
},
{
"input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0",
"output": "0"
},
{
"input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12",
"output": "54"
}
] | 1,591,871,868 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 218 | 0 | n,m,k=map(int,input().split())
a=[0]+[10**6]*m
for _ in range(n):
x,y=map(int,input().split())
if a[x]>y:a[x]=y
print(min(sum(a),k))
| Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.
Output Specification:
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
Demo Input:
['4 3 18\n2 3\n1 2\n3 6\n2 3\n', '2 2 13\n1 13\n2 12\n']
Demo Output:
['11\n', '13\n']
Note:
none | ```python
n,m,k=map(int,input().split())
a=[0]+[10**6]*m
for _ in range(n):
x,y=map(int,input().split())
if a[x]>y:a[x]=y
print(min(sum(a),k))
``` | 3.9455 |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"output": "444"
},
{
"input": "1000000",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "47",
"output": "44477777"
},
{
"input": "100",
"output": "4444777777777777"
},
{
"input": "700",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "485",
"output": "44447777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "111",
"output": "444447777777777777"
},
{
"input": "85",
"output": "4477777777777"
},
{
"input": "114",
"output": "444477777777777777"
},
{
"input": "474",
"output": "444777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "74",
"output": "47777777777"
},
{
"input": "1000",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "1024",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "4444",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "45784",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10000",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9854",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "186",
"output": "477777777777777777777777777"
},
{
"input": "10416",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10417",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "3840",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "100000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9876",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "99999",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "777777",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "854759",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "11000",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "18951",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999999",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "888887",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999998",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "40008",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10691",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "8",
"output": "44"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "999997",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999996",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999990",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999980",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "800000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "980000",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
}
] | 1,589,362,767 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 6,963,200 | n=int(input())
f=0
y=0
while(1):
if (n-7*y)<0:
break
x=((n-(7*y))/4)
if x==int(x):
f=1
break
y+=1
if f==0:
print(-1)
else:
x=int(x)
for i in range(x):
print(4,end="")
for i in range(y):
print(7,end="") | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Output Specification:
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
Demo Input:
['11\n', '10\n']
Demo Output:
['47\n', '-1\n']
Note:
none | ```python
n=int(input())
f=0
y=0
while(1):
if (n-7*y)<0:
break
x=((n-(7*y))/4)
if x==int(x):
f=1
break
y+=1
if f==0:
print(-1)
else:
x=int(x)
for i in range(x):
print(4,end="")
for i in range(y):
print(7,end="")
``` | 0 |
472 | C | Design Tutorial: Make It Nondeterministic | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.
Let's try to make a new task. Firstly we will use the following task. There are *n* people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are *n* people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation *p*?
More formally, if we denote the handle of the *i*-th person as *h**i*, then the following condition must hold: . | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of people.
The next *n* lines each contains two strings. The *i*-th line contains strings *f**i* and *s**i* (1<=≤<=|*f**i*|,<=|*s**i*|<=≤<=50) — the first name and last name of the *i*-th person. Each string consists only of lowercase English letters. All of the given 2*n* strings will be distinct.
The next line contains *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*). | If it is possible, output "YES", otherwise output "NO". | [
"3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3\n",
"3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2\n",
"2\ngalileo galilei\nnicolaus copernicus\n2 1\n",
"10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n1 2 3 4 5 6 7 8 9 10\n",
"10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n2 4 9 6 5 7 1 3 8 10\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.
In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright. | 1,500 | [
{
"input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3",
"output": "NO"
},
{
"input": "3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2",
"output": "YES"
},
{
"input": "2\ngalileo galilei\nnicolaus copernicus\n2 1",
"output": "YES"
},
{
"input": "10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n1 2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n2 4 9 6 5 7 1 3 8 10",
"output": "YES"
},
{
"input": "1\na b\n1",
"output": "YES"
},
{
"input": "6\na b\nc d\ne f\ng h\ni j\nk l\n1 2 3 4 5 6",
"output": "YES"
},
{
"input": "6\na b\nc d\ne f\ng h\ni j\nk l\n1 2 3 4 6 5",
"output": "NO"
},
{
"input": "6\na l\nb k\nc j\nd i\ne h\nf g\n1 3 5 2 4 6",
"output": "NO"
},
{
"input": "6\na l\nb k\nc j\nd i\ne h\nf g\n1 3 5 6 4 2",
"output": "YES"
},
{
"input": "5\nofxaenogpwskpjjo baoqtoeskrwjfm\nqtcmjzkvsoiwyuifmxu yrjjtmszpsuaaneetn\nvcuwolwntm lpfsjemzppwqgh\npiopqgktjlsg ncufxflxyzvwsaftiyd\ngxjkoxyzznwjrs clnohbgotljvqkmcjs\n5 1 4 2 3",
"output": "YES"
},
{
"input": "6\nzfnkpxaavrcvqhhkclcuiswawpghlqrlq wnvbzhvsjozlkwxowcvyclmehjkkvkxin\nzkxkvlnovnloxjdydujkjydaegzjypsgrzq dmiilhmkspokltabpvwalijhlitbfp\nldfbfggqsdqethdgkmbcwloluguxiluqjyr fewoondewvndcxticvpiqnvvdhsnzfd\nepokfmixjnawdfgkmqlcyirxuprrvudh xvijbdzqdyjwsyhjucytuxrxuiynxf\nxntrjusjwbfemnysqrloflcmuiiqxdwviaux vxwmfeyzhfiakbcaiidklvglxdxizbd\nyuamigghgdczicqjkhgfwahorgdocgwdjif nlnfwetlhwknpsfemhyotmycdbgdcbvws\n4 3 5 6 2 1",
"output": "NO"
},
{
"input": "1\nno np\n1",
"output": "YES"
},
{
"input": "5\naab aac\naad aae\naaf aag\naah aai\naaj aak\n5 4 3 2 1",
"output": "NO"
},
{
"input": "4\na b\nc d\nz e\nf g\n1 2 3 4",
"output": "YES"
},
{
"input": "2\naab aac\naa aaa\n1 2",
"output": "NO"
},
{
"input": "3\nf a\ng b\nc d\n1 2 3",
"output": "YES"
},
{
"input": "2\na b\nx y\n2 1",
"output": "NO"
},
{
"input": "3\na b\nz c\nd e\n1 2 3",
"output": "YES"
},
{
"input": "2\naa ab\nax ay\n2 1",
"output": "NO"
},
{
"input": "3\nd f\nz a\nb c\n1 2 3",
"output": "NO"
},
{
"input": "4\ng y\nh a\ni b\nd c\n1 2 3 4",
"output": "NO"
},
{
"input": "3\nd e\nf a\nb c\n1 2 3",
"output": "NO"
},
{
"input": "2\naaz aa\naab aac\n1 2",
"output": "YES"
},
{
"input": "4\na b\nd c\nh e\nf g\n1 2 3 4",
"output": "YES"
},
{
"input": "3\nb c\nf a\nd e\n1 2 3",
"output": "NO"
},
{
"input": "3\na b\nzzz zzzz\nz zz\n1 2 3",
"output": "NO"
}
] | 1,678,748,439 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,764,800 | import sys
input = sys.stdin.read().split('\n')
num_people = int(input.pop(0))
order = [int(x) - 1 for x in input.pop(num_people).split()]
first_names = []
last_names = []
for person in input:
person_arr = person.split()
first_names.append(person_arr[0])
last_names.append(person_arr[1])
prev = ""
valid = True
for pos in order:
first = first_names[pos]
last = last_names[pos]
if first < last:
if first > prev:
prev = first
elif last > prev:
prev = last
else:
valid = False
break
else:
if last > prev:
prev = last
elif first > prev:
prev = first
else:
valid = False
break
if valid:
print("YES")
else:
print("NO")
| Title: Design Tutorial: Make It Nondeterministic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.
Let's try to make a new task. Firstly we will use the following task. There are *n* people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are *n* people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation *p*?
More formally, if we denote the handle of the *i*-th person as *h**i*, then the following condition must hold: .
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of people.
The next *n* lines each contains two strings. The *i*-th line contains strings *f**i* and *s**i* (1<=≤<=|*f**i*|,<=|*s**i*|<=≤<=50) — the first name and last name of the *i*-th person. Each string consists only of lowercase English letters. All of the given 2*n* strings will be distinct.
The next line contains *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*).
Output Specification:
If it is possible, output "YES", otherwise output "NO".
Demo Input:
['3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3\n', '3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2\n', '2\ngalileo galilei\nnicolaus copernicus\n2 1\n', '10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n1 2 3 4 5 6 7 8 9 10\n', '10\nrean schwarzer\nfei claussell\nalisa reinford\neliot craig\nlaura arseid\njusis albarea\nmachias regnitz\nsara valestin\nemma millstein\ngaius worzel\n2 4 9 6 5 7 1 3 8 10\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.
In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright. | ```python
import sys
input = sys.stdin.read().split('\n')
num_people = int(input.pop(0))
order = [int(x) - 1 for x in input.pop(num_people).split()]
first_names = []
last_names = []
for person in input:
person_arr = person.split()
first_names.append(person_arr[0])
last_names.append(person_arr[1])
prev = ""
valid = True
for pos in order:
first = first_names[pos]
last = last_names[pos]
if first < last:
if first > prev:
prev = first
elif last > prev:
prev = last
else:
valid = False
break
else:
if last > prev:
prev = last
elif first > prev:
prev = first
else:
valid = False
break
if valid:
print("YES")
else:
print("NO")
``` | -1 |
|
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,686,803,372 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 35 | 62 | 0 | a=int(input())
c=sorted(list(map(int,input().split())))[::-1]
summa,i=0,0
ok=True
while summa<a:
summa+=c[i]
i+=1
if i==len(c):
print(-1)
ok=False
break
if ok==True:
print(i)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
a=int(input())
c=sorted(list(map(int,input().split())))[::-1]
summa,i=0,0
ok=True
while summa<a:
summa+=c[i]
i+=1
if i==len(c):
print(-1)
ok=False
break
if ok==True:
print(i)
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,664,239,986 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | import math
(n, m)= map(int, input().split(" "))
a= list(map(int, str(input()).split(" ")))
b= []
for i in range(n):
b.append(math.ceil(a[i]/m))
ma= n-1
for j in range(n-1,-1,-1):
if b[j]>b[ma]:
ma=j
print(ma+1) | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
import math
(n, m)= map(int, input().split(" "))
a= list(map(int, str(input()).split(" ")))
b= []
for i in range(n):
b.append(math.ceil(a[i]/m))
ma= n-1
for j in range(n-1,-1,-1):
if b[j]>b[ma]:
ma=j
print(ma+1)
``` | 3 |
|
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*.
Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad. | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company. | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n1001011011",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "10 5 8\n1000001110",
"output": "1"
},
{
"input": "10 1 10\n0000011111",
"output": "1"
},
{
"input": "4 1 4\n0011",
"output": "1"
},
{
"input": "10 3 7\n0000011111",
"output": "1"
},
{
"input": "5 1 5\n11010",
"output": "1"
},
{
"input": "6 1 6\n111000",
"output": "1"
},
{
"input": "2 1 2\n01",
"output": "1"
},
{
"input": "10 10 1\n0000011111",
"output": "1"
},
{
"input": "6 1 6\n000111",
"output": "1"
},
{
"input": "10 2 10\n0000011111",
"output": "1"
},
{
"input": "8 1 8\n11110000",
"output": "1"
},
{
"input": "6 1 5\n100000",
"output": "1"
},
{
"input": "16 4 12\n0000000011111111",
"output": "1"
},
{
"input": "6 1 5\n111000",
"output": "1"
},
{
"input": "8 2 7\n11110000",
"output": "1"
},
{
"input": "6 2 5\n111000",
"output": "1"
},
{
"input": "9 9 1\n111000000",
"output": "1"
},
{
"input": "2 2 1\n01",
"output": "1"
},
{
"input": "5 2 5\n00001",
"output": "1"
},
{
"input": "5 1 5\n10000",
"output": "1"
},
{
"input": "6 1 6\n011111",
"output": "1"
},
{
"input": "5 5 1\n11110",
"output": "1"
},
{
"input": "2 1 2\n10",
"output": "1"
},
{
"input": "4 2 4\n0001",
"output": "1"
},
{
"input": "10 1 10\n1111100000",
"output": "1"
},
{
"input": "8 4 5\n00001111",
"output": "1"
},
{
"input": "4 4 1\n0111",
"output": "1"
},
{
"input": "8 1 8\n00101001",
"output": "1"
}
] | 1,489,469,952 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 62 | 4,812,800 | from sys import stdin,stdout
a,x,y=list(map(int,input().split()))
length=input()
print(0 if length[x-1]==length[y-1] else 1 ) | Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*.
Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Input Specification:
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second.
Output Specification:
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
Demo Input:
['4 1 4\n1010\n', '5 5 2\n10110\n']
Demo Output:
['1', '0']
Note:
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company. | ```python
from sys import stdin,stdout
a,x,y=list(map(int,input().split()))
length=input()
print(0 if length[x-1]==length[y-1] else 1 )
``` | 3 |
|
689 | A | Mike and Cellphone | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in. | If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line. | [
"3\n586\n",
"2\n09\n",
"9\n123456789\n",
"3\n911\n"
] | [
"NO\n",
"NO\n",
"YES\n",
"YES\n"
] | You can find the picture clarifying the first sample case in the statement above. | 500 | [
{
"input": "3\n586",
"output": "NO"
},
{
"input": "2\n09",
"output": "NO"
},
{
"input": "9\n123456789",
"output": "YES"
},
{
"input": "3\n911",
"output": "YES"
},
{
"input": "3\n089",
"output": "NO"
},
{
"input": "3\n159",
"output": "YES"
},
{
"input": "9\n000000000",
"output": "NO"
},
{
"input": "4\n0874",
"output": "NO"
},
{
"input": "6\n235689",
"output": "NO"
},
{
"input": "2\n10",
"output": "YES"
},
{
"input": "3\n358",
"output": "NO"
},
{
"input": "6\n123456",
"output": "NO"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n0068",
"output": "NO"
},
{
"input": "6\n021149",
"output": "YES"
},
{
"input": "5\n04918",
"output": "YES"
},
{
"input": "2\n05",
"output": "NO"
},
{
"input": "4\n0585",
"output": "NO"
},
{
"input": "4\n0755",
"output": "NO"
},
{
"input": "2\n08",
"output": "NO"
},
{
"input": "4\n0840",
"output": "NO"
},
{
"input": "9\n103481226",
"output": "YES"
},
{
"input": "4\n1468",
"output": "NO"
},
{
"input": "7\n1588216",
"output": "NO"
},
{
"input": "9\n188758557",
"output": "NO"
},
{
"input": "1\n2",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "8\n23482375",
"output": "YES"
},
{
"input": "9\n246112056",
"output": "YES"
},
{
"input": "9\n256859223",
"output": "NO"
},
{
"input": "6\n287245",
"output": "NO"
},
{
"input": "8\n28959869",
"output": "NO"
},
{
"input": "9\n289887167",
"output": "YES"
},
{
"input": "4\n3418",
"output": "NO"
},
{
"input": "4\n3553",
"output": "NO"
},
{
"input": "2\n38",
"output": "NO"
},
{
"input": "6\n386126",
"output": "NO"
},
{
"input": "6\n392965",
"output": "NO"
},
{
"input": "1\n4",
"output": "NO"
},
{
"input": "6\n423463",
"output": "NO"
},
{
"input": "4\n4256",
"output": "NO"
},
{
"input": "8\n42937903",
"output": "YES"
},
{
"input": "1\n5",
"output": "NO"
},
{
"input": "8\n50725390",
"output": "YES"
},
{
"input": "9\n515821866",
"output": "NO"
},
{
"input": "2\n56",
"output": "NO"
},
{
"input": "2\n57",
"output": "NO"
},
{
"input": "7\n5740799",
"output": "NO"
},
{
"input": "9\n582526521",
"output": "NO"
},
{
"input": "9\n585284126",
"output": "NO"
},
{
"input": "1\n6",
"output": "NO"
},
{
"input": "3\n609",
"output": "NO"
},
{
"input": "2\n63",
"output": "NO"
},
{
"input": "3\n633",
"output": "NO"
},
{
"input": "7\n6668940",
"output": "NO"
},
{
"input": "5\n66883",
"output": "NO"
},
{
"input": "2\n68",
"output": "NO"
},
{
"input": "5\n69873",
"output": "YES"
},
{
"input": "1\n7",
"output": "NO"
},
{
"input": "4\n7191",
"output": "YES"
},
{
"input": "9\n722403540",
"output": "YES"
},
{
"input": "9\n769554547",
"output": "NO"
},
{
"input": "3\n780",
"output": "NO"
},
{
"input": "5\n78248",
"output": "NO"
},
{
"input": "4\n7844",
"output": "NO"
},
{
"input": "4\n7868",
"output": "NO"
},
{
"input": "1\n8",
"output": "NO"
},
{
"input": "6\n817332",
"output": "YES"
},
{
"input": "7\n8465393",
"output": "YES"
},
{
"input": "7\n8526828",
"output": "NO"
},
{
"input": "8\n85812664",
"output": "NO"
},
{
"input": "8\n93008225",
"output": "YES"
},
{
"input": "7\n9454566",
"output": "NO"
},
{
"input": "4\n9625",
"output": "NO"
},
{
"input": "8\n97862407",
"output": "YES"
},
{
"input": "3\n993",
"output": "NO"
},
{
"input": "3\n267",
"output": "YES"
},
{
"input": "3\n249",
"output": "YES"
},
{
"input": "3\n672",
"output": "YES"
},
{
"input": "3\n176",
"output": "YES"
},
{
"input": "3\n123",
"output": "NO"
},
{
"input": "3\n367",
"output": "YES"
},
{
"input": "2\n12",
"output": "NO"
},
{
"input": "4\n2580",
"output": "YES"
},
{
"input": "2\n20",
"output": "YES"
},
{
"input": "3\n492",
"output": "YES"
},
{
"input": "3\n167",
"output": "YES"
},
{
"input": "3\n970",
"output": "NO"
},
{
"input": "3\n460",
"output": "NO"
},
{
"input": "4\n4268",
"output": "NO"
},
{
"input": "4\n9394",
"output": "YES"
},
{
"input": "2\n13",
"output": "NO"
},
{
"input": "3\n729",
"output": "YES"
},
{
"input": "6\n456893",
"output": "YES"
}
] | 1,678,376,126 | 626 | PyPy 3 | OK | TESTS | 94 | 77 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
x = [3, 0, 0, 0, 1, 1, 1, 2, 2, 2]
y = [1, 0, 1, 2, 0, 1, 2, 0, 1, 2]
s0 = set()
for i, j in zip(x, y):
s0.add((i, j))
c = 0
for dx in range(-5, 6):
for dy in range(-5, 6):
ok = 1
for k in s:
x0, y0 = x[k - 48] + dx, y[k - 48] + dy
if not (x0, y0) in s0:
ok = 0
break
if ok:
c += 1
ans = "YES" if c == 1 else "NO"
print(ans) | Title: Mike and Cellphone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input Specification:
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in.
Output Specification:
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Demo Input:
['3\n586\n', '2\n09\n', '9\n123456789\n', '3\n911\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n', 'YES\n']
Note:
You can find the picture clarifying the first sample case in the statement above. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
x = [3, 0, 0, 0, 1, 1, 1, 2, 2, 2]
y = [1, 0, 1, 2, 0, 1, 2, 0, 1, 2]
s0 = set()
for i, j in zip(x, y):
s0.add((i, j))
c = 0
for dx in range(-5, 6):
for dy in range(-5, 6):
ok = 1
for k in s:
x0, y0 = x[k - 48] + dx, y[k - 48] + dy
if not (x0, y0) in s0:
ok = 0
break
if ok:
c += 1
ans = "YES" if c == 1 else "NO"
print(ans)
``` | 3 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,679,407,541 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | from sys import stdin
input=lambda :stdin.readline()[:-1]
n=int(input())
l=[]
for i in range(n):
l+=[input()]
l.sort()
print(l[n//2]) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
n=int(input())
l=[]
for i in range(n):
l+=[input()]
l.sort()
print(l[n//2])
``` | 3.969 |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,662,017,091 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 1,843,200 | from collections import deque
n, t = map(int, input().split())
portal = list(map(int, input().split()))
ochrd = deque()
ochrd.append(1 + portal[0])
prm = ochrd.popleft()
while prm <= t:
if prm == t:
print ('YES')
break
ochrd.append(prm + portal[prm - 1])
prm = ochrd.popleft()
else:
print ('NO')
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | ```python
from collections import deque
n, t = map(int, input().split())
portal = list(map(int, input().split()))
ochrd = deque()
ochrd.append(1 + portal[0])
prm = ochrd.popleft()
while prm <= t:
if prm == t:
print ('YES')
break
ochrd.append(prm + portal[prm - 1])
prm = ochrd.popleft()
else:
print ('NO')
``` | 3 |
|
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,692,384,495 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | v,v1=map(int,input().split())
if v1%2==1 and v1%3!=0:
for i in range(v+1,v1):
if i%2==0 or i%3==0:continue
else:print(i);print("NO");break
else:print("Yes")
else:print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none | ```python
v,v1=map(int,input().split())
if v1%2==1 and v1%3!=0:
for i in range(v+1,v1):
if i%2==0 or i%3==0:continue
else:print(i);print("NO");break
else:print("Yes")
else:print("NO")
``` | 0 |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,596,463,920 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,656,000 | a = int(input(), 2)
b = int(input(), 2)
print(bin(a ^ b)[2:].zfill(len(str(a)))) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
a = int(input(), 2)
b = int(input(), 2)
print(bin(a ^ b)[2:].zfill(len(str(a))))
``` | 0 |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,498,898,403 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 124 | 5,529,600 | k = int(input())
l = int(input())
n = 0
while k ** n <= l:
if (k ** n == l):
print("YES")
print(n - 1)
exit()
n += 1
print("NO")
| Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none | ```python
k = int(input())
l = int(input())
n = 0
while k ** n <= l:
if (k ** n == l):
print("YES")
print(n - 1)
exit()
n += 1
print("NO")
``` | 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,626,195,753 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 716 | 39,321,600 | n = int(input())
a = list(map(int, input().split()))
count, pos = [0 for _ in range(10**5+1)], [[] for _ in range(10**5+1)]
visited = []
for i, ai in enumerate(a):
count[ai] += 1
pos[ai] += [i]
t, x = 0, []
for key, occurrences in enumerate(count):
if occurrences == 0:
continue
elif occurrences == 1:
t += 1
x.append((key, 0))
elif occurrences == 2:
positions = pos[key]
t += 1
x.append((key, positions[1] - positions[0]))
else:
positions = pos[key]
expected_cd = positions[1] - positions[0]
condition = True
for i in range(2, occurrences, 1):
if positions[i] - positions[i-1] != expected_cd:
condition = False
break
if condition:
t += 1
x.append((key, expected_cd))
print(t)
x.sort(key = lambda x: x[0])
for i in range(t):
number, cd = x[i]
print(number, cd)
| 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
n = int(input())
a = list(map(int, input().split()))
count, pos = [0 for _ in range(10**5+1)], [[] for _ in range(10**5+1)]
visited = []
for i, ai in enumerate(a):
count[ai] += 1
pos[ai] += [i]
t, x = 0, []
for key, occurrences in enumerate(count):
if occurrences == 0:
continue
elif occurrences == 1:
t += 1
x.append((key, 0))
elif occurrences == 2:
positions = pos[key]
t += 1
x.append((key, positions[1] - positions[0]))
else:
positions = pos[key]
expected_cd = positions[1] - positions[0]
condition = True
for i in range(2, occurrences, 1):
if positions[i] - positions[i-1] != expected_cd:
condition = False
break
if condition:
t += 1
x.append((key, expected_cd))
print(t)
x.sort(key = lambda x: x[0])
for i in range(t):
number, cd = x[i]
print(number, cd)
``` | 3 |
|
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,665,843,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 62 | 0 | n=input().split()
l=[]
l1=[]
for i in n:
l.append(int(i))
l.sort()
for j in l:
if j not in l1:
l1.append(j)
if l[1]+l[2]+l[0]<=l[3] and len(l1)>2 and l[0]+l[1]!=l[2]:
print("IMPOSSIBLE")
else:
if l[1]+l[2]>l[3] or len(l1)==2:
print("TRIANGLE")
elif l[1]+l[2]<=l[3]:
print("SEGMENT")
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none | ```python
n=input().split()
l=[]
l1=[]
for i in n:
l.append(int(i))
l.sort()
for j in l:
if j not in l1:
l1.append(j)
if l[1]+l[2]+l[0]<=l[3] and len(l1)>2 and l[0]+l[1]!=l[2]:
print("IMPOSSIBLE")
else:
if l[1]+l[2]>l[3] or len(l1)==2:
print("TRIANGLE")
elif l[1]+l[2]<=l[3]:
print("SEGMENT")
``` | 0 |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872",
"output": "NO"
},
{
"input": "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326",
"output": "YES"
},
{
"input": "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024",
"output": "YES"
},
{
"input": "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627",
"output": "YES"
},
{
"input": "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563",
"output": "YES"
},
{
"input": "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943",
"output": "NO"
}
] | 1,608,028,158 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 312 | 1,331,200 | n = int(input())
nums = []
for j in range(n):
nums.append([int(j) for j in input().split()])
output = "NO"
for j in range(n):
for k in range(j + 1, n):
if nums[j][0] + nums[j][1] == nums[k][0]:
if nums[k][1] + nums[k][0] == nums[j][0]:
output = "YES"
break
if output == "YES":
break
print(output)
| Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
Output Specification:
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
Demo Input:
['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
n = int(input())
nums = []
for j in range(n):
nums.append([int(j) for j in input().split()])
output = "NO"
for j in range(n):
for k in range(j + 1, n):
if nums[j][0] + nums[j][1] == nums[k][0]:
if nums[k][1] + nums[k][0] == nums[j][0]:
output = "YES"
break
if output == "YES":
break
print(output)
``` | 3.91952 |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,695,172,801 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 2,252,800 | n = int(input())
laptops = [None] * n
for i in range(n):
laptops[i] = list(map(int, input().split()))
laptops = sorted(laptops)
flag = True
for i in range(n-1):
if laptops[i][1] > laptops[i+1][1]:
flag = False
else:
flag = True
if(flag):
print('Poor Alex')
else:
print('Happy Alex')
| Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
n = int(input())
laptops = [None] * n
for i in range(n):
laptops[i] = list(map(int, input().split()))
laptops = sorted(laptops)
flag = True
for i in range(n-1):
if laptops[i][1] > laptops[i+1][1]:
flag = False
else:
flag = True
if(flag):
print('Poor Alex')
else:
print('Happy Alex')
``` | 0 |
|
39 | J | Spelling Check | PROGRAMMING | 1,500 | [
"hashing",
"implementation",
"strings"
] | J. Spelling Check | 2 | 256 | Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? | The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. | In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. | [
"abdrakadabra\nabrakadabra\n",
"aa\na\n",
"competition\ncodeforces\n"
] | [
"1\n3\n",
"2\n1 2\n",
"0\n"
] | none | 0 | [
{
"input": "abdrakadabra\nabrakadabra",
"output": "1\n3 "
},
{
"input": "aa\na",
"output": "2\n1 2 "
},
{
"input": "competition\ncodeforces",
"output": "0"
},
{
"input": "ab\na",
"output": "1\n2 "
},
{
"input": "bb\nb",
"output": "2\n1 2 "
},
{
"input": "aab\nab",
"output": "2\n1 2 "
},
{
"input": "aabb\nabb",
"output": "2\n1 2 "
},
{
"input": "babaacaacaa\nbbaacaacaa",
"output": "1\n2 "
},
{
"input": "bccaabbcccc\nbccaabcccc",
"output": "2\n6 7 "
},
{
"input": "ababcaabaaa\nabacaabaaa",
"output": "1\n4 "
},
{
"input": "cccacaccacb\ncccacaccac",
"output": "1\n11 "
},
{
"input": "aaaaaaaaaaa\naaaaaaaaaa",
"output": "11\n1 2 3 4 5 6 7 8 9 10 11 "
},
{
"input": "lcaaxcbcjca\nccaaacccca",
"output": "0"
},
{
"input": "babbbtaamba\nbabbbaabba",
"output": "0"
},
{
"input": "xdfxmcnzpch\nazvotghvtk",
"output": "0"
},
{
"input": "ki\nb",
"output": "0"
},
{
"input": "vct\nie",
"output": "0"
},
{
"input": "feee\nsnl",
"output": "0"
},
{
"input": "cbxxxxzvks\ncbxxxzvks",
"output": "4\n3 4 5 6 "
},
{
"input": "qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur",
"output": "10\n11 12 13 14 15 16 17 18 19 20 "
}
] | 1,438,186,071 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 1,840 | 46,489,600 | s = input().strip()
t = input().strip()
diff = len(s) - 1
for i in range(len(t)):
if s[i] != t[i]:
diff = i
break
for i in range(diff + 1, len(s)):
if s[i] != t[i - 1]:
print(0)
import sys; sys.exit()
start = diff
while start != 0 and s[start - 1] == s[diff]:
start -= 1
print(diff - start + 1)
print(' '.join(map(str, range(start + 1, diff + 2))))
| Title: Spelling Check
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?
Input Specification:
The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.
Output Specification:
In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.
Demo Input:
['abdrakadabra\nabrakadabra\n', 'aa\na\n', 'competition\ncodeforces\n']
Demo Output:
['1\n3\n', '2\n1 2\n', '0\n']
Note:
none | ```python
s = input().strip()
t = input().strip()
diff = len(s) - 1
for i in range(len(t)):
if s[i] != t[i]:
diff = i
break
for i in range(diff + 1, len(s)):
if s[i] != t[i - 1]:
print(0)
import sys; sys.exit()
start = diff
while start != 0 and s[start - 1] == s[diff]:
start -= 1
print(diff - start + 1)
print(' '.join(map(str, range(start + 1, diff + 2))))
``` | 3.453406 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,645,960,116 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 154 | 1,433,600 | count = 0
n, m = [int(i) for i in input().split()]
for a in range(m + 1):
for b in range(n + 1):
if a ** 2 + b == n and a + b ** 2 == m:
count += 1
print(count) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
count = 0
n, m = [int(i) for i in input().split()]
for a in range(m + 1):
for b in range(n + 1):
if a ** 2 + b == n and a + b ** 2 == m:
count += 1
print(count)
``` | 3 |
|
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,677,109,090 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | num=int(input())
z=[int(i)for i in input().split()]
c=1
for i in range(num-1):
if z[i]<z[i+1]:
c+=1
else:
c=1
print(c) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
num=int(input())
z=[int(i)for i in input().split()]
c=1
for i in range(num-1):
if z[i]<z[i+1]:
c+=1
else:
c=1
print(c)
``` | 0 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,681,616,964 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | N = int(input())
S = input().strip()
c0,c1 = S.count("0"), S.count("1")
print(max(c0,c1)-min(c0,c1)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
N = int(input())
S = input().strip()
c0,c1 = S.count("0"), S.count("1")
print(max(c0,c1)-min(c0,c1))
``` | -1 |
|
10 | D | LCIS | PROGRAMMING | 2,800 | [
"dp"
] | D. LCIS | 1 | 256 | This problem differs from one which was on the online contest.
The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=<<=*a**i*<=+<=1 for *i*<=<<=*n*.
The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of indexes 1<=≤<=*i*1<=<<=*i*2<=<<=...<=<<=*i**k*<=≤<=*n* that *a**i**j*<==<=*s**j*. In other words, the sequence *s* can be derived from the sequence *a* by crossing out some elements.
You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line contains *m* space-separated integers from the range [0,<=109] — elements of the second sequence. | In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | [
"7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n",
"5\n1 2 0 2 1\n3\n1 0 1\n"
] | [
"3\n3 5 6 \n",
"2\n0 1 \n"
] | none | 0 | [
{
"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6",
"output": "3\n3 5 6 "
},
{
"input": "5\n1 2 0 2 1\n3\n1 0 1",
"output": "2\n0 1 "
},
{
"input": "2\n6 10\n3\n6 3 3",
"output": "1\n6 "
},
{
"input": "1\n7\n2\n7 9",
"output": "1\n7 "
},
{
"input": "3\n37 49 24\n3\n33 5 70",
"output": "0"
},
{
"input": "10\n7 10 1 2 1 7 1 5 9 9\n9\n6 2 5 6 7 7 5 5 2",
"output": "2\n2 7 "
},
{
"input": "9\n7 0 1 2 6 0 10 3 5\n4\n8 4 0 3",
"output": "2\n0 3 "
},
{
"input": "9\n7 4 4 5 0 6 5 4 10\n4\n5 2 10 9",
"output": "2\n5 10 "
},
{
"input": "8\n7 8 6 6 8 10 3 3\n5\n7 4 10 8 7",
"output": "2\n7 8 "
},
{
"input": "7\n4 2 4 3 10 3 6\n9\n7 5 2 3 0 1 6 1 4",
"output": "3\n2 3 6 "
},
{
"input": "1\n7\n10\n1 8 8 10 9 10 4 6 0 5",
"output": "0"
},
{
"input": "2\n5 2\n4\n8 8 0 4",
"output": "0"
},
{
"input": "3\n1 3 9\n10\n8 0 10 5 7 0 3 1 2 4",
"output": "1\n1 "
},
{
"input": "15\n10 4 7 7 10 1 4 9 1 10 9 6 8 8 2\n2\n0 4",
"output": "1\n4 "
},
{
"input": "16\n8 8 6 7 10 0 10 1 7 6 6 0 4 2 6 7\n12\n9 3 8 4 10 3 9 8 3 7 10 4",
"output": "2\n8 10 "
},
{
"input": "23\n174 172 196 135 91 174 208 92 132 53 202 118 5 244 161 140 71 21 185 56 60 195 217\n17\n38 218 120 77 22 214 164 194 79 195 36 167 42 89 201 80 11",
"output": "1\n195 "
},
{
"input": "53\n135 168 160 123 6 250 251 158 245 184 206 35 189 64 138 12 69 21 112 198 165 211 109 40 192 98 236 216 255 98 136 38 67 79 25 196 216 64 134 124 102 232 229 102 179 138 111 123 2 93 25 162 57\n57\n64 143 41 144 73 26 11 17 224 209 167 162 129 39 102 224 254 45 120 2 138 213 139 133 169 54 7 143 242 118 155 189 100 185 145 168 248 131 83 216 142 180 225 35 226 202 8 15 200 192 75 140 191 189 75 116 202",
"output": "3\n64 138 192 "
},
{
"input": "83\n95 164 123 111 177 71 38 225 103 59 210 209 117 139 115 140 66 21 39 84 14 227 0 43 90 233 96 98 232 237 108 139 55 220 14 225 134 39 68 167 193 125 86 216 87 14 94 75 255 24 165 98 177 191 239 123 98 90 29 52 155 231 187 90 180 1 31 237 167 145 242 115 61 190 47 41 61 206 191 248 126 196 26\n49\n234 134 9 207 37 95 116 239 105 197 191 15 151 249 156 235 17 161 197 199 87 78 191 188 44 151 179 238 72 29 228 157 174 99 190 114 95 185 160 168 58 216 131 151 233 204 213 87 76",
"output": "2\n95 233 "
},
{
"input": "13\n55 160 86 99 92 148 81 36 216 191 214 127 44\n85\n92 12 64 21 221 225 119 243 147 47 244 112 212 237 209 121 81 239 43 104 3 254 52 13 1 210 28 18 199 75 251 146 77 28 253 211 50 35 42 160 157 104 155 37 241 78 42 190 150 228 193 96 190 178 232 65 231 186 1 123 212 126 239 22 214 186 245 249 66 234 57 78 173 229 185 23 240 91 127 177 240 105 77 208 86",
"output": "2\n160 214 "
},
{
"input": "94\n100 161 99 102 209 51 5 188 217 53 121 5 233 55 25 156 136 195 243 157 110 202 136 151 86 171 253 38 126 40 27 76 60 119 222 52 134 104 184 146 133 220 88 108 246 61 215 184 181 134 223 164 41 193 232 217 38 192 226 91 81 99 204 232 178 4 187 61 160 255 121 142 191 114 114 181 226 49 86 55 252 169 59 190 246 93 21 22 17 18 120 88 93 144\n30\n61 51 176 38 119 33 100 185 103 84 161 166 103 227 43 200 127 53 52 89 19 215 76 254 110 30 239 247 11 182",
"output": "3\n51 53 110 "
},
{
"input": "6\n3 5 4 6 8 1\n10\n3 3 0 5 4 0 10 5 6 8",
"output": "4\n3 5 6 8 "
},
{
"input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "8\n2 3 4 5 6 8 9 5\n9\n2 2 3 4 5 6 6 8 9",
"output": "7\n2 3 4 5 6 8 9 "
},
{
"input": "8\n0 4 10 6 7 2 8 5\n7\n0 4 6 7 7 0 8",
"output": "5\n0 4 6 7 8 "
},
{
"input": "10\n0 1 2 3 4 5 6 7 8 9\n10\n0 1 2 3 4 5 6 7 8 9",
"output": "10\n0 1 2 3 4 5 6 7 8 9 "
},
{
"input": "17\n12 17 39 156 100 177 188 129 14 142 45 144 243 151 158 194 245\n16\n125 12 17 199 65 39 100 185 129 194 142 144 62 92 158 194",
"output": "9\n12 17 39 100 129 142 144 158 194 "
},
{
"input": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207\n20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207",
"output": "20\n7 17 24 27 36 45 62 92 93 94 98 112 114 138 143 156 173 199 204 207 "
},
{
"input": "13\n0 46 104 116 63 118 158 16 221 222 136 245 223\n9\n0 46 104 116 118 158 221 222 245",
"output": "9\n0 46 104 116 118 158 221 222 245 "
},
{
"input": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235\n15\n34 38 51 57 73 125 147 158 160 178 255 67 188 198 235",
"output": "13\n34 38 51 57 73 125 147 158 160 178 188 198 235 "
},
{
"input": "17\n25 29 37 207 122 189 118 42 54 95 154 160 162 225 228 237 248\n19\n25 29 248 37 147 209 42 54 255 95 154 160 162 225 228 237 73 248 10",
"output": "13\n25 29 37 42 54 95 154 160 162 225 228 237 248 "
},
{
"input": "10\n62914292 123971042 784965687 324817892 379711365 394545872 813282270 822333477 865397146 437913515\n9\n297835672 62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146",
"output": "8\n62914292 123971042 324817892 379711365 394545872 813282270 822333477 865397146 "
},
{
"input": "10\n130077811 57466561 335978192 71385678 434259735 454136111 482887469 530031703 688581885 809880630\n8\n373627898 57466561 71385678 434259735 454136111 482887469 530031703 809880630",
"output": "7\n57466561 71385678 434259735 454136111 482887469 530031703 809880630 "
},
{
"input": "17\n364396044 90653796 82853043 311258337 326557522 362475139 415783272 428510002 840021181 469284863 541444887 650535473 649258258 750028895 791368777 808443140 959785237\n13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237",
"output": "13\n82853043 311258337 326557522 362475139 415783272 428510002 469284863 541444887 649258258 750028895 791368777 808443140 959785237 "
},
{
"input": "3\n6379263 55134355 76061584\n3\n6379263 55134355 76061584",
"output": "3\n6379263 55134355 76061584 "
},
{
"input": "3\n48875076 71023491 76538219\n3\n48875076 71023491 76538219",
"output": "3\n48875076 71023491 76538219 "
},
{
"input": "5\n6621317 78540394 52064998 89150480 53659440\n3\n78540394 46008538 839195",
"output": "1\n78540394 "
},
{
"input": "2\n34665180 51128665\n5\n71074966 34665180 47089728 44119345 51128665",
"output": "2\n34665180 51128665 "
},
{
"input": "4\n3 4 9 1\n7\n5 3 8 9 10 2 1",
"output": "2\n3 9 "
}
] | 1,689,435,155 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689435155.9046495")# 1689435155.9046698 | Title: LCIS
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
This problem differs from one which was on the online contest.
The sequence *a*1,<=*a*2,<=...,<=*a**n* is called increasing, if *a**i*<=<<=*a**i*<=+<=1 for *i*<=<<=*n*.
The sequence *s*1,<=*s*2,<=...,<=*s**k* is called the subsequence of the sequence *a*1,<=*a*2,<=...,<=*a**n*, if there exist such a set of indexes 1<=≤<=*i*1<=<<=*i*2<=<<=...<=<<=*i**k*<=≤<=*n* that *a**i**j*<==<=*s**j*. In other words, the sequence *s* can be derived from the sequence *a* by crossing out some elements.
You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=500) — the length of the first sequence. The second line contains *n* space-separated integers from the range [0,<=109] — elements of the first sequence. The third line contains an integer *m* (1<=≤<=*m*<=≤<=500) — the length of the second sequence. The fourth line contains *m* space-separated integers from the range [0,<=109] — elements of the second sequence.
Output Specification:
In the first line output *k* — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
Demo Input:
['7\n2 3 1 6 5 4 6\n4\n1 3 5 6\n', '5\n1 2 0 2 1\n3\n1 0 1\n']
Demo Output:
['3\n3 5 6 \n', '2\n0 1 \n']
Note:
none | ```python
print("_RANDOM_GUESS_1689435155.9046495")# 1689435155.9046698
``` | 0 |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
},
{
"input": "2\n500000000 1000000000",
"output": "500000000"
},
{
"input": "2\n4 6",
"output": "-1"
},
{
"input": "5\n10 8 6 4 2",
"output": "2"
},
{
"input": "2\n6 10",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "1000000000"
},
{
"input": "2\n6 8",
"output": "-1"
},
{
"input": "5\n2 2 2 2 1000000000",
"output": "2"
},
{
"input": "2\n6 4",
"output": "-1"
}
] | 1,660,927,698 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 216 | 12,390,400 | n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if 1 in a:
print(1)
else:
s = a[0]
f = 0
for i in range(1,n):
if a[i]%s != 0:
f = 1
break
if f == 0:
print(s)
else:
print(-1) | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Output Specification:
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them.
Demo Input:
['3\n2 2 4\n', '5\n2 1 3 1 6\n', '3\n2 3 5\n']
Demo Output:
['2\n', '1\n', '-1\n']
Note:
none | ```python
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if 1 in a:
print(1)
else:
s = a[0]
f = 0
for i in range(1,n):
if a[i]%s != 0:
f = 1
break
if f == 0:
print(s)
else:
print(-1)
``` | 3 |
|
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line. | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "76 48",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "100 90",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB"
},
{
"input": "90 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG"
},
{
"input": "1 98",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 100",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "56 98",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "89 89",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "18 94",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "84 27",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "1 1",
"output": "GB"
},
{
"input": "1 2",
"output": "GBG"
},
{
"input": "2 1",
"output": "BGB"
},
{
"input": "1 34",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "46 2",
"output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "99 3",
"output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 100",
"output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "100 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "1 4",
"output": "GBGGG"
}
] | 1,620,272,256 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,963,200 | with open("test.txt","r") as fh:
content = fh.read()
n = int(content[0])
m = int(content[-1])
sigma = []
for i in range (0,(n+m)):
if n > 0:
sigma.append('B')
n -= 1
if m > 0:
m -= 1
sigma.append('G')
tau = ''.join([str(i) for i in sigma])
print(tau)
with open("output.txt","w") as g:
g.write(tau)
| Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input Specification:
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Output Specification:
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
Demo Input:
['3 3\n', '4 2\n']
Demo Output:
['GBGBGB\n', 'BGBGBB\n']
Note:
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | ```python
with open("test.txt","r") as fh:
content = fh.read()
n = int(content[0])
m = int(content[-1])
sigma = []
for i in range (0,(n+m)):
if n > 0:
sigma.append('B')
n -= 1
if m > 0:
m -= 1
sigma.append('G')
tau = ''.join([str(i) for i in sigma])
print(tau)
with open("output.txt","w") as g:
g.write(tau)
``` | -1 |
|
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80",
"output": "No"
},
{
"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58",
"output": "Yes"
},
{
"input": "4 1\n2 1 0 4\n3",
"output": "Yes"
},
{
"input": "2 1\n199 0\n200",
"output": "No"
},
{
"input": "3 2\n115 0 0\n145 191",
"output": "Yes"
},
{
"input": "5 1\n196 197 198 0 200\n199",
"output": "No"
},
{
"input": "5 1\n92 0 97 99 100\n93",
"output": "No"
},
{
"input": "3 1\n3 87 0\n81",
"output": "Yes"
},
{
"input": "3 1\n0 92 192\n118",
"output": "Yes"
},
{
"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22",
"output": "Yes"
},
{
"input": "100 1\n14 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 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\n67",
"output": "No"
},
{
"input": "100 5\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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 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 0 99 100\n98 64 55 52 29",
"output": "Yes"
},
{
"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27",
"output": "Yes"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n11",
"output": "Yes"
},
{
"input": "100 1\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n1",
"output": "No"
},
{
"input": "100 1\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 0\n100",
"output": "No"
},
{
"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65",
"output": "Yes"
},
{
"input": "100 2\n0 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 0 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n48 1",
"output": "Yes"
},
{
"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69",
"output": "Yes"
},
{
"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129",
"output": "No"
},
{
"input": "5 2\n0 2 7 0 10\n1 8",
"output": "Yes"
},
{
"input": "3 1\n5 4 0\n1",
"output": "Yes"
},
{
"input": "3 1\n1 0 3\n4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n1",
"output": "No"
},
{
"input": "2 1\n0 5\n7",
"output": "Yes"
},
{
"input": "5 1\n10 11 0 12 13\n1",
"output": "Yes"
},
{
"input": "5 1\n0 2 3 4 5\n6",
"output": "Yes"
},
{
"input": "6 2\n1 0 3 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "7 2\n1 2 3 0 0 6 7\n4 5",
"output": "Yes"
},
{
"input": "4 1\n1 2 3 0\n4",
"output": "No"
},
{
"input": "2 2\n0 0\n1 2",
"output": "Yes"
},
{
"input": "3 2\n1 0 0\n2 3",
"output": "Yes"
},
{
"input": "4 2\n1 0 4 0\n5 2",
"output": "Yes"
},
{
"input": "2 1\n0 1\n2",
"output": "Yes"
},
{
"input": "5 2\n1 0 4 0 6\n2 5",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 4 5\n1",
"output": "Yes"
},
{
"input": "3 1\n0 2 3\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 5 0\n6",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n5 0 2\n7",
"output": "Yes"
},
{
"input": "4 1\n4 5 0 8\n3",
"output": "Yes"
},
{
"input": "5 1\n10 11 12 0 14\n13",
"output": "No"
},
{
"input": "4 1\n1 2 0 4\n5",
"output": "Yes"
},
{
"input": "3 1\n0 11 14\n12",
"output": "Yes"
},
{
"input": "4 1\n1 3 0 4\n2",
"output": "Yes"
},
{
"input": "2 1\n0 5\n1",
"output": "No"
},
{
"input": "5 1\n1 2 0 4 7\n5",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n1",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 5 4\n6",
"output": "Yes"
},
{
"input": "4 2\n11 0 0 14\n13 12",
"output": "Yes"
},
{
"input": "2 1\n1 0\n2",
"output": "No"
},
{
"input": "3 1\n1 2 0\n3",
"output": "No"
},
{
"input": "4 1\n1 0 3 2\n4",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n5",
"output": "Yes"
},
{
"input": "3 1\n0 1 2\n3",
"output": "Yes"
},
{
"input": "4 1\n0 2 3 4\n5",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 0 4 5\n6",
"output": "Yes"
},
{
"input": "3 1\n1 2 0\n5",
"output": "No"
},
{
"input": "4 2\n1 0 0 4\n3 2",
"output": "Yes"
},
{
"input": "5 1\n2 3 0 5 7\n6",
"output": "Yes"
},
{
"input": "3 1\n2 3 0\n4",
"output": "No"
},
{
"input": "3 1\n1 0 11\n5",
"output": "No"
},
{
"input": "4 1\n7 9 5 0\n8",
"output": "Yes"
},
{
"input": "6 2\n1 2 3 0 5 0\n6 4",
"output": "Yes"
},
{
"input": "3 2\n0 1 0\n3 2",
"output": "Yes"
},
{
"input": "4 1\n6 9 5 0\n8",
"output": "Yes"
},
{
"input": "2 1\n0 3\n6",
"output": "Yes"
},
{
"input": "5 2\n1 2 0 0 5\n4 3",
"output": "Yes"
},
{
"input": "4 2\n2 0 0 8\n3 4",
"output": "Yes"
},
{
"input": "2 1\n0 2\n3",
"output": "Yes"
},
{
"input": "3 1\n0 4 5\n6",
"output": "Yes"
},
{
"input": "6 1\n1 2 3 4 0 5\n6",
"output": "Yes"
},
{
"input": "2 1\n2 0\n3",
"output": "No"
},
{
"input": "4 2\n11 0 0 200\n100 199",
"output": "Yes"
},
{
"input": "2 1\n5 0\n4",
"output": "Yes"
},
{
"input": "3 1\n1 0 5\n10",
"output": "Yes"
},
{
"input": "6 2\n1 2 0 0 5 6\n3 4",
"output": "Yes"
},
{
"input": "5 2\n1 0 3 0 5\n2 4",
"output": "Yes"
},
{
"input": "4 1\n1 4 0 8\n3",
"output": "Yes"
},
{
"input": "4 1\n5 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 7\n3 2",
"output": "Yes"
},
{
"input": "3 3\n0 0 0\n1 4 3",
"output": "Yes"
},
{
"input": "5 5\n0 0 0 0 0\n5 4 3 2 1",
"output": "Yes"
},
{
"input": "4 1\n3 9 4 0\n8",
"output": "Yes"
},
{
"input": "4 2\n1 0 0 4\n2 3",
"output": "Yes"
},
{
"input": "6 1\n2 4 0 8 9 10\n3",
"output": "Yes"
},
{
"input": "4 1\n0 3 5 6\n9",
"output": "Yes"
},
{
"input": "4 2\n1 2 0 0\n3 4",
"output": "Yes"
},
{
"input": "5 1\n2 3 4 5 0\n1",
"output": "Yes"
},
{
"input": "3 1\n2 0 4\n5",
"output": "Yes"
}
] | 1,496,865,509 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Jun 7 15:25:16 2017
@author: Gad
"""
def checker(size,string,replacements):
increasing = True
if int(size[1]) > 1:
return 'Yes'
else:
for i in range (int(size[0])):
if int (string[i]) == 0:
string[i] = replacements[0]
break
for i in range(int(size[0])-1):
if int (string[i]) > int(string[i+1]):
increasing = False
if increasing == False:
return 'Yes'
return 'No'
size = input().strip().split()
string = input().strip().split()
replacements= input().strip().split()
print(checker(size,string,replacements))
| Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing.
Input Specification:
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements.
The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total.
Output Specification:
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
Demo Input:
['4 2\n11 0 0 14\n5 4\n', '6 1\n2 3 0 8 9 10\n5\n', '4 1\n8 94 0 4\n89\n', '7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n', 'Yes\n']
Note:
In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 7 15:25:16 2017
@author: Gad
"""
def checker(size,string,replacements):
increasing = True
if int(size[1]) > 1:
return 'Yes'
else:
for i in range (int(size[0])):
if int (string[i]) == 0:
string[i] = replacements[0]
break
for i in range(int(size[0])-1):
if int (string[i]) > int(string[i+1]):
increasing = False
if increasing == False:
return 'Yes'
return 'No'
size = input().strip().split()
string = input().strip().split()
replacements= input().strip().split()
print(checker(size,string,replacements))
``` | 3 |
|
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,667,507,790 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 |
s = input()
h = ['h', 'e', 'l', 'l', 'o']
cnt = 0
for i in s:
if i == h[cnt]:
cnt += 1
if cnt == 5:
print('YES')
break
else:
if cnt == 5:
print('YES')
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()
h = ['h', 'e', 'l', 'l', 'o']
cnt = 0
for i in s:
if i == h[cnt]:
cnt += 1
if cnt == 5:
print('YES')
break
else:
if cnt == 5:
print('YES')
print('NO')
``` | 3.977 |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992",
"output": "42"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "6\n5 4 3 2 1 2",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "7\n99 100 1 2 3 4 5",
"output": "5"
},
{
"input": "5\n3 3 1 2 3",
"output": "3"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,693,828,121 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
l = list(map(int, input().split()))
c = 0
max_length = 0
for i in range(1, n):
if l[i - 1] > l[i]:
c += 1
else:
c = 0
max_length = max(max_length, c)
print(max_length + 1)
| Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
Demo Input:
['6\n2 2 1 3 4 1\n', '3\n2 2 9\n']
Demo Output:
['3', '3']
Note:
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | ```python
n = int(input())
l = list(map(int, input().split()))
c = 0
max_length = 0
for i in range(1, n):
if l[i - 1] > l[i]:
c += 1
else:
c = 0
max_length = max(max_length, c)
print(max_length + 1)
``` | 0 |
|
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,686,221,435 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | n=int(input())
x=str()
for i in range (n-1):
if i%2==0:
x=x+'I hate that '
else:
x=x+'I love that '
if n%2==1:
x=x+'I hate it'
else:
x=x+'I love it'
print(x)
| Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
n=int(input())
x=str()
for i in range (n-1):
if i%2==0:
x=x+'I hate that '
else:
x=x+'I love that '
if n%2==1:
x=x+'I hate it'
else:
x=x+'I love it'
print(x)
``` | 3 |
|
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 "
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 "
},
{
"input": "811",
"output": "811 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 1,697,965,045 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = [int(a) for a in range(2,int(input()))]
a = a[::-1]
a.append(1)
a.append(max(a) + 1)
a = a[::-1]
print(a) | Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
Output Specification:
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
Demo Input:
['1\n', '2\n']
Demo Output:
['1 ', '2 1 ']
Note:
none | ```python
a = [int(a) for a in range(2,int(input()))]
a = a[::-1]
a.append(1)
a.append(max(a) + 1)
a = a[::-1]
print(a)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,627,282,423 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 186 | 20,172,800 | string = input()
upper = 0
lower = 0
for i in range(len(string)):
if (ord(string[i]) >= 97 and
ord(string[i]) <= 122):
lower += 1
elif (ord(string[i]) >= 65 and
ord(string[i]) <= 90):
upper += 1
if(upper>lower):
print(string.upper())
elif(lower>upper):
print(string.lower())
elif(lower==upper):
print(string.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
string = input()
upper = 0
lower = 0
for i in range(len(string)):
if (ord(string[i]) >= 97 and
ord(string[i]) <= 122):
lower += 1
elif (ord(string[i]) >= 65 and
ord(string[i]) <= 90):
upper += 1
if(upper>lower):
print(string.upper())
elif(lower>upper):
print(string.lower())
elif(lower==upper):
print(string.lower())
``` | 3.915925 |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$). | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010",
"output": "Yes"
},
{
"input": "4\n0100",
"output": "No"
},
{
"input": "42\n011000100101001001101011011010100010011010",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "64\n1001001010010010100101010010010100100101001001001001010100101001",
"output": "Yes"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0000",
"output": "No"
},
{
"input": "4\n0001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "4\n0011",
"output": "No"
},
{
"input": "4\n0101",
"output": "Yes"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "4\n0111",
"output": "No"
},
{
"input": "4\n1000",
"output": "No"
},
{
"input": "4\n1001",
"output": "Yes"
},
{
"input": "4\n1010",
"output": "Yes"
},
{
"input": "4\n1100",
"output": "No"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "4\n1110",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "3\n000",
"output": "No"
},
{
"input": "3\n010",
"output": "Yes"
},
{
"input": "3\n011",
"output": "No"
},
{
"input": "3\n100",
"output": "No"
},
{
"input": "3\n110",
"output": "No"
},
{
"input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110",
"output": "No"
},
{
"input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101",
"output": "Yes"
},
{
"input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "15\n000010101010000",
"output": "No"
},
{
"input": "8\n10010100",
"output": "No"
},
{
"input": "5\n00100",
"output": "No"
},
{
"input": "6\n100100",
"output": "No"
},
{
"input": "7\n1000001",
"output": "No"
},
{
"input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "Yes"
}
] | 1,594,366,384 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 6,656,000 | a=int(input())
b=input().replace("10","1 0").replace("01","0 1").split()
for i in range(len(b)):
if len(b[i])!=1 :print("No");exit()
print("YES")
| Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$).
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output Specification:
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
Demo Input:
['3\n101\n', '4\n1011\n', '5\n10001\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | ```python
a=int(input())
b=input().replace("10","1 0").replace("01","0 1").split()
for i in range(len(b)):
if len(b[i])!=1 :print("No");exit()
print("YES")
``` | 0 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,398,198,308 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | n = int(input())
bunch = []
for i in range(n):
leaf = input()
if (leaf not in bunch):
bunch.append(leaf)
print(len(bunch))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
n = int(input())
bunch = []
for i in range(n):
leaf = input()
if (leaf not in bunch):
bunch.append(leaf)
print(len(bunch))
``` | 3.969 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,678,583,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n, k=map(int,input().split())
kalan=0
for i in range(n):
kalan+=i
if 240<=k+kalan*5:
break
print(kalan-1)
| Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
n, k=map(int,input().split())
kalan=0
for i in range(n):
kalan+=i
if 240<=k+kalan*5:
break
print(kalan-1)
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,684,238,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a = int(input())
c = []
m = ''
for i in range(a):
b = input()
if len(b) < 11:
c.append(b)
elif len(b) > 10:
m += b[0]
m += str(len(b))
m += b[-1]
c.append(m)
m = ''
print(c) | 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
a = int(input())
c = []
m = ''
for i in range(a):
b = input()
if len(b) < 11:
c.append(b)
elif len(b) > 10:
m += b[0]
m += str(len(b))
m += b[-1]
c.append(m)
m = ''
print(c)
``` | 0 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,574,358,374 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 218 | 0 | from math import sqrt
a,b,c=map(int,input().split())
d=4*(sqrt(a*b//c)+sqrt(c*b//a)+sqrt(a*c//b))
print(int(d)) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
from math import sqrt
a,b,c=map(int,input().split())
d=4*(sqrt(a*b//c)+sqrt(c*b//a)+sqrt(a*c//b))
print(int(d))
``` | 3 |
|
567 | E | President and Roads | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town *t*, for which his motorcade passes along some path from *s* to *t* (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from *s* to *t*, along which he will travel the fastest.
The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer. | The first lines contain four integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=≠<=*t*).
Next *m* lines contain the roads. Each road is given as a group of three integers *a**i*,<=*b**i*,<=*l**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*l**i*<=≤<=106) — the cities that are connected by the *i*-th road and the time needed to ride along it. The road is directed from city *a**i* to city *b**i*.
The cities are numbered from 1 to *n*. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from *s* to *t* along the roads. | Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the *i*-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.
If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes). | [
"6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1\n",
"3 3 1 3\n1 2 10\n2 3 10\n1 3 100\n",
"2 2 1 2\n1 2 1\n1 2 2\n"
] | [
"YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES\n",
"YES\nYES\nCAN 81\n",
"YES\nNO\n"
] | The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6. | 2,500 | [
{
"input": "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1",
"output": "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"
},
{
"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 100",
"output": "YES\nYES\nCAN 81"
},
{
"input": "2 2 1 2\n1 2 1\n1 2 2",
"output": "YES\nNO"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 19",
"output": "CAN 2\nCAN 2\nYES"
},
{
"input": "4 3 1 4\n1 2 1\n2 3 1\n3 4 1",
"output": "YES\nYES\nYES"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 2",
"output": "NO\nNO\nYES\nCAN 1"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "NO\nNO\nYES\nYES"
},
{
"input": "6 6 1 6\n1 2 2\n2 3 4\n2 4 3\n3 5 2\n4 5 3\n5 6 10",
"output": "YES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"
},
{
"input": "6 6 1 6\n1 2 2\n2 3 3\n2 4 3\n3 5 2\n4 5 3\n5 6 10",
"output": "YES\nYES\nCAN 2\nYES\nCAN 2\nYES"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "2 2 1 2\n1 2 6\n1 2 6",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 3 1 2\n1 2 7\n1 2 7\n1 2 7",
"output": "CAN 1\nCAN 1\nCAN 1"
},
{
"input": "2 10 1 2\n1 2 5\n1 2 5\n1 2 7\n1 2 5\n1 2 6\n1 2 5\n1 2 5\n1 2 6\n1 2 5\n1 2 6",
"output": "CAN 1\nCAN 1\nCAN 3\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 2"
},
{
"input": "3 2 1 2\n3 2 3\n1 3 6",
"output": "YES\nYES"
},
{
"input": "3 3 1 3\n2 3 7\n2 3 7\n1 2 6",
"output": "CAN 1\nCAN 1\nYES"
},
{
"input": "3 4 3 1\n2 1 4\n2 1 2\n3 2 1\n2 1 2",
"output": "CAN 3\nCAN 1\nYES\nCAN 1"
},
{
"input": "3 5 1 2\n1 3 3\n1 2 9\n3 2 6\n1 2 10\n1 3 3",
"output": "CAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1"
},
{
"input": "3 7 1 3\n1 3 11\n1 3 12\n1 2 2\n1 3 11\n1 2 2\n2 3 9\n2 3 9",
"output": "CAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 1"
},
{
"input": "5 7 3 2\n5 4 8\n3 1 2\n1 2 20\n1 5 8\n4 2 4\n1 5 8\n5 4 9",
"output": "CAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nCAN 2"
},
{
"input": "7 8 5 3\n4 3 5\n7 1 8\n2 1 16\n2 7 7\n2 6 21\n5 2 10\n6 4 4\n1 6 5",
"output": "YES\nYES\nCAN 2\nYES\nCAN 2\nYES\nYES\nYES"
},
{
"input": "6 8 1 6\n1 2 13\n3 2 3\n4 5 6\n1 6 28\n1 3 10\n1 4 18\n2 4 4\n5 6 4",
"output": "CAN 1\nCAN 1\nYES\nCAN 2\nCAN 1\nCAN 2\nYES\nYES"
},
{
"input": "7 10 4 7\n6 3 9\n2 1 4\n3 7 3\n5 2 6\n1 3 12\n5 2 6\n4 5 4\n4 5 3\n1 6 3\n4 6 16",
"output": "CAN 1\nCAN 1\nYES\nCAN 1\nCAN 1\nCAN 1\nCAN 2\nCAN 1\nCAN 1\nCAN 1"
},
{
"input": "10 13 2 10\n7 3 5\n6 1 10\n9 6 4\n4 10 48\n9 5 2\n1 10 3\n5 6 2\n7 6 19\n4 8 8\n2 4 8\n8 7 7\n7 6 20\n3 9 10",
"output": "CAN 1\nYES\nCAN 1\nCAN 2\nCAN 1\nYES\nCAN 1\nCAN 1\nYES\nYES\nYES\nCAN 2\nCAN 1"
},
{
"input": "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 4 3",
"output": "NO\nNO\nNO\nCAN 1"
},
{
"input": "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "NO\nCAN 3\nCAN 3\nYES\nYES\nYES"
},
{
"input": "5 6 1 5\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "NO\nCAN 3\nCAN 3\nYES\nYES\nYES"
},
{
"input": "2 1 1 2\n1 2 1",
"output": "YES"
},
{
"input": "3 3 1 3\n1 2 1\n1 3 2\n2 3 1",
"output": "NO\nCAN 1\nNO"
},
{
"input": "10 10 1 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "10 10 1 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "3 3 1 3\n1 2 1\n2 3 1\n1 3 2",
"output": "NO\nNO\nCAN 1"
},
{
"input": "6 7 1 6\n1 2 1000000\n2 3 1000000\n2 5 1000000\n1 3 1000000\n3 5 1000000\n2 4 1000000\n5 6 1000000",
"output": "CAN 1\nNO\nCAN 1\nCAN 1\nCAN 1\nNO\nYES"
},
{
"input": "2 1 1 2\n1 2 1000000",
"output": "YES"
},
{
"input": "2 2 1 2\n1 2 1000000\n1 2 1000000",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 2 1 2\n1 2 1000000\n1 2 1000000",
"output": "CAN 1\nCAN 1"
},
{
"input": "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000",
"output": "NO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO"
},
{
"input": "2 9 1 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 2\n1 2 1000000\n1 2 1000000\n1 2 1000000\n1 2 1000000",
"output": "CAN 999999\nCAN 999999\nCAN 999999\nCAN 999999\nYES\nCAN 999999\nCAN 999999\nCAN 999999\nCAN 999999"
},
{
"input": "3 2 1 3\n1 3 1\n1 2 1",
"output": "YES\nNO"
},
{
"input": "4 5 1 4\n1 2 1\n1 2 1\n2 3 1\n3 4 1\n3 4 1",
"output": "NO\nNO\nYES\nNO\nNO"
},
{
"input": "3 3 1 3\n1 2 666\n2 3 555\n3 1 1",
"output": "YES\nYES\nNO"
}
] | 1,692,445,539 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692445539.276827")# 1692445539.2768426 | Title: President and Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town *t*, for which his motorcade passes along some path from *s* to *t* (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from *s* to *t*, along which he will travel the fastest.
The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer.
Input Specification:
The first lines contain four integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=≠<=*t*).
Next *m* lines contain the roads. Each road is given as a group of three integers *a**i*,<=*b**i*,<=*l**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*l**i*<=≤<=106) — the cities that are connected by the *i*-th road and the time needed to ride along it. The road is directed from city *a**i* to city *b**i*.
The cities are numbered from 1 to *n*. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from *s* to *t* along the roads.
Output Specification:
Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the *i*-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.
If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes).
Demo Input:
['6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1\n', '3 3 1 3\n1 2 10\n2 3 10\n1 3 100\n', '2 2 1 2\n1 2 1\n1 2 2\n']
Demo Output:
['YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES\n', 'YES\nYES\nCAN 81\n', 'YES\nNO\n']
Note:
The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6. | ```python
print("_RANDOM_GUESS_1692445539.276827")# 1692445539.2768426
``` | 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,597,932,255 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | def lcm(x, y):
x, y = max(x, y), min(x, y)
for i in range(1, y+1):
if x*i%y==0:
return x*i
n, m, z = list(map(int, input().split()))
x = lcm(n, m)
print(z//x)
| 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
def lcm(x, y):
x, y = max(x, y), min(x, y)
for i in range(1, y+1):
if x*i%y==0:
return x*i
n, m, z = list(map(int, input().split()))
x = lcm(n, m)
print(z//x)
``` | 3 |
|
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7 3 9\n100",
"output": "10"
},
{
"input": "BSC\n100 1 1\n100 1 1\n100",
"output": "51"
},
{
"input": "SBBCCSBB\n1 50 100\n31 59 21\n100000",
"output": "370"
},
{
"input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800",
"output": "95502"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000",
"output": "1"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000",
"output": "42858"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358",
"output": "130594181"
},
{
"input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358",
"output": "647421579"
},
{
"input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587",
"output": "191668251"
},
{
"input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419",
"output": "140968956"
},
{
"input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314",
"output": "277425898"
},
{
"input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442",
"output": "217522127"
},
{
"input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273",
"output": "154164772"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575",
"output": "137826467"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575",
"output": "1355681897"
},
{
"input": "C\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000",
"output": "100000001"
},
{
"input": "B\n100 100 100\n1 1 1\n1",
"output": "101"
},
{
"input": "SC\n2 1 1\n1 1 1\n100000000000",
"output": "50000000001"
},
{
"input": "B\n100 1 1\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000",
"output": "100000000"
},
{
"input": "CC\n1 1 1\n100 100 100\n1",
"output": "0"
},
{
"input": "B\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1000000000000",
"output": "333333333433"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1",
"output": "100"
}
] | 1,686,428,349 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 |
import math
sandwich=input()
sand_dict={'B':0,'C':0,'S':0}
for s in sandwich:
sand_dict[s]+=1
has=input().split(' ')
has=[int(x) for x in has]
price=input().split(' ')
price=[int(x) for x in price]
money=int(input())
# money+=has[0]*price[0]*(1 if sand_dict['B']>0 else 0)+has[1]*price[1]*(1 if sand_dict['S']>0 else 0)+has[2]*price[2]*(1 if sand_dict['C']>0 else 0)
#print("money ",money)
# one_sand=sand_dict['B']*price[0]+sand_dict['S']*price[1]+sand_dict['C']*price[2]
#print("one_sand ",one_sand)
# print(math.floor(money/one_sand))
left=0
right=10**12
while(left<right):
mid=int((left+right)/2)
cost_req=0
cost_req=((mid*sand_dict['B']-has[0])*price[0] if mid*sand_dict['B']>has[0] else 0) + ((mid*sand_dict['S']-has[1])*price[1] if mid*sand_dict['S']>has[1] else 0) + ((mid*sand_dict['C']-has[2])*price[2] if mid*sand_dict['C']>has[2] else 0)
# if sand_dict['B']*mid>has[0]:
# cost_req+=(sand_dict['B']*mid-has[0])*price[0]
# if sand_dict['S']*mid>has[1]:
# cost_req+=(sand_dict['S']*mid-has[1])*price[1]
# if sand_dict['C']*mid>has[2]:
# cost_req+=(sand_dict['C']*mid-has[2])*price[2]
if cost_req > money:
right=mid-1
else:
res=mid
left=mid+1
print(mid)
| Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
Input Specification:
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
Demo Input:
['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n']
Demo Output:
['2\n', '7\n', '200000000001\n']
Note:
none | ```python
import math
sandwich=input()
sand_dict={'B':0,'C':0,'S':0}
for s in sandwich:
sand_dict[s]+=1
has=input().split(' ')
has=[int(x) for x in has]
price=input().split(' ')
price=[int(x) for x in price]
money=int(input())
# money+=has[0]*price[0]*(1 if sand_dict['B']>0 else 0)+has[1]*price[1]*(1 if sand_dict['S']>0 else 0)+has[2]*price[2]*(1 if sand_dict['C']>0 else 0)
#print("money ",money)
# one_sand=sand_dict['B']*price[0]+sand_dict['S']*price[1]+sand_dict['C']*price[2]
#print("one_sand ",one_sand)
# print(math.floor(money/one_sand))
left=0
right=10**12
while(left<right):
mid=int((left+right)/2)
cost_req=0
cost_req=((mid*sand_dict['B']-has[0])*price[0] if mid*sand_dict['B']>has[0] else 0) + ((mid*sand_dict['S']-has[1])*price[1] if mid*sand_dict['S']>has[1] else 0) + ((mid*sand_dict['C']-has[2])*price[2] if mid*sand_dict['C']>has[2] else 0)
# if sand_dict['B']*mid>has[0]:
# cost_req+=(sand_dict['B']*mid-has[0])*price[0]
# if sand_dict['S']*mid>has[1]:
# cost_req+=(sand_dict['S']*mid-has[1])*price[1]
# if sand_dict['C']*mid>has[2]:
# cost_req+=(sand_dict['C']*mid-has[2])*price[2]
if cost_req > money:
right=mid-1
else:
res=mid
left=mid+1
print(mid)
``` | 0 |
|
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him. | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt",
"output": "NO"
},
{
"input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos",
"output": "YES"
},
{
"input": "3\naaa\naaa\naaa",
"output": "NO"
},
{
"input": "3\naca\noec\nzba",
"output": "NO"
},
{
"input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "3\nxxx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxx\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxxx",
"output": "NO"
},
{
"input": "3\nxax\nxxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naaa\nxax",
"output": "NO"
},
{
"input": "3\naax\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxaa\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\naax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaa",
"output": "NO"
},
{
"input": "3\nxfx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\nafa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaf",
"output": "NO"
},
{
"input": "3\nxox\nxxx\nxxx",
"output": "NO"
},
{
"input": "3\naxa\naax\nxxa",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxox",
"output": "NO"
},
{
"input": "3\nxox\nooo\nxox",
"output": "NO"
},
{
"input": "3\naaa\naab\nbbb",
"output": "NO"
},
{
"input": "3\nxxx\nsxs\nxsx",
"output": "NO"
},
{
"input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba",
"output": "NO"
},
{
"input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba",
"output": "NO"
},
{
"input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxxx",
"output": "NO"
},
{
"input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox",
"output": "NO"
},
{
"input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox",
"output": "NO"
},
{
"input": "3\naaa\nbab\naba",
"output": "NO"
}
] | 1,693,401,425 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n = int(input())
the_list = []
for i in range(n):
the_list += [input()]
a = 0
for i in the_list:
if i[a] != the_list[0][0] or i[-(a + 1)] != the_list[0][0]:
print("NO")
exit(0)
a += 1
if the_list[0][1] != the_list[0][0]:
s = 0
for i in the_list:
s += i.count(the_list[0][1])
if s == (n * n) - (n * 2 - 1):
print("YES")
exit(0)
print("NO") | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Output Specification:
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
Demo Input:
['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
the_list = []
for i in range(n):
the_list += [input()]
a = 0
for i in the_list:
if i[a] != the_list[0][0] or i[-(a + 1)] != the_list[0][0]:
print("NO")
exit(0)
a += 1
if the_list[0][1] != the_list[0][0]:
s = 0
for i in the_list:
s += i.count(the_list[0][1])
if s == (n * n) - (n * 2 - 1):
print("YES")
exit(0)
print("NO")
``` | 3 |
|
453 | B | Little Pony and Harmony Chest | PROGRAMMING | 2,000 | [
"bitmasks",
"brute force",
"dp"
] | null | null | Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.
A sequence of positive integers *b**i* is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence *b**i* which minimizes the following expression:
You are given sequence *a**i*, help Princess Twilight to find the key. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements of the sequences *a* and *b*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=30). | Output the key — sequence *b**i* that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them. | [
"5\n1 1 1 1 1\n",
"5\n1 6 4 2 8\n"
] | [
"1 1 1 1 1 ",
"1 5 3 1 8 "
] | none | 1,000 | [
{
"input": "5\n1 1 1 1 1",
"output": "1 1 1 1 1 "
},
{
"input": "5\n1 6 4 2 8",
"output": "1 5 3 1 8 "
},
{
"input": "10\n16 3 16 10 12 5 14 14 15 27",
"output": "19 1 17 7 11 1 16 13 15 29 "
},
{
"input": "10\n8 7 11 5 17 24 28 18 7 8",
"output": "9 7 11 5 17 23 29 19 1 8 "
},
{
"input": "10\n22 17 28 14 14 26 20 28 21 27",
"output": "23 17 31 13 11 25 19 29 16 27 "
},
{
"input": "10\n28 13 14 9 26 21 25 16 4 22",
"output": "29 13 14 11 27 19 25 17 1 23 "
},
{
"input": "100\n11 27 18 3 26 1 23 2 28 21 28 18 7 26 13 4 12 11 1 29 9 23 6 27 15 6 26 25 11 21 26 29 29 8 18 29 3 24 2 28 7 7 11 23 26 29 30 18 30 23 17 24 25 12 16 26 2 4 30 2 19 2 27 16 17 21 30 17 10 8 16 7 1 3 27 22 23 28 16 9 15 28 10 15 26 8 20 6 21 12 24 16 13 7 12 8 23 16 29 24",
"output": "11 27 17 1 25 1 23 1 19 13 1 1 1 1 1 1 1 1 1 53 1 1 1 1 1 1 1 1 1 1 1 49 47 1 1 43 1 1 1 1 1 1 1 1 1 29 41 1 37 1 1 1 1 1 1 1 1 1 32 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "10\n26 25 10 6 28 11 23 22 8 23",
"output": "27 25 13 7 29 11 23 19 8 17 "
},
{
"input": "30\n24 11 1 17 15 11 12 8 6 25 22 23 9 3 30 3 10 28 15 8 4 28 3 28 26 14 24 1 6 19",
"output": "43 11 1 17 13 7 1 1 1 25 19 23 1 1 41 1 1 37 1 1 1 31 1 29 27 1 16 1 1 1 "
},
{
"input": "30\n11 20 1 17 6 20 22 16 20 22 21 8 3 28 30 2 27 14 10 14 29 21 13 3 13 27 11 18 2 15",
"output": "11 19 1 17 1 16 25 13 7 23 1 1 1 41 37 1 31 1 1 1 29 1 1 1 1 27 1 1 1 1 "
},
{
"input": "30\n17 16 18 4 3 22 28 4 4 17 9 30 2 11 29 12 8 17 9 12 13 11 13 18 28 17 10 12 14 20",
"output": "17 16 19 1 1 25 37 1 1 13 7 31 1 11 29 1 1 1 1 1 1 1 1 1 27 1 1 1 1 23 "
},
{
"input": "30\n9 26 5 7 29 17 19 22 1 28 5 6 9 8 13 9 3 4 16 16 11 24 22 20 12 9 16 22 2 11",
"output": "7 41 1 1 37 17 19 31 1 29 1 1 1 1 13 1 1 1 16 11 1 27 25 1 1 1 1 23 1 1 "
},
{
"input": "30\n15 1 29 2 20 5 3 2 15 17 1 28 9 20 26 5 28 7 7 7 26 15 23 14 19 23 15 19 23 8",
"output": "13 1 43 1 19 1 1 1 11 17 1 41 7 16 37 1 31 1 1 1 29 1 27 1 1 25 1 1 23 1 "
},
{
"input": "30\n15 3 16 26 17 7 8 6 29 12 27 4 16 25 10 2 9 24 6 19 10 12 23 15 3 7 13 13 27 6",
"output": "13 1 16 41 17 7 1 1 37 11 31 1 1 29 1 1 1 25 1 19 1 1 23 1 1 1 1 1 27 1 "
},
{
"input": "30\n21 13 3 13 22 2 30 16 26 23 22 3 7 7 23 20 13 13 13 10 24 25 10 9 2 13 20 24 23 3",
"output": "19 13 1 11 17 1 43 16 41 37 7 1 1 1 31 1 1 1 1 1 29 27 1 1 1 1 1 25 23 1 "
},
{
"input": "100\n17 7 25 13 9 17 18 17 29 7 9 25 26 3 18 25 21 14 21 21 27 30 30 24 29 30 2 14 17 17 8 19 6 20 11 9 19 21 20 25 21 11 29 26 22 8 1 30 27 20 10 16 20 10 17 2 14 21 18 15 19 6 26 8 15 19 20 8 1 23 10 11 30 14 9 9 17 9 11 22 13 5 19 26 9 10 3 9 6 24 26 27 6 14 9 24 20 13 14 23",
"output": "17 7 25 13 1 11 1 1 53 1 1 23 19 1 1 1 1 1 1 1 27 47 43 1 41 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 1 1 1 1 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n9 4 19 29 6 27 23 5 13 19 27 23 25 7 24 22 24 9 4 25 11 21 17 17 14 14 1 16 29 14 7 20 25 2 22 19 16 1 7 6 3 21 28 7 2 18 10 18 20 7 13 4 12 23 29 23 1 22 18 7 19 14 18 19 24 9 5 26 18 14 23 2 10 10 29 19 3 29 29 10 18 13 8 26 22 30 29 2 19 29 13 25 2 13 13 17 18 25 1 7",
"output": "1 1 19 53 1 27 23 1 13 17 25 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 43 1 1 41 37 1 1 1 1 1 1 32 31 1 1 29 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n15 6 12 24 10 29 15 23 27 22 9 15 24 4 15 19 5 4 11 24 17 4 18 11 20 6 29 13 11 11 6 21 7 30 24 29 5 18 8 1 1 22 10 4 20 28 28 30 27 10 24 8 5 11 5 22 3 22 9 13 11 1 25 14 10 22 3 22 28 11 19 29 19 6 19 20 3 10 18 20 1 7 11 18 14 6 3 1 26 5 30 22 5 25 18 26 8 23 26 29",
"output": "13 1 11 23 7 53 1 19 27 17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 1 1 1 1 1 1 43 1 41 1 1 1 1 1 1 1 1 1 25 1 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 29 "
},
{
"input": "100\n15 2 7 11 7 24 21 19 2 3 5 20 2 25 21 7 8 29 10 14 23 17 18 5 5 4 28 7 29 24 27 14 4 12 13 23 10 28 10 29 28 1 1 1 17 22 16 4 4 28 13 4 5 1 3 5 4 23 25 13 10 2 25 1 20 5 2 24 15 2 9 20 15 16 22 13 4 22 29 8 7 15 23 18 13 12 7 24 25 2 17 20 1 8 22 3 28 4 21 29",
"output": "13 1 7 11 1 23 19 17 1 1 1 1 1 25 1 1 1 53 1 1 1 1 1 1 1 1 47 1 43 1 27 1 1 1 1 1 1 41 1 37 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 31 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 29 "
},
{
"input": "100\n26 9 21 8 11 14 9 17 4 18 24 30 19 10 6 13 3 5 1 16 21 5 22 18 26 24 13 8 1 27 18 4 30 7 10 2 3 26 24 4 20 28 20 17 29 13 25 11 4 18 26 20 16 24 13 16 21 30 7 13 24 16 1 20 1 1 24 6 20 7 27 22 8 19 13 17 9 3 4 19 22 12 21 13 8 30 22 22 4 24 30 13 13 21 26 10 29 24 7 12",
"output": "25 7 19 1 11 13 1 17 1 1 23 53 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 27 1 1 47 1 1 1 1 1 1 1 1 43 1 1 41 1 1 1 1 1 1 1 1 1 1 1 1 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 32 1 1 1 1 31 1 1 1 1 1 29 1 1 1 "
},
{
"input": "100\n30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30",
"output": "53 49 47 43 41 37 32 31 29 27 25 23 19 17 13 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "1\n30",
"output": "30 "
},
{
"input": "30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "15\n2 2 2 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\n6",
"output": "6 "
},
{
"input": "3\n2 2 15",
"output": "2 1 15 "
}
] | 1,599,209,766 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 4,000 | 11,673,600 | def optimal_seq(A):
def is_valid(number):
for factor in factors[number]:
if factor in used:
return False
return True
def mark_factors(number):
nonlocal used
for prime_factor in factors[number]:
used.add(prime_factor)
def unmark_factors(number):
nonlocal used
for prime_factor in factors[number]:
used.remove(prime_factor)
def propagate(A, i, b, d):
nonlocal curr_min, curr_seq
mark_factors(b)
curr_seq.append(b)
curr_min += d
backtracker(A, i + 1)
unmark_factors(b)
curr_seq.pop()
curr_min -= d
def backtracker(A, i = 0):
nonlocal global_min, global_seq
if i == len(A):
if not global_seq or curr_min < global_min:
global_min = curr_min
global_seq = curr_seq[:]
else:
if is_valid(A[i]):
propagate(A, i, A[i], 0)
for d in range(1, 30):
if curr_min + d >= global_min:
return
b = A[i] - d
if b > 0:
if is_valid(b):
propagate(A, i, b, d)
else:
return
b = A[i] + d
if is_valid(b):
propagate(A, i, b, d)
global_min = 3000
global_seq = []
curr_min = 0
curr_seq = []
used = set()
primes = []
factors = [[] for _ in range(60)]
for number in range(2, 60):
if not factors[number]:
primes.append(number)
for multiple in range(number, 60, number):
factors[multiple].append(number)
new_A = sorted(A)
initial_seq = [1] * (max(0, len(A) - len(primes))) + primes[:min(len(A), len(primes))]
initial_min = 0
for a, b in zip(new_A, initial_seq):
initial_min += min(abs(a - b), (a - 1))
global_min = initial_min
backtracker(A)
return global_seq
n = int(input())
A = list(map(int, input().split()))
print(*optimal_seq(A))
| Title: Little Pony and Harmony Chest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.
A sequence of positive integers *b**i* is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence *b**i* which minimizes the following expression:
You are given sequence *a**i*, help Princess Twilight to find the key.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements of the sequences *a* and *b*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=30).
Output Specification:
Output the key — sequence *b**i* that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.
Demo Input:
['5\n1 1 1 1 1\n', '5\n1 6 4 2 8\n']
Demo Output:
['1 1 1 1 1 ', '1 5 3 1 8 ']
Note:
none | ```python
def optimal_seq(A):
def is_valid(number):
for factor in factors[number]:
if factor in used:
return False
return True
def mark_factors(number):
nonlocal used
for prime_factor in factors[number]:
used.add(prime_factor)
def unmark_factors(number):
nonlocal used
for prime_factor in factors[number]:
used.remove(prime_factor)
def propagate(A, i, b, d):
nonlocal curr_min, curr_seq
mark_factors(b)
curr_seq.append(b)
curr_min += d
backtracker(A, i + 1)
unmark_factors(b)
curr_seq.pop()
curr_min -= d
def backtracker(A, i = 0):
nonlocal global_min, global_seq
if i == len(A):
if not global_seq or curr_min < global_min:
global_min = curr_min
global_seq = curr_seq[:]
else:
if is_valid(A[i]):
propagate(A, i, A[i], 0)
for d in range(1, 30):
if curr_min + d >= global_min:
return
b = A[i] - d
if b > 0:
if is_valid(b):
propagate(A, i, b, d)
else:
return
b = A[i] + d
if is_valid(b):
propagate(A, i, b, d)
global_min = 3000
global_seq = []
curr_min = 0
curr_seq = []
used = set()
primes = []
factors = [[] for _ in range(60)]
for number in range(2, 60):
if not factors[number]:
primes.append(number)
for multiple in range(number, 60, number):
factors[multiple].append(number)
new_A = sorted(A)
initial_seq = [1] * (max(0, len(A) - len(primes))) + primes[:min(len(A), len(primes))]
initial_min = 0
for a, b in zip(new_A, initial_seq):
initial_min += min(abs(a - b), (a - 1))
global_min = initial_min
backtracker(A)
return global_seq
n = int(input())
A = list(map(int, input().split()))
print(*optimal_seq(A))
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,675,434,128 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
for i in range(n):
w = input()
s = len(w)
if s > 10:
print(w[0] + str(s - 2) + w[s-1])
else:
print(w) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n = int(input())
for i in range(n):
w = input()
s = len(w)
if s > 10:
print(w[0] + str(s - 2) + w[s-1])
else:
print(w)
``` | 3.977 |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt? | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
"input": "100 1000000000 20",
"output": "10000034"
},
{
"input": "1000 1000 994",
"output": "1"
},
{
"input": "100000000 200000000 54345",
"output": "10001"
},
{
"input": "1000000000 1000000000 1",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 500000000",
"output": "1"
},
{
"input": "1000 1000 3",
"output": "1"
},
{
"input": "100000000 200020000 54345",
"output": "10001"
},
{
"input": "100 108037 18",
"output": "1115"
},
{
"input": "100000000 200020001 54345",
"output": "10002"
},
{
"input": "200 6585 2",
"output": "112"
},
{
"input": "30000 30593 5980",
"output": "25"
},
{
"input": "40000 42107 10555",
"output": "46"
},
{
"input": "50003 50921 192",
"output": "31"
},
{
"input": "100000 113611 24910",
"output": "117"
},
{
"input": "1000000 483447163 83104",
"output": "21965"
},
{
"input": "10000000 10021505 600076",
"output": "147"
},
{
"input": "100000000 102144805 2091145",
"output": "1465"
},
{
"input": "1000000000 1000000000 481982093",
"output": "1"
},
{
"input": "100 999973325 5",
"output": "9999778"
},
{
"input": "200 999999109 61",
"output": "5000053"
},
{
"input": "30000 999999384 5488",
"output": "43849"
},
{
"input": "40000 999997662 8976",
"output": "38038"
},
{
"input": "50003 999999649 405",
"output": "44320"
},
{
"input": "100000 999899822 30885",
"output": "31624"
},
{
"input": "1000000 914032367 528790",
"output": "30217"
},
{
"input": "10000000 999617465 673112",
"output": "31459"
},
{
"input": "100000000 993180275 362942",
"output": "29887"
},
{
"input": "1000000000 1000000000 331431458",
"output": "1"
},
{
"input": "100 10466 89",
"output": "144"
},
{
"input": "200 5701 172",
"output": "84"
},
{
"input": "30000 36932 29126",
"output": "84"
},
{
"input": "40000 40771 22564",
"output": "28"
},
{
"input": "50003 51705 49898",
"output": "42"
},
{
"input": "100000 149408 74707",
"output": "223"
},
{
"input": "1000000 194818222 998601",
"output": "18389"
},
{
"input": "10000000 10748901 8882081",
"output": "866"
},
{
"input": "100000000 106296029 98572386",
"output": "2510"
},
{
"input": "1000000000 1000000000 193988157",
"output": "1"
},
{
"input": "100 999981057 92",
"output": "9999852"
},
{
"input": "200 999989691 199",
"output": "5000046"
},
{
"input": "30000 999995411 24509",
"output": "43846"
},
{
"input": "40000 999998466 30827",
"output": "37930"
},
{
"input": "50003 999997857 48387",
"output": "43163"
},
{
"input": "100000 999731886 98615",
"output": "43371"
},
{
"input": "1000000 523220797 654341",
"output": "22853"
},
{
"input": "10000000 999922591 8157724",
"output": "31464"
},
{
"input": "100000000 999834114 93836827",
"output": "29998"
},
{
"input": "1000000000 1000000000 912549504",
"output": "1"
},
{
"input": "1000 97654978 234",
"output": "97976"
},
{
"input": "1000 97654977 234",
"output": "97975"
},
{
"input": "1000234 97653889 1",
"output": "13903"
},
{
"input": "1000234 97653890 1",
"output": "13904"
},
{
"input": "3450234 97656670 3000000",
"output": "9707"
},
{
"input": "3450234 97656669 3000000",
"output": "9706"
},
{
"input": "3 1000000000 2",
"output": "333333334"
},
{
"input": "2 1000000000 1",
"output": "500000000"
},
{
"input": "2 1000000000 2",
"output": "500000000"
},
{
"input": "3 1000000000 1",
"output": "333333334"
},
{
"input": "3 1000000000 3",
"output": "333333334"
},
{
"input": "2 999999999 1",
"output": "500000000"
},
{
"input": "2 999999999 2",
"output": "500000000"
},
{
"input": "1 999999999 1",
"output": "999999999"
}
] | 1,485,115,854 | 6,954 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 62 | 5,120,000 | import re
import math
entrada = input()
match = re.search('(\d*) (\d*) (\d*)', entrada)
n = int(match.group(1)) # hobbits
m = int(match.group(2)) # Almofadas
k = int(match.group(3))-1 # Posicao
pretotal = m//n
if m%n == 0:
print(pretotal+((m-pretotal*n)%n//2)+1)
else:
print(pretotal+((m-pretotal*n)%n//2)) | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the *k*-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input Specification:
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Output Specification:
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
Demo Input:
['4 6 2\n', '3 10 3\n', '3 6 1\n']
Demo Output:
['2\n', '4\n', '3\n']
Note:
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | ```python
import re
import math
entrada = input()
match = re.search('(\d*) (\d*) (\d*)', entrada)
n = int(match.group(1)) # hobbits
m = int(match.group(2)) # Almofadas
k = int(match.group(3))-1 # Posicao
pretotal = m//n
if m%n == 0:
print(pretotal+((m-pretotal*n)%n//2)+1)
else:
print(pretotal+((m-pretotal*n)%n//2))
``` | 0 |
|
617 | D | Polyline | PROGRAMMING | 1,700 | [
"constructive algorithms",
"implementation"
] | null | null | There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of. | Each of the three lines of the input contains two integers. The *i*-th line contains integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th point. It is guaranteed that all points are distinct. | Print a single number — the minimum possible number of segments of the polyline. | [
"1 -1\n1 1\n1 2\n",
"-1 -1\n-1 3\n4 3\n",
"1 1\n2 3\n3 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | The variant of the polyline in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/b41b4dad8437bd7a69f6ab01eaedf010b82ba7b8.png" style="max-width: 100.0%;max-height: 100.0%;"/> The variant of the polyline in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/7410d2247b3381e5b27422609f90ff027e071812.png" style="max-width: 100.0%;max-height: 100.0%;"/> The variant of the polyline in the third sample: <img class="tex-graphics" src="https://espresso.codeforces.com/3a5018422eb982f0a2a9bd7f1fd7ab23777a0813.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,750 | [
{
"input": "1 -1\n1 1\n1 2",
"output": "1"
},
{
"input": "-1 -1\n-1 3\n4 3",
"output": "2"
},
{
"input": "1 1\n2 3\n3 2",
"output": "3"
},
{
"input": "1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000",
"output": "2"
},
{
"input": "-510073119 -991063686\n583272581 -991063686\n623462417 -991063686",
"output": "1"
},
{
"input": "-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611",
"output": "2"
},
{
"input": "127447697 -311048187\n-644646254 135095006\n127447697 135095006",
"output": "2"
},
{
"input": "-609937696 436598127\n-189924209 241399893\n-883780251 296798182",
"output": "3"
},
{
"input": "-931665727 768789996\n234859675 808326671\n-931665727 879145023",
"output": "3"
},
{
"input": "899431605 238425805\n899431605 339067352\n940909482 333612216",
"output": "3"
},
{
"input": "143495802 -137905447\n-922193757 -660311216\n-922193757 659147504",
"output": "3"
},
{
"input": "-759091260 362077211\n-759091260 123892252\n-79714253 226333388",
"output": "3"
},
{
"input": "-495060442 -389175621\n79351129 -146107545\n-495060442 59059286",
"output": "3"
},
{
"input": "-485581506 973584319\n-762068259 670458753\n-485581506 -661338021",
"output": "3"
},
{
"input": "-865523810 66779936\n-865523810 879328244\n551305309 495319633",
"output": "3"
},
{
"input": "-985816934 85994062\n490801388 171721095\n-985816934 265995176",
"output": "3"
},
{
"input": "-322848128 276304614\n-228010033 -361111909\n-137761352 276304614",
"output": "3"
},
{
"input": "648743183 -329867260\n680098341 -988370978\n594847608 -988370978",
"output": "3"
},
{
"input": "-636111887 -755135651\n-411477790 -755135651\n-540985255 -808506689",
"output": "3"
},
{
"input": "-280166733 -215262264\n-257537874 640677716\n-288509263 640677716",
"output": "3"
},
{
"input": "158219297 -796751401\n464911767 780525998\n25054022 780525998",
"output": "3"
},
{
"input": "-76151678 894169660\n125930178 -434000890\n259457432 894169660",
"output": "3"
},
{
"input": "403402592 55070913\n-703565711 55070913\n-141194091 -66977045",
"output": "3"
},
{
"input": "-485970125 725016060\n-972748484 -602121312\n183987969 -602121312",
"output": "3"
},
{
"input": "-494824697 -964138793\n-494824697 671151995\n-24543485 877798954",
"output": "2"
},
{
"input": "-504439520 685616264\n-575788481 178485261\n-575788481 -998856787",
"output": "2"
},
{
"input": "446038601 -598441655\n446038601 -781335731\n-446725217 -862937359",
"output": "2"
},
{
"input": "443336387 317738308\n-731455437 682073969\n443336387 -487472781",
"output": "2"
},
{
"input": "-954908844 156002304\n-954908844 507051490\n-377680300 878914758",
"output": "2"
},
{
"input": "437180709 -829478932\n-775395571 -605325538\n-775395571 298582830",
"output": "2"
},
{
"input": "791725263 -592101263\n791725263 -401786481\n953501658 -699705540",
"output": "2"
},
{
"input": "621619191 -223521454\n621619191 -746436580\n-886355353 -920817120",
"output": "2"
},
{
"input": "353770247 742032246\n391091420 742032246\n113505964 105784687",
"output": "2"
},
{
"input": "-386452587 -689699105\n-51244121 425743943\n736584134 425743943",
"output": "2"
},
{
"input": "-354329375 -222798859\n-636793392 28344958\n989602966 -222798859",
"output": "2"
},
{
"input": "439039590 -419754858\n-16966935 -979701468\n276072230 -979701468",
"output": "2"
},
{
"input": "-160622039 260994846\n-981120537 -453711571\n-899331084 260994846",
"output": "2"
},
{
"input": "755966021 -977934315\n-693932164 -977934315\n780740735 341305212",
"output": "2"
},
{
"input": "997183648 -430699196\n555277138 -34246328\n962365828 -34246328",
"output": "2"
},
{
"input": "394482565 -5842724\n-120921456 -5842724\n474336847 -666083693",
"output": "2"
},
{
"input": "451140644 -552066345\n451140644 97091285\n643901618 -552066345",
"output": "2"
},
{
"input": "-397991545 510063044\n347795937 510063044\n-397991545 944965447",
"output": "2"
},
{
"input": "361702696 891912906\n742864513 891912906\n361702696 616808838",
"output": "2"
},
{
"input": "950548287 766404840\n995400182 976310818\n950548287 976310818",
"output": "2"
},
{
"input": "512806478 -76305905\n51445888 -189759697\n512806478 -189759697",
"output": "2"
},
{
"input": "134061442 -132620069\n-215253638 -132620069\n134061442 112298311",
"output": "2"
},
{
"input": "-225194635 772128906\n-9640584 -636384130\n-9640584 772128906",
"output": "2"
},
{
"input": "976530519 -932140580\n418643692 -845327922\n976530519 -845327922",
"output": "2"
},
{
"input": "-960958311 -757098377\n-960958311 -153001649\n-960958311 567188828",
"output": "1"
},
{
"input": "487214658 518775922\n487214658 -869675495\n487214658 -106351878",
"output": "1"
},
{
"input": "58011742 175214671\n-853914900 175214671\n-245334045 175214671",
"output": "1"
},
{
"input": "306134424 46417066\n-503106271 46417066\n-286564055 46417066",
"output": "1"
},
{
"input": "150098962 830455428\n-70279563 -160635038\n-721135733 -627254059",
"output": "3"
},
{
"input": "-664035427 -710202693\n527339005 -8499215\n414350757 -966228511",
"output": "3"
}
] | 1,695,450,453 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 62 | 0 | def mid(a,b,c):
return c>=max(a,b) or c<=min(a,b)
x1,y1=list(map(int,input().split()))
x2,y2=list(map(int,input().split()))
x3,y3=list(map(int,input().split()))
if x1==x2==x3 or y1==y2==y3:
print(1)
else:
# if x1==x2 and (y1==y3 or y2==y3):
# print(2)
# elif x1==x3 and (y1==y2 or y2==y3):
# print(2)
# elif x3==x2 and (y1==y2 or y1==y3):
# print(2)
# elif y1==y2 and (x1==x3 or x2==x3):
# print(2)
# elif y1==y3 and (x1==x2 or x2==x3):
# print(2)
# elif y3==y2 and (x1==x2 or x1==x3):
# print(2)
if x1==x2 and mid(y1,y2,y3):
print(2)
elif x3==x2 and mid(y2,y3,y1):
print(2)
elif x1==x3 and mid(y1,y3,y2):
print(2)
elif y1==y2 and mid(x1,x2,x3):
print(2)
elif y3==y2 and mid(x2,x3,x1):
print(2)
elif y1==y3 and mid(x1,x3,x2):
print(2)
else:
print(3) | Title: Polyline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.
Input Specification:
Each of the three lines of the input contains two integers. The *i*-th line contains integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the coordinates of the *i*-th point. It is guaranteed that all points are distinct.
Output Specification:
Print a single number — the minimum possible number of segments of the polyline.
Demo Input:
['1 -1\n1 1\n1 2\n', '-1 -1\n-1 3\n4 3\n', '1 1\n2 3\n3 2\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
The variant of the polyline in the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/b41b4dad8437bd7a69f6ab01eaedf010b82ba7b8.png" style="max-width: 100.0%;max-height: 100.0%;"/> The variant of the polyline in the second sample: <img class="tex-graphics" src="https://espresso.codeforces.com/7410d2247b3381e5b27422609f90ff027e071812.png" style="max-width: 100.0%;max-height: 100.0%;"/> The variant of the polyline in the third sample: <img class="tex-graphics" src="https://espresso.codeforces.com/3a5018422eb982f0a2a9bd7f1fd7ab23777a0813.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
def mid(a,b,c):
return c>=max(a,b) or c<=min(a,b)
x1,y1=list(map(int,input().split()))
x2,y2=list(map(int,input().split()))
x3,y3=list(map(int,input().split()))
if x1==x2==x3 or y1==y2==y3:
print(1)
else:
# if x1==x2 and (y1==y3 or y2==y3):
# print(2)
# elif x1==x3 and (y1==y2 or y2==y3):
# print(2)
# elif x3==x2 and (y1==y2 or y1==y3):
# print(2)
# elif y1==y2 and (x1==x3 or x2==x3):
# print(2)
# elif y1==y3 and (x1==x2 or x2==x3):
# print(2)
# elif y3==y2 and (x1==x2 or x1==x3):
# print(2)
if x1==x2 and mid(y1,y2,y3):
print(2)
elif x3==x2 and mid(y2,y3,y1):
print(2)
elif x1==x3 and mid(y1,y3,y2):
print(2)
elif y1==y2 and mid(x1,x2,x3):
print(2)
elif y3==y2 and mid(x2,x3,x1):
print(2)
elif y1==y3 and mid(x1,x3,x2):
print(2)
else:
print(3)
``` | 3 |
|
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,551,182,703 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 218 | 0 | def main():
bags = int(input())
if bags < 1 or bags > 100:
return 0
string = input()
string = string.split(" ")
if len(string) < 1 or len(string) != bags:
return 0
imp = 0
par = 0
soma = 0
for i in range(bags):
soma += int(string[i])
if int(string[i]) % 2 == 0:
par += 1
else:
imp += 1
if soma % 2 == 0:
print(par)
else:
print(imp)
return
main() | 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
def main():
bags = int(input())
if bags < 1 or bags > 100:
return 0
string = input()
string = string.split(" ")
if len(string) < 1 or len(string) != bags:
return 0
imp = 0
par = 0
soma = 0
for i in range(bags):
soma += int(string[i])
if int(string[i]) % 2 == 0:
par += 1
else:
imp += 1
if soma % 2 == 0:
print(par)
else:
print(imp)
return
main()
``` | 3 |
|
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,685,173,563 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x = int(input())
list_of_digits=[]
while x > 0:
list_of_digits.append(x%10)
x = x//10
final_list=[]
for i in list_of_digits:
if i>=5:
final_list.append(9-i)
else:
final_list.append(i)
final_list.reverse()
final_value=0
for i in final_list:
final_value = final_value*10 + i
print(final_value)
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none | ```python
x = int(input())
list_of_digits=[]
while x > 0:
list_of_digits.append(x%10)
x = x//10
final_list=[]
for i in list_of_digits:
if i>=5:
final_list.append(9-i)
else:
final_list.append(i)
final_list.reverse()
final_value=0
for i in final_list:
final_value = final_value*10 + i
print(final_value)
``` | 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,675,957,809 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | import sys
input = sys.stdin.readline
output = sys.stdout.write
def main():
word = input().rstrip()
translated = input().rstrip()
state = True
l = len(word)
r = len(translated)
if l != r:
output('NO')
else:
for i in range(l):
if word[i] == translated[l - i -1]:
continue
else:
state = False
break
if state:
output('YES')
else:
output('NO')
if __name__ == '__main__':
main()
| 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
import sys
input = sys.stdin.readline
output = sys.stdout.write
def main():
word = input().rstrip()
translated = input().rstrip()
state = True
l = len(word)
r = len(translated)
if l != r:
output('NO')
else:
for i in range(l):
if word[i] == translated[l - i -1]:
continue
else:
state = False
break
if state:
output('YES')
else:
output('NO')
if __name__ == '__main__':
main()
``` | 3.977 |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992",
"output": "42"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "6\n5 4 3 2 1 2",
"output": "2"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "7\n99 100 1 2 3 4 5",
"output": "5"
},
{
"input": "5\n3 3 1 2 3",
"output": "3"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,693,828,289 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n = int(input())
l = list(map(int, input().split()))
c = 0
max_difference = 0
last_peak_index = 0
for i in range(1, n):
if l[i - 1] > l[i]:
last_peak_index = i - 1
max_difference = max(max_difference, i - last_peak_index)
print(max_difference)
| Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
Demo Input:
['6\n2 2 1 3 4 1\n', '3\n2 2 9\n']
Demo Output:
['3', '3']
Note:
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | ```python
n = int(input())
l = list(map(int, input().split()))
c = 0
max_difference = 0
last_peak_index = 0
for i in range(1, n):
if l[i - 1] > l[i]:
last_peak_index = i - 1
max_difference = max(max_difference, i - last_peak_index)
print(max_difference)
``` | 0 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,685,400,195 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | l = input().split(' ')
n, m, count = int(l[0]), int(l[1]), 0
for i in range(10000):
p = pow(i, 2)
if i + pow(n-p, 2) == m and n - p >= 0:
count += 1
print(count) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
l = input().split(' ')
n, m, count = int(l[0]), int(l[1]), 0
for i in range(10000):
p = pow(i, 2)
if i + pow(n-p, 2) == m and n - p >= 0:
count += 1
print(count)
``` | 3 |
|
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 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0",
"output": "51"
},
{
"input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1",
"output": "16"
},
{
"input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1",
"output": "11"
},
{
"input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1",
"output": "56"
},
{
"input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0",
"output": "17"
},
{
"input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3",
"output": "9"
},
{
"input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0",
"output": "54"
},
{
"input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3",
"output": "19"
},
{
"input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3",
"output": "9"
},
{
"input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1",
"output": "57"
},
{
"input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1",
"output": "17"
},
{
"input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2",
"output": "9"
},
{
"input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1",
"output": "61"
},
{
"input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2",
"output": "15"
},
{
"input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2",
"output": "14"
},
{
"input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2",
"output": "63"
},
{
"input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3",
"output": "15"
},
{
"input": "100\n1 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 2",
"output": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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,688,728,458 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 108 | 1,740,800 | n=int(input())
a=list(map(int,input().split()))
import functools
@functools.lru_cache(maxsize=None)
def dp(i,state):
if i==n:
return 0
if state==0:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return min(1+dp(i+1,0),dp(i+1,1))
elif a[i]==2:
return min(1+dp(i+1,0),dp(i+1,2))
else:
return min(1+dp(i+1,0),dp(i+1,1),dp(i+1,2))
elif state==1:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return (1+dp(i+1,0))
elif a[i]==2:
return min(1+dp(i+1,0),dp(i+1,2))
else:
return min(1+dp(i+1,0),dp(i+1,2))
elif state==2:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return min(1+dp(i+1,0),dp(i+1,1))
elif a[i]==2:
return (1+dp(i+1,0))
else:
return min(1+dp(i+1,0),dp(i+1,1))
else:
return 1+dp(i+1,0)
print(dp(0,0))
| 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())
a=list(map(int,input().split()))
import functools
@functools.lru_cache(maxsize=None)
def dp(i,state):
if i==n:
return 0
if state==0:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return min(1+dp(i+1,0),dp(i+1,1))
elif a[i]==2:
return min(1+dp(i+1,0),dp(i+1,2))
else:
return min(1+dp(i+1,0),dp(i+1,1),dp(i+1,2))
elif state==1:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return (1+dp(i+1,0))
elif a[i]==2:
return min(1+dp(i+1,0),dp(i+1,2))
else:
return min(1+dp(i+1,0),dp(i+1,2))
elif state==2:
if a[i]==0:
return 1+dp(i+1,0)
elif a[i]==1:
return min(1+dp(i+1,0),dp(i+1,1))
elif a[i]==2:
return (1+dp(i+1,0))
else:
return min(1+dp(i+1,0),dp(i+1,1))
else:
return 1+dp(i+1,0)
print(dp(0,0))
``` | 3 |
|
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,697,362,127 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | input_list = list(map(int, input().split()))
a, b, c = input_list
diff1 = abs(abs(a-b) - abs(a-c))
diff3 = abs(abs(b-a) - abs(b-c))
diff5 = abs(abs(c-a) - abs(c-b))
if diff1 <= diff3 and diff1 <= diff5:
print(abs(a-b) + abs(a-c))
elif diff3 <= diff1 and diff3 <= diff5:
print(abs(b-a) + abs(b-c))
else:
print(abs(c-a) + abs(c-b))
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
input_list = list(map(int, input().split()))
a, b, c = input_list
diff1 = abs(abs(a-b) - abs(a-c))
diff3 = abs(abs(b-a) - abs(b-c))
diff5 = abs(abs(c-a) - abs(c-b))
if diff1 <= diff3 and diff1 <= diff5:
print(abs(a-b) + abs(a-c))
elif diff3 <= diff1 and diff3 <= diff5:
print(abs(b-a) + abs(b-c))
else:
print(abs(c-a) + abs(c-b))
``` | 0 |
|
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"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 1 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 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 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 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "83"
},
{
"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 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "74"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "52"
},
{
"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 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 1,629,640,559 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 20,172,800 | n=int(input())
l=list(map(int,input().split()))
a=[0];b=[0];ans=0;t1=0;t2=0
for i in range(len(l)-1):
if l[i]<=l[i+1]:
t1+=1
a.append(t1)
else :
a.append(0)
t1=0
for j in range(len(l)-1,0,-1):
if l[j]<l[j-1]:
t2+=1
b.append(t2)
else :
b.append(0)
t2=0
# print(a)
# print(b)
for i in range(n-1):
ans=max(a[i]+b[i]+1,ans)
print(ans) | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output Specification:
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Demo Input:
['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split()))
a=[0];b=[0];ans=0;t1=0;t2=0
for i in range(len(l)-1):
if l[i]<=l[i+1]:
t1+=1
a.append(t1)
else :
a.append(0)
t1=0
for j in range(len(l)-1,0,-1):
if l[j]<l[j-1]:
t2+=1
b.append(t2)
else :
b.append(0)
t2=0
# print(a)
# print(b)
for i in range(n-1):
ans=max(a[i]+b[i]+1,ans)
print(ans)
``` | 0 |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors. | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors. | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,697,286,909 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 102,400 | class SegmentTree:
def __init__(self, n, arr):
self.n = n
self.tree = [0] * (4 * n)
self.lazy = [0] * (4 * n)
self.build(1, 0, n - 1, arr)
def build(self, v, tl, tr, arr):
if tl == tr:
self.tree[v] = arr[tl]
else:
tm = (tl + tr) // 2
self.build(2 * v, tl, tm, arr)
self.build(2 * v + 1, tm + 1, tr, arr)
self.tree[v] = self.tree[2 * v] + self.tree[2 * v + 1]
def update(self, v, tl, tr, l, r, x):
if l > r:
return
if l == tl and r == tr:
self.tree[v] -= x
self.lazy[v] += x
else:
tm = (tl + tr) // 2
self.push(v)
self.update(2 * v, tl, tm, l, min(r, tm), x)
self.update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x)
self.tree[v] = self.tree[2 * v] + self.tree[2 * v + 1]
def query(self, v, tl, tr, l, r):
if l > r:
return 0
if l == tl and r == tr:
return self.tree[v]
tm = (tl + tr) // 2
self.push(v)
left = self.query(2 * v, tl, tm, l, min(r, tm))
right = self.query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r)
return left + right
def push(self, v):
self.tree[2 * v] -= self.lazy[v]
self.tree[2 * v + 1] -= self.lazy[v]
self.lazy[2 * v] += self.lazy[v]
self.lazy[2 * v + 1] += self.lazy[v]
self.lazy[v] = 0
n, q = map(int, input().split())
warriors = list(map(int, input().split()))
attacks = list(map(int, input().split()))
tree = SegmentTree(n, warriors)
for i in range(q):
arrows = attacks[i]
standing_warriors = tree.query(1, 0, n - 1, 0, n - 1)
if arrows >= standing_warriors:
tree.update(1, 0, n - 1, 0, n - 1, standing_warriors)
else:
left, right = 0, n - 1
while left < right:
mid = (left + right) // 2
if tree.query(1, 0, n - 1, mid, mid) <= arrows:
left = mid + 1
else:
right = mid
tree.update(1, 0, n - 1, left, n - 1, arrows)
print(standing_warriors)
| Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | ```python
class SegmentTree:
def __init__(self, n, arr):
self.n = n
self.tree = [0] * (4 * n)
self.lazy = [0] * (4 * n)
self.build(1, 0, n - 1, arr)
def build(self, v, tl, tr, arr):
if tl == tr:
self.tree[v] = arr[tl]
else:
tm = (tl + tr) // 2
self.build(2 * v, tl, tm, arr)
self.build(2 * v + 1, tm + 1, tr, arr)
self.tree[v] = self.tree[2 * v] + self.tree[2 * v + 1]
def update(self, v, tl, tr, l, r, x):
if l > r:
return
if l == tl and r == tr:
self.tree[v] -= x
self.lazy[v] += x
else:
tm = (tl + tr) // 2
self.push(v)
self.update(2 * v, tl, tm, l, min(r, tm), x)
self.update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x)
self.tree[v] = self.tree[2 * v] + self.tree[2 * v + 1]
def query(self, v, tl, tr, l, r):
if l > r:
return 0
if l == tl and r == tr:
return self.tree[v]
tm = (tl + tr) // 2
self.push(v)
left = self.query(2 * v, tl, tm, l, min(r, tm))
right = self.query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r)
return left + right
def push(self, v):
self.tree[2 * v] -= self.lazy[v]
self.tree[2 * v + 1] -= self.lazy[v]
self.lazy[2 * v] += self.lazy[v]
self.lazy[2 * v + 1] += self.lazy[v]
self.lazy[v] = 0
n, q = map(int, input().split())
warriors = list(map(int, input().split()))
attacks = list(map(int, input().split()))
tree = SegmentTree(n, warriors)
for i in range(q):
arrows = attacks[i]
standing_warriors = tree.query(1, 0, n - 1, 0, n - 1)
if arrows >= standing_warriors:
tree.update(1, 0, n - 1, 0, n - 1, standing_warriors)
else:
left, right = 0, n - 1
while left < right:
mid = (left + right) // 2
if tree.query(1, 0, n - 1, mid, mid) <= arrows:
left = mid + 1
else:
right = mid
tree.update(1, 0, n - 1, left, n - 1, arrows)
print(standing_warriors)
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,682,745,536 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
word=[]
selected=[]
ss=[]
for i in range(0, n):
w=input()
word.append(w)
for i in range(0, n):
counter = 0
for j in word[i]:
counter+=1
if (counter>10):
selected.append(word[i][0])
selected.append((counter-2))
selected.append(word[i][counter-1])
for I in range(0,len(selected)):
print(selected[I], end="")
selected.clear()
print()
elif (counter<=12):
print(word[i])
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n = int(input())
word=[]
selected=[]
ss=[]
for i in range(0, n):
w=input()
word.append(w)
for i in range(0, n):
counter = 0
for j in word[i]:
counter+=1
if (counter>10):
selected.append(word[i][0])
selected.append((counter-2))
selected.append(word[i][counter-1])
for I in range(0,len(selected)):
print(selected[I], end="")
selected.clear()
print()
elif (counter<=12):
print(word[i])
``` | 3.977 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 1,657,882,779 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 | n=input()
if n.count("1")+n.count("4")!=len(n)or n[0]=="4"or"1444"in n:print("NO")
else:print("YES") | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input Specification:
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Output Specification:
Print "YES" if *n* is a magic number or print "NO" if it's not.
Demo Input:
['114114\n', '1111\n', '441231\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n=input()
if n.count("1")+n.count("4")!=len(n)or n[0]=="4"or"1444"in n:print("NO")
else:print("YES")
``` | 3 |
|
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input": "3 2 W\nOO\nWW\nWW",
"output": "1"
},
{
"input": "3 3 U\nUOO\nUVV\nUVV",
"output": "2"
},
{
"input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.",
"output": "1"
},
{
"input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ",
"output": "2"
},
{
"input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN",
"output": "3"
},
{
"input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J",
"output": "3"
},
{
"input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB",
"output": "2"
},
{
"input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..",
"output": "3"
},
{
"input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA",
"output": "4"
},
{
"input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY",
"output": "6"
},
{
"input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA",
"output": "4"
}
] | 1,599,131,294 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 204,800 | import numpy as np
def readInput():
m=int(input("enter the number of rows"))
n=int(input("enter the number of coloumns"))
c=input("enter the president desk colour of single character,eg:Red-R")
a=[]
for i in range(m):
a.append([])
for j in range(n):
deputChar=input("enter the deputies desk color in the place for {} and {} as a character for empty place give .".format(i,j))
a[i].append(deputChar)
#print(deputChar)
count=0
for k in range(m):
for l in range(n):
if(a[k][l]==c):
if((a[k+1][l]) or (a[k-1][l]) or (a[k][l+1]) or (a[k][l-1])!=c):
count+1
return count
def slovingPresidentOffice():
x=readInput()
print(x)
slovingPresidentOffice()
| Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input Specification:
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output Specification:
Print the only number — the amount of President's deputies.
Demo Input:
['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n']
Demo Output:
['2\n', '0\n']
Note:
none | ```python
import numpy as np
def readInput():
m=int(input("enter the number of rows"))
n=int(input("enter the number of coloumns"))
c=input("enter the president desk colour of single character,eg:Red-R")
a=[]
for i in range(m):
a.append([])
for j in range(n):
deputChar=input("enter the deputies desk color in the place for {} and {} as a character for empty place give .".format(i,j))
a[i].append(deputChar)
#print(deputChar)
count=0
for k in range(m):
for l in range(n):
if(a[k][l]==c):
if((a[k+1][l]) or (a[k-1][l]) or (a[k][l+1]) or (a[k][l-1])!=c):
count+1
return count
def slovingPresidentOffice():
x=readInput()
print(x)
slovingPresidentOffice()
``` | -1 |
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,578,675,069 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 307,200 | n=int(input())
s=0
x1=0
y1=0
z1=0
for i in range(n):
x,y,z=map(int,input().split())
s=s+x+y+z
x1=x1+x
y1=y1+y
z1=z1+z
if s==0 and x1==0 and y1==0 and z1==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())
s=0
x1=0
y1=0
z1=0
for i in range(n):
x,y,z=map(int,input().split())
s=s+x+y+z
x1=x1+x
y1=y1+y
z1=z1+z
if s==0 and x1==0 and y1==0 and z1==0:
print('YES')
else:
print('NO')
``` | 3.944928 |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "5\n1 4 5 2 3",
"output": "4"
},
{
"input": "6\n4 6 3 5 2 1",
"output": "5"
},
{
"input": "7\n1 5 3 6 2 4 7",
"output": "6"
},
{
"input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75",
"output": "94"
},
{
"input": "8\n4 5 3 8 6 7 1 2",
"output": "6"
},
{
"input": "9\n6 8 5 3 4 7 9 2 1",
"output": "8"
},
{
"input": "10\n8 7 10 1 2 3 4 6 5 9",
"output": "7"
},
{
"input": "11\n5 4 6 9 10 11 7 3 1 2 8",
"output": "8"
},
{
"input": "12\n3 6 7 8 9 10 12 5 4 2 11 1",
"output": "11"
},
{
"input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6",
"output": "10"
},
{
"input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8",
"output": "8"
},
{
"input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9",
"output": "9"
},
{
"input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16",
"output": "15"
},
{
"input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17",
"output": "16"
},
{
"input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10",
"output": "11"
},
{
"input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1",
"output": "18"
},
{
"input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1",
"output": "19"
},
{
"input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21",
"output": "20"
},
{
"input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1",
"output": "21"
},
{
"input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6",
"output": "22"
},
{
"input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4",
"output": "16"
},
{
"input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25",
"output": "24"
},
{
"input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3",
"output": "21"
},
{
"input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1",
"output": "26"
},
{
"input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2",
"output": "27"
},
{
"input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26",
"output": "22"
},
{
"input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7",
"output": "26"
},
{
"input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7",
"output": "18"
},
{
"input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28",
"output": "30"
},
{
"input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3",
"output": "29"
},
{
"input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12",
"output": "33"
},
{
"input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7",
"output": "21"
},
{
"input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8",
"output": "35"
},
{
"input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28",
"output": "35"
},
{
"input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29",
"output": "34"
},
{
"input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1",
"output": "38"
},
{
"input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1",
"output": "39"
},
{
"input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6",
"output": "34"
},
{
"input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35",
"output": "41"
},
{
"input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1",
"output": "42"
},
{
"input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28",
"output": "37"
},
{
"input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1",
"output": "44"
},
{
"input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30",
"output": "34"
},
{
"input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2",
"output": "41"
},
{
"input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7",
"output": "38"
},
{
"input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31",
"output": "40"
},
{
"input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40",
"output": "38"
},
{
"input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32",
"output": "43"
},
{
"input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39",
"output": "48"
},
{
"input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49",
"output": "52"
},
{
"input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53",
"output": "41"
},
{
"input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52",
"output": "48"
},
{
"input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15",
"output": "46"
},
{
"input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57",
"output": "56"
},
{
"input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50",
"output": "57"
},
{
"input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20",
"output": "58"
},
{
"input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1",
"output": "59"
},
{
"input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21",
"output": "60"
},
{
"input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62",
"output": "61"
},
{
"input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17",
"output": "46"
},
{
"input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47",
"output": "55"
},
{
"input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64",
"output": "62"
},
{
"input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29",
"output": "65"
},
{
"input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32",
"output": "45"
},
{
"input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3",
"output": "64"
},
{
"input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63",
"output": "45"
},
{
"input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35",
"output": "64"
},
{
"input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21",
"output": "50"
},
{
"input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56",
"output": "57"
},
{
"input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21",
"output": "45"
},
{
"input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58",
"output": "63"
},
{
"input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58",
"output": "74"
},
{
"input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68",
"output": "75"
},
{
"input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34",
"output": "62"
},
{
"input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72",
"output": "70"
},
{
"input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58",
"output": "77"
},
{
"input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78",
"output": "52"
},
{
"input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55",
"output": "69"
},
{
"input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52",
"output": "53"
},
{
"input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69",
"output": "66"
},
{
"input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38",
"output": "80"
},
{
"input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78",
"output": "84"
},
{
"input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3",
"output": "70"
},
{
"input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85",
"output": "58"
},
{
"input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67",
"output": "87"
},
{
"input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89",
"output": "88"
},
{
"input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25",
"output": "60"
},
{
"input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1",
"output": "90"
},
{
"input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72",
"output": "67"
},
{
"input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34",
"output": "85"
},
{
"input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68",
"output": "69"
},
{
"input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1",
"output": "94"
},
{
"input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56",
"output": "86"
},
{
"input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90",
"output": "95"
},
{
"input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1",
"output": "97"
},
{
"input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71",
"output": "87"
},
{
"input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37",
"output": "89"
},
{
"input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1",
"output": "99"
},
{
"input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42",
"output": "65"
},
{
"input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93",
"output": "87"
},
{
"input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11",
"output": "81"
},
{
"input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75",
"output": "99"
},
{
"input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67",
"output": "96"
},
{
"input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56",
"output": "62"
},
{
"input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100",
"output": "99"
},
{
"input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64",
"output": "97"
},
{
"input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57",
"output": "98"
},
{
"input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69",
"output": "98"
},
{
"input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14",
"output": "98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "3"
},
{
"input": "4\n1 2 4 3",
"output": "3"
},
{
"input": "4\n1 3 2 4",
"output": "3"
},
{
"input": "4\n1 3 4 2",
"output": "3"
},
{
"input": "4\n1 4 2 3",
"output": "3"
},
{
"input": "4\n1 4 3 2",
"output": "3"
},
{
"input": "4\n2 1 3 4",
"output": "3"
},
{
"input": "4\n2 1 4 3",
"output": "2"
},
{
"input": "4\n2 4 1 3",
"output": "2"
},
{
"input": "4\n2 4 3 1",
"output": "3"
},
{
"input": "4\n3 1 2 4",
"output": "3"
},
{
"input": "4\n3 1 4 2",
"output": "2"
},
{
"input": "4\n3 2 1 4",
"output": "3"
},
{
"input": "4\n3 2 4 1",
"output": "3"
},
{
"input": "4\n3 4 1 2",
"output": "2"
},
{
"input": "4\n3 4 2 1",
"output": "3"
},
{
"input": "4\n4 1 2 3",
"output": "3"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "4\n4 2 1 3",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "4\n4 3 2 1",
"output": "3"
},
{
"input": "8\n2 5 6 4 8 3 1 7",
"output": "6"
},
{
"input": "5\n2 3 1 5 4",
"output": "3"
},
{
"input": "6\n2 5 3 6 4 1",
"output": "5"
},
{
"input": "6\n5 4 2 6 1 3",
"output": "4"
},
{
"input": "6\n4 2 3 1 6 5",
"output": "4"
},
{
"input": "6\n5 4 2 1 6 3",
"output": "4"
},
{
"input": "9\n7 2 3 4 5 6 1 9 8",
"output": "7"
},
{
"input": "6\n3 2 1 4 6 5",
"output": "4"
},
{
"input": "6\n2 3 4 1 6 5",
"output": "4"
},
{
"input": "10\n5 2 3 4 1 6 7 8 10 9",
"output": "8"
},
{
"input": "6\n5 2 3 1 6 4",
"output": "4"
},
{
"input": "10\n2 9 3 4 1 10 5 6 7 8",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 1 8 10 9",
"output": "8"
},
{
"input": "8\n2 3 4 5 1 6 8 7",
"output": "6"
},
{
"input": "6\n2 1 3 4 5 6",
"output": "5"
}
] | 1,590,993,134 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 155 | 0 | n=int(input())
l=list(map(int,input().split()))
a=max(l)
b=min(l)
c=abs((l[0])-a)
d=abs(l[0]-b)
e=abs(l[-1]-a)
f=abs(l[-1]-b)
print(max(c,d,e,f)) | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Output Specification:
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Demo Input:
['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n']
Demo Output:
['3\n', '6\n', '5\n']
Note:
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | ```python
n=int(input())
l=list(map(int,input().split()))
a=max(l)
b=min(l)
c=abs((l[0])-a)
d=abs(l[0]-b)
e=abs(l[-1]-a)
f=abs(l[-1]-b)
print(max(c,d,e,f))
``` | 0 |
|
929 | B | Места в самолёте | PROGRAMMING | 1,300 | [
"*special",
"implementation"
] | null | null | В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, которые часто летают) и обычные.
Перед вами стоит задача рассадить ещё *k* обычных пассажиров так, чтобы суммарное число соседей у статусных пассажиров было минимально возможным. Два пассажира считаются соседями, если они сидят в одном ряду и между ними нет других мест и прохода между рядами. Если пассажир является соседним пассажиром для двух статусных пассажиров, то его следует учитывать в сумме соседей дважды. | В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.', то это свободное место. Если очередной символ равен 'S', то на текущем месте будет сидеть статусный пассажир. Если очередной символ равен 'P', то на текущем месте будет сидеть обычный пассажир.
Гарантируется, что количество свободных мест не меньше *k*. Гарантируется, что все ряды удовлетворяют описанному в условии формату. | В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите строчную букву 'x' вместо символа '.'. | [
"1 2\nSP.-SS.S-S.S\n",
"4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n"
] | [
"5\nSPx-SSxS-S.S\n",
"15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n"
] | В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажира, который сидит на самом левом месте уже есть сосед. Также на четвёртом и пятом местах слева сидят статусные пассажиры, являющиеся соседями друг для друга (что добавляет к сумме 2).
Таким образом, после посадки ещё двух обычных пассажиров, итоговое суммарное количество соседей у статусных пассажиров станет равно пяти. | 1,000 | [
{
"input": "1 2\nSP.-SS.S-S.S",
"output": "5\nSPx-SSxS-S.S"
},
{
"input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP",
"output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP"
},
{
"input": "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP",
"output": "13\nxSx-SSSP-xxS\nSxx-xSPP-S.P\n.S.-PPPP-PSP"
},
{
"input": "5 6\nPP.-PS.P-P..\nPPS-SP..-P.P\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP",
"output": "6\nPPx-PS.P-Pxx\nPPS-SPxx-PxP\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP"
},
{
"input": "1 1\n..S-PS..-.PP",
"output": "1\nx.S-PS..-.PP"
},
{
"input": "2 2\nPP.-S.SS-.S.\nSSP-SSSS-S.S",
"output": "12\nPPx-S.SS-xS.\nSSP-SSSS-S.S"
},
{
"input": "30 1\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP",
"output": "0\nPPP-PPPx-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP"
},
{
"input": "1 1\nSPS-....-P.P",
"output": "2\nSPS-x...-P.P"
},
{
"input": "2 1\nSSS-S.S.-SSS\nSSP-.PP.-S.S",
"output": "11\nSSS-S.S.-SSS\nSSP-xPP.-S.S"
},
{
"input": "30 1\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP",
"output": "0\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPx-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP"
}
] | 1,520,076,102 | 71,202 | Python 3 | OK | TESTS | 47 | 77 | 5,734,400 | n, k = map(int, input().split())
r = list()
for i in range(n):
r.append(['-'] + list(input()) + ['-'])
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
if (r[i][j - 1] != 'S') and (r[i][j + 1] != 'S'):
r[i][j] = "x"
k -= 1
if k == 0:
break
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
if ((r[i][j - 1] == 'S') or (r[i][j + 1] == 'S')) and (r[i][j - 1] != r[i][j + 1]):
r[i][j] = 'x'
k -= 1
if k == 0:
break
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
r[i][j] = 'x'
k -= 1
if k == 0:
break
count1 = 0
for i in range(n):
for j in range(1, 13):
if r[i][j] == 'S':
if (r[i][j - 1] == 'P') or (r[i][j - 1] == 'x') or (r[i][j - 1] == 'S'):
count1 += 1
if (r[i][j + 1] == 'P') or (r[i][j + 1] == 'x') or (r[i][j + 1] == 'S'):
count1 += 1
print(count1)
for i in range(n):
for j in range(1, 13):
print(r[i][j], end='')
print("") | Title: Места в самолёте
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, которые часто летают) и обычные.
Перед вами стоит задача рассадить ещё *k* обычных пассажиров так, чтобы суммарное число соседей у статусных пассажиров было минимально возможным. Два пассажира считаются соседями, если они сидят в одном ряду и между ними нет других мест и прохода между рядами. Если пассажир является соседним пассажиром для двух статусных пассажиров, то его следует учитывать в сумме соседей дважды.
Input Specification:
В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.', то это свободное место. Если очередной символ равен 'S', то на текущем месте будет сидеть статусный пассажир. Если очередной символ равен 'P', то на текущем месте будет сидеть обычный пассажир.
Гарантируется, что количество свободных мест не меньше *k*. Гарантируется, что все ряды удовлетворяют описанному в условии формату.
Output Specification:
В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите строчную букву 'x' вместо символа '.'.
Demo Input:
['1 2\nSP.-SS.S-S.S\n', '4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n']
Demo Output:
['5\nSPx-SSxS-S.S\n', '15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n']
Note:
В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажира, который сидит на самом левом месте уже есть сосед. Также на четвёртом и пятом местах слева сидят статусные пассажиры, являющиеся соседями друг для друга (что добавляет к сумме 2).
Таким образом, после посадки ещё двух обычных пассажиров, итоговое суммарное количество соседей у статусных пассажиров станет равно пяти. | ```python
n, k = map(int, input().split())
r = list()
for i in range(n):
r.append(['-'] + list(input()) + ['-'])
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
if (r[i][j - 1] != 'S') and (r[i][j + 1] != 'S'):
r[i][j] = "x"
k -= 1
if k == 0:
break
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
if ((r[i][j - 1] == 'S') or (r[i][j + 1] == 'S')) and (r[i][j - 1] != r[i][j + 1]):
r[i][j] = 'x'
k -= 1
if k == 0:
break
for i in range(n):
if k == 0:
break
for j in range(1, 13):
if r[i][j] == '.':
r[i][j] = 'x'
k -= 1
if k == 0:
break
count1 = 0
for i in range(n):
for j in range(1, 13):
if r[i][j] == 'S':
if (r[i][j - 1] == 'P') or (r[i][j - 1] == 'x') or (r[i][j - 1] == 'S'):
count1 += 1
if (r[i][j + 1] == 'P') or (r[i][j + 1] == 'x') or (r[i][j + 1] == 'S'):
count1 += 1
print(count1)
for i in range(n):
for j in range(1, 13):
print(r[i][j], end='')
print("")
``` | 3 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,641,999,156 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 186 | 0 | # Input
s = input()
# Main
countUpperCases = 0
for char in s:
if char.isupper():
countUpperCases += 1
if countUpperCases > len(s) - countUpperCases:
print(s.upper())
else:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
# Input
s = input()
# Main
countUpperCases = 0
for char in s:
if char.isupper():
countUpperCases += 1
if countUpperCases > len(s) - countUpperCases:
print(s.upper())
else:
print(s.lower())
``` | 3.9535 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,561,391,637 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 0 | a, b=[int(j) for j in input().split()]
p, v, n=0, 0, 0
for i in range(6):
if abs(i+1-a)<abs(i+1-b):
p+=1
elif abs(i+1-b)<abs(i+1-a):
v+=1
else:
n+=1
print(p, n, v) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a, b=[int(j) for j in input().split()]
p, v, n=0, 0, 0
for i in range(6):
if abs(i+1-a)<abs(i+1-b):
p+=1
elif abs(i+1-b)<abs(i+1-a):
v+=1
else:
n+=1
print(p, n, v)
``` | 3 |
|
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,696,139,839 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | nums = list(map(int, input().split()))
nums.sort()
diff = nums[1] - nums[0] + nums[2] - nums[1]
print(diff)
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
nums = list(map(int, input().split()))
nums.sort()
diff = nums[1] - nums[0] + nums[2] - nums[1]
print(diff)
``` | 3 |
|
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output": "No"
},
{
"input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC",
"output": "No"
},
{
"input": "1\nC",
"output": "No"
},
{
"input": "1\n?",
"output": "Yes"
},
{
"input": "2\nMY",
"output": "No"
},
{
"input": "2\n?M",
"output": "Yes"
},
{
"input": "2\nY?",
"output": "Yes"
},
{
"input": "2\n??",
"output": "Yes"
},
{
"input": "3\n??C",
"output": "Yes"
},
{
"input": "3\nM??",
"output": "Yes"
},
{
"input": "3\nYCM",
"output": "No"
},
{
"input": "3\n?C?",
"output": "Yes"
},
{
"input": "3\nMC?",
"output": "Yes"
},
{
"input": "4\nCYCM",
"output": "No"
},
{
"input": "4\nM?CM",
"output": "No"
},
{
"input": "4\n??YM",
"output": "Yes"
},
{
"input": "4\nC???",
"output": "Yes"
},
{
"input": "10\nMCYM?MYM?C",
"output": "Yes"
},
{
"input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC",
"output": "Yes"
},
{
"input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC",
"output": "No"
},
{
"input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y",
"output": "Yes"
},
{
"input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?",
"output": "No"
},
{
"input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "Yes"
},
{
"input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C",
"output": "No"
},
{
"input": "4\nM??C",
"output": "Yes"
},
{
"input": "6\nY?C??C",
"output": "Yes"
},
{
"input": "5\nC???Y",
"output": "Yes"
},
{
"input": "5\nC??MY",
"output": "Yes"
},
{
"input": "5\nCY??M",
"output": "Yes"
},
{
"input": "4\nC??Y",
"output": "Yes"
},
{
"input": "52\n??????????????????????????????????????????????????YY",
"output": "No"
},
{
"input": "3\nYY?",
"output": "No"
},
{
"input": "5\nCC??Y",
"output": "No"
},
{
"input": "8\nCMC??MCM",
"output": "Yes"
},
{
"input": "7\nM?YCM??",
"output": "Yes"
},
{
"input": "6\n?CC???",
"output": "No"
},
{
"input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM",
"output": "No"
},
{
"input": "4\nC??M",
"output": "Yes"
},
{
"input": "4\n?C?M",
"output": "Yes"
},
{
"input": "6\nMC??MC",
"output": "Yes"
}
] | 1,521,911,998 | 6,298 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 93 | 7,065,600 | n = int(input())
query = list(input())
arr = [0 for i in range(n)]
ans=[]
low = 0
high = len(query)
while low!=high:
if query[low]!="?" and low!=len(query)-1:
if query[low]==query[low+1]:
ans.append("no")
break
low+=1
if "no" in ans:
print("No")
else:
print("Yes") | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
Output Specification:
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n']
Demo Output:
['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n']
Note:
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | ```python
n = int(input())
query = list(input())
arr = [0 for i in range(n)]
ans=[]
low = 0
high = len(query)
while low!=high:
if query[low]!="?" and low!=len(query)-1:
if query[low]==query[low+1]:
ans.append("no")
break
low+=1
if "no" in ans:
print("No")
else:
print("Yes")
``` | 0 |
|
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. | The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
"input": "4744000695826",
"output": "YES"
},
{
"input": "10000000004744744",
"output": "YES"
},
{
"input": "446486416781684178",
"output": "YES"
},
{
"input": "999999999",
"output": "NO"
},
{
"input": "7777",
"output": "YES"
},
{
"input": "87414417444",
"output": "NO"
},
{
"input": "111222333444555667",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "4700",
"output": "NO"
},
{
"input": "3794555488744477",
"output": "NO"
},
{
"input": "444444444444444444",
"output": "NO"
},
{
"input": "474447447774444774",
"output": "NO"
},
{
"input": "777777777777777",
"output": "NO"
},
{
"input": "34777745021000000",
"output": "NO"
},
{
"input": "963",
"output": "NO"
},
{
"input": "855474448854788540",
"output": "NO"
},
{
"input": "999999999999994744",
"output": "YES"
},
{
"input": "400000000474",
"output": "YES"
},
{
"input": "123456789123456789",
"output": "YES"
},
{
"input": "740577777584945874",
"output": "NO"
},
{
"input": "7777777",
"output": "YES"
},
{
"input": "4444000111222333",
"output": "YES"
},
{
"input": "9847745885202111",
"output": "YES"
},
{
"input": "123456000000",
"output": "NO"
},
{
"input": "4744447444444",
"output": "NO"
},
{
"input": "7477",
"output": "YES"
},
{
"input": "4747477",
"output": "YES"
},
{
"input": "777777777444444444",
"output": "NO"
}
] | 1,695,623,175 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | def findlucky(n):
while n > 0:
d = n % 10
if d != 4 and d != 7:
return "NO"
n //= 10
return "YES"
n = int(input())
print(findlucky(n))
| Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output Specification:
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
Demo Input:
['40047\n', '7747774\n', '1000000000000000000\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | ```python
def findlucky(n):
while n > 0:
d = n % 10
if d != 4 and d != 7:
return "NO"
n //= 10
return "YES"
n = int(input())
print(findlucky(n))
``` | 0 |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn",
"output": "IGNORE HIM!"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx",
"output": "CHAT WITH HER!"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt",
"output": "IGNORE HIM!"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk",
"output": "IGNORE HIM!"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz",
"output": "IGNORE HIM!"
},
{
"input": "tgcdptnkc",
"output": "IGNORE HIM!"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi",
"output": "IGNORE HIM!"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp",
"output": "IGNORE HIM!"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia",
"output": "IGNORE HIM!"
},
{
"input": "fpellxwskyekoyvrfnuf",
"output": "CHAT WITH HER!"
},
{
"input": "xninyvkuvakfbs",
"output": "IGNORE HIM!"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak",
"output": "CHAT WITH HER!"
},
{
"input": "kmsk",
"output": "IGNORE HIM!"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz",
"output": "CHAT WITH HER!"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq",
"output": "CHAT WITH HER!"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm",
"output": "IGNORE HIM!"
},
{
"input": "ppcpbnhwoizajrl",
"output": "IGNORE HIM!"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv",
"output": "CHAT WITH HER!"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw",
"output": "IGNORE HIM!"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu",
"output": "CHAT WITH HER!"
},
{
"input": "ojjvpnkrxibyevxk",
"output": "CHAT WITH HER!"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg",
"output": "IGNORE HIM!"
},
{
"input": "hkdbykboclchfdsuovvpknwqr",
"output": "IGNORE HIM!"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu",
"output": "IGNORE HIM!"
},
{
"input": "rafcaanqytfclvfdegak",
"output": "CHAT WITH HER!"
},
{
"input": "xczn",
"output": "CHAT WITH HER!"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp",
"output": "IGNORE HIM!"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika",
"output": "CHAT WITH HER!"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh",
"output": "CHAT WITH HER!"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg",
"output": "CHAT WITH HER!"
},
{
"input": "udlpagtpq",
"output": "CHAT WITH HER!"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy",
"output": "CHAT WITH HER!"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten",
"output": "CHAT WITH HER!"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb",
"output": "CHAT WITH HER!"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr",
"output": "CHAT WITH HER!"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc",
"output": "IGNORE HIM!"
},
{
"input": "lnpdosnceumubvk",
"output": "IGNORE HIM!"
},
{
"input": "efrk",
"output": "CHAT WITH HER!"
},
{
"input": "temnownneghnrujforif",
"output": "IGNORE HIM!"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta",
"output": "IGNORE HIM!"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh",
"output": "IGNORE HIM!"
},
{
"input": "gwntwbpj",
"output": "IGNORE HIM!"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim",
"output": "IGNORE HIM!"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd",
"output": "CHAT WITH HER!"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx",
"output": "IGNORE HIM!"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks",
"output": "CHAT WITH HER!"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx",
"output": "CHAT WITH HER!"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc",
"output": "CHAT WITH HER!"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr",
"output": "IGNORE HIM!"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc",
"output": "IGNORE HIM!"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq",
"output": "CHAT WITH HER!"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj",
"output": "IGNORE HIM!"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom",
"output": "CHAT WITH HER!"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo",
"output": "CHAT WITH HER!"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh",
"output": "IGNORE HIM!"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa",
"output": "CHAT WITH HER!"
},
{
"input": "oh",
"output": "CHAT WITH HER!"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri",
"output": "IGNORE HIM!"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp",
"output": "CHAT WITH HER!"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp",
"output": "CHAT WITH HER!"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo",
"output": "CHAT WITH HER!"
},
{
"input": "mnmbupgo",
"output": "IGNORE HIM!"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl",
"output": "IGNORE HIM!"
},
{
"input": "yocxrzspinchmhtmqo",
"output": "CHAT WITH HER!"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv",
"output": "CHAT WITH HER!"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad",
"output": "IGNORE HIM!"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli",
"output": "CHAT WITH HER!"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy",
"output": "IGNORE HIM!"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd",
"output": "IGNORE HIM!"
},
{
"input": "acrzbavz",
"output": "CHAT WITH HER!"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza",
"output": "IGNORE HIM!"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws",
"output": "CHAT WITH HER!"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff",
"output": "CHAT WITH HER!"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu",
"output": "CHAT WITH HER!"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw",
"output": "IGNORE HIM!"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy",
"output": "CHAT WITH HER!"
},
{
"input": "rhh",
"output": "CHAT WITH HER!"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo",
"output": "IGNORE HIM!"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn",
"output": "CHAT WITH HER!"
},
{
"input": "urigreuzpxnej",
"output": "CHAT WITH HER!"
}
] | 1,694,717,098 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | # Read the input user name
user_name = input()
# Count the number of distinct characters using a set
distinct_chars = set(user_name)
# Check if the count is even or odd and print the result accordingly
if len(distinct_chars) % 2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
| Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
Input Specification:
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
Output Specification:
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
Demo Input:
['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n']
Demo Output:
['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n']
Note:
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | ```python
# Read the input user name
user_name = input()
# Count the number of distinct characters using a set
distinct_chars = set(user_name)
# Check if the count is even or odd and print the result accordingly
if len(distinct_chars) % 2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
``` | 3 |
|
711 | B | Chris and Magic Square | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid (), each column of the grid (), and the two long diagonals of the grid (the main diagonal — and the secondary diagonal — ) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of rows and columns of the magic grid.
*n* lines follow, each of them contains *n* integers. The *j*-th number in the *i*-th of them denotes *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109 or *a**i*,<=*j*<==<=0), the number in the *i*-th row and *j*-th column of the magic grid. If the corresponding cell is empty, *a**i*,<=*j* will be equal to 0. Otherwise, *a**i*,<=*j* is positive.
It is guaranteed that there is exactly one pair of integers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) such that *a**i*,<=*j*<==<=0. | Output a single integer, the positive integer *x* (1<=≤<=*x*<=≤<=1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer *x* does not exist, output <=-<=1 instead.
If there are multiple solutions, you may print any of them. | [
"3\n4 0 2\n3 5 7\n8 1 6\n",
"4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1\n",
"4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1\n"
] | [
"9\n",
"1\n",
"-1\n"
] | In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square. | 1,000 | [
{
"input": "3\n4 0 2\n3 5 7\n8 1 6",
"output": "9"
},
{
"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1",
"output": "1"
},
{
"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1",
"output": "-1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 0 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59",
"output": "76"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 0 1000000000\n1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "3\n3 8 1\n2 4 6\n7 0 5",
"output": "-1"
},
{
"input": "3\n1 2 2\n2 2 1\n0 1 2",
"output": "-1"
},
{
"input": "3\n1 6 10\n5 6 16\n0 5 1",
"output": "-1"
},
{
"input": "3\n2 2 1\n1 2 2\n0 1 2",
"output": "-1"
},
{
"input": "3\n1 2 2\n2 2 1\n2 1 0",
"output": "-1"
},
{
"input": "3\n2016 2016 2016\n2016 0 2016\n2016 2016 2016",
"output": "2016"
},
{
"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 0 34\n11 36 18 43 100 50 77 27 84 59",
"output": "9"
},
{
"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 0 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59",
"output": "88"
},
{
"input": "3\n2 2 1\n1 2 2\n2 1 0",
"output": "-1"
},
{
"input": "10\n92 67 99 74 1 51 8 58 15 0\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59",
"output": "40"
},
{
"input": "4\n2 2 2 2\n2 0 2 2\n3 2 2 1\n2 2 2 2",
"output": "-1"
},
{
"input": "3\n1 15 5\n11 7 3\n9 0 13",
"output": "-1"
},
{
"input": "3\n61 0 41\n11 31 51\n21 71 1",
"output": "-1"
},
{
"input": "3\n3 0 3\n2 3 2\n2 3 2",
"output": "-1"
},
{
"input": "3\n0 2 2\n3 1 1\n1 2 2",
"output": "-1"
},
{
"input": "3\n1 0 1\n1 1 2\n1 1 1",
"output": "-1"
},
{
"input": "3\n1 0 1\n2 1 2\n2 1 2",
"output": "-1"
},
{
"input": "3\n1 0 1\n4 1 4\n1 1 1",
"output": "-1"
},
{
"input": "3\n1 1 1\n1 1 0\n1 2 1",
"output": "-1"
},
{
"input": "3\n2 0 1\n1 2 1\n1 1 2",
"output": "-1"
},
{
"input": "3\n1 2 2\n3 1 1\n0 2 2",
"output": "-1"
},
{
"input": "4\n0 1 1 1\n1 1 1 1\n1 1 1 2\n1 1 2 1",
"output": "-1"
},
{
"input": "4\n1 1 0 1\n1 1 1 1\n1 1 1 1\n1 2 1 1",
"output": "-1"
},
{
"input": "5\n1 1 1000000000 1000000000 1000000000\n1 1000000000 1 1000000000 1000000000\n0 1 1 1 1\n1 1000000000 1000000000 1000000000 1\n1 1000000000 1000000000 1 1000000000",
"output": "2999999998"
},
{
"input": "3\n5 5 5\n6 5 0\n5 5 5",
"output": "-1"
},
{
"input": "3\n1 0 1\n50 1 500\n2 1 2",
"output": "-1"
},
{
"input": "9\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1 1 1 0 1 1 1 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1",
"output": "3999999997"
},
{
"input": "3\n7 22 1\n4 10 16\n19 0 13",
"output": "-1"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 0\n1 2 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "-1"
},
{
"input": "4\n3 6 0 2\n5 5 7 1\n1 7 4 6\n2 9 1 6",
"output": "-1"
},
{
"input": "5\n1 2 1 1 1\n1 1 2 1 1\n2 1 1 0 1\n1 1 1 1 2\n1 1 1 2 1",
"output": "-1"
},
{
"input": "11\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 13 1 1 5 5 5 5\n5 5 5 5 5 9 1 5 5 5 5\n5 5 5 5 0 5 13 5 5 5 5",
"output": "-1"
},
{
"input": "2\n5 5\n5 0",
"output": "5"
},
{
"input": "5\n10 10 1 10 10\n1 1 0 1 1\n10 10 1 10 10\n10 10 1 10 10\n10 10 1 10 10",
"output": "-1"
},
{
"input": "5\n1 1 1 2 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "-1"
},
{
"input": "3\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000\n1000000000 0 1000000000",
"output": "1000000000"
},
{
"input": "3\n3 3 3\n0 2 5\n1 1 1",
"output": "-1"
},
{
"input": "4\n2 2 3 1\n1 0 3 3\n4 3 4 1\n1 2 3 1",
"output": "-1"
},
{
"input": "3\n1 1 2\n2 1 0\n1 2 1",
"output": "-1"
},
{
"input": "2\n1 2\n1 0",
"output": "-1"
},
{
"input": "2\n0 535\n535 535",
"output": "535"
},
{
"input": "6\n0 1 1 1 1 1\n1 1 1000000000 1000000000 1000000000 1000000000\n1 1000000000 1 1000000000 1000000000 1000000000\n1 1000000000 1000000000 1 1000000000 1000000000\n1 1000000000 1000000000 1000000000 1 1000000000\n1 1000000000 1000000000 1000000000 1000000000 1",
"output": "3999999997"
},
{
"input": "4\n2 6 0 3\n5 5 7 1\n5 1 3 9\n6 6 1 5",
"output": "-1"
},
{
"input": "5\n2 1 2 1 2\n2 2 2 2 2\n2 2 0 2 2\n2 2 2 2 2\n2 2 2 2 2",
"output": "-1"
},
{
"input": "3\n1 2 3\n1 0 3\n1 2 3",
"output": "-1"
},
{
"input": "3\n0 1 2\n1 2 1\n2 1 1",
"output": "-1"
},
{
"input": "4\n2 3 2 3\n3 2 3 0\n2 4 2 2\n3 1 3 3",
"output": "-1"
},
{
"input": "3\n1 1 1\n1 0 1\n1 2 1",
"output": "-1"
},
{
"input": "3\n1 1 1\n1 4 1\n1 1 0",
"output": "-1"
},
{
"input": "5\n1 1 2 1 1\n1 1 1 1 1\n1 1 1 0 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "-1"
},
{
"input": "3\n0 1 1\n1 1 1\n1 1 2",
"output": "-1"
},
{
"input": "3\n1 2 1\n1 0 1\n1 2 1",
"output": "-1"
},
{
"input": "3\n6 7 2\n1 0 9\n8 3 4",
"output": "5"
},
{
"input": "3\n1 1 1\n1 1 1\n1 0 1",
"output": "1"
},
{
"input": "3\n3 6 0\n3 3 5\n5 2 4",
"output": "-1"
},
{
"input": "5\n1 2 2 2 1\n1 1 1 1 0\n2 2 1 2 1\n2 1 2 1 1\n1 2 2 2 1",
"output": "-1"
},
{
"input": "4\n1 1 1 1\n1 1 1 0\n1 1 2 1\n1 1 1 1",
"output": "-1"
},
{
"input": "3\n13 0 19\n16 10 4\n1 22 7",
"output": "-1"
},
{
"input": "4\n1 2 2 1\n2 1 0 2\n2 1 1 2\n1 2 2 1",
"output": "-1"
}
] | 1,631,059,475 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | # 3
# 4 0 2
# 3 5 7
# 8 1 6
def main():
n = int(input())
matrix = []
x, y = -1, -1
maxi, mini =0,0
for i in range(n):
sum=0
row = [int(j) for j in input().split()]
for k in range(len(row)):
sum+=row[k]
if(row[k]==0):
x,y=i,k
if(sum>maxi):
maxi=sum
if(mini==0 or sum<maxi):
# print(sum)
mini=sum
matrix.append(row)
matrix[x][y] = maxi - mini
print(maxi,mini)
# check sums of rows
for i in range(n):
res = 0
for j in range(n):
res += matrix[i][j]
if(res!=maxi):
print(-1)
return
# check sum of colmuns
for i in range(n):
res = 0
for j in range(n):
res += matrix[j][i]
if(res!=maxi):
print("sum of colmuns",-1)
return
# check sums of dialong right
res = 0
for i in range(n):
for j in range(n):
if(i==j):
res += matrix[i][j]
if(res!=maxi):
print("dialong right",-1)
return
# check sums of dialong left
res = 0
for i in range(n):
for j in range(n):
if(n-i-1==j):#3-0-1=2 3-1-1=1 3-2-1=0
res += matrix[i][j]
if(res!=maxi):
print("dialong left",-1)
return
print(matrix[x][y])# answer
# for i in range(n):
# a = list(map(int, input().split(' ')))
if __name__=='__main__':
main()
| Title: Chris and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a *n*<=×<=*n* magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell.
Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid (), each column of the grid (), and the two long diagonals of the grid (the main diagonal — and the secondary diagonal — ) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of rows and columns of the magic grid.
*n* lines follow, each of them contains *n* integers. The *j*-th number in the *i*-th of them denotes *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109 or *a**i*,<=*j*<==<=0), the number in the *i*-th row and *j*-th column of the magic grid. If the corresponding cell is empty, *a**i*,<=*j* will be equal to 0. Otherwise, *a**i*,<=*j* is positive.
It is guaranteed that there is exactly one pair of integers *i*,<=*j* (1<=≤<=*i*,<=*j*<=≤<=*n*) such that *a**i*,<=*j*<==<=0.
Output Specification:
Output a single integer, the positive integer *x* (1<=≤<=*x*<=≤<=1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer *x* does not exist, output <=-<=1 instead.
If there are multiple solutions, you may print any of them.
Demo Input:
['3\n4 0 2\n3 5 7\n8 1 6\n', '4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1\n', '4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1\n']
Demo Output:
['9\n', '1\n', '-1\n']
Note:
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed,
The sum of numbers in each row is:
4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15.
The sum of numbers in each column is:
4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15.
The sum of numbers in the two diagonals is:
4 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square. | ```python
# 3
# 4 0 2
# 3 5 7
# 8 1 6
def main():
n = int(input())
matrix = []
x, y = -1, -1
maxi, mini =0,0
for i in range(n):
sum=0
row = [int(j) for j in input().split()]
for k in range(len(row)):
sum+=row[k]
if(row[k]==0):
x,y=i,k
if(sum>maxi):
maxi=sum
if(mini==0 or sum<maxi):
# print(sum)
mini=sum
matrix.append(row)
matrix[x][y] = maxi - mini
print(maxi,mini)
# check sums of rows
for i in range(n):
res = 0
for j in range(n):
res += matrix[i][j]
if(res!=maxi):
print(-1)
return
# check sum of colmuns
for i in range(n):
res = 0
for j in range(n):
res += matrix[j][i]
if(res!=maxi):
print("sum of colmuns",-1)
return
# check sums of dialong right
res = 0
for i in range(n):
for j in range(n):
if(i==j):
res += matrix[i][j]
if(res!=maxi):
print("dialong right",-1)
return
# check sums of dialong left
res = 0
for i in range(n):
for j in range(n):
if(n-i-1==j):#3-0-1=2 3-1-1=1 3-2-1=0
res += matrix[i][j]
if(res!=maxi):
print("dialong left",-1)
return
print(matrix[x][y])# answer
# for i in range(n):
# a = list(map(int, input().split(' ')))
if __name__=='__main__':
main()
``` | 0 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,593,337,320 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 6,656,000 | n=int(input())
l=list(map(int,input().split()))
s=sum(l)
if (s+1)%(n+1)==1:
print(2)
else:
print(1) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
if (s+1)%(n+1)==1:
print(2)
else:
print(1)
``` | 0 |
|
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,676,689,708 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 46 | 0 | n,t,k,d = [int(x) for x in input().split()]
# t1 = ((n+k-1)//k)*t
# t2 = ((n // k) * (t//2)) +d
# print(t1,t2)
# # if t2 > t1:
# # print('NO')
# # else :print('YES')
g = (n+k-1)//k
o1=0
o2=d
for i in range(g):
if o1<=o2:o1+=t
else : o2+=t
if (max(o1,o2) < (g*t)):
print('YES')
else :
print('NO')
| Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | ```python
n,t,k,d = [int(x) for x in input().split()]
# t1 = ((n+k-1)//k)*t
# t2 = ((n // k) * (t//2)) +d
# print(t1,t2)
# # if t2 > t1:
# # print('NO')
# # else :print('YES')
g = (n+k-1)//k
o1=0
o2=d
for i in range(g):
if o1<=o2:o1+=t
else : o2+=t
if (max(o1,o2) < (g*t)):
print('YES')
else :
print('NO')
``` | 3 |
|
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string. | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss",
"output": "1"
},
{
"input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs",
"output": "2"
},
{
"input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi",
"output": "2"
},
{
"input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn",
"output": "1"
},
{
"input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti",
"output": "2"
},
{
"input": "rmeetriiitijmrenmeiijt",
"output": "0"
},
{
"input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne",
"output": "1"
},
{
"input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer",
"output": "2"
},
{
"input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim",
"output": "2"
},
{
"input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm",
"output": "3"
},
{
"input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn",
"output": "3"
},
{
"input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni",
"output": "1"
},
{
"input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm",
"output": "2"
},
{
"input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet",
"output": "3"
},
{
"input": "jrjshtjstteh",
"output": "0"
},
{
"input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn",
"output": "2"
},
{
"input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn",
"output": "2"
},
{
"input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei",
"output": "1"
},
{
"input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin",
"output": "2"
},
{
"input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin",
"output": "1"
},
{
"input": "rnsrsmretjiitrjthhritniijhjmm",
"output": "0"
},
{
"input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj",
"output": "3"
},
{
"input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni",
"output": "0"
},
{
"input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis",
"output": "2"
},
{
"input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh",
"output": "3"
},
{
"input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei",
"output": "3"
},
{
"input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs",
"output": "1"
},
{
"input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj",
"output": "1"
},
{
"input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj",
"output": "2"
},
{
"input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii",
"output": "1"
},
{
"input": "iihienhirmnihh",
"output": "0"
},
{
"input": "ismtthhshjmhisssnmnhe",
"output": "0"
},
{
"input": "rhsmnrmhejshinnjrtmtsssijimimethnm",
"output": "0"
},
{
"input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj",
"output": "3"
},
{
"input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes",
"output": "2"
},
{
"input": "ssrmjmjeeetrnimemrhimes",
"output": "0"
},
{
"input": "n",
"output": "0"
},
{
"input": "ni",
"output": "0"
},
{
"input": "nine",
"output": "0"
},
{
"input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen",
"output": "13"
},
{
"input": "ninetee",
"output": "0"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd",
"output": "0"
},
{
"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch",
"output": "0"
},
{
"input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq",
"output": "0"
},
{
"input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz",
"output": "13"
},
{
"input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee",
"output": "3"
},
{
"input": "ttttiiiieeeeeeeeeeeennnnnnnnn",
"output": "4"
},
{
"input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn",
"output": "3"
},
{
"input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt",
"output": "4"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn",
"output": "3"
},
{
"input": "nineeen",
"output": "0"
},
{
"input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii",
"output": "0"
},
{
"input": "nineteenieteenieteenieteenieteenieteenieteen",
"output": "4"
},
{
"input": "nineteenineteenineteenineteenineteen",
"output": "5"
}
] | 1,554,909,937 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 409,600 | from collections import defaultdict
s = input()
d = defaultdict(int)
for i in range(len(s)):
d[s[i]] += 1
print(min(d['n']//3, d['i'], d['e']//3, d['t'])) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters.
Help her to find the maximum number of "nineteen"s that she can get in her string.
Input Specification:
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Output Specification:
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
Demo Input:
['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n']
Demo Output:
['2', '2', '2']
Note:
none | ```python
from collections import defaultdict
s = input()
d = defaultdict(int)
for i in range(len(s)):
d[s[i]] += 1
print(min(d['n']//3, d['i'], d['e']//3, d['t']))
``` | 0 |
|
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1 900",
"output": "-1 -1"
},
{
"input": "1 9",
"output": "9 9"
},
{
"input": "1 0",
"output": "0 0"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "1 2",
"output": "2 2"
},
{
"input": "1 8",
"output": "8 8"
},
{
"input": "1 10",
"output": "-1 -1"
},
{
"input": "1 11",
"output": "-1 -1"
},
{
"input": "2 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "2 2",
"output": "11 20"
},
{
"input": "2 8",
"output": "17 80"
},
{
"input": "2 10",
"output": "19 91"
},
{
"input": "2 11",
"output": "29 92"
},
{
"input": "2 16",
"output": "79 97"
},
{
"input": "2 17",
"output": "89 98"
},
{
"input": "2 18",
"output": "99 99"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "2 20",
"output": "-1 -1"
},
{
"input": "2 900",
"output": "-1 -1"
},
{
"input": "3 1",
"output": "100 100"
},
{
"input": "3 2",
"output": "101 200"
},
{
"input": "3 3",
"output": "102 300"
},
{
"input": "3 9",
"output": "108 900"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "3 20",
"output": "299 992"
},
{
"input": "3 21",
"output": "399 993"
},
{
"input": "3 26",
"output": "899 998"
},
{
"input": "3 27",
"output": "999 999"
},
{
"input": "3 28",
"output": "-1 -1"
},
{
"input": "3 100",
"output": "-1 -1"
},
{
"input": "100 0",
"output": "-1 -1"
},
{
"input": "100 1",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 2",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 9",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 10",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 11",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 296",
"output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 297",
"output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 298",
"output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 299",
"output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 300",
"output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 301",
"output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 895",
"output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994"
},
{
"input": "100 896",
"output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995"
},
{
"input": "100 897",
"output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996"
},
{
"input": "100 898",
"output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997"
},
{
"input": "100 899",
"output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"
},
{
"input": "100 900",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 900",
"output": "-1 -1"
},
{
"input": "99 891",
"output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 892",
"output": "-1 -1"
},
{
"input": "96 364",
"output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000"
},
{
"input": "97 206",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "98 250",
"output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "99 96",
"output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 215",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "5 18",
"output": "10089 99000"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "3 3",
"output": "102 300"
}
] | 1,696,073,386 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | m, s = map(int, input().split())
if (m > s or 9*(m) < s):
print("-1 -1")
else:
smallest = [0] * m
smallest[0] = 1
smallest_sum = s - 1
ptr = m - 1
while smallest_sum > 0:
if smallest_sum >= 9:
smallest[ptr] = 9
smallest_sum = smallest_sum - 9
else:
smallest[ptr] += smallest_sum
smallest_sum = 0
ptr -= 1
answer_smallest = "".join(map(str , smallest))
largest = [0] * m
largest[0] = 9
largest_sum = s - 9
ptr = 1
while largest_sum > 0:
if largest_sum >= 9:
largest[ptr] = 9
largest_sum = largest_sum - 9
else:
largest[ptr] = largest_sum
largest_sum = 0
ptr += 1
answer_largest = "".join(map(str , largest))
print(answer_smallest , answer_largest)
| Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input Specification:
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
Output Specification:
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Demo Input:
['2 15\n', '3 0\n']
Demo Output:
['69 96\n', '-1 -1\n']
Note:
none | ```python
m, s = map(int, input().split())
if (m > s or 9*(m) < s):
print("-1 -1")
else:
smallest = [0] * m
smallest[0] = 1
smallest_sum = s - 1
ptr = m - 1
while smallest_sum > 0:
if smallest_sum >= 9:
smallest[ptr] = 9
smallest_sum = smallest_sum - 9
else:
smallest[ptr] += smallest_sum
smallest_sum = 0
ptr -= 1
answer_smallest = "".join(map(str , smallest))
largest = [0] * m
largest[0] = 9
largest_sum = s - 9
ptr = 1
while largest_sum > 0:
if largest_sum >= 9:
largest[ptr] = 9
largest_sum = largest_sum - 9
else:
largest[ptr] = largest_sum
largest_sum = 0
ptr += 1
answer_largest = "".join(map(str , largest))
print(answer_smallest , answer_largest)
``` | 0 |
|
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
"output": "NO"
},
{
"input": "sZecYdUvZHrXx?",
"output": "NO"
},
{
"input": "uMtXK?",
"output": "NO"
},
{
"input": "U?",
"output": "YES"
},
{
"input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?",
"output": "NO"
},
{
"input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?",
"output": "NO"
},
{
"input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?",
"output": "NO"
},
{
"input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?",
"output": "NO"
},
{
"input": "YhCuZnrWUBEed?",
"output": "NO"
},
{
"input": "hh?",
"output": "NO"
},
{
"input": "whU?",
"output": "YES"
},
{
"input": "fgwg?",
"output": "NO"
},
{
"input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?",
"output": "NO"
},
{
"input": "n?",
"output": "NO"
},
{
"input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?",
"output": "NO"
},
{
"input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?",
"output": "NO"
},
{
"input": " J ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " o ?",
"output": "YES"
},
{
"input": " T ?",
"output": "NO"
},
{
"input": " q ?",
"output": "NO"
},
{
"input": " j ?",
"output": "NO"
},
{
"input": " c ?",
"output": "NO"
},
{
"input": " B ?",
"output": "NO"
},
{
"input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?",
"output": "YES"
},
{
"input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?",
"output": "YES"
},
{
"input": "wGsfZCSwN PEUhNUrLfABrxA?",
"output": "YES"
},
{
"input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?",
"output": "YES"
},
{
"input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?",
"output": "YES"
},
{
"input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?",
"output": "YES"
},
{
"input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?",
"output": "YES"
}
] | 1,588,075,928 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | vowels = ['a', 'e', 'i', 'o', 'u', 'y']
question = input().strip()[:-1].strip()
lower_question = [q.lower() for q in question]
decide = lower_question[-1]
if decide in vowels:
print('YES')
else:
print(decide)
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.
Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
Input Specification:
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Output Specification:
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
Demo Input:
['Is it a melon?\n', 'Is it an apple?\n', 'Is it a banana ?\n', 'Is it an apple and a banana simultaneouSLY?\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
none | ```python
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
question = input().strip()[:-1].strip()
lower_question = [q.lower() for q in question]
decide = lower_question[-1]
if decide in vowels:
print('YES')
else:
print(decide)
``` | 0 |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4",
"output": "-1"
},
{
"input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4",
"output": "-1"
},
{
"input": "1\n2 4",
"output": "0"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "2\n1 1\n3 3",
"output": "0"
},
{
"input": "2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1 1\n1 2",
"output": "-1"
},
{
"input": "5\n1 2\n6 6\n1 1\n3 3\n6 1",
"output": "1"
},
{
"input": "5\n5 4\n2 6\n6 2\n1 4\n6 2",
"output": "0"
},
{
"input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1",
"output": "0"
},
{
"input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5",
"output": "-1"
},
{
"input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1",
"output": "1"
},
{
"input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4",
"output": "-1"
},
{
"input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2",
"output": "0"
},
{
"input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5",
"output": "-1"
},
{
"input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4",
"output": "-1"
},
{
"input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4",
"output": "-1"
},
{
"input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6",
"output": "1"
},
{
"input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5",
"output": "1"
},
{
"input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3",
"output": "1"
},
{
"input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5",
"output": "1"
},
{
"input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5",
"output": "-1"
},
{
"input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6",
"output": "-1"
},
{
"input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1",
"output": "-1"
},
{
"input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6",
"output": "-1"
},
{
"input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4",
"output": "1"
},
{
"input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6",
"output": "-1"
},
{
"input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2",
"output": "0"
},
{
"input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3",
"output": "-1"
},
{
"input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3",
"output": "-1"
},
{
"input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4",
"output": "-1"
},
{
"input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5",
"output": "1"
},
{
"input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1",
"output": "1"
},
{
"input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5",
"output": "-1"
},
{
"input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2",
"output": "0"
},
{
"input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1",
"output": "0"
},
{
"input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2",
"output": "1"
},
{
"input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2",
"output": "0"
},
{
"input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2",
"output": "-1"
},
{
"input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5",
"output": "0"
},
{
"input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1",
"output": "-1"
},
{
"input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5",
"output": "-1"
},
{
"input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3",
"output": "-1"
},
{
"input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5",
"output": "0"
},
{
"input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4",
"output": "-1"
},
{
"input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2",
"output": "-1"
},
{
"input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2",
"output": "1"
},
{
"input": "1\n2 2",
"output": "0"
},
{
"input": "3\n2 4\n6 6\n3 3",
"output": "-1"
},
{
"input": "2\n3 6\n4 1",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n3 3",
"output": "-1"
},
{
"input": "3\n2 3\n1 1\n2 3",
"output": "1"
},
{
"input": "3\n2 2\n2 1\n1 2",
"output": "1"
},
{
"input": "3\n1 1\n1 1\n1 1",
"output": "-1"
}
] | 1,587,542,502 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 342 | 1,228,800 | n=int(input())
a=[]
for i in range(0,n):
a.append([int(j)for j in input().split()])
def isEven(x,l):
up=0
down=0
for i in range(0,l):
up+=x[i][0]
down+=x[i][1]
if up%2==0 and down%2==0:
return 'yes'
else:
return 'no'
flag=0
if isEven(a,n)=='yes':
print('0')
else:
for i in range(0,n):
c=a.copy()
temp=c[i][0]
c[i][0]=c[i][1]
c[i][1]=temp
if isEven(c,n)=='yes':
flag=1
break
if flag==1:
print('1')
else:
print('-1')
| 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
n=int(input())
a=[]
for i in range(0,n):
a.append([int(j)for j in input().split()])
def isEven(x,l):
up=0
down=0
for i in range(0,l):
up+=x[i][0]
down+=x[i][1]
if up%2==0 and down%2==0:
return 'yes'
else:
return 'no'
flag=0
if isEven(a,n)=='yes':
print('0')
else:
for i in range(0,n):
c=a.copy()
temp=c[i][0]
c[i][0]=c[i][1]
c[i][1]=temp
if isEven(c,n)=='yes':
flag=1
break
if flag==1:
print('1')
else:
print('-1')
``` | 3 |
|
938 | B | Run For Your Prize | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. | Print one integer — the minimum number of seconds it will take to collect all prizes. | [
"3\n2 3 9\n",
"2\n2 999995\n"
] | [
"8\n",
"5\n"
] | In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | 0 | [
{
"input": "3\n2 3 9",
"output": "8"
},
{
"input": "2\n2 999995",
"output": "5"
},
{
"input": "1\n20",
"output": "19"
},
{
"input": "6\n2 3 500000 999997 999998 999999",
"output": "499999"
},
{
"input": "1\n999999",
"output": "1"
},
{
"input": "1\n510000",
"output": "490000"
},
{
"input": "3\n2 5 27",
"output": "26"
},
{
"input": "2\n600000 800000",
"output": "400000"
},
{
"input": "5\n2 5 6 27 29",
"output": "28"
},
{
"input": "1\n500001",
"output": "499999"
},
{
"input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055",
"output": "98054"
},
{
"input": "1\n900000",
"output": "100000"
},
{
"input": "1\n500000",
"output": "499999"
},
{
"input": "1\n999998",
"output": "2"
},
{
"input": "3\n999997 999998 999999",
"output": "3"
},
{
"input": "2\n999997 999999",
"output": "3"
},
{
"input": "2\n2 999998",
"output": "2"
},
{
"input": "2\n500000 500001",
"output": "499999"
},
{
"input": "1\n500002",
"output": "499998"
},
{
"input": "1\n700000",
"output": "300000"
},
{
"input": "2\n2 999999",
"output": "1"
},
{
"input": "2\n999998 999999",
"output": "2"
},
{
"input": "1\n999995",
"output": "5"
},
{
"input": "2\n499999 500001",
"output": "499999"
},
{
"input": "1\n499999",
"output": "499998"
},
{
"input": "2\n100 999900",
"output": "100"
},
{
"input": "2\n499999 500000",
"output": "499999"
},
{
"input": "2\n500001 999999",
"output": "499999"
},
{
"input": "3\n500000 500001 500002",
"output": "499999"
},
{
"input": "2\n2 500001",
"output": "499999"
},
{
"input": "2\n499999 999999",
"output": "499998"
},
{
"input": "2\n2 500000",
"output": "499999"
},
{
"input": "4\n2 3 4 999999",
"output": "3"
},
{
"input": "2\n100000 500001",
"output": "499999"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n800000",
"output": "200000"
},
{
"input": "1\n505050",
"output": "494950"
},
{
"input": "1\n753572",
"output": "246428"
},
{
"input": "2\n576696 760487",
"output": "423304"
},
{
"input": "10\n3 4 5 6 7 8 9 10 11 12",
"output": "11"
},
{
"input": "4\n2 3 4 5",
"output": "4"
},
{
"input": "4\n999996 999997 999998 999999",
"output": "4"
}
] | 1,520,430,868 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 12,902,400 | class RFYP:
def main(self):
n = int(input())
prize = [int(x) for x in input().split()]
temp = 1
count = 0
for i in range(n):
if(prize[i] - 2 < 999999 - prize[i]):
count = count + prize[i] - temp
else:
count = count + 999999 - prize[i]
temp = prize[i]
print(count)
r = RFYP()
r.main() | Title: Run For Your Prize
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Output Specification:
Print one integer — the minimum number of seconds it will take to collect all prizes.
Demo Input:
['3\n2 3 9\n', '2\n2 999995\n']
Demo Output:
['8\n', '5\n']
Note:
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | ```python
class RFYP:
def main(self):
n = int(input())
prize = [int(x) for x in input().split()]
temp = 1
count = 0
for i in range(n):
if(prize[i] - 2 < 999999 - prize[i]):
count = count + prize[i] - temp
else:
count = count + 999999 - prize[i]
temp = prize[i]
print(count)
r = RFYP()
r.main()
``` | 0 |
|
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,694,835,049 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | heights = list(map(int, input().split(" ")))
n = heights[0]
t = heights[1]
#print(a + " " + b)
line = list(input())
#print(line)
def swap(x, y, data):
temp = data[x]
data[x] = data[y]
data[y] = temp
skipNext = False
for i in range(t):
for j in range(n-1):
if skipNext:
skipNext = not skipNext
continue
if(line[j] == 'B'):
if(line[j+1]=='G'):
swap(j, j+1, line)
skipNext = True #move to the next person in the queue
for char in line:
print(char, end="")
print() | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none | ```python
heights = list(map(int, input().split(" ")))
n = heights[0]
t = heights[1]
#print(a + " " + b)
line = list(input())
#print(line)
def swap(x, y, data):
temp = data[x]
data[x] = data[y]
data[y] = temp
skipNext = False
for i in range(t):
for j in range(n-1):
if skipNext:
skipNext = not skipNext
continue
if(line[j] == 'B'):
if(line[j+1]=='G'):
swap(j, j+1, line)
skipNext = True #move to the next person in the queue
for char in line:
print(char, end="")
print()
``` | 0 |
|
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,660,283,786 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 93 | 14,438,400 | n=int(input())
li=list(map(int,input().split()))
lst=li.copy()
lst.sort()
if(li==lst):
print(0)
quit()
y=li.index(lst[0])
sub=li[y:]
# print(sub)
if(sub+li[:y])==lst:
print(len(sub))
else:print(-1) | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
n=int(input())
li=list(map(int,input().split()))
lst=li.copy()
lst.sort()
if(li==lst):
print(0)
quit()
y=li.index(lst[0])
sub=li[y:]
# print(sub)
if(sub+li[:y])==lst:
print(len(sub))
else:print(-1)
``` | 0 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,697,255,591 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
s=input()
s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s2=set(s)
if s2.upper()==s1:
print("YES")
else:
print("NO") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n = int(input())
s=input()
s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s2=set(s)
if s2.upper()==s1:
print("YES")
else:
print("NO")
``` | -1 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,638,027,969 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 102,400 | from collections import Counter
n = int(input(""))
lista =[]
for i in range(0,n):
lista.append(input(''))
m = list(dict(Counter(lista)).values())
i = m.index(max(m))
print(list(dict(Counter(lista)).keys())[i])
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
from collections import Counter
n = int(input(""))
lista =[]
for i in range(0,n):
lista.append(input(''))
m = list(dict(Counter(lista)).values())
i = m.index(max(m))
print(list(dict(Counter(lista)).keys())[i])
``` | 3.976809 |
1,010 | B | Rocket | PROGRAMMING | 1,800 | [
"binary search",
"interactive"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers). | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | 750 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": "6 queries, x=3"
},
{
"input": "30 5 16\n0 1 1 1 0",
"output": "6 queries, x=16"
},
{
"input": "60 6 21\n1 0 0 1 0 1",
"output": "11 queries, x=21"
},
{
"input": "100 7 73\n0 0 0 1 0 1 1",
"output": "14 queries, x=73"
},
{
"input": "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0",
"output": "58 queries, x=958572235"
},
{
"input": "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1",
"output": "59 queries, x=116044407"
},
{
"input": "300 8 165\n1 1 1 0 0 1 1 0",
"output": "16 queries, x=165"
},
{
"input": "600 9 150\n0 0 1 0 1 0 1 0 1",
"output": "19 queries, x=150"
},
{
"input": "1000 10 140\n0 0 0 0 1 0 0 0 0 0",
"output": "20 queries, x=140"
},
{
"input": "3000 11 1896\n1 0 1 1 0 0 0 0 1 1 1",
"output": "21 queries, x=1896"
},
{
"input": "6000 12 4679\n1 0 1 1 1 1 1 0 0 0 0 1",
"output": "23 queries, x=4679"
},
{
"input": "10000 13 4977\n1 0 1 1 0 0 0 1 0 0 1 1 0",
"output": "26 queries, x=4977"
},
{
"input": "30000 14 60\n1 1 1 0 0 1 0 1 0 0 1 0 0 0",
"output": "28 queries, x=60"
},
{
"input": "60000 15 58813\n0 1 1 0 1 1 0 0 0 1 1 1 1 0 1",
"output": "27 queries, x=58813"
},
{
"input": "100000 16 79154\n1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 1",
"output": "32 queries, x=79154"
},
{
"input": "300000 17 11107\n1 0 0 0 1 0 0 0 1 1 1 0 0 1 1 1 0",
"output": "34 queries, x=11107"
},
{
"input": "600000 18 146716\n0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1",
"output": "37 queries, x=146716"
},
{
"input": "1000000 19 418016\n1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0",
"output": "38 queries, x=418016"
},
{
"input": "3000000 20 642518\n1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1",
"output": "41 queries, x=642518"
},
{
"input": "6000000 21 3516807\n0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0",
"output": "43 queries, x=3516807"
},
{
"input": "10000000 22 8115129\n1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1",
"output": "42 queries, x=8115129"
},
{
"input": "30000000 23 10362635\n0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0",
"output": "48 queries, x=10362635"
},
{
"input": "60000000 24 52208533\n1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 0",
"output": "46 queries, x=52208533"
},
{
"input": "100000000 25 51744320\n0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1",
"output": "50 queries, x=51744320"
},
{
"input": "300000000 26 264009490\n1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1",
"output": "54 queries, x=264009490"
},
{
"input": "600000000 27 415720732\n1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 1 0",
"output": "56 queries, x=415720732"
},
{
"input": "1000000000 28 946835863\n0 0 1 0 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0",
"output": "58 queries, x=946835863"
},
{
"input": "1000000000 29 124919287\n0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0",
"output": "59 queries, x=124919287"
},
{
"input": "1000000000 30 202669473\n1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 0",
"output": "58 queries, x=202669473"
},
{
"input": "1000000000 13 532121080\n1 1 1 0 1 1 0 0 0 0 1 0 1",
"output": "42 queries, x=532121080"
},
{
"input": "1000000000 27 105669924\n0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1",
"output": "57 queries, x=105669924"
},
{
"input": "1000000000 11 533994576\n0 0 1 0 1 1 1 1 0 1 0",
"output": "38 queries, x=533994576"
},
{
"input": "1000000000 9 107543421\n1 0 0 1 1 1 1 1 1",
"output": "39 queries, x=107543421"
},
{
"input": "1000000000 23 976059561\n1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1",
"output": "53 queries, x=976059561"
},
{
"input": "1000000000 7 549608406\n1 1 1 0 1 1 1",
"output": "36 queries, x=549608406"
},
{
"input": "1000000000 21 123157250\n0 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1",
"output": "49 queries, x=123157250"
},
{
"input": "1000000000 19 696706094\n0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0",
"output": "47 queries, x=696706094"
},
{
"input": "1000000000 3 125030747\n0 0 0",
"output": "33 queries, x=125030747"
},
{
"input": "1000000000 17 993546887\n1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1",
"output": "46 queries, x=993546887"
},
{
"input": "1000000000 15 567095731\n1 1 1 0 0 1 1 1 0 1 0 0 1 0 0",
"output": "45 queries, x=567095731"
},
{
"input": "1000000000 29 140644576\n1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0",
"output": "58 queries, x=140644576"
},
{
"input": "1000000000 13 714193420\n0 1 0 0 0 1 0 0 0 0 1 1 1",
"output": "43 queries, x=714193420"
},
{
"input": "1000000000 27 142518072\n0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 0",
"output": "52 queries, x=142518072"
},
{
"input": "1000000000 25 11034213\n0 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0",
"output": "54 queries, x=11034213"
},
{
"input": "1000000000 9 584583057\n1 1 1 0 0 1 0 0 0",
"output": "35 queries, x=584583057"
},
{
"input": "1000000000 23 863164606\n1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1",
"output": "53 queries, x=863164606"
},
{
"input": "1000000000 21 731680746\n1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1",
"output": "51 queries, x=731680746"
},
{
"input": "1000000000 5 305229590\n0 0 1 1 0",
"output": "35 queries, x=305229590"
},
{
"input": "1000000000 3 28521539\n0 0 1",
"output": "31 queries, x=28521539"
},
{
"input": "1000000000 3 602070383\n0 1 1",
"output": "32 queries, x=602070383"
},
{
"input": "1000000000 2 880651931\n1 1",
"output": "30 queries, x=880651931"
},
{
"input": "1000000000 16 749168072\n1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0",
"output": "46 queries, x=749168072"
},
{
"input": "1000000000 30 322716916\n1 0 1 1 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0",
"output": "58 queries, x=322716916"
},
{
"input": "1000000000 14 191233057\n0 0 1 0 0 1 1 1 1 0 0 0 1 1",
"output": "43 queries, x=191233057"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 1 1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1\n1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1000000000 30 1000000000\n0 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1",
"output": "60 queries, x=1000000000"
},
{
"input": "1 30 1\n1 1 1 0 1 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0",
"output": "1 queries, x=1"
},
{
"input": "1 30 1\n1 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1",
"output": "1 queries, x=1"
},
{
"input": "2 1 2\n1",
"output": "2 queries, x=2"
},
{
"input": "1000000000 1 1000000000\n1",
"output": "31 queries, x=1000000000"
},
{
"input": "10000 1 10000\n1",
"output": "15 queries, x=10000"
},
{
"input": "1000000000 1 999999999\n1",
"output": "30 queries, x=999999999"
},
{
"input": "100000 2 15\n1 0",
"output": "19 queries, x=15"
},
{
"input": "200000 1 110000\n1",
"output": "17 queries, x=110000"
},
{
"input": "123456789 1 42\n1",
"output": "27 queries, x=42"
},
{
"input": "1000000000 1 9\n1",
"output": "30 queries, x=9"
},
{
"input": "200000 2 100002\n1 0",
"output": "19 queries, x=100002"
},
{
"input": "1000000000 3 234567890\n0 1 0",
"output": "31 queries, x=234567890"
},
{
"input": "1000000000 5 321732193\n1 1 0 1 0",
"output": "35 queries, x=321732193"
},
{
"input": "1000000000 1 804289384\n1",
"output": "27 queries, x=804289384"
},
{
"input": "1000000000 2 999999998\n1 0",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 5 384618761\n0 1 1 0 1",
"output": "33 queries, x=384618761"
},
{
"input": "100000000 1 100\n0",
"output": "28 queries, x=100"
},
{
"input": "1000000000 1 804289384\n0",
"output": "27 queries, x=804289384"
},
{
"input": "100000000 1 100000000\n1",
"output": "28 queries, x=100000000"
},
{
"input": "40 1 4\n0",
"output": "6 queries, x=4"
},
{
"input": "1000000000 2 999999998\n0 1",
"output": "32 queries, x=999999998"
},
{
"input": "1000000000 1 1000000000\n0",
"output": "31 queries, x=1000000000"
},
{
"input": "1000000000 2 255555555\n1 0",
"output": "31 queries, x=255555555"
},
{
"input": "1000000000 2 1000000000\n0 1",
"output": "32 queries, x=1000000000"
},
{
"input": "1000000000 1 999999999\n0",
"output": "30 queries, x=999999999"
},
{
"input": "1000000000 2 888888888\n0 1",
"output": "31 queries, x=888888888"
},
{
"input": "1000000000 1 77000000\n1",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 123456789\n1",
"output": "27 queries, x=123456789"
},
{
"input": "10000 1 228\n0",
"output": "14 queries, x=228"
},
{
"input": "1000000000 1 12345\n1",
"output": "31 queries, x=12345"
},
{
"input": "1000000000 1 77000000\n0",
"output": "31 queries, x=77000000"
},
{
"input": "1000000000 1 23333\n0",
"output": "31 queries, x=23333"
},
{
"input": "1000000000 4 100\n0 1 0 1",
"output": "34 queries, x=100"
},
{
"input": "100000000 1 200\n1",
"output": "27 queries, x=200"
},
{
"input": "1000000000 3 5\n0 1 0",
"output": "33 queries, x=5"
},
{
"input": "1000000000 12 2\n1 1 1 1 1 1 0 0 1 1 1 1",
"output": "41 queries, x=2"
},
{
"input": "1000000000 1 5\n0",
"output": "31 queries, x=5"
},
{
"input": "100000 2 99999\n0 0",
"output": "18 queries, x=99999"
},
{
"input": "100000 2 2\n0 1",
"output": "18 queries, x=2"
},
{
"input": "1000000 1 91923\n0",
"output": "21 queries, x=91923"
},
{
"input": "1000000 2 1235\n0 1",
"output": "22 queries, x=1235"
},
{
"input": "1000000000 1 5\n1",
"output": "31 queries, x=5"
},
{
"input": "100000000 2 1234567\n0 1",
"output": "28 queries, x=1234567"
},
{
"input": "1000000000 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "1000000000 4 999999999\n1 0 0 1",
"output": "33 queries, x=999999999"
},
{
"input": "1000000000 4 1000000000\n1 0 1 0",
"output": "34 queries, x=1000000000"
},
{
"input": "1000000000 4 1\n1 0 1 0",
"output": "1 queries, x=1"
},
{
"input": "1000000000 5 500\n1 1 0 0 1",
"output": "34 queries, x=500"
},
{
"input": "1000 1 13\n1",
"output": "11 queries, x=13"
},
{
"input": "999999999 2 123456789\n1 0",
"output": "31 queries, x=123456789"
},
{
"input": "1000000000 5 1000000000\n1 1 1 1 1",
"output": "35 queries, x=1000000000"
},
{
"input": "1000000000 3 123456789\n1 0 1",
"output": "29 queries, x=123456789"
},
{
"input": "1000000000 1 123\n1",
"output": "29 queries, x=123"
},
{
"input": "10 1 9\n1",
"output": "4 queries, x=9"
},
{
"input": "1000000000 1 1\n0",
"output": "1 queries, x=1"
},
{
"input": "100000000 2 12345678\n0 1",
"output": "28 queries, x=12345678"
},
{
"input": "1000000000 30 1000000000\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",
"output": "60 queries, x=1000000000"
},
{
"input": "805306369 30 805306369\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",
"output": "60 queries, x=805306369"
},
{
"input": "1000000000 2 123\n0 1",
"output": "30 queries, x=123"
},
{
"input": "1000000000 1 9\n0",
"output": "30 queries, x=9"
},
{
"input": "100000 2 90000\n1 0",
"output": "18 queries, x=90000"
},
{
"input": "1000000000 2 123456789\n1 0",
"output": "28 queries, x=123456789"
},
{
"input": "1000000000 2 804289384\n1 0",
"output": "28 queries, x=804289384"
},
{
"input": "1000000000 30 999999970\n1 0 0 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 1",
"output": "60 queries, x=999999970"
}
] | 1,552,649,959 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | def f():
m, n = map(int, input().split())
B = []
for i in range(n):
print(1)
#System.out.flush()
k = int(input())
if k == 0:
print(1)
return 0
else:
if k == 1:
B.append(1)
else:
B.append(0)
left = 0
right = m
ans = 0
while left + 1 < right:
middle = (left + right) // 2
print(middle)
#System.out.flush()
k = int(input())
if k == 0:
print(middle)
return 0
elif k == 1 and B[ans] == 1 or k == -1 and B[ans] == 0:
right = middle
else:
left = middle
f()
| Title: Rocket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.
Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.
Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.
In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.
You can ask the rocket no more than $60$ questions.
Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.
Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).
Input Specification:
The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.
Output Specification:
none
Demo Input:
['5 2\n1\n-1\n-1\n1\n0\n']
Demo Output:
['1\n2\n4\n5\n3\n']
Note:
In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;
on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;
on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;
on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;
on the fifth query ($3$) the correct and incorrect answer is $0$. | ```python
def f():
m, n = map(int, input().split())
B = []
for i in range(n):
print(1)
#System.out.flush()
k = int(input())
if k == 0:
print(1)
return 0
else:
if k == 1:
B.append(1)
else:
B.append(0)
left = 0
right = m
ans = 0
while left + 1 < right:
middle = (left + right) // 2
print(middle)
#System.out.flush()
k = int(input())
if k == 0:
print(middle)
return 0
elif k == 1 and B[ans] == 1 or k == -1 and B[ans] == 0:
right = middle
else:
left = middle
f()
``` | 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": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX"
},
{
"input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO",
"output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO"
},
{
"input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD",
"output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD"
},
{
"input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW",
"output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW"
},
{
"input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL",
"output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL"
},
{
"input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC",
"output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC"
},
{
"input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN",
"output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN"
},
{
"input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE",
"output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE"
},
{
"input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP",
"output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP"
},
{
"input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG",
"output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG"
},
{
"input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV",
"output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV"
},
{
"input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI",
"output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI"
},
{
"input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX",
"output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX"
},
{
"input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ",
"output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ"
},
{
"input": "P",
"output": "P"
},
{
"input": "Xyzzy",
"output": "Xyzzy"
},
{
"input": "Zzz",
"output": "Zzz"
},
{
"input": "Zp",
"output": "Zp"
}
] | 1,698,829,515 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=int(input())
print(math.ceil(n/5))
| 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
n=int(input())
print(math.ceil(n/5))
``` | -1 |
|
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below). | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input. | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
},
{
"input": "55",
"output": "composite 6"
},
{
"input": "89",
"output": "prime 15"
},
{
"input": "3",
"output": "prime 16"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "8",
"output": "composite 2"
},
{
"input": "11",
"output": "prime 15"
},
{
"input": "12",
"output": "composite 2"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "36",
"output": "composite 2"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "51",
"output": "composite 8"
},
{
"input": "53",
"output": "prime 15"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "64",
"output": "composite 2"
},
{
"input": "81",
"output": "composite 3"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "97",
"output": "prime 15"
},
{
"input": "99",
"output": "composite 3"
},
{
"input": "100",
"output": "composite 2"
},
{
"input": "26",
"output": "composite 7"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "82",
"output": "composite 14"
},
{
"input": "87",
"output": "composite 11"
},
{
"input": "85",
"output": "composite 8"
},
{
"input": "74",
"output": "composite 13"
},
{
"input": "86",
"output": "composite 15"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "58",
"output": "composite 11"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "22",
"output": "composite 6"
},
{
"input": "23",
"output": "prime 15"
},
{
"input": "62",
"output": "composite 12"
},
{
"input": "38",
"output": "composite 9"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "34",
"output": "composite 8"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "16",
"output": "composite 2"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "69",
"output": "composite 10"
},
{
"input": "65",
"output": "composite 7"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "18",
"output": "composite 4"
}
] | 1,468,858,034 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | #!/usr/bin/env python3
from sys import stdout
def main():
primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)
print('\n'.join([str(x) for x in primes]))
stdout.flush()
ans = [input() for _ in primes]
print('composite' if ans.count('yes') >= 2 else 'prime')
if __name__ == '__main__':
main()
| Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).
Input Specification:
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Output Specification:
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input.
Demo Input:
['yes\nno\nyes\n', 'no\nyes\nno\nno\nno\n']
Demo Output:
['2\n80\n5\ncomposite\n', '58\n59\n78\n78\n2\nprime\n']
Note:
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | ```python
#!/usr/bin/env python3
from sys import stdout
def main():
primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)
print('\n'.join([str(x) for x in primes]))
stdout.flush()
ans = [input() for _ in primes]
print('composite' if ans.count('yes') >= 2 else 'prime')
if __name__ == '__main__':
main()
``` | 0 |
|
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"input": "2 2\n20 10",
"output": "1"
},
{
"input": "2 1\n20 1",
"output": "2"
},
{
"input": "3 1\n1 2 3",
"output": "1"
},
{
"input": "3 1\n2 1 3",
"output": "2"
},
{
"input": "3 1\n3 2 1",
"output": "3"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "3 2\n3 2 1",
"output": "2"
},
{
"input": "3 3\n1 2 3",
"output": "1"
},
{
"input": "4 2\n9 8 11 7",
"output": "1"
},
{
"input": "4 2\n10 1 2 3",
"output": "2"
},
{
"input": "6 3\n56 56 56 2 1 2",
"output": "4"
},
{
"input": "8 3\n1 1 1 1 2 60 90 1",
"output": "1"
},
{
"input": "4 1\n1 5 2 2",
"output": "1"
},
{
"input": "4 2\n4 6 7 4",
"output": "1"
},
{
"input": "10 4\n1 1 1 4 4 4 4 4 4 3",
"output": "1"
},
{
"input": "6 3\n1 2 1 3 1 1",
"output": "1"
},
{
"input": "5 2\n100 100 100 1 1",
"output": "4"
}
] | 1,689,883,173 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 2,867,200 | n, k = map(int, input().split())
h = [int(i) for i in input().split()]
pref_sum = [h[0]]
sumk = []
for i in range(1, n):
pref_sum.append(pref_sum[i-1] + h[i])
for l in range(0, n-k):
if l == 0:
sumk.append(pref_sum[k-1])
else:
sumk.append(pref_sum[l+k-1] - pref_sum[l-1])
print(sumk.index(min(sumk))+1) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
Input Specification:
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Output Specification:
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
Demo Input:
['7 3\n1 2 6 1 1 7 1\n']
Demo Output:
['3\n']
Note:
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | ```python
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
pref_sum = [h[0]]
sumk = []
for i in range(1, n):
pref_sum.append(pref_sum[i-1] + h[i])
for l in range(0, n-k):
if l == 0:
sumk.append(pref_sum[k-1])
else:
sumk.append(pref_sum[l+k-1] - pref_sum[l-1])
print(sumk.index(min(sumk))+1)
``` | -1 |
|
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,675,429,567 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | # Way Too Long Words
t = int(input())
for tt in range(t):
s = input()
n = len(s)
if (n<10):
print(s)
else:
print(s[0] + str(n-2) + s[-1]) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
# Way Too Long Words
t = int(input())
for tt in range(t):
s = input()
n = len(s)
if (n<10):
print(s)
else:
print(s[0] + str(n-2) + s[-1])
``` | 0 |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,695,553,125 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | k , n , w = int(print())
somme = 0
for i in range (w) :
somme = somme + i - k
if somme > n :
x = somme -k
print (x)
else :
print (0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k , n , w = int(print())
somme = 0
for i in range (w) :
somme = somme + i - k
if somme > n :
x = somme -k
print (x)
else :
print (0)
``` | -1 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,659,415,884 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | m=int(input())
n=int(input())
print (n*m/2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m=int(input())
n=int(input())
print (n*m/2)
``` | -1 |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,584,119,364 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 124 | 0 | n=int(input())
l1=[]
for i in range(n):
s=input()
if s in l1:
print("Yes")
else:
print("No")
l1.append(s) | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | ```python
n=int(input())
l1=[]
for i in range(n):
s=input()
if s in l1:
print("Yes")
else:
print("No")
l1.append(s)
``` | 3 |
|
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,503,598,733 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 0 | sticks = [int(x) for x in input().split()]
alien = True
for stick in sticks:
if sticks.count(stick) >= 4:
for i in range(4):
sticks.remove(stick)
alien = False
break
if not alien:
if abs(sticks[0] - sticks[1]) > 0:
print("Bear")
else:
print("Elephant")
else:
print("Alien")
| 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
sticks = [int(x) for x in input().split()]
alien = True
for stick in sticks:
if sticks.count(stick) >= 4:
for i in range(4):
sticks.remove(stick)
alien = False
break
if not alien:
if abs(sticks[0] - sticks[1]) > 0:
print("Bear")
else:
print("Elephant")
else:
print("Alien")
``` | 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,539,921,469 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | I = input(); a = int(input()) - 1
if len(I) == 5:
a -= 1
print("L") if a != 0 else print("R") | 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
I = input(); a = int(input()) - 1
if len(I) == 5:
a -= 1
print("L") if a != 0 else print("R")
``` | -1 |
|
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"output": "50"
},
{
"input": "50 250",
"output": "0"
},
{
"input": "29 116",
"output": "0"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "46 127",
"output": "11"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "36 99",
"output": "9"
},
{
"input": "45 104",
"output": "31"
},
{
"input": "13 57",
"output": "0"
},
{
"input": "25 106",
"output": "0"
},
{
"input": "8 19",
"output": "5"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "13 32",
"output": "7"
},
{
"input": "47 128",
"output": "13"
},
{
"input": "17 73",
"output": "0"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "38 137",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "36 155",
"output": "0"
},
{
"input": "5 15",
"output": "0"
},
{
"input": "27 75",
"output": "6"
},
{
"input": "21 73",
"output": "0"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "49 177",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "44 173",
"output": "0"
},
{
"input": "49 219",
"output": "0"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "10 28",
"output": "2"
}
] | 1,697,420,583 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print('test')
# Mon Oct 16 2023 04:43:00 GMT+0300 (Moscow Standard Time)
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
Input Specification:
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Output Specification:
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
Demo Input:
['4 8\n', '4 10\n', '1 3\n']
Demo Output:
['4\n', '2\n', '0\n']
Note:
In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | ```python
print('test')
# Mon Oct 16 2023 04:43:00 GMT+0300 (Moscow Standard Time)
``` | 0 |
|
95 | B | Lucky Numbers | PROGRAMMING | 1,800 | [
"dp",
"greedy"
] | B. Lucky Numbers | 2 | 256 | Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*. | The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes. | Output the least super lucky number that is more than or equal to *n*. | [
"4500\n",
"47\n"
] | [
"4747\n",
"47\n"
] | none | 1,000 | [
{
"input": "4500",
"output": "4747"
},
{
"input": "47",
"output": "47"
},
{
"input": "1",
"output": "47"
},
{
"input": "12",
"output": "47"
},
{
"input": "4587",
"output": "4747"
},
{
"input": "100",
"output": "4477"
},
{
"input": "1007",
"output": "4477"
},
{
"input": "99999999",
"output": "4444477777"
},
{
"input": "49102094540227023300",
"output": "74444444444777777777"
},
{
"input": "1000000000",
"output": "4444477777"
},
{
"input": "777777",
"output": "44447777"
},
{
"input": "99999999",
"output": "4444477777"
},
{
"input": "474",
"output": "4477"
},
{
"input": "85469",
"output": "444777"
},
{
"input": "7474747",
"output": "44447777"
},
{
"input": "2145226",
"output": "44447777"
},
{
"input": "5556585",
"output": "44447777"
},
{
"input": "87584777",
"output": "4444477777"
},
{
"input": "77777777",
"output": "4444477777"
},
{
"input": "1000000000",
"output": "4444477777"
},
{
"input": "999999999",
"output": "4444477777"
},
{
"input": "74477744",
"output": "74477744"
},
{
"input": "444444444",
"output": "4444477777"
},
{
"input": "467549754",
"output": "4444477777"
},
{
"input": "147474747",
"output": "4444477777"
},
{
"input": "555",
"output": "4477"
},
{
"input": "100000",
"output": "444777"
},
{
"input": "74777443",
"output": "74777444"
},
{
"input": "4700007",
"output": "44447777"
},
{
"input": "70070077",
"output": "74444777"
},
{
"input": "123",
"output": "4477"
},
{
"input": "7474",
"output": "7474"
},
{
"input": "3696",
"output": "4477"
},
{
"input": "5594108733309806863211189515406929423407691887690557101598403485",
"output": "7444444444444444444444444444444447777777777777777777777777777777"
},
{
"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224",
"output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777"
},
{
"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115",
"output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"
},
{
"input": "300315701225398103949172355218103087569515283105400017868730132769291700939035921405014640214190659140126383204458315111136164707153628616177467538307534664174018683245377348638677858006052356516328838399769950207054982712314494543889750490268253870160095357456864075250350735474301206523459172092665900965024129501630212966373988276932458849720393142004789869863743947961634907491797090041095838600303393556660079821519800685499052949978754418782241756597476926001413610822",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150",
"output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447",
"output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444"
},
{
"input": "474777447477447774447777477444444747747747447474",
"output": "474777447477447774447777477444444747747747447474"
},
{
"input": "4610011341130234325130111223432762111322200032405402224411031600004377332320125004161111207316702630337013246237324411010232123224431343463152610127222227432331505230001434422203415026064601462701340036346273331432110074431135223142761441433403414301432300263254301342131314327333745711213130421310313153504022700431534463141461236322033420140324202221402036761452134031253152442133141307046425107520",
"output": "4744444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "35881905331681060827588553219538774024143083787975",
"output": "44444444444444444444444447777777777777777777777777"
},
{
"input": "221020945402270233",
"output": "444444444777777777"
},
{
"input": "241925018843248944336317949908388280315030601139576419352009710",
"output": "4444444444444444444444444444444477777777777777777777777777777777"
},
{
"input": "888999577",
"output": "4444477777"
},
{
"input": "10",
"output": "47"
},
{
"input": "7",
"output": "47"
},
{
"input": "50",
"output": "74"
},
{
"input": "70",
"output": "74"
},
{
"input": "74700",
"output": "444777"
},
{
"input": "1024",
"output": "4477"
},
{
"input": "73",
"output": "74"
},
{
"input": "74710000",
"output": "74744477"
},
{
"input": "444000000",
"output": "4444477777"
},
{
"input": "4",
"output": "47"
},
{
"input": "1",
"output": "47"
},
{
"input": "9",
"output": "47"
},
{
"input": "99",
"output": "4477"
},
{
"input": "48",
"output": "74"
},
{
"input": "4747474749",
"output": "4747474774"
},
{
"input": "4747474774",
"output": "4747474774"
},
{
"input": "77777777",
"output": "4444477777"
},
{
"input": "4777",
"output": "7447"
},
{
"input": "7748",
"output": "444777"
},
{
"input": "7773",
"output": "444777"
},
{
"input": "19",
"output": "47"
},
{
"input": "447777",
"output": "474477"
}
] | 1,684,164,758 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 86 | 622 | 20,480,000 | from sys import stdin, stdout
from collections import deque
MOD = 10 ** 9 + 7
INF = float('inf')
sze = 10 ** 4 + 1
EPS = 10 ** -6
s = stdin.readline().strip()
challenger = []
for i in range(len(s)):
if s[i] in '47':
challenger.append(s[i])
elif s[i] in '89':
update = []
for j in range(1, len(challenger) + 1):
if challenger[-j] == '4':
update += ['7'] + challenger[:-j][::-1]
break
else:
update.append('4')
else:
update.append('4')
challenger = update[::-1] + ['4' for j in range(len(s[i:]))]
break
elif s[i] < '4':
challenger += ['4' for j in range(len(s[i:]))]
break
else:
challenger += ['7'] + ['4' for j in range(len(s[i:]) - 1)]
break
while True:
if challenger.count('4') == challenger.count('7'):
break
if len(challenger) % 2:
challenger = ['4' for i in range((len(challenger) + 1) // 2)] + ['7' for i in range((len(challenger) + 1) // 2)]
elif challenger.count('4') > challenger.count('7'):
cnt = challenger.count('4') - challenger.count('7')
for i in range(len(challenger) - 1, -1, -1):
if challenger[i] == '4':#1
challenger[i] = '7'
cnt -= 2
if not cnt:
break
else:
cnt = [0 for i in range(len(challenger))]
cnt[-1] = challenger[-1] == '7'
for i in range(2, len(challenger) + 1):
cnt[-i] = cnt[-i + 1] + (challenger[-i] == '7')
if not challenger[:len(challenger) // 2].count('4'):
challenger = ['4' for i in range((len(challenger) + 2) // 2)] + ['7' for i in range((len(challenger) + 2) // 2)]
else:
first, second = challenger.count('4'), challenger.count('7')
for j in range(len(challenger) - 2, -1, -1):
if challenger[j] == '4' and cnt[j + 1] * 2 + first >= second:
challenger[j] = '7'
for z in range(j + 1, len(challenger)):
challenger[z] = '4'
break
stdout.write(''.join(challenger))
# Made By Mostafa_Khaled | Title: Lucky Numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*.
Input Specification:
The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes.
Output Specification:
Output the least super lucky number that is more than or equal to *n*.
Demo Input:
['4500\n', '47\n']
Demo Output:
['4747\n', '47\n']
Note:
none | ```python
from sys import stdin, stdout
from collections import deque
MOD = 10 ** 9 + 7
INF = float('inf')
sze = 10 ** 4 + 1
EPS = 10 ** -6
s = stdin.readline().strip()
challenger = []
for i in range(len(s)):
if s[i] in '47':
challenger.append(s[i])
elif s[i] in '89':
update = []
for j in range(1, len(challenger) + 1):
if challenger[-j] == '4':
update += ['7'] + challenger[:-j][::-1]
break
else:
update.append('4')
else:
update.append('4')
challenger = update[::-1] + ['4' for j in range(len(s[i:]))]
break
elif s[i] < '4':
challenger += ['4' for j in range(len(s[i:]))]
break
else:
challenger += ['7'] + ['4' for j in range(len(s[i:]) - 1)]
break
while True:
if challenger.count('4') == challenger.count('7'):
break
if len(challenger) % 2:
challenger = ['4' for i in range((len(challenger) + 1) // 2)] + ['7' for i in range((len(challenger) + 1) // 2)]
elif challenger.count('4') > challenger.count('7'):
cnt = challenger.count('4') - challenger.count('7')
for i in range(len(challenger) - 1, -1, -1):
if challenger[i] == '4':#1
challenger[i] = '7'
cnt -= 2
if not cnt:
break
else:
cnt = [0 for i in range(len(challenger))]
cnt[-1] = challenger[-1] == '7'
for i in range(2, len(challenger) + 1):
cnt[-i] = cnt[-i + 1] + (challenger[-i] == '7')
if not challenger[:len(challenger) // 2].count('4'):
challenger = ['4' for i in range((len(challenger) + 2) // 2)] + ['7' for i in range((len(challenger) + 2) // 2)]
else:
first, second = challenger.count('4'), challenger.count('7')
for j in range(len(challenger) - 2, -1, -1):
if challenger[j] == '4' and cnt[j + 1] * 2 + first >= second:
challenger[j] = '7'
for z in range(j + 1, len(challenger)):
challenger[z] = '4'
break
stdout.write(''.join(challenger))
# Made By Mostafa_Khaled
``` | 3.806353 |
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,678,010,307 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | # A. Дабстеп
def func(str2):
return str2.replace('WUB', ' ')
str1 = input()
print(func(str1))
| 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
# A. Дабстеп
def func(str2):
return str2.replace('WUB', ' ')
str1 = input()
print(func(str1))
``` | 3 |
|
833 | B | The Bakery | PROGRAMMING | 2,200 | [
"binary search",
"data structures",
"divide and conquer",
"dp",
"two pointers"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has.
She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of *n* cakes the oven is going to bake today. Slastyona has to pack exactly *k* boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes).
Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5. | 1,250 | [
{
"input": "4 1\n1 2 2 1",
"output": "2"
},
{
"input": "7 2\n1 3 3 1 4 4 4",
"output": "5"
},
{
"input": "8 3\n7 7 8 7 7 8 1 7",
"output": "6"
},
{
"input": "50 5\n2 39 16 20 32 36 29 42 14 23 9 4 28 17 45 16 46 1 39 33 47 15 34 43 6 6 12 15 46 11 32 16 31 12 41 33 47 35 22 3 10 4 9 36 22 22 17 33 15 46",
"output": "49"
},
{
"input": "50 6\n41 23 41 16 33 6 25 15 15 11 14 12 21 2 16 42 25 3 5 17 37 11 10 50 33 28 1 35 9 50 40 8 33 14 43 34 8 42 6 31 21 11 39 34 2 30 33 44 38 45",
"output": "50"
},
{
"input": "50 7\n34 49 9 4 29 13 17 46 12 12 14 20 11 36 33 19 46 5 28 48 35 7 31 7 21 47 3 5 26 42 6 50 27 15 45 39 20 48 1 5 37 30 11 36 28 35 8 13 19 45",
"output": "50"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "42 12\n18 1 14 10 6 40 25 10 39 7 36 25 36 11 11 24 38 27 22 26 41 38 24 35 1 6 15 40 7 14 41 11 38 5 41 32 28 2 38 22 12 2",
"output": "42"
},
{
"input": "2 2\n1 1",
"output": "2"
}
] | 1,690,531,171 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 102,400 | class SegmentTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (4 * size)
def update(self, node, left, right, index, value):
if left == right == index:
self.tree[node] = value
return
mid = (left + right) // 2
if index <= mid:
self.update(2 * node, left, mid, index, value)
else:
self.update(2 * node + 1, mid + 1, right, index, value)
self.tree[node] = self.tree[2 * node] + self.tree[2 * node + 1]
def query(self, node, left, right, ql, qr):
if ql > right or qr < left:
return 0
if ql <= left and qr >= right:
return self.tree[node]
mid = (left + right) // 2
return self.query(2 * node, left, mid, ql, qr) + self.query(2 * node + 1, mid + 1, right, ql, qr)
def max_total_value(n, k, cakes):
last_occurrence = [-1] * (n + 1)
segment_tree = SegmentTree(n)
dp_table = [[0] * (k + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
dp_table[i][1] = dp_table[i - 1][1] + (cakes[i] != cakes[i - 1])
for j in range(2, k + 1):
for i in range(1, n + 1):
dp_table[i][j] = dp_table[i][1]
if last_occurrence[cakes[i]] != -1:
dp_table[i][j] = max(dp_table[i][j], dp_table[last_occurrence[cakes[i]]][j - 1] + segment_tree.query(1, 1, n, last_occurrence[cakes[i]] + 1, i) * (i - last_occurrence[cakes[i]]))
segment_tree.update(1, 1, n, i, 1)
last_occurrence[cakes[i]] = i
return dp_table[n][k]
# Input
n, k = map(int, input().split())
cakes = [0] + list(map(int, input().split())) # Adding a dummy value at the beginning for 1-based indexing
# Output
print(max_total_value(n, k, cakes)) | Title: The Bakery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has.
She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of *n* cakes the oven is going to bake today. Slastyona has to pack exactly *k* boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes).
Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them.
Output Specification:
Print the only integer – the maximum total value of all boxes with cakes.
Demo Input:
['4 1\n1 2 2 1\n', '7 2\n1 3 3 1 4 4 4\n', '8 3\n7 7 8 7 7 8 1 7\n']
Demo Output:
['2\n', '5\n', '6\n']
Note:
In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5. | ```python
class SegmentTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (4 * size)
def update(self, node, left, right, index, value):
if left == right == index:
self.tree[node] = value
return
mid = (left + right) // 2
if index <= mid:
self.update(2 * node, left, mid, index, value)
else:
self.update(2 * node + 1, mid + 1, right, index, value)
self.tree[node] = self.tree[2 * node] + self.tree[2 * node + 1]
def query(self, node, left, right, ql, qr):
if ql > right or qr < left:
return 0
if ql <= left and qr >= right:
return self.tree[node]
mid = (left + right) // 2
return self.query(2 * node, left, mid, ql, qr) + self.query(2 * node + 1, mid + 1, right, ql, qr)
def max_total_value(n, k, cakes):
last_occurrence = [-1] * (n + 1)
segment_tree = SegmentTree(n)
dp_table = [[0] * (k + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
dp_table[i][1] = dp_table[i - 1][1] + (cakes[i] != cakes[i - 1])
for j in range(2, k + 1):
for i in range(1, n + 1):
dp_table[i][j] = dp_table[i][1]
if last_occurrence[cakes[i]] != -1:
dp_table[i][j] = max(dp_table[i][j], dp_table[last_occurrence[cakes[i]]][j - 1] + segment_tree.query(1, 1, n, last_occurrence[cakes[i]] + 1, i) * (i - last_occurrence[cakes[i]]))
segment_tree.update(1, 1, n, i, 1)
last_occurrence[cakes[i]] = i
return dp_table[n][k]
# Input
n, k = map(int, input().split())
cakes = [0] + list(map(int, input().split())) # Adding a dummy value at the beginning for 1-based indexing
# Output
print(max_total_value(n, k, cakes))
``` | 0 |
|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,681,815,434 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 8 | 496 | 67,072,000 | import math
def lcs(a, b):
lengths = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]
for i, x in enumerate(a):
for j, y in enumerate(b):
if x == y:
lengths[i + 1][j + 1] = lengths[i][j] + 1
else:
lengths[i + 1][j + 1] = max(lengths[i + 1][j], lengths[i][j + 1])
result = []
x, y = len(a), len(b)
while x != 0 and y != 0:
if lengths[x][y] == lengths[x - 1][y]:
x -= 1
elif lengths[x][y] == lengths[x][y - 1]:
y -= 1
else:
result.append(a[x - 1])
x -= 1
y -= 1
return result[::-1]
station = input()
first = input()
second = input()
ss = first+second
forward = len(lcs(station,ss)) == len(ss)
backward = len(lcs(station[::-1],ss)) == len(ss)
if forward and backward:
print("both")
elif forward == True and backward == False:
print("forward")
elif forward == False and backward == True:
print("backward")
else:
print("fantasy") | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | ```python
import math
def lcs(a, b):
lengths = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]
for i, x in enumerate(a):
for j, y in enumerate(b):
if x == y:
lengths[i + 1][j + 1] = lengths[i][j] + 1
else:
lengths[i + 1][j + 1] = max(lengths[i + 1][j], lengths[i][j + 1])
result = []
x, y = len(a), len(b)
while x != 0 and y != 0:
if lengths[x][y] == lengths[x - 1][y]:
x -= 1
elif lengths[x][y] == lengths[x][y - 1]:
y -= 1
else:
result.append(a[x - 1])
x -= 1
y -= 1
return result[::-1]
station = input()
first = input()
second = input()
ss = first+second
forward = len(lcs(station,ss)) == len(ss)
backward = len(lcs(station[::-1],ss)) == len(ss)
if forward and backward:
print("both")
elif forward == True and backward == False:
print("forward")
elif forward == False and backward == True:
print("backward")
else:
print("fantasy")
``` | 0 |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 1,572,685,439 | 2,147,483,647 | PyPy 3 | OK | TESTS | 133 | 156 | 0 | s=input()
f=0
for i in range(len(s)-1,-1,-1):
sub=s[0:i+1]
if(sub!=sub[::-1]):
f=1
print(i+1)
break
if f==0:
print(0)
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
Input Specification:
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
Output Specification:
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
Demo Input:
['mew\n', 'wuffuw\n', 'qqqqqqqq\n']
Demo Output:
['3\n', '5\n', '0\n']
Note:
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | ```python
s=input()
f=0
for i in range(len(s)-1,-1,-1):
sub=s[0:i+1]
if(sub!=sub[::-1]):
f=1
print(i+1)
break
if f==0:
print(0)
``` | 3 |
|
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting. | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
{
"input": "10 3 4 5",
"output": "3"
},
{
"input": "100 23 15 50",
"output": "2"
},
{
"input": "3119 3515 1021 7",
"output": "11"
},
{
"input": "918 102 1327 1733",
"output": "9"
},
{
"input": "3164 42 430 1309",
"output": "15"
},
{
"input": "3043 317 1141 2438",
"output": "7"
},
{
"input": "26 1 772 2683",
"output": "26"
},
{
"input": "370 2 1 15",
"output": "370"
},
{
"input": "734 12 6 2",
"output": "367"
},
{
"input": "418 18 14 17",
"output": "29"
},
{
"input": "18 16 28 9",
"output": "2"
},
{
"input": "14 6 2 17",
"output": "7"
},
{
"input": "29 27 18 2",
"output": "2"
},
{
"input": "29 12 7 10",
"output": "3"
},
{
"input": "27 23 4 3",
"output": "9"
},
{
"input": "5 14 5 2",
"output": "1"
},
{
"input": "5 17 26 5",
"output": "1"
},
{
"input": "9 1 10 3",
"output": "9"
},
{
"input": "2 19 15 1",
"output": "2"
},
{
"input": "4 6 4 9",
"output": "1"
},
{
"input": "10 6 2 9",
"output": "5"
},
{
"input": "2 2 9 6",
"output": "1"
},
{
"input": "6 2 4 1",
"output": "6"
},
{
"input": "27 24 5 27",
"output": "1"
},
{
"input": "2683 83 26 2709",
"output": "101"
},
{
"input": "728 412 789 158",
"output": "3"
},
{
"input": "3964 4 2916 176",
"output": "991"
},
{
"input": "3399 2035 2 3334",
"output": "683"
},
{
"input": "3455 244 3301 3",
"output": "991"
},
{
"input": "595 2263 3625 1",
"output": "595"
},
{
"input": "4000 1 1 1",
"output": "4000"
},
{
"input": "3999 2 2 3999",
"output": "1"
},
{
"input": "25 6 8 11",
"output": "3"
},
{
"input": "4000 500 1000 2000",
"output": "8"
},
{
"input": "53 10 11 23",
"output": "5"
},
{
"input": "100 100 1 1",
"output": "100"
},
{
"input": "17 3 4 10",
"output": "5"
},
{
"input": "413 101 102 105",
"output": "4"
},
{
"input": "490 4 49 50",
"output": "111"
},
{
"input": "3999 2 3 3",
"output": "1999"
},
{
"input": "8 3 8 4",
"output": "2"
},
{
"input": "5 1 3 3",
"output": "5"
},
{
"input": "100 3 17 22",
"output": "27"
},
{
"input": "4000 2 3 4",
"output": "2000"
},
{
"input": "4000 3 3 5",
"output": "1332"
},
{
"input": "13 4 6 7",
"output": "2"
},
{
"input": "4000 5 2 2",
"output": "2000"
},
{
"input": "3999 2 2 3",
"output": "1999"
},
{
"input": "4000 33 7 3333",
"output": "564"
},
{
"input": "60 33 20 9",
"output": "4"
},
{
"input": "100 9 11 99",
"output": "10"
},
{
"input": "2009 6 8 9",
"output": "334"
}
] | 1,690,312,202 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def cortar_cinta(original, longitud1, longitud2, longitud3):
variable_dinamica = [-1] * (original + 1)
variable_dinamica[0] = 0
for i in range(1, original + 1):
if i >= longitud1:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1)
if i >= longitud2:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud2] + 1)
if i >= longitud3:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud3] + 1)
return variable_dinamica[original]
entrada = input()
original, longitud1, longitud2, longitud3 = map(int, entrada.split())
print(cortar_cinta(original, longitud1, longitud2, longitud3))
def cortar_cinta(original, longitud1, longitud2, longitud3):
variable_dinamica = [-1] * (original + 1)
variable_dinamica[0] = 0
for i in range(1, original + 1):
if i >= longitud1:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1)
if i >= longitud2:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud2] + 1)
if i >= longitud3:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud3] + 1)
return variable_dinamica[original]
entrada = input()
original, longitud1, longitud2, longitud3 = map(int, entrada.split())
print(cortar_cinta(original, longitud1, longitud2, longitud3))
| Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
Input Specification:
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Output Specification:
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
Demo Input:
['5 5 3 2\n', '7 5 5 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | ```python
def cortar_cinta(original, longitud1, longitud2, longitud3):
variable_dinamica = [-1] * (original + 1)
variable_dinamica[0] = 0
for i in range(1, original + 1):
if i >= longitud1:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1)
if i >= longitud2:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud2] + 1)
if i >= longitud3:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud3] + 1)
return variable_dinamica[original]
entrada = input()
original, longitud1, longitud2, longitud3 = map(int, entrada.split())
print(cortar_cinta(original, longitud1, longitud2, longitud3))
def cortar_cinta(original, longitud1, longitud2, longitud3):
variable_dinamica = [-1] * (original + 1)
variable_dinamica[0] = 0
for i in range(1, original + 1):
if i >= longitud1:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud1] + 1)
if i >= longitud2:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud2] + 1)
if i >= longitud3:
variable_dinamica[i] = max(variable_dinamica[i], variable_dinamica[i - longitud3] + 1)
return variable_dinamica[original]
entrada = input()
original, longitud1, longitud2, longitud3 = map(int, entrada.split())
print(cortar_cinta(original, longitud1, longitud2, longitud3))
``` | -1 |
|
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 1,688,063,053 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 31 | 0 | n = int(input())
s = input()
last = []
first = []
is_last = True
for i in range(n-1,-1,-1):
if is_last:
last.append(s[i])
else:
first.append(s[i])
is_last = not is_last
# print(first)
# print(last)
ans = ''.join(first)
ans = ans + ''.join(last[::-1])
print(ans) | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Output Specification:
Print the word that Polycarp encoded.
Demo Input:
['5\nlogva\n', '2\nno\n', '4\nabba\n']
Demo Output:
['volga\n', 'no\n', 'baba\n']
Note:
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | ```python
n = int(input())
s = input()
last = []
first = []
is_last = True
for i in range(n-1,-1,-1):
if is_last:
last.append(s[i])
else:
first.append(s[i])
is_last = not is_last
# print(first)
# print(last)
ans = ''.join(first)
ans = ans + ''.join(last[::-1])
print(ans)
``` | 3 |