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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
982 | C | Cut 'em all! | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"greedy",
"trees"
] | null | null | You're given a tree with $n$ vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. | The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree.
The next $n - 1$ lines contain two integers $u$, $v$ ($1 \le u, v \le n$) each, describing the vertices connected by the $i$-th edge.
It's guaranteed that the given edges form a tree. | Output a single integer $k$ — the maximum number of edges that can be removed to leave all connected components with even size, or $-1$ if it is impossible to remove edges in order to satisfy this property. | [
"4\n2 4\n4 1\n3 1\n",
"3\n1 2\n1 3\n",
"10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5\n",
"2\n1 2\n"
] | [
"1",
"-1",
"4",
"0"
] | In the first example you can remove the edge between vertices $1$ and $4$. The graph after that will have two connected components with two vertices in each.
In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $-1$. | 1,500 | [
{
"input": "4\n2 4\n4 1\n3 1",
"output": "1"
},
{
"input": "3\n1 2\n1 3",
"output": "-1"
},
{
"input": "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5",
"output": "4"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4\n1 2\n1 3\n1 4",
"output": "0"
}
] | 1,622,115,241 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 358 | 13,721,600 | import sys,collections
input = sys.stdin.readline
def bfs(adj_list,n):
c=[1]*n;v=[-1]*n;v[0]=0;q=[0]
while q:
x=q[-1];flag=False
for to in adj_list[x]:
if v[to]==-1:
v[to]=x
q.append(to)
flag=True
if not flag:
q.pop()
c[v[x]]+=c[x]
ans=0
for i in c[1:]:
if i&1==0:ans+=1
print(ans)
n=int(input())
if n%2==1:print(-1);exit()
adj_list=[[]for _ in range(n+10)]
for _ in range(n-1):
a,b=map(int,input().split())
a-=1;b-=1
adj_list[a].append(b)
adj_list[b].append(a)
bfs(adj_list,n)
| Title: Cut 'em all!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a tree with $n$ vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Input Specification:
The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree.
The next $n - 1$ lines contain two integers $u$, $v$ ($1 \le u, v \le n$) each, describing the vertices connected by the $i$-th edge.
It's guaranteed that the given edges form a tree.
Output Specification:
Output a single integer $k$ — the maximum number of edges that can be removed to leave all connected components with even size, or $-1$ if it is impossible to remove edges in order to satisfy this property.
Demo Input:
['4\n2 4\n4 1\n3 1\n', '3\n1 2\n1 3\n', '10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5\n', '2\n1 2\n']
Demo Output:
['1', '-1', '4', '0']
Note:
In the first example you can remove the edge between vertices $1$ and $4$. The graph after that will have two connected components with two vertices in each.
In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $-1$. | ```python
import sys,collections
input = sys.stdin.readline
def bfs(adj_list,n):
c=[1]*n;v=[-1]*n;v[0]=0;q=[0]
while q:
x=q[-1];flag=False
for to in adj_list[x]:
if v[to]==-1:
v[to]=x
q.append(to)
flag=True
if not flag:
q.pop()
c[v[x]]+=c[x]
ans=0
for i in c[1:]:
if i&1==0:ans+=1
print(ans)
n=int(input())
if n%2==1:print(-1);exit()
adj_list=[[]for _ in range(n+10)]
for _ in range(n-1):
a,b=map(int,input().split())
a-=1;b-=1
adj_list[a].append(b)
adj_list[b].append(a)
bfs(adj_list,n)
``` | 3 |
|
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group. | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "3 4\n2553\n6856\n5133",
"output": "2"
},
{
"input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285",
"output": "6"
},
{
"input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994",
"output": "4"
},
{
"input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898",
"output": "9"
},
{
"input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143",
"output": "18"
},
{
"input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619",
"output": "11"
},
{
"input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6",
"output": "7"
},
{
"input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162",
"output": "23"
},
{
"input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6",
"output": "10"
},
{
"input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41",
"output": "21"
},
{
"input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119",
"output": "2"
},
{
"input": "3 3\n111\n111\n999",
"output": "1"
},
{
"input": "3 3\n119\n181\n711",
"output": "3"
},
{
"input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111",
"output": "15"
},
{
"input": "2 20\n22222222222222222222\n11111111111111111111",
"output": "1"
},
{
"input": "3 3\n233\n222\n111",
"output": "2"
},
{
"input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111",
"output": "3"
},
{
"input": "4 1\n1\n9\n9\n9",
"output": "3"
},
{
"input": "3 3\n123\n321\n132",
"output": "3"
},
{
"input": "3 3\n113\n332\n322",
"output": "3"
},
{
"input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111",
"output": "2"
},
{
"input": "3 3\n321\n231\n123",
"output": "3"
},
{
"input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222",
"output": "1"
},
{
"input": "3 3\n221\n111\n111",
"output": "3"
}
] | 1,666,032,661 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | val=input().split()
val=[int(x) for x in val]
n=val[0]
m=val[1]
liss=[]
for i in range(n):
t=input()
liss.append(t)
st=set()
for j in range(m):
val=liss[0][j]
for i in range(1,n):
if val<liss[i][j]:
val=liss[i][j]
for k in range(n):
if liss[k][j]==val:
st.add(k)
print(len(st))
| Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group.
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Output Specification:
Print the single number — the number of successful students in the given group.
Demo Input:
['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | ```python
val=input().split()
val=[int(x) for x in val]
n=val[0]
m=val[1]
liss=[]
for i in range(n):
t=input()
liss.append(t)
st=set()
for j in range(m):
val=liss[0][j]
for i in range(1,n):
if val<liss[i][j]:
val=liss[i][j]
for k in range(n):
if liss[k][j]==val:
st.add(k)
print(len(st))
``` | 3 |
|
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"input": "1000\n999",
"output": "1"
},
{
"input": "1000\n1",
"output": "250000"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n999",
"output": "249001"
},
{
"input": "2\n998",
"output": "248502"
},
{
"input": "999\n2",
"output": "249001"
},
{
"input": "998\n2",
"output": "248502"
},
{
"input": "2\n1000",
"output": "249500"
},
{
"input": "1000\n2",
"output": "249500"
},
{
"input": "1\n999",
"output": "249500"
},
{
"input": "999\n1",
"output": "249500"
},
{
"input": "188\n762",
"output": "82656"
},
{
"input": "596\n777",
"output": "8281"
},
{
"input": "773\n70",
"output": "123904"
},
{
"input": "825\n729",
"output": "2352"
},
{
"input": "944\n348",
"output": "89102"
},
{
"input": "352\n445",
"output": "2209"
},
{
"input": "529\n656",
"output": "4096"
},
{
"input": "19\n315",
"output": "22052"
},
{
"input": "138\n370",
"output": "13572"
},
{
"input": "546\n593",
"output": "576"
},
{
"input": "285\n242",
"output": "484"
},
{
"input": "773\n901",
"output": "4160"
},
{
"input": "892\n520",
"output": "34782"
},
{
"input": "864\n179",
"output": "117649"
},
{
"input": "479\n470",
"output": "25"
},
{
"input": "967\n487",
"output": "57840"
},
{
"input": "648\n106",
"output": "73712"
},
{
"input": "58\n765",
"output": "125316"
},
{
"input": "235\n56",
"output": "8100"
},
{
"input": "285\n153",
"output": "4422"
},
{
"input": "943\n13",
"output": "216690"
},
{
"input": "675\n541",
"output": "4556"
},
{
"input": "4\n912",
"output": "206570"
}
] | 1,520,178,590 | 890 | Python 3 | OK | TESTS | 40 | 77 | 5,632,000 | a=int(input())
b=int(input())
diff=abs(a-b)
odd=False
if diff&1==1:
odd=True
diff=diff//2
first=(diff*(diff+1))//2
if odd:
diff+=1
second=(diff*(diff+1))//2
print(first+second)
else:
print(first*2) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6.
The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
Input Specification:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*.
Output Specification:
Print the minimum possible total tiredness if the friends meet in the same point.
Demo Input:
['3\n4\n', '101\n99\n', '5\n10\n']
Demo Output:
['1\n', '2\n', '9\n']
Note:
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.
In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9. | ```python
a=int(input())
b=int(input())
diff=abs(a-b)
odd=False
if diff&1==1:
odd=True
diff=diff//2
first=(diff*(diff+1))//2
if odd:
diff+=1
second=(diff*(diff+1))//2
print(first+second)
else:
print(first*2)
``` | 3 |
|
359 | A | Table | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times. | The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner. | Print a single number — the minimum number of operations Simon needs to carry out his idea. | [
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n"
] | [
"4\n",
"2\n"
] | In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1). | 500 | [
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "4 32\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "7 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "2"
},
{
"input": "13 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 3\n0 1 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "4 3\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 0\n1 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "4 4\n0 0 0 0\n0 1 1 0\n0 1 1 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 1 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 1 1\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "5 5\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
}
] | 1,614,454,411 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 409,600 | import sys,random,math
'''
def gcd(x,y):
if y==0:
return x
else:
return gcd(y,x%y)
def pollard(n):
i = 1
x = random.randint(0,n-1)
y = x
k = 2
while True:
i = i+1
x = (x*x - 1)%n
d = gcd(y-x,n)
if d!=1 and d!=n:
print(d)
if i == k:
y = x
k = 2*k
'''
n, m = map(int,input().split())
uh = []
for i in range(n):
a = list(map(int,input().split()))
try:
if (i == 0 or i == n-1) and (a.index(1) == 0 or a.index(1) == m-1):
print(1)
sys.exit()
uh.append(a.index(1))
except ValueError:
pass
for i in uh:
if (i == 0 or i == m-1):
print(2)
sys.exit()
print(4)
| Title: Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
Input Specification:
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
Output Specification:
Print a single number — the minimum number of operations Simon needs to carry out his idea.
Demo Input:
['3 3\n0 0 0\n0 1 0\n0 0 0\n', '4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1). | ```python
import sys,random,math
'''
def gcd(x,y):
if y==0:
return x
else:
return gcd(y,x%y)
def pollard(n):
i = 1
x = random.randint(0,n-1)
y = x
k = 2
while True:
i = i+1
x = (x*x - 1)%n
d = gcd(y-x,n)
if d!=1 and d!=n:
print(d)
if i == k:
y = x
k = 2*k
'''
n, m = map(int,input().split())
uh = []
for i in range(n):
a = list(map(int,input().split()))
try:
if (i == 0 or i == n-1) and (a.index(1) == 0 or a.index(1) == m-1):
print(1)
sys.exit()
uh.append(a.index(1))
except ValueError:
pass
for i in uh:
if (i == 0 or i == m-1):
print(2)
sys.exit()
print(4)
``` | 0 |
|
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,667,322,218 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = map(int,input().split())
maxi = (m*n)//2
if maxi != 0:
print(maxi)
else:
print(0)
| 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,n = map(int,input().split())
maxi = (m*n)//2
if maxi != 0:
print(maxi)
else:
print(0)
``` | 3.977 |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\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\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\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
},
{
"input": "3\n6\n6\n6",
"output": "YES\nYES\nYES"
},
{
"input": "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n1\n52\n76",
"output": "NO\nYES\nYES"
},
{
"input": "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\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\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\nYES\nYES\nYES\nYES"
},
{
"input": "3\n3\n2\n1",
"output": "YES\nNO\nNO"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\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\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\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,645,282,554 | 2,147,483,647 | Python 3 | OK | TESTS | 8 | 31 | 0 | n = int(input())
cont = 0
while cont < n:
i = int(input())
if i == 0:
print('NO')
cont += 1
elif i < 7:
if i%3 == 0:
print('YES')
elif i%3 != 0:
print('NO')
cont += 1
elif i >= 7:
if i%3 == 0:
print('YES')
elif i%7 == 0:
print('YES')
elif i%3 != 0 and i%7 != 0:
while True:
i = i - 7
if i <= 0:
print('NO')
break
elif i%3 == 0:
print('YES')
break
cont += 1
| Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks.
Help Ivan to answer this question for several values of *x*!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat.
Output Specification:
Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO.
Demo Input:
['2\n6\n5\n']
Demo Output:
['YES\nNO\n']
Note:
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | ```python
n = int(input())
cont = 0
while cont < n:
i = int(input())
if i == 0:
print('NO')
cont += 1
elif i < 7:
if i%3 == 0:
print('YES')
elif i%3 != 0:
print('NO')
cont += 1
elif i >= 7:
if i%3 == 0:
print('YES')
elif i%7 == 0:
print('YES')
elif i%3 != 0 and i%7 != 0:
while True:
i = i - 7
if i <= 0:
print('NO')
break
elif i%3 == 0:
print('YES')
break
cont += 1
``` | 3 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,667,272,553 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 296 | 5,120,000 | t = int(input())
tree = []
coor = []
for i in range(t):
n,m = [int(x) for x in input().split()]
tree.append(n)
coor.append(m)
if t == 1:
num = 1
else:
num = 2
for i in range(1,t-1):
if tree[i]-coor[i] > tree[i-1]:
num += 1
elif tree[i]+coor[i] < tree[i+1]:
num += 1
tree[i] += coor[i]
print(str(num))
| Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
t = int(input())
tree = []
coor = []
for i in range(t):
n,m = [int(x) for x in input().split()]
tree.append(n)
coor.append(m)
if t == 1:
num = 1
else:
num = 2
for i in range(1,t-1):
if tree[i]-coor[i] > tree[i-1]:
num += 1
elif tree[i]+coor[i] < tree[i+1]:
num += 1
tree[i] += coor[i]
print(str(num))
``` | 3 |
|
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,682,258,159 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 122 | 1,536,000 | def main():
n , m = map(int, input().split())
kol = 0
for a in range(n):
for b in range(m):
if (a**2 + b) == n and (a + b ** 2) == m:
kol += 1
#print(a, b)
print(kol)
main()
| 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
def main():
n , m = map(int, input().split())
kol = 0
for a in range(n):
for b in range(m):
if (a**2 + b) == n and (a + b ** 2) == m:
kol += 1
#print(a, b)
print(kol)
main()
``` | 0 |
|
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,697,223,942 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
graph = {}
for i in range(1, n+1):
inp = int(input())
if inp == -1:
graph[i] = graph.get(i, [])
continue
if inp in graph:
graph[inp].append(i)
else:
graph[inp] = [i]
graph[i] = graph.get(i, [])
visited = {}
c = 0
def dfs(node, value):
global c
if value:
c += 1
visited[node] = None
for neig in graph[node]:
if neig not in visited:
dfs(neig, not value)
for i in range(1, n+1):
if len(graph[i]) == 0: continue
dfs(i, True)
if len(graph) - len(visited) != 0 and c == 0:
c = 1
print(c) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
n = int(input())
graph = {}
for i in range(1, n+1):
inp = int(input())
if inp == -1:
graph[i] = graph.get(i, [])
continue
if inp in graph:
graph[inp].append(i)
else:
graph[inp] = [i]
graph[i] = graph.get(i, [])
visited = {}
c = 0
def dfs(node, value):
global c
if value:
c += 1
visited[node] = None
for neig in graph[node]:
if neig not in visited:
dfs(neig, not value)
for i in range(1, n+1):
if len(graph[i]) == 0: continue
dfs(i, True)
if len(graph) - len(visited) != 0 and c == 0:
c = 1
print(c)
``` | 0 |
|
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club. | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
{
"input": "5 4\n1 4\n4 3\n4 5\n5 2",
"output": "2"
},
{
"input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11",
"output": "4"
},
{
"input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7",
"output": "2"
},
{
"input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6",
"output": "0"
},
{
"input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3",
"output": "0"
},
{
"input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5",
"output": "0"
},
{
"input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6",
"output": "1"
},
{
"input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4",
"output": "0"
},
{
"input": "95 0",
"output": "0"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39",
"output": "2"
},
{
"input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51",
"output": "3"
},
{
"input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41",
"output": "3"
},
{
"input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65",
"output": "5"
},
{
"input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7",
"output": "4"
},
{
"input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35",
"output": "4"
},
{
"input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65",
"output": "8"
},
{
"input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36",
"output": "4"
},
{
"input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70",
"output": "4"
},
{
"input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66",
"output": "3"
},
{
"input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27",
"output": "8"
},
{
"input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51",
"output": "4"
},
{
"input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75",
"output": "5"
},
{
"input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31",
"output": "3"
},
{
"input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35",
"output": "8"
},
{
"input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37",
"output": "3"
},
{
"input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41",
"output": "4"
},
{
"input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53",
"output": "5"
}
] | 1,595,243,392 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 434 | 23,961,600 | n,m = list(map(int,input().split(" ")))
adj = {i:[] for i in range(1,n+1)}
deg = {i:0 for i in range(1,n+1)}
for t in range(m):
x,y = list(map(int,input().split(" ")))
adj[x].append(y)
adj[y].append(x)
deg[x] += 1
deg[y] += 1
ans = 0
while True:
if 1 in deg.values():
ans += 1
l = [key for (key,value) in deg.items() if value==1]
for i in l:
deg[i] = 0
for k in adj[i]:
deg[k] -= 1
continue
break
print(ans) | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
Input Specification:
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Output Specification:
Print the single number — the number of groups of students that will be kicked out from the club.
Demo Input:
['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | ```python
n,m = list(map(int,input().split(" ")))
adj = {i:[] for i in range(1,n+1)}
deg = {i:0 for i in range(1,n+1)}
for t in range(m):
x,y = list(map(int,input().split(" ")))
adj[x].append(y)
adj[y].append(x)
deg[x] += 1
deg[y] += 1
ans = 0
while True:
if 1 in deg.values():
ans += 1
l = [key for (key,value) in deg.items() if value==1]
for i in l:
deg[i] = 0
for k in adj[i]:
deg[k] -= 1
continue
break
print(ans)
``` | 3 |
|
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n#.#.\n.#.#",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n#.#.\n#.#.",
"output": "NO"
},
{
"input": ".#.#\n.#.#\n.#.#\n.#.#",
"output": "NO"
},
{
"input": "#..#\n.##.\n####\n####",
"output": "YES"
},
{
"input": "#.#.\n.###\n#.#.\n.###",
"output": "YES"
},
{
"input": "#..#\n.##.\n.##.\n#..#",
"output": "YES"
},
{
"input": ".##.\n.#..\n##.#\n#..#",
"output": "YES"
},
{
"input": ".##.\n##..\n#..#\n..##",
"output": "YES"
},
{
"input": "##..\n##..\n..##\n..##",
"output": "YES"
},
{
"input": ".#..\n###.\n.#.#\n..#.",
"output": "YES"
},
{
"input": "###.\n###.\n...#\n...#",
"output": "YES"
},
{
"input": "#.##\n##.#\n#.##\n##.#",
"output": "YES"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.##",
"output": "YES"
},
{
"input": "##..\n..##\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..##\n##..\n..##",
"output": "YES"
},
{
"input": "##..\n...#\n##..\n...#",
"output": "YES"
},
{
"input": ".#..\n..#.\n.#..\n..#.",
"output": "YES"
},
{
"input": "....\n....\n....\n.#.#",
"output": "YES"
},
{
"input": "....\n....\n....\n...#",
"output": "YES"
}
] | 1,608,980,206 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 108 | 0 | s = ''
for i in range(4):
s += input().strip()
if s.count('#')!=s.count('.'):
print("YES")
else:
print("NO")
| Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color.
Input Specification:
Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black.
Output Specification:
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Demo Input:
['####\n.#..\n####\n....\n', '####\n....\n####\n....\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | ```python
s = ''
for i in range(4):
s += input().strip()
if s.count('#')!=s.count('.'):
print("YES")
else:
print("NO")
``` | 0 |
|
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely. | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,651,263,760 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 763 | 37,376,000 |
def which_groups_are_in(a, b, gs):
for i in range(len(gs)):
if a in gs[i]:
ga = i
if b in gs[i]:
gb = i
return ga, gb
def get_group(a, g):
if not g[a]["pointer"]:
return g[a]["friends"]
return get_group(g[a]["pointer"], g)
n_pessoas, n_pares = [int(x) for x in input().split()]
precos = [int(x) for x in input().split()]
pessoas = {}
for i in range(n_pessoas):
pessoas[i+1] = {"friends": {i+1},"pointer":0}
for i in range(n_pares):
a, b = [int(x) for x in input().split()]
pessoas[a]["friends"] = pessoas[a]["friends"].union(get_group(b, pessoas))
pessoas[b]["pointer"] = a
total = 0
for p in pessoas.keys():
if not pessoas[p]["pointer"]:
total += min(precos[x-1] for x in pessoas[p]["friends"])
print(total)
| Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Output Specification:
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Demo Input:
['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n']
Demo Output:
['10\n', '55\n', '15\n']
Note:
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | ```python
def which_groups_are_in(a, b, gs):
for i in range(len(gs)):
if a in gs[i]:
ga = i
if b in gs[i]:
gb = i
return ga, gb
def get_group(a, g):
if not g[a]["pointer"]:
return g[a]["friends"]
return get_group(g[a]["pointer"], g)
n_pessoas, n_pares = [int(x) for x in input().split()]
precos = [int(x) for x in input().split()]
pessoas = {}
for i in range(n_pessoas):
pessoas[i+1] = {"friends": {i+1},"pointer":0}
for i in range(n_pares):
a, b = [int(x) for x in input().split()]
pessoas[a]["friends"] = pessoas[a]["friends"].union(get_group(b, pessoas))
pessoas[b]["pointer"] = a
total = 0
for p in pessoas.keys():
if not pessoas[p]["pointer"]:
total += min(precos[x-1] for x in pessoas[p]["friends"])
print(total)
``` | 0 |
|
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store. | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input": "31",
"output": "31"
},
{
"input": "97",
"output": "97"
},
{
"input": "1000000000000",
"output": "10"
},
{
"input": "15",
"output": "15"
},
{
"input": "894",
"output": "894"
},
{
"input": "271",
"output": "271"
},
{
"input": "2457",
"output": "273"
},
{
"input": "2829",
"output": "2829"
},
{
"input": "5000",
"output": "10"
},
{
"input": "20",
"output": "10"
},
{
"input": "68",
"output": "34"
},
{
"input": "3096",
"output": "258"
},
{
"input": "1024",
"output": "2"
},
{
"input": "1048576",
"output": "2"
},
{
"input": "413933789280",
"output": "25870861830"
},
{
"input": "817634153013",
"output": "817634153013"
},
{
"input": "56517269141",
"output": "56517269141"
},
{
"input": "30707328551",
"output": "30707328551"
},
{
"input": "279564127218",
"output": "10354226934"
},
{
"input": "491159577042",
"output": "18191095446"
},
{
"input": "734337660466",
"output": "734337660466"
},
{
"input": "808453785117",
"output": "808453785117"
},
{
"input": "55926835837",
"output": "55926835837"
},
{
"input": "294809951965",
"output": "294809951965"
},
{
"input": "537988035389",
"output": "76855433627"
},
{
"input": "822722434952",
"output": "205680608738"
},
{
"input": "699511759613",
"output": "699511759613"
},
{
"input": "942689843037",
"output": "104743315893"
},
{
"input": "663634158717",
"output": "663634158717"
},
{
"input": "213612977250",
"output": "11730"
},
{
"input": "999999999989",
"output": "999999999989"
},
{
"input": "999999999988",
"output": "499999999994"
},
{
"input": "87178291200",
"output": "30030"
},
{
"input": "927668721948",
"output": "463834360974"
},
{
"input": "562436815639",
"output": "37927"
},
{
"input": "302981118597",
"output": "35853"
},
{
"input": "5",
"output": "5"
},
{
"input": "9",
"output": "3"
},
{
"input": "36",
"output": "6"
},
{
"input": "2231",
"output": "2231"
},
{
"input": "27648",
"output": "6"
},
{
"input": "40320",
"output": "210"
},
{
"input": "648000",
"output": "30"
},
{
"input": "999966000289",
"output": "999983"
},
{
"input": "999985999949",
"output": "999985999949"
},
{
"input": "991921850317",
"output": "9973"
}
] | 1,636,211,519 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 4,505,600 | # Code by : Sam._.072
import math
n = int(input())
if n==1:
print(1)
exit()
if n%2==0:
x=n//2
else:
for i in range(n//2,-1,-1):
if n%i==0:
x=i
break
f=[n,x]
for i in range(x-1,0,-1):
if n%i==0:
f.append(i)
j=0
while True:
y=int(math.sqrt(f[j]))
z=0
for i in range(y,1,-1):
if f[j]%(i*i)==0:
z=-1
j+=1
break
if z==0:
x=f[j]
break
# print(z)
print(x)
| Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
Input Specification:
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Output Specification:
Print the answer in one line.
Demo Input:
['10\n', '12\n']
Demo Output:
['10\n', '6\n']
Note:
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | ```python
# Code by : Sam._.072
import math
n = int(input())
if n==1:
print(1)
exit()
if n%2==0:
x=n//2
else:
for i in range(n//2,-1,-1):
if n%i==0:
x=i
break
f=[n,x]
for i in range(x-1,0,-1):
if n%i==0:
f.append(i)
j=0
while True:
y=int(math.sqrt(f[j]))
z=0
for i in range(y,1,-1):
if f[j]%(i*i)==0:
z=-1
j+=1
break
if z==0:
x=f[j]
break
# print(z)
print(x)
``` | 0 |
|
274 | D | Lovely Matrix | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs",
"greedy",
"sortings"
] | null | null | Lenny had an *n*<=×<=*m* matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely.
One day when Lenny was at school his little brother was playing with Lenny's matrix in his room. He erased some of the entries of the matrix and changed the order of some of its columns. When Lenny got back home he was very upset. Now Lenny wants to recover his matrix.
Help him to find an order for the columns of the matrix so that it's possible to fill in the erased entries of the matrix to achieve a lovely matrix again. Note, that you can fill the erased entries of the matrix with any integers. | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=105). Each of the next *n* lines contains *m* space-separated integers representing the matrix. An integer -1 shows an erased entry of the matrix. All other integers (each of them is between 0 and 109 inclusive) represent filled entries. | If there exists no possible reordering of the columns print -1. Otherwise the output should contain *m* integers *p*1,<=*p*2,<=...,<=*p**m* showing the sought permutation of columns. So, the first column of the lovely matrix will be *p*1-th column of the initial matrix, the second column of the lovely matrix will be *p*2-th column of the initial matrix and so on. | [
"3 3\n1 -1 -1\n1 2 1\n2 -1 1\n",
"2 3\n1 2 2\n2 5 4\n",
"2 3\n1 2 3\n3 2 1\n"
] | [
"3 1 2 \n",
"1 3 2 \n",
"-1\n"
] | none | 2,000 | [] | 1,572,605,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 204,800 | n, m = map(int, input().split())
b = [map(int, input().split()) for _ in range(n)]
c = [n - x.count(-1) for x in zip(*b)]
d = []
for r in b:
t = {}
for i, x in enumerate(r):
if x != -1:
if x not in t:
t[x] = set()
t[x].add(i)
d.append([x for i, x in sorted(t.items())][:: -1])
p = [i for i, x in enumerate(c) if not x]
for v in d:
if v:
for x in v[-1]:
c[x] -= 1
if not c[x]:
p.append(x)
r = []
while p:
x = p.pop()
r.append(x + 1)
for i, v in enumerate(d):
if v:
v[-1].discard(x)
if not v[-1]:
d[i].pop()
if d[i]:
for y in d[i][-1]:
c[y] -= 1
if not c[y]:
p.append(y)
print([-1, ' '.join(map(str, r))][len(r) == m])
| Title: Lovely Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny had an *n*<=×<=*m* matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely.
One day when Lenny was at school his little brother was playing with Lenny's matrix in his room. He erased some of the entries of the matrix and changed the order of some of its columns. When Lenny got back home he was very upset. Now Lenny wants to recover his matrix.
Help him to find an order for the columns of the matrix so that it's possible to fill in the erased entries of the matrix to achieve a lovely matrix again. Note, that you can fill the erased entries of the matrix with any integers.
Input Specification:
The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=105). Each of the next *n* lines contains *m* space-separated integers representing the matrix. An integer -1 shows an erased entry of the matrix. All other integers (each of them is between 0 and 109 inclusive) represent filled entries.
Output Specification:
If there exists no possible reordering of the columns print -1. Otherwise the output should contain *m* integers *p*1,<=*p*2,<=...,<=*p**m* showing the sought permutation of columns. So, the first column of the lovely matrix will be *p*1-th column of the initial matrix, the second column of the lovely matrix will be *p*2-th column of the initial matrix and so on.
Demo Input:
['3 3\n1 -1 -1\n1 2 1\n2 -1 1\n', '2 3\n1 2 2\n2 5 4\n', '2 3\n1 2 3\n3 2 1\n']
Demo Output:
['3 1 2 \n', '1 3 2 \n', '-1\n']
Note:
none | ```python
n, m = map(int, input().split())
b = [map(int, input().split()) for _ in range(n)]
c = [n - x.count(-1) for x in zip(*b)]
d = []
for r in b:
t = {}
for i, x in enumerate(r):
if x != -1:
if x not in t:
t[x] = set()
t[x].add(i)
d.append([x for i, x in sorted(t.items())][:: -1])
p = [i for i, x in enumerate(c) if not x]
for v in d:
if v:
for x in v[-1]:
c[x] -= 1
if not c[x]:
p.append(x)
r = []
while p:
x = p.pop()
r.append(x + 1)
for i, v in enumerate(d):
if v:
v[-1].discard(x)
if not v[-1]:
d[i].pop()
if d[i]:
for y in d[i][-1]:
c[y] -= 1
if not c[y]:
p.append(y)
print([-1, ' '.join(map(str, r))][len(r) == m])
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 0 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 1,537,702,872 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | symbol = ["a", "e", "i", "o", "u"]
a = input()
i = 2
while i < len(a):
if not (a[i] in symbol) and not(a[i - 1] in symbol) and not (a[i - 2] in symbol) and a[i - 2:i + 1] != a[i - 2] * 3:
a = a[:i] + " " + a[i:]
i = i + 4
else:
i = i + 1
print(a)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input Specification:
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output Specification:
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Demo Input:
['hellno\n', 'abacaba\n', 'asdfasdf\n']
Demo Output:
['hell no \n', 'abacaba \n', 'asd fasd f \n']
Note:
none | ```python
symbol = ["a", "e", "i", "o", "u"]
a = input()
i = 2
while i < len(a):
if not (a[i] in symbol) and not(a[i - 1] in symbol) and not (a[i - 2] in symbol) and a[i - 2:i + 1] != a[i - 2] * 3:
a = a[:i] + " " + a[i:]
i = i + 4
else:
i = i + 1
print(a)
``` | 0 |
|
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS. | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "[]{[]({)([",
"output": "Impossible"
},
{
"input": "(([{>}{[{[)]]>>]",
"output": "7"
},
{
"input": "((<>)[]<]><]",
"output": "3"
},
{
"input": "[[([[(>]>)))[<)>",
"output": "6"
},
{
"input": "({)[}<)](}",
"output": "5"
},
{
"input": "(}{)[<][)(]}",
"output": "6"
},
{
"input": ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([",
"output": "Impossible"
},
{
"input": "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>[[>{>>>[<]}<>>)[>]<{)<[><(<]][>(>]>][(<][{]}(()<[()[>><<])<]})]<]}{)",
"output": "45"
},
{
"input": "[<<{{((}[}<<)<)>})(][{>}})((>)<[)[>}[})[)>()[()[((}<<(>)<>](<>(}[>})[[[{)<}<<(}{>>}[<([[])<><)]<{>}[>>>{({>)}]})>)",
"output": "42"
},
{
"input": "(<[([(<({>(}{]>[(})])}])()<<}{]{[>]>(>>[(>>}[){(}<[{(()]{{<(<{][[{<><{<{)<>>]}}}{)(}{})}[<))>>}((({>){({}{{]}]>>}})>))",
"output": "43"
},
{
"input": "{(]}<([]<]{>]<{<({{{<>))}[({(}{)[}({>]}}<<)}<]))(<>(>{>{{{)<}({<]<>{)(>[)>{({}<([<[[)]><>{]}}(>]{}<)[})]}]]}]}>}",
"output": "40"
},
{
"input": "<(([)]<[}>{)>][[(<()({{{>>((]<}<{{<>}><<[)}[[)([[)[)}<]<{(<>){([)><{[([[][({])})<][(}]}>>[){)[({>){(}[}})>}>]>)]}))})>}]",
"output": "45"
},
{
"input": ")(",
"output": "Impossible"
},
{
"input": "[[[[[[[[",
"output": "Impossible"
}
] | 1,633,967,407 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 421 | 10,547,200 | l=[]
c = 0
for i in input():
if i in "[<{(":
l.append(i)
elif len(l) > 0:
if l.pop() != {'}':'{', ')':'(', ']':'[', '>':'<'}[i]:
c += 1
else:
print("Impossible")
break
else:
if (len(l) > 0):
print("Impossible")
else:
print(c)
| Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS.
Input Specification:
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
Output Specification:
If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*.
Demo Input:
['[<}){}\n', '{()}[]\n', ']]\n']
Demo Output:
['2', '0', 'Impossible']
Note:
none | ```python
l=[]
c = 0
for i in input():
if i in "[<{(":
l.append(i)
elif len(l) > 0:
if l.pop() != {'}':'{', ')':'(', ']':'[', '>':'<'}[i]:
c += 1
else:
print("Impossible")
break
else:
if (len(l) > 0):
print("Impossible")
else:
print(c)
``` | 3 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,693,922,984 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 0 | n = int(input())
my_listx = []
my_listy = []
my_listz = []
for i in range(n):
a, b, c = input().split(' ')
my_listx.append(int(a))
my_listy.append(int(b))
my_listz.append(int(c))
sum_numbersx = 0
sum_numbersy = 0
sum_numbersz = 0
for i in my_listx:
sum_numbersx += i
for i in my_listx:
sum_numbersy += i
for i in my_listx:
sum_numbersz += i
if (sum_numbersx == 0)&(sum_numbersy == 0)&(sum_numbersz == 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())
my_listx = []
my_listy = []
my_listz = []
for i in range(n):
a, b, c = input().split(' ')
my_listx.append(int(a))
my_listy.append(int(b))
my_listz.append(int(c))
sum_numbersx = 0
sum_numbersy = 0
sum_numbersz = 0
for i in my_listx:
sum_numbersx += i
for i in my_listx:
sum_numbersy += i
for i in my_listx:
sum_numbersz += i
if (sum_numbersx == 0)&(sum_numbersy == 0)&(sum_numbersz == 0):
print("YES")
else:
print("NO")
``` | 3.969 |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 1,673,607,732 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | a = str(input())
q = len(a)
w = "AB"
e = "BA"
s = a.count("ABA")
if w in a and e in a and q > 3 and s != 1 :
print("YES")
else:
print("NO")
| Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Output Specification:
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Demo Input:
['ABA\n', 'BACFAB\n', 'AXBYBXA\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | ```python
a = str(input())
q = len(a)
w = "AB"
e = "BA"
s = a.count("ABA")
if w in a and e in a and q > 3 and s != 1 :
print("YES")
else:
print("NO")
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,511,972,030 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
list = input().split()
list = [int(i) for i in list]
list1=[]
list2=[]
count = 0
for i in list:
if i%2==0 :
count +=1
list1.append(i)
else:
list2.append(i)
if count =1:
print(list1[0])
else:
print(list2[0]) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
list = input().split()
list = [int(i) for i in list]
list1=[]
list2=[]
count = 0
for i in list:
if i%2==0 :
count +=1
list1.append(i)
else:
list2.append(i)
if count =1:
print(list1[0])
else:
print(list2[0])
``` | -1 |
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,665,240,335 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 93 | 0 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
ok = 0
ans = "Yes"
for i in range(n - 1):
if s[i] == s[i + 1] and s[i] ^ 63:
ans = "No"
break
elif s[i] == s[i + 1]:
ok = 1
for i in range(1, n - 1):
if s[i] == 63 and s[i - 1] == s[i + 1]:
ok = 1
break
if s[0] == 63 or s[-1] == 63:
ok = 1
if not ok:
ans = "No"
print(ans) | 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
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
ok = 0
ans = "Yes"
for i in range(n - 1):
if s[i] == s[i + 1] and s[i] ^ 63:
ans = "No"
break
elif s[i] == s[i + 1]:
ok = 1
for i in range(1, n - 1):
if s[i] == 63 and s[i - 1] == s[i + 1]:
ok = 1
break
if s[0] == 63 or s[-1] == 63:
ok = 1
if not ok:
ans = "No"
print(ans)
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,491,641,772 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 5,529,600 | a=input()
b=input()
rev=a[::-1]
if rev==b:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
a=input()
b=input()
rev=a[::-1]
if rev==b:
print('YES')
else:
print('NO')
``` | 3.9587 |
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=<<=*j*<=<<=*a*2 for some *a*1 and *a*2 from *A*).
Write a program that will determine the maximum number of elements in a pretty set of positions. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string *s* does not contain any lowercase letters, so the answer is 0. | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh",
"output": "8"
},
{
"input": "2\nAZ",
"output": "0"
},
{
"input": "28\nAabcBabcCBNMaaaaabbbbbcccccc",
"output": "3"
},
{
"input": "200\nrsgraosldglhdoorwhkrsehjpuxrjuwgeanjgezhekprzarelduuaxdnspzjuooguuwnzkowkuhzduakdrzpnslauejhrrkalwpurpuuswdgeadlhjwzjgegwpknepazwwleulppwrlgrgedlwdzuodzropsrrkxusjnuzshdkjrxxpgzanzdrpnggdwxarpwohxdepJ",
"output": "17"
},
{
"input": "1\nk",
"output": "1"
},
{
"input": "1\nH",
"output": "0"
},
{
"input": "2\nzG",
"output": "1"
},
{
"input": "2\ngg",
"output": "1"
},
{
"input": "2\nai",
"output": "2"
},
{
"input": "20\npEjVrKWLIFCZjIHgggVU",
"output": "1"
},
{
"input": "20\niFSiiigiYFSKmDnMGcgM",
"output": "2"
},
{
"input": "20\nedxedxxxCQiIVmYEUtLi",
"output": "3"
},
{
"input": "20\nprnchweyabjvzkoqiltm",
"output": "20"
},
{
"input": "35\nQLDZNKFXKVSVLUVHRTDPQYMSTDXBELXBOTS",
"output": "0"
},
{
"input": "35\nbvZWiitgxodztelnYUyljYGnCoWluXTvBLp",
"output": "10"
},
{
"input": "35\nBTexnaeplecllxwlanarpcollawHLVMHIIF",
"output": "10"
},
{
"input": "35\nhhwxqysolegsthsvfcqiryenbujbrrScobu",
"output": "20"
},
{
"input": "26\npbgfqosklxjuzmdheyvawrictn",
"output": "26"
},
{
"input": "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl",
"output": "20"
},
{
"input": "100\nhXYLXKUMBrGkjqQJTGbGWAfmztqqapdbjbhcualhypgnaieKXmhzGMnqXVlcPesskfaEVgvWQTTShRRnEtFahWDyuBzySMpugxCM",
"output": "19"
},
{
"input": "100\nucOgELrgjMrFOgtHzqgvUgtHngKJxdMFKBjfcCppciqmGZXXoiSZibgpadshyljqrwxbomzeutvnhTLGVckZUmyiFPLlwuLBFito",
"output": "23"
},
{
"input": "200\nWTCKAKLVGXSYFVMVJDUYERXNMVNTGWXUGRFCGMYXJQGLODYZTUIDENHYEGFKXFIEUILAMESAXAWZXVCZPJPEYUXBITHMTZOTMKWITGRSFHODKVJHPAHVVWTCTHIVAWAREQXWMPUWQSTPPJFHKGKELBTPUYDAVIUMGASPUEDIODRYXIWCORHOSLIBLOZUNJPHHMXEXOAY",
"output": "0"
},
{
"input": "200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQhUTUQDgXhMjJZgFSSiHhMKuTgZQYJqAqKBpHoHddddddddddddddddXSSYNKNnRrKuOjAVKZlRLzCjExPdHaDHBT",
"output": "1"
},
{
"input": "200\nitSYxgOLlwOoAkkkkkzzzzzzzzkzkzkzkkkkkzkzzkzUDJSKybRPBvaIDsNuWImPJvrHkKiMeYukWmtHtgZSyQsgYanZvXNbKXBlFLSUcqRnGWSriAvKxsTkDJfROqaKdzXhvJsPEDATueCraWOGEvRDWjPwXuiNpWsEnCuhDcKWOQxjBkdBqmFatWFkgKsbZuLtRGtY",
"output": "2"
},
{
"input": "200\noggqoqqogoqoggggoggqgooqggogogooogqqgggoqgggqoqogogggogggqgooqgqggqqqoqgqgoooqgqogqoggoqqgqoqgoooqoogooqoogqoqoqqgoqgoqgggogqqqoqoggoqoqqoqggqoggooqqqoqggoggqqqqqqqqqgogqgggggooogogqgggqogqgoqoqogoooq",
"output": "3"
},
{
"input": "200\nCtclUtUnmqFniaLqGRmMoUMeLyFfAgWxIZxdrBarcRQprSOGcdUYsmDbooSuOvBLgrYlgaIjJtFgcxJKHGkCXpYfVKmUbouuIqGstFrrwJzYQqjjqqppqqqqqpqqqjpjjpjqjXRYkfPhGAatOigFuItkKxkjCBLdiNMVGjmdWNMgOOvmaJEdGsWNoaERrINNKqKeQajv",
"output": "3"
},
{
"input": "200\nmeZNrhqtSTSmktGQnnNOTcnyAMTKSixxKQKiagrMqRYBqgbRlsbJhvtNeHVUuMCyZLCnsIixRYrYEAkfQOxSVqXkrPqeCZQksInzRsRKBgvIqlGVPxPQnypknSXjgMjsjElcqGsaJRbegJVAKtWcHoOnzHqzhoKReqBBsOhZYLaYJhmqOMQsizdCsQfjUDHcTtHoeYwu",
"output": "4"
},
{
"input": "200\nvFAYTHJLZaivWzSYmiuDBDUFACDSVbkImnVaXBpCgrbgmTfXKJfoglIkZxWPSeVSFPnHZDNUAqLyhjLXSuAqGLskBlDxjxGPJyGdwzlPfIekwsblIrkxzfhJeNoHywdfAGlJzqXOfQaKceSqViVFTRJEGfACnsFeSFpOYisIHJciqTMNAmgeXeublTvfWoPnddtvKIyF",
"output": "6"
},
{
"input": "200\ngnDdkqJjYvduVYDSsswZDvoCouyaYZTfhmpSakERWLhufZtthWsfbQdTGwhKYjEcrqWBOyxBbiFhdLlIjChLOPiOpYmcrJgDtXsJfmHtLrabyGKOfHQRukEtTzwoqBHfmyVXPebfcpGQacLkGWFwerszjdHpTBXGssYXmGHlcCBgBXyGJqxbVhvDffLyCrZnxonABEXV",
"output": "7"
},
{
"input": "200\nBmggKNRZBXPtJqlJaXLdKKQLDJvXpDuQGupiRQfDwCJCJvAlDDGpPZNOvXkrdKOFOEFBVfrsZjWyHPoKGzXmTAyPJGEmxCyCXpeAdTwbrMtWLmlmGNqxvuxmqpmtpuhrmxxtrquSLFYVlnSYgRJDYHWgHBbziBLZRwCIJNvbtsEdLLxmTbnjkoqSPAuzEeTYLlmejOUH",
"output": "9"
},
{
"input": "200\nMkuxcDWdcnqsrlTsejehQKrTwoOBRCUAywqSnZkDLRmVBDVoOqdZHbrInQQyeRFAjiYYmHGrBbWgWstCPfLPRdNVDXBdqFJsGQfSXbufsiogybEhKDlWfPazIuhpONwGzZWaQNwVnmhTqWdewaklgjwaumXYDGwjSeEcYXjkVtLiYSWULEnTFukIlWQGWsXwWRMJGTcI",
"output": "10"
},
{
"input": "200\nOgMBgYeuMJdjPtLybvwmGDrQEOhliaabEtwulzNEjsfnaznXUMoBbbxkLEwSQzcLrlJdjJCLGVNBxorghPxTYCoqniySJMcilpsqpBAbqdzqRUDVaYOgqGhGrxlIJkyYgkOdTUgRZwpgIkeZFXojLXpDilzirHVVadiHaMrxhzodzpdvhvrzdzxbhmhdpxqqpoDegfFQ",
"output": "11"
},
{
"input": "200\nOLaJOtwultZLiZPSYAVGIbYvbIuZkqFZXwfsqpsavCDmBMStAuUFLBVknWDXNzmiuUYIsUMGxtoadWlPYPqvqSvpYdOiJRxFzGGnnmstniltvitnrmyrblnqyruylummmlsqtqitlbulvtuitiqimuintbimqyurviuntqnnvslynlNYMpYVKYwKVTbIUVdlNGrcFZON",
"output": "12"
},
{
"input": "200\nGAcmlaqfjSAQLvXlkhxujXgSbxdFAwnoxDuldDvYmpUhTWJdcEQSdARLrozJzIgFVCkzPUztWIpaGfiKeqzoXinEjVuoKqyBHmtFjBWcRdBmyjviNlGAIkpikjAimmBgayfphrstfbjexjbttzfzfzaysxfyrjazfhtpghnbbeffjhxrjxpttesgzrnrfbgzzsRsCgmz",
"output": "15"
},
{
"input": "200\nYRvIopNqSTYDhViTqCLMwEbTTIdHkoeuBmAJWhgtOgVxlcHSsavDNzMfpwTghkBvYEtCYQxicLUxdgAcaCzOOgbQYsfnaTXFlFxbeEiGwdNvxwHzkTdKtWlqzalwniDDBDipkxfflpaqkfkgfezbkxdvzemlfohwtgytzzywmwhvzUgPlPdeAVqTPAUZbogQheRXetvT",
"output": "20"
},
{
"input": "200\nNcYVomemswLCUqVRSDKHCknlBmqeSWhVyRzQrnZaOANnTGqsRFMjpczllcEVebqpxdavzppvztxsnfmtcharzqlginndyjkawzurqkxJLXiXKNZTIIxhSQghDpjwzatEqnLMTLxwoEKpHytvWkKFDUcZjLShCiVdocxRvvJtbXHCDGpJvMwRKWLhcTFtswdLUHkbhfau",
"output": "25"
},
{
"input": "200\nDxNZuvkTkQEqdWIkLzcKAwfqvZQiptnTazydSCTIfGjDhLMrlPZiKEsqIdDhgKPAlEvXyzNwWtYorotgkcwydpabjqnzubaksdchucxtkmjzfretdmvlxgklyvicrtftvztsbiUaQorfNIYUOdwQDRsKpxLUiLknbLbinilpPXPTTwLAnXVpMHBaAcKWgDBeOFabPtXU",
"output": "26"
},
{
"input": "4\nabbc",
"output": "3"
},
{
"input": "3\naaa",
"output": "1"
},
{
"input": "3\naba",
"output": "2"
},
{
"input": "3\nabb",
"output": "2"
},
{
"input": "3\nbba",
"output": "2"
},
{
"input": "3\nAaa",
"output": "1"
},
{
"input": "3\nAba",
"output": "2"
},
{
"input": "3\naBa",
"output": "1"
},
{
"input": "3\naAa",
"output": "1"
},
{
"input": "3\naAb",
"output": "1"
},
{
"input": "3\nAaA",
"output": "1"
},
{
"input": "5\naBacd",
"output": "3"
},
{
"input": "5\naAabc",
"output": "3"
}
] | 1,638,873,241 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | n=int(input())
s=input()
a,res=[],0
for i in range(n):
if s[i].isupper():
a.append(i)
res=max(res,len(set(s[:a[0]])))
for i in range(1,len(a)):
res=max(res,len(set(s[a[i-1]+1:a[i]])))
res=max(res,len(set(s[a[len(a)-1]+1:n])))
print(res) | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=<<=*j*<=<<=*a*2 for some *a*1 and *a*2 from *A*).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters.
Output Specification:
Print maximum number of elements in pretty set of positions for string *s*.
Demo Input:
['11\naaaaBaabAbA\n', '12\nzACaAbbaazzC\n', '3\nABC\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string *s* does not contain any lowercase letters, so the answer is 0. | ```python
n=int(input())
s=input()
a,res=[],0
for i in range(n):
if s[i].isupper():
a.append(i)
res=max(res,len(set(s[:a[0]])))
for i in range(1,len(a)):
res=max(res,len(set(s[a[i-1]+1:a[i]])))
res=max(res,len(set(s[a[len(a)-1]+1:n])))
print(res)
``` | -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,668,826,795 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import sys
input_file = sys.stdin
output_file = sys.stdout
n = int(input_file.readline().strip())
for i in range(n):
word = input_file.readline().strip()
if len(word) > 10:
word_2 = f"{word[0]}{len(word)}{word[len(word) - 1]}"
output_file.write(word_2)
else:
output_file.write(word)
| 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
import sys
input_file = sys.stdin
output_file = sys.stdout
n = int(input_file.readline().strip())
for i in range(n):
word = input_file.readline().strip()
if len(word) > 10:
word_2 = f"{word[0]}{len(word)}{word[len(word) - 1]}"
output_file.write(word_2)
else:
output_file.write(word)
``` | 0 |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2",
"output": "5\n7\n5\n5\n2\n7\n7\n13\n4"
},
{
"input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7",
"output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326"
},
{
"input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29",
"output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772"
},
{
"input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12",
"output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195"
},
{
"input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1",
"output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2"
},
{
"input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2",
"output": "6\n1\n6\n1\n5\n6\n1\n5"
},
{
"input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4",
"output": "22\n10\n10\n6\n12\n36\n6\n14\n16"
},
{
"input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4",
"output": "11\n11\n2\n10\n1\n3\n10\n12\n12"
},
{
"input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5",
"output": "8\n27\n1\n8\n26"
},
{
"input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8",
"output": "10\n2\n13\n10"
},
{
"input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5",
"output": "9\n24\n28"
},
{
"input": "1\n1\n2\n1 1 1\n2 1 1",
"output": "1\n1"
}
] | 1,631,930,872 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 28,569,600 | input()
lst = []
vn = list(map(int,input().split()))
v2 = sorted(vn)
for i in range(int(input())):
answer = 0
mirai = list(map(int,input().split()))
if mirai[0] == 1:
for x in range(mirai[1]-1,mirai[2]):
answer += vn[x]
lst.append(answer)
else:
for x in range(mirai[1]-1,mirai[2]):
answer += v2[x]
lst.append(answer)
for i in lst: print(i) | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Output Specification:
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
Demo Input:
['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n']
Demo Output:
['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n']
Note:
Please note that the answers to the questions may overflow 32-bit integer type. | ```python
input()
lst = []
vn = list(map(int,input().split()))
v2 = sorted(vn)
for i in range(int(input())):
answer = 0
mirai = list(map(int,input().split()))
if mirai[0] == 1:
for x in range(mirai[1]-1,mirai[2]):
answer += vn[x]
lst.append(answer)
else:
for x in range(mirai[1]-1,mirai[2]):
answer += v2[x]
lst.append(answer)
for i in lst: print(i)
``` | 0 |
|
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###"
},
{
"input": "45 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,680,541,829 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 62 | 3,072,000 | n , m = map(int, input().split())
count = 0
for i in range(1, n+1):
for j in range(m):
if i % 2 == 0:
if count % 2 == 0:
print('.' * (m-1) + '#', end='')
count += 1
break
else:
print('#' + '.' * (m-1) , end='')
count += 1
break
else:
print('#', end='')
print() | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
n , m = map(int, input().split())
count = 0
for i in range(1, n+1):
for j in range(m):
if i % 2 == 0:
if count % 2 == 0:
print('.' * (m-1) + '#', end='')
count += 1
break
else:
print('#' + '.' * (m-1) , end='')
count += 1
break
else:
print('#', end='')
print()
``` | 3 |
|
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"output": "10"
},
{
"input": "2 1\n2 1",
"output": "2"
},
{
"input": "2 2\n2 4\n1 4",
"output": "8"
},
{
"input": "2 3\n1 7\n1 2\n1 5",
"output": "12"
},
{
"input": "4 1\n2 2",
"output": "4"
},
{
"input": "4 2\n1 10\n4 4",
"output": "22"
},
{
"input": "4 3\n1 4\n6 4\n1 7",
"output": "19"
},
{
"input": "5 1\n10 5",
"output": "25"
},
{
"input": "5 2\n3 9\n2 2",
"output": "31"
},
{
"input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8",
"output": "42"
},
{
"input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7",
"output": "41"
},
{
"input": "10 1\n9 4",
"output": "36"
},
{
"input": "10 2\n14 3\n1 3",
"output": "30"
},
{
"input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10",
"output": "71"
},
{
"input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4",
"output": "70"
},
{
"input": "10 4\n1 5\n5 2\n1 9\n3 3",
"output": "33"
},
{
"input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4",
"output": "716"
},
{
"input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4",
"output": "8218"
},
{
"input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10",
"output": "84715"
},
{
"input": "100000 3\n2975 2\n35046 4\n61979 9",
"output": "703945"
},
{
"input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9",
"output": "8794569"
},
{
"input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3",
"output": "85022733"
},
{
"input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5",
"output": "749254060"
},
{
"input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3",
"output": "1332923354"
},
{
"input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5",
"output": "996523209"
},
{
"input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6",
"output": "630991750"
},
{
"input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8",
"output": "931584598"
},
{
"input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6",
"output": "1447294907"
},
{
"input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1",
"output": "1634907859"
},
{
"input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10",
"output": "1305347138"
},
{
"input": "200000000 3\n65170000 7\n20790088 1\n74616133 4",
"output": "775444620"
},
{
"input": "200000000 2\n11823018 6\n100000000 9",
"output": "970938108"
},
{
"input": "200000000 1\n100000000 6",
"output": "600000000"
},
{
"input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5",
"output": "1152034197"
},
{
"input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6",
"output": "1095537357"
},
{
"input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5",
"output": "83"
},
{
"input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10",
"output": "54980855"
},
{
"input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6",
"output": "939368573"
},
{
"input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5",
"output": "1158946383"
},
{
"input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3",
"output": "1131379312"
},
{
"input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9",
"output": "79"
},
{
"input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7",
"output": "45116295"
},
{
"input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6",
"output": "1489289257"
},
{
"input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3",
"output": "961871671"
},
{
"input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4",
"output": "664376069"
}
] | 1,530,620,621 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 248 | 0 | n,m=input().split()
n,m=[int(n),int(m)]
a=[]
for i in range(0,m):
a.append([int(i) for i in input().split()])
a.sort(key=lambda x:x[1], reverse=True)
c=0
for i in range(0,m):
if a[0][0]<=n:
c+=(a[i][0]*a[i][1])
n=n-a[i][0]
else:
c+=(n*a[i][1])
break
print(c) | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output Specification:
Output the only number — answer to the problem.
Demo Input:
['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n']
Demo Output:
['62\n', '7\n']
Note:
none | ```python
n,m=input().split()
n,m=[int(n),int(m)]
a=[]
for i in range(0,m):
a.append([int(i) for i in input().split()])
a.sort(key=lambda x:x[1], reverse=True)
c=0
for i in range(0,m):
if a[0][0]<=n:
c+=(a[i][0]*a[i][1])
n=n-a[i][0]
else:
c+=(n*a[i][1])
break
print(c)
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,646,215,538 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input()
l1 = ['h','e','l','l','o']
flag = True
j = 0
for i in range(len(n)):
if n[i] == l1[j]:
j +=1
if j == 5:
print("YES")
flag = False
break
if flag = True:
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
n = input()
l1 = ['h','e','l','l','o']
flag = True
j = 0
for i in range(len(n)):
if n[i] == l1[j]:
j +=1
if j == 5:
print("YES")
flag = False
break
if flag = True:
print("NO")
``` | -1 |
903 | D | Almost Difference | PROGRAMMING | 2,200 | [
"data structures",
"math"
] | null | null | Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print one integer — the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | [
"5\n1 2 3 1 3\n",
"4\n6 6 5 5\n",
"4\n6 6 4 4\n"
] | [
"4\n",
"0\n",
"-8\n"
] | In the first example:
1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">3</sub>) = 2; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">5</sub>) = 2; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>) = 0; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">5</sub>) = 0; 1. *d*(*a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>) = - 2; 1. *d*(*a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">5</sub>) = 0; 1. *d*(*a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>) = 2. | 0 | [
{
"input": "5\n1 2 3 1 3",
"output": "4"
},
{
"input": "4\n6 6 5 5",
"output": "0"
},
{
"input": "4\n6 6 4 4",
"output": "-8"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1000000000",
"output": "999999999"
},
{
"input": "5\n1 999999996 999999998 999999994 1000000000",
"output": "3999999992"
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "-1774"
},
{
"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917",
"output": "-91018"
},
{
"input": "100\n7 8 5 9 5 6 6 9 7 6 8 7 5 10 7 2 6 1 8 10 7 9 9 8 9 6 8 5 10 6 3 7 5 8 9 7 6 1 9 9 6 9 9 2 10 4 4 6 7 9 7 7 9 10 6 10 8 6 4 7 5 5 8 10 10 7 6 9 8 1 5 1 6 6 2 9 8 4 6 6 9 10 6 1 9 9 9 6 1 8 9 2 8 7 1 10 8 2 4 7",
"output": "-1713"
},
{
"input": "100\n82 81 14 33 78 80 15 60 89 82 79 13 15 17 25 13 21 20 63 26 62 63 79 36 18 21 88 92 27 18 59 64 18 96 28 4 76 43 26 25 89 88 96 33 27 97 52 37 92 80 23 18 78 14 88 5 3 14 85 72 84 75 41 3 51 92 91 79 18 78 19 79 8 35 85 86 78 17 51 36 100 32 49 95 2 100 67 72 55 53 42 3 21 100 12 51 50 79 47 2",
"output": "6076"
},
{
"input": "5\n3 1 1 1 3",
"output": "0"
},
{
"input": "1\n22955",
"output": "0"
},
{
"input": "1\n32955",
"output": "0"
}
] | 1,587,854,189 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 608 | 37,888,000 | n = int(input())
arr = [int(e) for e in input().split()]
m={}
f={}
for i in arr:
m[i] = 0
m[i-1] = 0
m[i+1] = 0
f[i] = 0
f[i-1] = 0
f[i+1] = 0
for i in arr:
m[i] += 1
ans = 0
for i in range(n):
tot = n
left = i
right = n-i-1
left -= f[arr[i]]
left -= f[arr[i]-1]
left -= f[arr[i]+1]
f[arr[i]] += 1
right -= (m[arr[i]]-f[arr[i]])
right -= (m[arr[i]+1]-f[arr[i]+1])
right -= (m[arr[i]-1]-f[arr[i]-1])
ans += (left*arr[i] - right*arr[i])
print(ans) | Title: Almost Difference
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
Print one integer — the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*.
Demo Input:
['5\n1 2 3 1 3\n', '4\n6 6 5 5\n', '4\n6 6 4 4\n']
Demo Output:
['4\n', '0\n', '-8\n']
Note:
In the first example:
1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">3</sub>) = 2; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">5</sub>) = 2; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>) = 0; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">5</sub>) = 0; 1. *d*(*a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>) = - 2; 1. *d*(*a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">5</sub>) = 0; 1. *d*(*a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>) = 2. | ```python
n = int(input())
arr = [int(e) for e in input().split()]
m={}
f={}
for i in arr:
m[i] = 0
m[i-1] = 0
m[i+1] = 0
f[i] = 0
f[i-1] = 0
f[i+1] = 0
for i in arr:
m[i] += 1
ans = 0
for i in range(n):
tot = n
left = i
right = n-i-1
left -= f[arr[i]]
left -= f[arr[i]-1]
left -= f[arr[i]+1]
f[arr[i]] += 1
right -= (m[arr[i]]-f[arr[i]])
right -= (m[arr[i]+1]-f[arr[i]+1])
right -= (m[arr[i]-1]-f[arr[i]-1])
ans += (left*arr[i] - right*arr[i])
print(ans)
``` | 3 |
|
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them. | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
{
"input": "1 1000000000",
"output": "NO"
},
{
"input": "999999999 1000000000",
"output": "NO"
},
{
"input": "1 2",
"output": "YES\n2\n1 2 "
},
{
"input": "1 536870912",
"output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 "
},
{
"input": "11111 11111111",
"output": "YES\n4\n11111 111111 1111111 11111111 "
},
{
"input": "59139 946224",
"output": "YES\n5\n59139 118278 236556 473112 946224 "
},
{
"input": "9859 19718",
"output": "YES\n2\n9859 19718 "
},
{
"input": "25987 51974222",
"output": "YES\n5\n25987 259871 2598711 25987111 51974222 "
},
{
"input": "9411 188222222",
"output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 "
},
{
"input": "25539 510782222",
"output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 "
},
{
"input": "76259 610072",
"output": "YES\n4\n76259 152518 305036 610072 "
},
{
"input": "92387 184774",
"output": "YES\n2\n92387 184774 "
},
{
"input": "8515 85151111",
"output": "YES\n5\n8515 85151 851511 8515111 85151111 "
},
{
"input": "91939 9193911",
"output": "YES\n3\n91939 919391 9193911 "
},
{
"input": "30518 610361",
"output": "YES\n3\n30518 61036 610361 "
},
{
"input": "46646 373168844",
"output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 "
},
{
"input": "30070 300701",
"output": "YES\n2\n30070 300701 "
},
{
"input": "13494 1079528",
"output": "YES\n5\n13494 134941 269882 539764 1079528 "
},
{
"input": "96918 775344422",
"output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 "
},
{
"input": "13046 260921",
"output": "YES\n3\n13046 26092 260921 "
},
{
"input": "29174 5834811",
"output": "YES\n4\n29174 58348 583481 5834811 "
},
{
"input": "79894 319576421",
"output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 "
},
{
"input": "96022 1920442",
"output": "YES\n3\n96022 960221 1920442 "
},
{
"input": "79446 6355681",
"output": "YES\n5\n79446 158892 317784 635568 6355681 "
},
{
"input": "5440 27853056",
"output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 "
},
{
"input": "250000000 705032705",
"output": "NO"
},
{
"input": "17 35",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
}
] | 1,639,399,404 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a,b = map(int,input().split())
newB = b
k=1
lis=[]
lis.append(newB)
while(b>0):
if(b%2 == 0):
if(b == a):
break
b = b//2
k+=1
lis.append(b)
else:
if(b == a):
break
b = (b-1)//10
k+=1
lis.append(b)
lis = lis[::-1]
string = ' '.join([str(i) for i in lis])
if(b == a):
print('YES')
print(k)
print(string)
else:
print('NO') | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible.
Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
Input Specification:
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
Output Specification:
If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where:
- *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=<<=*i*<=≤<=*k*).
If there are multiple answers, print any of them.
Demo Input:
['2 162\n', '4 42\n', '100 40021\n']
Demo Output:
['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n']
Note:
none | ```python
a,b = map(int,input().split())
newB = b
k=1
lis=[]
lis.append(newB)
while(b>0):
if(b%2 == 0):
if(b == a):
break
b = b//2
k+=1
lis.append(b)
else:
if(b == a):
break
b = (b-1)//10
k+=1
lis.append(b)
lis = lis[::-1]
string = ' '.join([str(i) for i in lis])
if(b == a):
print('YES')
print(k)
print(string)
else:
print('NO')
``` | 0 |
|
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,698,955,795 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | val = int(input())
while val != 0:
digit = val % 10
if digit == 4 or digit == 7:
print("YES")
break
val //= 10
else:
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
val = int(input())
while val != 0:
digit = val % 10
if digit == 4 or digit == 7:
print("YES")
break
val //= 10
else:
print("NO")
``` | 0 |
|
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\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 54 "
},
{
"input": "4",
"output": "2\n1 3 "
},
{
"input": "6",
"output": "3\n1 2 3 "
},
{
"input": "7",
"output": "3\n1 2 4 "
},
{
"input": "8",
"output": "3\n1 2 5 "
},
{
"input": "10",
"output": "4\n1 2 3 4 "
},
{
"input": "11",
"output": "4\n1 2 3 5 "
},
{
"input": "12",
"output": "4\n1 2 3 6 "
},
{
"input": "13",
"output": "4\n1 2 3 7 "
},
{
"input": "14",
"output": "4\n1 2 3 8 "
},
{
"input": "15",
"output": "5\n1 2 3 4 5 "
},
{
"input": "16",
"output": "5\n1 2 3 4 6 "
},
{
"input": "20",
"output": "5\n1 2 3 4 10 "
},
{
"input": "21",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "22",
"output": "6\n1 2 3 4 5 7 "
},
{
"input": "27",
"output": "6\n1 2 3 4 5 12 "
},
{
"input": "28",
"output": "7\n1 2 3 4 5 6 7 "
},
{
"input": "29",
"output": "7\n1 2 3 4 5 6 8 "
},
{
"input": "35",
"output": "7\n1 2 3 4 5 6 14 "
},
{
"input": "36",
"output": "8\n1 2 3 4 5 6 7 8 "
},
{
"input": "37",
"output": "8\n1 2 3 4 5 6 7 9 "
},
{
"input": "44",
"output": "8\n1 2 3 4 5 6 7 16 "
},
{
"input": "45",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "46",
"output": "9\n1 2 3 4 5 6 7 8 10 "
},
{
"input": "230",
"output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40 "
},
{
"input": "231",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "232",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 "
},
{
"input": "239",
"output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 29 "
},
{
"input": "629",
"output": "34\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 68 "
},
{
"input": "630",
"output": "35\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 "
},
{
"input": "631",
"output": "35\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 36 "
},
{
"input": "945",
"output": "42\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 84 "
},
{
"input": "946",
"output": "43\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 "
},
{
"input": "947",
"output": "43\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 44 "
},
{
"input": "989",
"output": "43\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 86 "
},
{
"input": "990",
"output": "44\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 "
},
{
"input": "991",
"output": "44\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 45 "
},
{
"input": "956",
"output": "43\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 53 "
},
{
"input": "981",
"output": "43\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 78 "
},
{
"input": "867",
"output": "41\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 47 "
},
{
"input": "906",
"output": "42\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 45 "
},
{
"input": "999",
"output": "44\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 53 "
},
{
"input": "100",
"output": "13\n1 2 3 4 5 6 7 8 9 10 11 12 22 "
},
{
"input": "126",
"output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 21 "
}
] | 1,559,133,466 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 139 | 0 | n=int(input())
l=[]
t=1
while t<=n:
l.append(t)
n-=t
t+=1
l[-1]=l[-1]+n
print(len(l))
print(*l)
| Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
Input Specification:
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Output Specification:
Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them.
Demo Input:
['5\n', '9\n', '2\n']
Demo Output:
['2\n2 3\n', '3\n3 5 1\n', '1\n2 \n']
Note:
none | ```python
n=int(input())
l=[]
t=1
while t<=n:
l.append(t)
n-=t
t+=1
l[-1]=l[-1]+n
print(len(l))
print(*l)
``` | 3 |
|
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct. | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
{
"input": "3\n2 3",
"output": "1"
},
{
"input": "3\n2 1",
"output": "3"
},
{
"input": "3\n3 1",
"output": "2"
},
{
"input": "3\n3 2",
"output": "1"
},
{
"input": "5\n2 3 4 5",
"output": "1"
},
{
"input": "5\n5 4 3 2",
"output": "1"
},
{
"input": "5\n5 2 4 3",
"output": "1"
},
{
"input": "5\n1 2 3 4",
"output": "5"
},
{
"input": "5\n2 1 3 4",
"output": "5"
},
{
"input": "5\n1 5 3 4",
"output": "2"
},
{
"input": "5\n1 4 5 2",
"output": "3"
},
{
"input": "5\n2 1 5 3",
"output": "4"
},
{
"input": "5\n2 3 4 5",
"output": "1"
}
] | 1,591,250,196 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 156 | 7,270,400 | import sys
input=sys.stdin.buffer.readline
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
z=0
for i in range(0,n-1):
if arr[i]==i+1:
continue
else:
print(i+1)
z=1
break
if z==0:
print(n) | Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct.
Output Specification:
Print the number of the episode that Polycarpus hasn't watched.
Demo Input:
['10\n3 8 10 1 7 9 6 5 2\n']
Demo Output:
['4\n']
Note:
none | ```python
import sys
input=sys.stdin.buffer.readline
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
z=0
for i in range(0,n-1):
if arr[i]==i+1:
continue
else:
print(i+1)
z=1
break
if z==0:
print(n)
``` | 3 |
|
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan. | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters. | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",
"output": "Impossible"
},
{
"input": "|\nZXCVBANMIO",
"output": "XVAMO|ZCBNI"
},
{
"input": "|C\nA",
"output": "A|C"
},
{
"input": "|\nAB",
"output": "B|A"
},
{
"input": "A|XYZ\nUIOPL",
"output": "Impossible"
},
{
"input": "K|B\nY",
"output": "Impossible"
},
{
"input": "EQJWDOHKZRBISPLXUYVCMNFGT|\nA",
"output": "Impossible"
},
{
"input": "|MACKERIGZPVHNDYXJBUFLWSO\nQT",
"output": "Impossible"
},
{
"input": "ERACGIZOVPT|WXUYMDLJNQS\nKB",
"output": "ERACGIZOVPTB|WXUYMDLJNQSK"
},
{
"input": "CKQHRUZMISGE|FBVWPXDLTJYN\nOA",
"output": "CKQHRUZMISGEA|FBVWPXDLTJYNO"
},
{
"input": "V|CMOEUTAXBFWSK\nDLRZJGIYNQHP",
"output": "VDLRZJGIYNQHP|CMOEUTAXBFWSK"
},
{
"input": "QWHNMALDGKTJ|\nPBRYVXZUESCOIF",
"output": "QWHNMALDGKTJF|PBRYVXZUESCOI"
},
{
"input": "|\nFXCVMUEWZAHNDOSITPRLKQJYBG",
"output": "XVUWANOIPLQYG|FCMEZHDSTRKJB"
},
{
"input": "IB|PCGHZ\nFXWTJQNEKAUM",
"output": "Impossible"
},
{
"input": "EC|IWAXQ\nJUHSRKGZTOMYN",
"output": "ECJUHRGTMN|IWAXQSKZOY"
},
{
"input": "VDINYMA|UQKWBCLRHZJ\nXEGOF",
"output": "Impossible"
},
{
"input": "ZLTPSIQUBAR|XFDEMYC\nHNOJWG",
"output": "ZLTPSIQUBARG|XFDEMYCHNOJW"
},
{
"input": "R|FLZOTJNU\nGIYHKVX",
"output": "RGIYHKVX|FLZOTJNU"
},
{
"input": "W|TL\nQROFSADYPKHEJNMXBZVUCIG",
"output": "WQOSDPHJMBVCG|TLRFAYKENXZUI"
},
{
"input": "NRDFQSEKLAYMOT|ZH\nGUXIBJCVPW",
"output": "Impossible"
},
{
"input": "FGRT|\nAC",
"output": "Impossible"
},
{
"input": "|FGRT\nAC",
"output": "Impossible"
},
{
"input": "A|\nB",
"output": "A|B"
},
{
"input": "|A\nB",
"output": "B|A"
},
{
"input": "|\nA",
"output": "Impossible"
},
{
"input": "|\nQWERTYUIOPASDFGHJKLZXCVBNM",
"output": "WRYIPSFHKZCBM|QETUOADGJLXVN"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBN|\nM",
"output": "Impossible"
},
{
"input": "QWERTY|VBN\nUIOPASDFGHJKLZXC",
"output": "Impossible"
},
{
"input": "ABC|D\nKSL",
"output": "Impossible"
},
{
"input": "A|BCDEF\nGH",
"output": "Impossible"
},
{
"input": "|ABC\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDE",
"output": "Impossible"
},
{
"input": "|ASD\nX",
"output": "Impossible"
},
{
"input": "AB|CDEF\nXYZRT",
"output": "Impossible"
}
] | 1,606,082,082 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 108 | 307,200 | #!/bin/python3
"""
PROBLEM LINK: https://codeforces.com/contest/382/problem/A
"""
def checkScaleEquilibrium(leftScale, rightScale, unusedMasses):
leftScaleQuantity = len(leftScale)
rightScaleQuantity = len(rightScale)
unusedMassesQuantity = len(unusedMasses)
scalesDifferential = abs(leftScaleQuantity - rightScaleQuantity)
if(scalesDifferential == 0):
if(unusedMassesQuantity % 2 == 0):
for i in range(0, len(unusedMasses), 2):
leftScale += unusedMasses[i]
rightScale += unusedMasses[i+1]
return leftScale + "|" + rightScale
else:
return "Impossible"
else:
if(scalesDifferential % 2 == 0):
if(unusedMassesQuantity >= scalesDifferential and unusedMassesQuantity % 2 == 0):
for mass in unusedMasses:
if(leftScaleQuantity > rightScaleQuantity):
rightScale += mass
rightScaleQuantity += 1
else:
leftScale += mass
leftScaleQuantity += 1
return leftScale + "|" + rightScale
else:
return "Impossible"
else:
if(unusedMassesQuantity >= scalesDifferential and unusedMassesQuantity % 2 != 0):
for mass in unusedMasses:
if(leftScaleQuantity > rightScaleQuantity):
rightScale += mass
rightScaleQuantity += 1
else:
leftScale += mass
leftScaleQuantity += 1
return leftScale + "|" + rightScale
else:
return "Impossible"
if __name__ == '__main__':
twoScales = input().strip().split("|")
unusedMasses = input().strip()
leftScale = twoScales[0]
rightScale = twoScales[1]
res = checkScaleEquilibrium(leftScale, rightScale, unusedMasses)
print(res)
| Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input Specification:
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output Specification:
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Demo Input:
['AC|T\nL\n', '|ABC\nXYZ\n', 'W|T\nF\n', 'ABC|\nD\n']
Demo Output:
['AC|TL\n', 'XYZ|ABC\n', 'Impossible\n', 'Impossible\n']
Note:
none | ```python
#!/bin/python3
"""
PROBLEM LINK: https://codeforces.com/contest/382/problem/A
"""
def checkScaleEquilibrium(leftScale, rightScale, unusedMasses):
leftScaleQuantity = len(leftScale)
rightScaleQuantity = len(rightScale)
unusedMassesQuantity = len(unusedMasses)
scalesDifferential = abs(leftScaleQuantity - rightScaleQuantity)
if(scalesDifferential == 0):
if(unusedMassesQuantity % 2 == 0):
for i in range(0, len(unusedMasses), 2):
leftScale += unusedMasses[i]
rightScale += unusedMasses[i+1]
return leftScale + "|" + rightScale
else:
return "Impossible"
else:
if(scalesDifferential % 2 == 0):
if(unusedMassesQuantity >= scalesDifferential and unusedMassesQuantity % 2 == 0):
for mass in unusedMasses:
if(leftScaleQuantity > rightScaleQuantity):
rightScale += mass
rightScaleQuantity += 1
else:
leftScale += mass
leftScaleQuantity += 1
return leftScale + "|" + rightScale
else:
return "Impossible"
else:
if(unusedMassesQuantity >= scalesDifferential and unusedMassesQuantity % 2 != 0):
for mass in unusedMasses:
if(leftScaleQuantity > rightScaleQuantity):
rightScale += mass
rightScaleQuantity += 1
else:
leftScale += mass
leftScaleQuantity += 1
return leftScale + "|" + rightScale
else:
return "Impossible"
if __name__ == '__main__':
twoScales = input().strip().split("|")
unusedMasses = input().strip()
leftScale = twoScales[0]
rightScale = twoScales[1]
res = checkScaleEquilibrium(leftScale, rightScale, unusedMasses)
print(res)
``` | 3 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,684,427,131 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | inp = input().split(",")
inp = [i[1:] for i in inp]
inp[len(inp) - 1] = inp[len(inp) - 1][0]
if inp[0] == "}":
print(0)
else:
print(len(set(inp))) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
inp = input().split(",")
inp = [i[1:] for i in inp]
inp[len(inp) - 1] = inp[len(inp) - 1][0]
if inp[0] == "}":
print(0)
else:
print(len(set(inp)))
``` | 3 |
|
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,565,959,742 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | import math
n=input().split()
sdis=(int(n[3])-int(n[1]))**2+(int(n[4])-int(n[2]))**2
dis=int(math.sqrt(sdis))
rad=2*int(n[0])
if(dis*dis is sdis):
if(dis%(rad) is 0):
print(dis//rad)
else:
print(dis//rad+1)
else:
print(dis//rad+1)
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
n=input().split()
sdis=(int(n[3])-int(n[1]))**2+(int(n[4])-int(n[2]))**2
dis=int(math.sqrt(sdis))
rad=2*int(n[0])
if(dis*dis is sdis):
if(dis%(rad) is 0):
print(dis//rad)
else:
print(dis//rad+1)
else:
print(dis//rad+1)
``` | 0 |
|
603 | A | Alternative Thinking | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"math"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have. | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 500 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
"output": "3"
},
{
"input": "56\n10101011010101010101010101010101010101011010101010101010",
"output": "56"
},
{
"input": "50\n01011010110101010101010101010101010101010101010100",
"output": "49"
},
{
"input": "7\n0110100",
"output": "7"
},
{
"input": "8\n11011111",
"output": "5"
},
{
"input": "6\n000000",
"output": "3"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "59\n10101010101010101010101010101010101010101010101010101010101",
"output": "59"
},
{
"input": "88\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "88"
},
{
"input": "93\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "93"
},
{
"input": "70\n0101010101010101010101010101010101010101010101010101010101010101010101",
"output": "70"
},
{
"input": "78\n010101010101010101010101010101101010101010101010101010101010101010101010101010",
"output": "78"
},
{
"input": "83\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010",
"output": "83"
},
{
"input": "87\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010",
"output": "87"
},
{
"input": "65\n01010101101010101010101010101010101010101010101010101010101010101",
"output": "65"
},
{
"input": "69\n010101010101010101101010101010101010101010101010101010101010101010101",
"output": "69"
},
{
"input": "74\n01010101010101010101010101010101010101010101010101010101010101000101010101",
"output": "74"
},
{
"input": "77\n01010101010101001010101010101010100101010101010101010101010101010101010101010",
"output": "77"
},
{
"input": "60\n101010110101010101010101010110101010101010101010101010101010",
"output": "60"
},
{
"input": "89\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010",
"output": "89"
},
{
"input": "68\n01010101010101010101010101010101010100101010100101010101010100101010",
"output": "67"
},
{
"input": "73\n0101010101010101010101010101010101010101010111011010101010101010101010101",
"output": "72"
},
{
"input": "55\n1010101010101010010101010101101010101010101010100101010",
"output": "54"
},
{
"input": "85\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010",
"output": "84"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1111111111",
"output": "3"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "3\n000",
"output": "3"
},
{
"input": "3\n001",
"output": "3"
},
{
"input": "3\n010",
"output": "3"
},
{
"input": "3\n011",
"output": "3"
},
{
"input": "3\n100",
"output": "3"
},
{
"input": "3\n101",
"output": "3"
},
{
"input": "3\n110",
"output": "3"
},
{
"input": "3\n111",
"output": "3"
},
{
"input": "4\n0000",
"output": "3"
},
{
"input": "4\n0001",
"output": "4"
},
{
"input": "4\n0010",
"output": "4"
},
{
"input": "4\n0011",
"output": "4"
},
{
"input": "4\n0100",
"output": "4"
},
{
"input": "4\n0101",
"output": "4"
},
{
"input": "4\n0110",
"output": "4"
},
{
"input": "4\n0111",
"output": "4"
},
{
"input": "4\n1000",
"output": "4"
},
{
"input": "4\n1001",
"output": "4"
},
{
"input": "4\n1010",
"output": "4"
},
{
"input": "4\n1011",
"output": "4"
},
{
"input": "4\n1100",
"output": "4"
},
{
"input": "4\n1101",
"output": "4"
},
{
"input": "4\n1110",
"output": "4"
},
{
"input": "4\n1111",
"output": "3"
},
{
"input": "5\n00000",
"output": "3"
},
{
"input": "5\n00001",
"output": "4"
},
{
"input": "5\n00010",
"output": "5"
},
{
"input": "5\n00011",
"output": "4"
},
{
"input": "5\n00100",
"output": "5"
},
{
"input": "5\n00101",
"output": "5"
},
{
"input": "5\n00110",
"output": "5"
},
{
"input": "5\n00111",
"output": "4"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "5\n01001",
"output": "5"
},
{
"input": "5\n01010",
"output": "5"
},
{
"input": "5\n01011",
"output": "5"
},
{
"input": "5\n01100",
"output": "5"
},
{
"input": "5\n01101",
"output": "5"
},
{
"input": "5\n01110",
"output": "5"
},
{
"input": "5\n01111",
"output": "4"
},
{
"input": "5\n10000",
"output": "4"
},
{
"input": "5\n10001",
"output": "5"
},
{
"input": "5\n10010",
"output": "5"
},
{
"input": "5\n10100",
"output": "5"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "5\n10110",
"output": "5"
},
{
"input": "5\n10111",
"output": "5"
},
{
"input": "5\n11000",
"output": "4"
},
{
"input": "5\n11001",
"output": "5"
},
{
"input": "5\n11010",
"output": "5"
},
{
"input": "5\n11011",
"output": "5"
},
{
"input": "5\n11100",
"output": "4"
},
{
"input": "5\n11101",
"output": "5"
},
{
"input": "5\n11110",
"output": "4"
},
{
"input": "5\n11111",
"output": "3"
}
] | 1,684,869,466 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 46 | 1,740,800 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
S = input()
adds = 0
ans = 1
l=float('inf')
r = -1
for i in range(1,N):
if S[i]!=S[i-1]:
ans+=1
else:
l = min(l,i)
r = max(r,i-1)
if r>l:
adds=2
if N>1 and (S[0]==S[1] or S[-1]==S[-2]):
adds = max(adds, 1)
print(min(N,ans+adds))
| Title: Alternative Thinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input Specification:
The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO.
Output Specification:
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Demo Input:
['8\n10000011\n', '2\n01\n']
Demo Output:
['5\n', '2\n']
Note:
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
S = input()
adds = 0
ans = 1
l=float('inf')
r = -1
for i in range(1,N):
if S[i]!=S[i-1]:
ans+=1
else:
l = min(l,i)
r = max(r,i-1)
if r>l:
adds=2
if N>1 and (S[0]==S[1] or S[-1]==S[-2]):
adds = max(adds, 1)
print(min(N,ans+adds))
``` | 0 |
|
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,522,238,323 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 7,065,600 | n = int(input())
s = input()
for i in range(n - 1):
if s[i] == s[i + 1] != '?':
print('NO')
break
else:
flag = False
a = 0
for i in range(n):
if s[i] == '?':
if i != 0:
b = s[i - 1]
else:
b = 'gg'
a += 1
else:
c = s[i]
if a != 0:
if b == 'gg' or b == c or b != c and a % 2 == 0:
print('YES')
break
else:
print('NO') | 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())
s = input()
for i in range(n - 1):
if s[i] == s[i + 1] != '?':
print('NO')
break
else:
flag = False
a = 0
for i in range(n):
if s[i] == '?':
if i != 0:
b = s[i - 1]
else:
b = 'gg'
a += 1
else:
c = s[i]
if a != 0:
if b == 'gg' or b == c or b != c and a % 2 == 0:
print('YES')
break
else:
print('NO')
``` | 0 |
|
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,610,906,210 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 0 | inp = str(input())
lenn = str(input())
counter =0
for i in range(len(lenn)):
if inp[counter]==lenn[i]:
counter+=1
print(counter+1)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
inp = str(input())
lenn = str(input())
counter =0
for i in range(len(lenn)):
if inp[counter]==lenn[i]:
counter+=1
print(counter+1)
``` | 3 |
|
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor! | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has. | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194",
"output": "360142248"
},
{
"input": "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845",
"output": "2404943"
},
{
"input": "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394",
"output": "34445194"
},
{
"input": "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541",
"output": "25390787"
},
{
"input": "3\n1 1 1000000000",
"output": "999999999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 1000000000",
"output": "999999956"
},
{
"input": "5\n100000000 100000000 100000000 100000000 500000000",
"output": "100000001"
},
{
"input": "3\n300000000 300000000 600000000",
"output": "1"
},
{
"input": "5\n10 4 3 2 1",
"output": "1"
},
{
"input": "3\n800000000 1 1",
"output": "799999999"
},
{
"input": "3\n1000000000 1 1",
"output": "999999999"
}
] | 1,462,368,337 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 93 | 7,782,400 | n = int(input())
sides = list(map(int, input().split()))
print(2 * max(sides) - sum(sides) + 1)
| Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor!
Input Specification:
The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has.
Output Specification:
Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods.
Demo Input:
['3\n1 2 1\n', '5\n20 4 3 2 1\n']
Demo Output:
['1\n', '11\n']
Note:
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | ```python
n = int(input())
sides = list(map(int, input().split()))
print(2 * max(sides) - sum(sides) + 1)
``` | 3 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,636,961,932 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
d={}
k =[]
for i in range(ii()):
a,b = msi()
d[a] = d.get(a,0)+int(b)
k.append([a,b])
h = max(d.values())
for i in d:
if d[i]>=h:
print(i)
break | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
d={}
k =[]
for i in range(ii()):
a,b = msi()
d[a] = d.get(a,0)+int(b)
k.append([a,b])
h = max(d.values())
for i in d:
if d[i]>=h:
print(i)
break
``` | 0 |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,696,865,072 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 122 | 0 | problem = input()
sorted_problem = sorted(problem.split("+"))
a = "+".join(sorted_problem)
print(a)
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
problem = input()
sorted_problem = sorted(problem.split("+"))
a = "+".join(sorted_problem)
print(a)
``` | 3 |
|
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,694,582,382 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | c=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
j=0
for i in range(1,c+1):
if i in x[1::] or i in y[1::]:
j+=1
if j == c:
print("I become the guy.")
else:
print("Oh, my keyboard!") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
c=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
j=0
for i in range(1,c+1):
if i in x[1::] or i in y[1::]:
j+=1
if j == c:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 3 |
|
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
{
"input": "1 1000\n1 1000",
"output": "1001"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2"
},
{
"input": "2 7\n6 3\n1 5",
"output": "9"
},
{
"input": "2 100\n99 2\n1 10",
"output": "101"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "6"
},
{
"input": "3 7\n1 6\n5 5\n6 1",
"output": "10"
},
{
"input": "2 100\n4 100\n7 99",
"output": "106"
},
{
"input": "2 10\n9 3\n1 4",
"output": "12"
},
{
"input": "2 5\n4 4\n5 4",
"output": "9"
},
{
"input": "2 10\n9 10\n6 11",
"output": "19"
},
{
"input": "2 100\n99 9\n1 10",
"output": "108"
},
{
"input": "2 7\n3 5\n7 4",
"output": "11"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9",
"output": "12"
},
{
"input": "2 1000\n1 2\n1000 1",
"output": "1001"
},
{
"input": "2 20\n1 1\n2 2",
"output": "20"
},
{
"input": "2 20\n10 10\n19 9",
"output": "28"
}
] | 1,543,598,756 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | def hotel(lst):
m = 0
for elem in lst:
if elem[0] + elem[1] > m:
m = elem[0] + elem[1]
return m
n, s = [int(i) for i in input().split()]
a = list()
for j in range(n):
f, t = [int(z) for z in input().split()]
a.append([f, t])
print(hotel(a))
| Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input Specification:
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Output Specification:
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Demo Input:
['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n']
Demo Output:
['11\n', '79\n']
Note:
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | ```python
def hotel(lst):
m = 0
for elem in lst:
if elem[0] + elem[1] > m:
m = elem[0] + elem[1]
return m
n, s = [int(i) for i in input().split()]
a = list()
for j in range(n):
f, t = [int(z) for z in input().split()]
a.append([f, t])
print(hotel(a))
``` | 0 |
|
987 | C | Three displays | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation"
] | null | null | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay. | The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display. | If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$. | [
"5\n2 4 5 4 10\n40 30 20 10 40\n",
"3\n100 101 100\n2 4 5\n",
"10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n"
] | [
"90\n",
"-1\n",
"33\n"
] | In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | 1,250 | [
{
"input": "5\n2 4 5 4 10\n40 30 20 10 40",
"output": "90"
},
{
"input": "3\n100 101 100\n2 4 5",
"output": "-1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13",
"output": "33"
},
{
"input": "3\n1 2 3\n100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "3\n999999998 999999999 1000000000\n100000000 100000000 99999999",
"output": "299999999"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n23219513 68171337 12183499 5549873 73542337 66661387 79397647 34495917 31413076 50918417",
"output": "85904709"
},
{
"input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n61699500 83254572 59454419 27833657 55743179 99661234 94729965 75591136 62937826 3626886 73906880 3664913 39990362 94385934 33153747 23840219 64514676 14746017 13062847 65187713",
"output": "72432912"
},
{
"input": "3\n1 2 3\n1 1 1",
"output": "3"
}
] | 1,687,752,717 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 140 | 9,625,600 | # Problem: C. Three displays
# Contest: Codeforces - Codeforces Round 485 (Div. 2)
# URL: https://codeforces.com/problemset/problem/987/C
# Memory Limit: 256 MB
# Time Limit: 1000 ms
import sys
from bisect import bisect_left
RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。
MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/problemset/problem/987/C
输入 n(3≤n≤3000) 和长度均为 n 的数组 a(1≤a[i]≤1e9) 和数组 b(1≤b[i]≤1e8)。
输出在满足 i<j<k 且 a[i]<a[j]<a[k] 的前提下,b[i]+b[j]+b[k] 的最小值。
如果不存在这样的 (i,j,k),输出 -1。
进阶:O(nlogn)。
进阶:改成 a 的长为 4 的递增子序列(本题长为 3)。改成 5?改成 m?
输入
5
2 4 5 4 10
40 30 20 10 40
输出 90
输入
3
100 101 100
2 4 5
输出 -1
输入
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
输出 33
"""
inf = 10 ** 9
# 187 ms
def solve1():
n, = RI()
a = RILST()
b = RILST()
f, g = [inf] * n, [inf] * n
for i in range(1, n):
for j in range(i):
if a[j] < a[i]:
f[i] = min(f[i], b[j] + b[i])
for i in range(2, n):
for j in range(i):
if a[j] < a[i]:
g[i] = min(g[i], f[j] + b[i])
ans = min(g)
if ans == inf:
return print(-1)
print(ans)
# 124 ms
def solve2():
n, = RI()
a = RILST()
b = RILST()
f, g = [inf] * n, [inf] * n
for i in range(1, n):
for j in range(i):
if a[j] < a[i] and f[i] > b[j] + b[i]:
f[i] = b[j] + b[i]
for i in range(2, n):
for j in range(i):
if a[j] < a[i] and g[i] > f[j] + b[i]:
g[i] = f[j] + b[i]
ans = min(g)
if ans == inf:
return print(-1)
print(ans)
class ZKW:
# n = 1
# size = 1
# log = 2
# d = [0]
# op = None
# e = 10 ** 15
"""自低向上非递归写法线段树,0_indexed
tmx = ZKW(pre, max, -2 ** 61)
"""
__slots__ = ('n', 'op', 'e', 'log', 'size', 'd')
def __init__(self, V, OP, E):
"""
V: 原数组
OP: 操作:max,min,sum
E: 每个元素默认值
"""
self.n = len(V)
self.op = OP
self.e = E
self.log = (self.n - 1).bit_length()
self.size = 1 << self.log
self.d = [E for i in range(2 * self.size)]
for i in range(self.n):
self.d[self.size + i] = V[i]
for i in range(self.size - 1, 0, -1):
self.update(i)
def set(self, p, x):
# assert 0 <= p and p < self.n
update = self.update
p += self.size
self.d[p] = x
for i in range(1, self.log + 1):
update(p >> i)
def get(self, p):
# assert 0 <= p and p < self.n
return self.d[p + self.size]
def query(self, l, r): # [l,r)左闭右开
# assert 0 <= l and l <= r and r <= self.n
sml, smr, op, d = self.e, self.e, self.op, self.d
l += self.size
r += self.size
while l < r:
if l & 1:
sml = op(sml, d[l])
l += 1
if r & 1:
smr = op(d[r - 1], smr)
r -= 1
l >>= 1
r >>= 1
return self.op(sml, smr)
def all_query(self):
return self.d[1]
def max_right(self, l, f):
"""返回l右侧第一个不满足f的位置"""
# assert 0 <= l and l <= self.n
# assert f(self.e)
if l == self.n:
return self.n
l += self.size
sm, op, d, size = self.e, self.op, self.d, self.size
while True:
while l % 2 == 0:
l >>= 1
if not (f(op(sm, d[l]))):
while l < size:
l = 2 * l
if f(op(sm, d[l])):
sm = op(sm, d[l])
l += 1
return l - size
sm = op(sm, d[l])
l += 1
if (l & -l) == l:
break
return self.n
def min_left(self, r, f):
"""返回r左侧连续满足f的最远位置的位置"""
# assert 0 <= r and r < self.n
# assert f(self.e)
if r == 0:
return 0
r += self.size
sm, op, d, size = self.e, self.op, self.d, self.size
while True:
r -= 1
while r > 1 and (r % 2):
r >>= 1
if not (f(op(d[r], sm))):
while r < size:
r = (2 * r + 1)
if f(op(d[r], sm)):
sm = op(d[r], sm)
r -= 1
return r + 1 - size
sm = op(d[r], sm)
if (r & -r) == r:
break
return 0
def update(self, k):
self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])
def __str__(self):
return str([self.get(i) for i in range(self.n)])
# 124 ms
def solve():
n, = RI()
a = RILST()
b = RILST()
h = sorted(set(a))
f1 = ZKW([inf] * len(h), min, inf)
f2 = ZKW([inf] * len(h), min, inf)
ans = inf
for k, v in zip(a, b):
x = bisect_left(h, k)
ans = min(ans, f2.query(0, x) + v)
f2.set(x, min(f2.get(x), f1.query(0, x) + v))
f1.set(x, min(f1.get(x), v))
if ans == inf:
return print(-1)
print(ans)
if __name__ == '__main__':
solve()
| Title: Three displays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
Input Specification:
The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display.
Output Specification:
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$.
Demo Input:
['5\n2 4 5 4 10\n40 30 20 10 40\n', '3\n100 101 100\n2 4 5\n', '10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n']
Demo Output:
['90\n', '-1\n', '33\n']
Note:
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | ```python
# Problem: C. Three displays
# Contest: Codeforces - Codeforces Round 485 (Div. 2)
# URL: https://codeforces.com/problemset/problem/987/C
# Memory Limit: 256 MB
# Time Limit: 1000 ms
import sys
from bisect import bisect_left
RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
# print = lambda d: sys.stdout.write(str(d) + "\n") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。
MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/problemset/problem/987/C
输入 n(3≤n≤3000) 和长度均为 n 的数组 a(1≤a[i]≤1e9) 和数组 b(1≤b[i]≤1e8)。
输出在满足 i<j<k 且 a[i]<a[j]<a[k] 的前提下,b[i]+b[j]+b[k] 的最小值。
如果不存在这样的 (i,j,k),输出 -1。
进阶:O(nlogn)。
进阶:改成 a 的长为 4 的递增子序列(本题长为 3)。改成 5?改成 m?
输入
5
2 4 5 4 10
40 30 20 10 40
输出 90
输入
3
100 101 100
2 4 5
输出 -1
输入
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
输出 33
"""
inf = 10 ** 9
# 187 ms
def solve1():
n, = RI()
a = RILST()
b = RILST()
f, g = [inf] * n, [inf] * n
for i in range(1, n):
for j in range(i):
if a[j] < a[i]:
f[i] = min(f[i], b[j] + b[i])
for i in range(2, n):
for j in range(i):
if a[j] < a[i]:
g[i] = min(g[i], f[j] + b[i])
ans = min(g)
if ans == inf:
return print(-1)
print(ans)
# 124 ms
def solve2():
n, = RI()
a = RILST()
b = RILST()
f, g = [inf] * n, [inf] * n
for i in range(1, n):
for j in range(i):
if a[j] < a[i] and f[i] > b[j] + b[i]:
f[i] = b[j] + b[i]
for i in range(2, n):
for j in range(i):
if a[j] < a[i] and g[i] > f[j] + b[i]:
g[i] = f[j] + b[i]
ans = min(g)
if ans == inf:
return print(-1)
print(ans)
class ZKW:
# n = 1
# size = 1
# log = 2
# d = [0]
# op = None
# e = 10 ** 15
"""自低向上非递归写法线段树,0_indexed
tmx = ZKW(pre, max, -2 ** 61)
"""
__slots__ = ('n', 'op', 'e', 'log', 'size', 'd')
def __init__(self, V, OP, E):
"""
V: 原数组
OP: 操作:max,min,sum
E: 每个元素默认值
"""
self.n = len(V)
self.op = OP
self.e = E
self.log = (self.n - 1).bit_length()
self.size = 1 << self.log
self.d = [E for i in range(2 * self.size)]
for i in range(self.n):
self.d[self.size + i] = V[i]
for i in range(self.size - 1, 0, -1):
self.update(i)
def set(self, p, x):
# assert 0 <= p and p < self.n
update = self.update
p += self.size
self.d[p] = x
for i in range(1, self.log + 1):
update(p >> i)
def get(self, p):
# assert 0 <= p and p < self.n
return self.d[p + self.size]
def query(self, l, r): # [l,r)左闭右开
# assert 0 <= l and l <= r and r <= self.n
sml, smr, op, d = self.e, self.e, self.op, self.d
l += self.size
r += self.size
while l < r:
if l & 1:
sml = op(sml, d[l])
l += 1
if r & 1:
smr = op(d[r - 1], smr)
r -= 1
l >>= 1
r >>= 1
return self.op(sml, smr)
def all_query(self):
return self.d[1]
def max_right(self, l, f):
"""返回l右侧第一个不满足f的位置"""
# assert 0 <= l and l <= self.n
# assert f(self.e)
if l == self.n:
return self.n
l += self.size
sm, op, d, size = self.e, self.op, self.d, self.size
while True:
while l % 2 == 0:
l >>= 1
if not (f(op(sm, d[l]))):
while l < size:
l = 2 * l
if f(op(sm, d[l])):
sm = op(sm, d[l])
l += 1
return l - size
sm = op(sm, d[l])
l += 1
if (l & -l) == l:
break
return self.n
def min_left(self, r, f):
"""返回r左侧连续满足f的最远位置的位置"""
# assert 0 <= r and r < self.n
# assert f(self.e)
if r == 0:
return 0
r += self.size
sm, op, d, size = self.e, self.op, self.d, self.size
while True:
r -= 1
while r > 1 and (r % 2):
r >>= 1
if not (f(op(d[r], sm))):
while r < size:
r = (2 * r + 1)
if f(op(d[r], sm)):
sm = op(d[r], sm)
r -= 1
return r + 1 - size
sm = op(d[r], sm)
if (r & -r) == r:
break
return 0
def update(self, k):
self.d[k] = self.op(self.d[2 * k], self.d[2 * k + 1])
def __str__(self):
return str([self.get(i) for i in range(self.n)])
# 124 ms
def solve():
n, = RI()
a = RILST()
b = RILST()
h = sorted(set(a))
f1 = ZKW([inf] * len(h), min, inf)
f2 = ZKW([inf] * len(h), min, inf)
ans = inf
for k, v in zip(a, b):
x = bisect_left(h, k)
ans = min(ans, f2.query(0, x) + v)
f2.set(x, min(f2.get(x), f1.query(0, x) + v))
f1.set(x, min(f1.get(x), v))
if ans == inf:
return print(-1)
print(ans)
if __name__ == '__main__':
solve()
``` | 3 |
|
453 | A | Little Pony and Expected Maximum | PROGRAMMING | 1,600 | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times. | A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value | 500 | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "3 10",
"output": "2.982641534996"
},
{
"input": "3 6",
"output": "2.910836762689"
},
{
"input": "1 8",
"output": "1.000000000000"
},
{
"input": "24438 9",
"output": "21994.699969310015"
},
{
"input": "94444 9",
"output": "85000.099992058866"
},
{
"input": "8 66716",
"output": "8.000000000000"
},
{
"input": "4 25132",
"output": "4.000000000000"
},
{
"input": "51520 73331",
"output": "51519.682650242677"
},
{
"input": "54230 31747",
"output": "54228.743352775018"
},
{
"input": "24236 90163",
"output": "24235.975171545670"
},
{
"input": "26946 99523",
"output": "26945.974480086279"
},
{
"input": "50323 7",
"output": "44033.124988408454"
},
{
"input": "53033 3",
"output": "39775.249995286234"
},
{
"input": "55743 5",
"output": "46452.999992525307"
},
{
"input": "59964 79",
"output": "59214.949890211828"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "3 1",
"output": "2.000000000000"
},
{
"input": "1 2",
"output": "1.000000000000"
},
{
"input": "53513 34040",
"output": "53511.875329020870"
},
{
"input": "100000 100000",
"output": "99999.418033254507"
},
{
"input": "1 100000",
"output": "1.000000000000"
},
{
"input": "100000 1",
"output": "50000.499999999935"
},
{
"input": "2 100000",
"output": "2.000000000000"
},
{
"input": "100000 2",
"output": "66667.166665000332"
},
{
"input": "50000 100000",
"output": "49999.843487110789"
},
{
"input": "99999 1111",
"output": "99909.571915885972"
},
{
"input": "99999 99999",
"output": "99998.418033254609"
},
{
"input": "1000 1000",
"output": "999.419018443269"
},
{
"input": "50000 50000",
"output": "49999.418043215679"
},
{
"input": "88888 88888",
"output": "88887.418034499773"
},
{
"input": "99999 100000",
"output": "99998.418042461126"
},
{
"input": "100000 555",
"output": "99820.643422392372"
},
{
"input": "10000 10000",
"output": "9999.418122897887"
},
{
"input": "100000 5001",
"output": "99980.503829474910"
},
{
"input": "100000 1000",
"output": "99900.599066768002"
}
] | 1,563,530,503 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 358 | 8,806,400 | iarr = list(map(int,input().split()))
m = iarr[0]
n = iarr[1]
ans = 0
powi = [0 for i in range(m+1)]
deno = pow(m,n)
for i in range(1,m+1):
powi[i] = pow(i/m,n)
for i in range(1,m+1):
ans += (powi[i] - powi[i-1])*i
print(ans)
| Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
Input Specification:
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output Specification:
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
Demo Input:
['6 1\n', '6 3\n', '2 2\n']
Demo Output:
['3.500000000000\n', '4.958333333333\n', '1.750000000000\n']
Note:
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value | ```python
iarr = list(map(int,input().split()))
m = iarr[0]
n = iarr[1]
ans = 0
powi = [0 for i in range(m+1)]
deno = pow(m,n)
for i in range(1,m+1):
powi[i] = pow(i/m,n)
for i in range(1,m+1):
ans += (powi[i] - powi[i-1])*i
print(ans)
``` | 3 |
|
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the *i*-th row and *j*-th column as (*i*,<=*j*).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as *n* segments. Each segment is described by three integers *r**i*,<=*a**i*,<=*b**i* (*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (*x*0,<=*y*0) to square (*x*1,<=*y*1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point. | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contain the descriptions of these segments. The *i*-th line contains three space-separated integers *r**i*,<=*a**i*,<=*b**i* (1<=≤<=*r**i*,<=*a**i*,<=*b**i*<=≤<=109,<=*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105. | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10 10",
"output": "2"
},
{
"input": "6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15",
"output": "1"
},
{
"input": "13 16 20 10\n18\n13 16 16\n20 10 10\n19 10 10\n12 15 15\n20 10 10\n18 11 11\n19 10 10\n19 10 10\n20 10 10\n19 10 10\n20 10 10\n20 10 10\n19 10 10\n18 11 11\n13 16 16\n12 15 15\n19 10 10\n19 10 10",
"output": "-1"
},
{
"input": "89 29 88 30\n16\n87 31 31\n14 95 95\n98 88 89\n96 88 88\n14 97 97\n13 97 98\n100 88 88\n88 32 32\n99 88 89\n90 29 29\n87 31 31\n15 94 96\n89 29 29\n88 32 32\n97 89 89\n88 29 30",
"output": "1"
},
{
"input": "30 14 39 19\n31\n35 7 11\n37 11 12\n32 13 13\n37 5 6\n46 13 13\n37 14 14\n31 13 13\n43 13 19\n45 15 19\n46 13 13\n32 17 17\n41 14 19\n30 14 14\n43 13 17\n34 16 18\n44 11 19\n38 13 13\n40 12 20\n37 16 18\n46 16 18\n34 10 14\n36 9 10\n36 15 19\n38 15 19\n42 13 19\n33 14 15\n35 15 19\n33 17 18\n39 12 20\n36 5 7\n45 12 12",
"output": "9"
},
{
"input": "2 1 1 1\n2\n1 1 2\n2 1 2",
"output": "1"
},
{
"input": "1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200",
"output": "1"
},
{
"input": "1 1 1000000000 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200",
"output": "-1"
}
] | 1,635,076,748 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,434 | 14,848,000 | from collections import deque
x0, y0, x1, y1 = map(int, input().split())
n = int(input())
g = {}
for _ in range(n):
r, a, b = map(int, input().split())
for i in range(a, b + 1):
g[(r, i)] = -1
g[(x0, y0)] = 0
q = deque([(x0, y0)])
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
while len(q) > 0:
c = q.popleft()
for i in range(8):
m = (c[0] + dx[i], c[1] + dy[i])
if m in g and g[m] == -1:
q.append(m)
g[m] = g[c] + 1
print(g[(x1, y1)]) | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the *i*-th row and *j*-th column as (*i*,<=*j*).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as *n* segments. Each segment is described by three integers *r**i*,<=*a**i*,<=*b**i* (*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (*x*0,<=*y*0) to square (*x*1,<=*y*1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point.
Input Specification:
The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contain the descriptions of these segments. The *i*-th line contains three space-separated integers *r**i*,<=*a**i*,<=*b**i* (1<=≤<=*r**i*,<=*a**i*,<=*b**i*<=≤<=109,<=*a**i*<=≤<=*b**i*), denoting that cells in columns from number *a**i* to number *b**i* inclusive in the *r**i*-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105.
Output Specification:
If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one.
Demo Input:
['5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n', '3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n', '1 1 2 10\n2\n1 1 3\n2 6 10\n']
Demo Output:
['4\n', '6\n', '-1\n']
Note:
none | ```python
from collections import deque
x0, y0, x1, y1 = map(int, input().split())
n = int(input())
g = {}
for _ in range(n):
r, a, b = map(int, input().split())
for i in range(a, b + 1):
g[(r, i)] = -1
g[(x0, y0)] = 0
q = deque([(x0, y0)])
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
while len(q) > 0:
c = q.popleft()
for i in range(8):
m = (c[0] + dx[i], c[1] + dy[i])
if m in g and g[m] == -1:
q.append(m)
g[m] = g[c] + 1
print(g[(x1, y1)])
``` | 3 |
|
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance. | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses. | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"output": "296"
},
{
"input": "76\n46\n77\n11",
"output": "860"
},
{
"input": "80\n42\n1\n37",
"output": "79"
},
{
"input": "8\n80\n55\n1",
"output": "61"
},
{
"input": "10\n13\n72\n17",
"output": "117"
},
{
"input": "9\n24\n1\n63",
"output": "8"
},
{
"input": "65\n5\n8\n7",
"output": "320"
},
{
"input": "56\n8\n9\n3",
"output": "170"
},
{
"input": "59\n8\n1\n2",
"output": "58"
},
{
"input": "75\n50\n50\n5",
"output": "415"
},
{
"input": "75\n54\n76\n66",
"output": "3996"
},
{
"input": "73\n71\n69\n66",
"output": "4755"
},
{
"input": "83\n58\n88\n16",
"output": "1354"
},
{
"input": "74\n31\n11\n79",
"output": "803"
},
{
"input": "62\n27\n16\n72",
"output": "976"
},
{
"input": "72\n95\n27\n9",
"output": "657"
},
{
"input": "1\n2\n2\n1",
"output": "0"
},
{
"input": "1\n1\n1\n1",
"output": "0"
},
{
"input": "1\n1\n1\n99",
"output": "0"
},
{
"input": "100\n100\n100\n100",
"output": "9900"
},
{
"input": "2\n1\n1\n3",
"output": "1"
},
{
"input": "1\n3\n2\n1",
"output": "0"
},
{
"input": "1\n5\n6\n1",
"output": "0"
},
{
"input": "1\n2\n6\n1",
"output": "0"
},
{
"input": "1\n30\n20\n1",
"output": "0"
},
{
"input": "1\n15\n13\n11",
"output": "0"
},
{
"input": "1\n100\n50\n1",
"output": "0"
},
{
"input": "1\n2\n3\n1",
"output": "0"
},
{
"input": "5\n5\n5\n5",
"output": "20"
},
{
"input": "1\n100\n50\n5",
"output": "0"
},
{
"input": "1\n5\n7\n3",
"output": "0"
},
{
"input": "1\n3\n4\n2",
"output": "0"
},
{
"input": "3\n3\n3\n3",
"output": "6"
},
{
"input": "1\n99\n98\n1",
"output": "0"
},
{
"input": "5\n3\n3\n1",
"output": "6"
},
{
"input": "2\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1\n7\n8",
"output": "1"
},
{
"input": "2\n2\n2\n1",
"output": "2"
},
{
"input": "2\n2\n3\n1",
"output": "2"
},
{
"input": "1\n5\n6\n2",
"output": "0"
},
{
"input": "100\n1\n1\n100",
"output": "99"
},
{
"input": "2\n3\n2\n1",
"output": "2"
},
{
"input": "1\n99\n98\n97",
"output": "0"
}
] | 1,508,152,263 | 363 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,529,600 | n = int(input())
a = int(input())
b = int(input())
c = int(input())
l = sorted([a,b,c])
if n == 1:
print(0)
else:
result = 0
n -= 1
while n > 0:
result += l[0]
n -= 1
if n == 0:
break
else:
result += l[1]
n -= 1
print(result)
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters.
For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).
Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance.
Input Specification:
First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses.
Output Specification:
Output one number — minimum distance in meters Winnie must go through to have a meal *n* times.
Demo Input:
['3\n2\n3\n1\n', '1\n2\n3\n5\n']
Demo Output:
['3\n', '0\n']
Note:
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | ```python
n = int(input())
a = int(input())
b = int(input())
c = int(input())
l = sorted([a,b,c])
if n == 1:
print(0)
else:
result = 0
n -= 1
while n > 0:
result += l[0]
n -= 1
if n == 0:
break
else:
result += l[1]
n -= 1
print(result)
``` | 0 |
|
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
},
{
"input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8",
"output": "7"
},
{
"input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227",
"output": "15"
},
{
"input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5",
"output": "8"
},
{
"input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103",
"output": "21"
},
{
"input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404",
"output": "31"
},
{
"input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7",
"output": "17"
},
{
"input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99",
"output": "35"
},
{
"input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587",
"output": "45"
},
{
"input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6",
"output": "27"
},
{
"input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24",
"output": "38"
},
{
"input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227",
"output": "70"
},
{
"input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9",
"output": "59"
},
{
"input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39",
"output": "64"
},
{
"input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199",
"output": "64"
},
{
"input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3",
"output": "7"
},
{
"input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87",
"output": "70"
},
{
"input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460",
"output": "78"
},
{
"input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2",
"output": "74"
},
{
"input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433",
"output": "42"
},
{
"input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63",
"output": "2"
},
{
"input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440",
"output": "1"
},
{
"input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8",
"output": "3"
},
{
"input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68",
"output": "7"
},
{
"input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116",
"output": "6"
},
{
"input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36",
"output": "30"
},
{
"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718",
"output": "52"
},
{
"input": "1\n1\n1",
"output": "1"
}
] | 1,568,412,835 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
sizes_usb = sys.argv
no_flash_drives = sizes_usb.pop(0)
size_file = sizes_usb.pop(0)
sizes_usb.sort(reverse = True)
usb_needed = 0
for elements in sizes:
size_remaining = size_file - elements
usb_needed += 1
if size_remaining >= 0:
break
return usb_needed
| Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input Specification:
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Output Specification:
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
Demo Input:
['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | ```python
import sys
sizes_usb = sys.argv
no_flash_drives = sizes_usb.pop(0)
size_file = sizes_usb.pop(0)
sizes_usb.sort(reverse = True)
usb_needed = 0
for elements in sizes:
size_remaining = size_file - elements
usb_needed += 1
if size_remaining >= 0:
break
return usb_needed
``` | -1 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,662,734,930 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | my_input = input().split()
a = int(my_input[2])
my_input.pop()
my_input1 = []
if a * a < int(my_input[0]) * int(my_input[1]):
[(my_input1.append(a * int(int(x) / a + 1))) for x in my_input]
x = my_input1[0] * my_input1[1]
print(int(x / (a ** 2)))
else:
print(1)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
my_input = input().split()
a = int(my_input[2])
my_input.pop()
my_input1 = []
if a * a < int(my_input[0]) * int(my_input[1]):
[(my_input1.append(a * int(int(x) / a + 1))) for x in my_input]
x = my_input1[0] * my_input1[1]
print(int(x / (a ** 2)))
else:
print(1)
``` | 0 |
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2",
"output": "3"
},
{
"input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2",
"output": "5"
}
] | 1,665,065,968 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 77 | 2,355,200 | def dfs(start,end,color):
global cond
if cond:return
visited.add(start)
for child in nodes[start]:
if cond : return
if child==end:
if color in pair[(min(child,start),max(child,start))]:
cond=True ; return
else:
if child not in visited and color in pair[(min(child,start),max(child,start))]:
dfs(child,end,color)
if cond : return
n,m=map(int,input().split()) ; nodes=dict() ; pair=dict() ; colors=dict()
for i in range(m):
x,y,c=map(int,input().split())
if x not in nodes: nodes[x]={y}
else: nodes[x].add(y)
if y not in nodes: nodes[y]={x}
else: nodes[y].add(x)
if (x,y) in pair: pair[(x,y)].append(c)
else: pair[(x,y)]=[c]
if x in colors: colors[x].add(c)
else: colors[x]={c}
if y in colors: colors[y].add(c)
else: colors[y]={c}
for i in range(int(input())):
n1,n2=map(int,input().split()) ; ans=0
for j in colors[n1].intersection(colors[n2]):
visited=set() ; cond=False
dfs(n1,n2,j)
if cond:ans+=1
print(ans)
| Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
Input Specification:
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
Output Specification:
For each query, print the answer in a separate line.
Demo Input:
['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n']
Demo Output:
['2\n1\n0\n', '1\n1\n1\n1\n2\n']
Note:
Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | ```python
def dfs(start,end,color):
global cond
if cond:return
visited.add(start)
for child in nodes[start]:
if cond : return
if child==end:
if color in pair[(min(child,start),max(child,start))]:
cond=True ; return
else:
if child not in visited and color in pair[(min(child,start),max(child,start))]:
dfs(child,end,color)
if cond : return
n,m=map(int,input().split()) ; nodes=dict() ; pair=dict() ; colors=dict()
for i in range(m):
x,y,c=map(int,input().split())
if x not in nodes: nodes[x]={y}
else: nodes[x].add(y)
if y not in nodes: nodes[y]={x}
else: nodes[y].add(x)
if (x,y) in pair: pair[(x,y)].append(c)
else: pair[(x,y)]=[c]
if x in colors: colors[x].add(c)
else: colors[x]={c}
if y in colors: colors[y].add(c)
else: colors[y]={c}
for i in range(int(input())):
n1,n2=map(int,input().split()) ; ans=0
for j in colors[n1].intersection(colors[n2]):
visited=set() ; cond=False
dfs(n1,n2,j)
if cond:ans+=1
print(ans)
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,695,231,996 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 124 | 0 | def DieRoll():
others=list(map(int,input().split()))
maxOthers=max(others)
NumbersToGet=6-maxOthers+1
if NumbersToGet==1:
return '1/6'
elif NumbersToGet==2:
return '1/3'
elif NumbersToGet==3:
return '1/2'
elif NumbersToGet==4:
return '2/3'
elif NumbersToGet==5:
return '5/6'
elif NumbersToGet==6:
return '1/1'
print(DieRoll()) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
def DieRoll():
others=list(map(int,input().split()))
maxOthers=max(others)
NumbersToGet=6-maxOthers+1
if NumbersToGet==1:
return '1/6'
elif NumbersToGet==2:
return '1/3'
elif NumbersToGet==3:
return '1/2'
elif NumbersToGet==4:
return '2/3'
elif NumbersToGet==5:
return '5/6'
elif NumbersToGet==6:
return '1/1'
print(DieRoll())
``` | 3.938 |
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9.
The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).
Assume that both players play optimally. Who will win the game? | The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.
In the empty grid, Akshat cannot make any move, hence he will lose.
Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks. | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
{
"input": "1 3",
"output": "Akshat"
},
{
"input": "2 1",
"output": "Akshat"
},
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "3 1",
"output": "Akshat"
},
{
"input": "3 2",
"output": "Malvika"
},
{
"input": "68 42",
"output": "Malvika"
},
{
"input": "1 35",
"output": "Akshat"
},
{
"input": "25 70",
"output": "Akshat"
},
{
"input": "59 79",
"output": "Akshat"
},
{
"input": "65 63",
"output": "Akshat"
},
{
"input": "46 6",
"output": "Malvika"
},
{
"input": "28 82",
"output": "Malvika"
},
{
"input": "98 98",
"output": "Malvika"
},
{
"input": "98 99",
"output": "Malvika"
},
{
"input": "98 100",
"output": "Malvika"
},
{
"input": "99 98",
"output": "Malvika"
},
{
"input": "99 99",
"output": "Akshat"
},
{
"input": "99 100",
"output": "Akshat"
},
{
"input": "100 98",
"output": "Malvika"
},
{
"input": "100 99",
"output": "Akshat"
},
{
"input": "100 100",
"output": "Malvika"
},
{
"input": "3 4",
"output": "Akshat"
}
] | 1,689,733,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | a,b=map(int,input().split())
if (a+b)%3==0 or (a+b)<3:
print("Akshat")
else:
print("Malvika") | Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*·*m*<==<=9 intersection points, numbered from 1 to 9.
The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).
Assume that both players play optimally. Who will win the game?
Input Specification:
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Output Specification:
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
Demo Input:
['2 2\n', '2 3\n', '3 3\n']
Demo Output:
['Malvika\n', 'Malvika\n', 'Akshat\n']
Note:
Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.
In the empty grid, Akshat cannot make any move, hence he will lose.
Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks. | ```python
a,b=map(int,input().split())
if (a+b)%3==0 or (a+b)<3:
print("Akshat")
else:
print("Malvika")
``` | 0 |
|
292 | E | Copying Data | PROGRAMMING | 1,900 | [
"data structures"
] | null | null | We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.
More formally, you've got two arrays of integers *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* of length *n*. Also, you've got *m* queries of two types:
1. Copy the subsegment of array *a* of length *k*, starting from position *x*, into array *b*, starting from position *y*, that is, execute *b**y*<=+<=*q*<==<=*a**x*<=+<=*q* for all integer *q* (0<=≤<=*q*<=<<=*k*). The given operation is correct — both subsegments do not touch unexistent elements. 1. Determine the value in position *x* of array *b*, that is, find value *b**x*.
For each query of the second type print the result — the value of the corresponding element of array *b*. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=109). The third line contains an array of integers *b*1,<=*b*2,<=...,<=*b**n* (|*b**i*|<=≤<=109).
Next *m* lines contain the descriptions of the queries. The *i*-th line first contains integer *t**i* — the type of the *i*-th query (1<=≤<=*t**i*<=≤<=2). If *t**i*<==<=1, then the *i*-th query means the copying operation. If *t**i*<==<=2, then the *i*-th query means taking the value in array *b*. If *t**i*<==<=1, then the query type is followed by three integers *x**i*,<=*y**i*,<=*k**i* (1<=≤<=*x**i*,<=*y**i*,<=*k**i*<=≤<=*n*) — the parameters of the copying query. If *t**i*<==<=2, then the query type is followed by integer *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the position in array *b*.
All numbers in the lines are separated with single spaces. It is guaranteed that all the queries are correct, that is, the copying borders fit into the borders of arrays *a* and *b*. | For each second type query print the result on a single line. | [
"5 10\n1 2 0 -1 3\n3 1 5 -2 0\n2 5\n1 3 3 3\n2 5\n2 4\n2 1\n1 2 1 4\n2 1\n2 4\n1 4 2 1\n2 2\n"
] | [
"0\n3\n-1\n3\n2\n3\n-1\n"
] | none | 2,500 | [
{
"input": "5 10\n1 2 0 -1 3\n3 1 5 -2 0\n2 5\n1 3 3 3\n2 5\n2 4\n2 1\n1 2 1 4\n2 1\n2 4\n1 4 2 1\n2 2",
"output": "0\n3\n-1\n3\n2\n3\n-1"
},
{
"input": "1 4\n-2\n1\n1 1 1 1\n2 1\n1 1 1 1\n1 1 1 1",
"output": "-2"
},
{
"input": "2 5\n-3 2\n3 -4\n1 1 1 2\n2 1\n2 1\n1 2 2 1\n2 1",
"output": "-3\n-3\n-3"
},
{
"input": "3 6\n4 -3 0\n1 3 -5\n2 2\n2 3\n1 2 1 2\n1 2 1 2\n2 2\n2 2",
"output": "3\n-5\n0\n0"
},
{
"input": "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4",
"output": "2"
},
{
"input": "10 10\n-1 1 -1 2 -2 2 1 2 -1 0\n-1 -2 2 0 1 -1 -1 2 -2 1\n2 1\n2 2\n2 8\n1 6 8 1\n2 5\n2 9\n1 1 7 4\n2 5\n2 2\n2 3",
"output": "-1\n-2\n2\n1\n-2\n1\n-2\n2"
},
{
"input": "15 5\n1 0 3 1 2 1 -2 0 2 3 2 -1 -1 -1 -3\n-1 -1 1 -2 2 -2 -2 -3 -2 -1 -1 -3 -2 1 3\n1 7 15 1\n2 8\n2 3\n1 9 15 1\n1 4 11 3",
"output": "-3\n1"
},
{
"input": "20 30\n5 6 -6 10 10 -6 10 7 0 -10 3 1 -7 -9 1 -7 5 1 -1 1\n8 10 -10 -1 -9 3 9 -9 6 5 10 -2 -5 -9 1 3 -4 -1 -8 -7\n2 14\n1 8 11 1\n2 7\n1 6 17 1\n1 9 2 7\n1 12 1 7\n2 20\n2 5\n1 14 8 2\n1 8 17 4\n2 4\n1 11 12 9\n2 8\n2 3\n2 2\n1 17 7 2\n1 3 18 1\n2 11\n1 5 12 6\n1 12 7 1\n2 16\n2 11\n2 10\n2 19\n2 20\n2 18\n1 18 20 1\n2 13\n1 3 18 2\n1 20 5 1",
"output": "-9\n9\n-7\n-7\n1\n-9\n-9\n-7\n7\n0\n7\n5\n1\n-1\n-6\n-6"
}
] | 1,602,919,165 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 10,956,800 | from math import ceil, log2;
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# A utility function to get the
# middle index from corner indexes.
def value(ss, se, si, i):
global res
if ss > i or se < i:
return
if len(st[si]):
if st[si][2] > res[2]:
res = st[si]
if ss == se and ss == i:
return
mid = ss+(se-ss)//2
value(ss, mid, si * 2 + 1, i)
value(mid + 1, se, si * 2 + 2, i)
def querySTUtil(ss, se, strt, end,si):
if ss > end or se < strt:
return
if ss >= strt and se <= end:
st[si] = [x, y, p]
return
mid = ss+(se-ss)//2
querySTUtil(ss, mid, strt, end, si * 2 + 1)
querySTUtil(mid + 1, se, strt, end, si * 2 + 2)
return
def query(strt, end):
querySTUtil(0, n - 1, strt, end, 0)
""" Function to construct segment tree
from given array. This function allocates memory
for segment tree and calls constructSTUtil() to
fill the allocated memory """
def constructST(arr, n):
# Allocate memory for the segment tree
# Height of segment tree
x = (int)(ceil(log2(n)));
# Maximum size of segment tree
max_size = 2 * (int)(2 ** x) - 1;
# Allocate memory
st = [[]] * max_size;
# Fill the allocated memory st
# Return the constructed segment tree
return st
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
st = constructST(b, n)
p = 1
for j in range(m):
c = list(map(int, input().split()))
if c[0] == 1:
x, y, k = c[1] - 1, c[2] - 1, c[3] - 1
if x + k < n:
query(y, min(n - 1, y + k))
else:
query(y, min(n - 1, y + n - 1 - x))
p += 1
else:
res=[0,0,0]
value(0, n - 1, 0, c[1] - 1)
if res[2] == 0:
print(b[c[1] - 1])
else:
print(a[res[0] + c[1] - 1 - res[1]]) | Title: Copying Data
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.
More formally, you've got two arrays of integers *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* of length *n*. Also, you've got *m* queries of two types:
1. Copy the subsegment of array *a* of length *k*, starting from position *x*, into array *b*, starting from position *y*, that is, execute *b**y*<=+<=*q*<==<=*a**x*<=+<=*q* for all integer *q* (0<=≤<=*q*<=<<=*k*). The given operation is correct — both subsegments do not touch unexistent elements. 1. Determine the value in position *x* of array *b*, that is, find value *b**x*.
For each query of the second type print the result — the value of the corresponding element of array *b*.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=109). The third line contains an array of integers *b*1,<=*b*2,<=...,<=*b**n* (|*b**i*|<=≤<=109).
Next *m* lines contain the descriptions of the queries. The *i*-th line first contains integer *t**i* — the type of the *i*-th query (1<=≤<=*t**i*<=≤<=2). If *t**i*<==<=1, then the *i*-th query means the copying operation. If *t**i*<==<=2, then the *i*-th query means taking the value in array *b*. If *t**i*<==<=1, then the query type is followed by three integers *x**i*,<=*y**i*,<=*k**i* (1<=≤<=*x**i*,<=*y**i*,<=*k**i*<=≤<=*n*) — the parameters of the copying query. If *t**i*<==<=2, then the query type is followed by integer *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the position in array *b*.
All numbers in the lines are separated with single spaces. It is guaranteed that all the queries are correct, that is, the copying borders fit into the borders of arrays *a* and *b*.
Output Specification:
For each second type query print the result on a single line.
Demo Input:
['5 10\n1 2 0 -1 3\n3 1 5 -2 0\n2 5\n1 3 3 3\n2 5\n2 4\n2 1\n1 2 1 4\n2 1\n2 4\n1 4 2 1\n2 2\n']
Demo Output:
['0\n3\n-1\n3\n2\n3\n-1\n']
Note:
none | ```python
from math import ceil, log2;
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# A utility function to get the
# middle index from corner indexes.
def value(ss, se, si, i):
global res
if ss > i or se < i:
return
if len(st[si]):
if st[si][2] > res[2]:
res = st[si]
if ss == se and ss == i:
return
mid = ss+(se-ss)//2
value(ss, mid, si * 2 + 1, i)
value(mid + 1, se, si * 2 + 2, i)
def querySTUtil(ss, se, strt, end,si):
if ss > end or se < strt:
return
if ss >= strt and se <= end:
st[si] = [x, y, p]
return
mid = ss+(se-ss)//2
querySTUtil(ss, mid, strt, end, si * 2 + 1)
querySTUtil(mid + 1, se, strt, end, si * 2 + 2)
return
def query(strt, end):
querySTUtil(0, n - 1, strt, end, 0)
""" Function to construct segment tree
from given array. This function allocates memory
for segment tree and calls constructSTUtil() to
fill the allocated memory """
def constructST(arr, n):
# Allocate memory for the segment tree
# Height of segment tree
x = (int)(ceil(log2(n)));
# Maximum size of segment tree
max_size = 2 * (int)(2 ** x) - 1;
# Allocate memory
st = [[]] * max_size;
# Fill the allocated memory st
# Return the constructed segment tree
return st
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
st = constructST(b, n)
p = 1
for j in range(m):
c = list(map(int, input().split()))
if c[0] == 1:
x, y, k = c[1] - 1, c[2] - 1, c[3] - 1
if x + k < n:
query(y, min(n - 1, y + k))
else:
query(y, min(n - 1, y + n - 1 - x))
p += 1
else:
res=[0,0,0]
value(0, n - 1, 0, c[1] - 1)
if res[2] == 0:
print(b[c[1] - 1])
else:
print(a[res[0] + c[1] - 1 - res[1]])
``` | 0 |
|
171 | B | Star | PROGRAMMING | 1,300 | [
"*special",
"combinatorics"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257). | Print a single integer *output* (1<=≤<=*output*<=≤<=2·109). | [
"2\n"
] | [
"13"
] | none | 0 | [
{
"input": "2",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "37"
},
{
"input": "4",
"output": "73"
},
{
"input": "5",
"output": "121"
},
{
"input": "6",
"output": "181"
},
{
"input": "7",
"output": "253"
},
{
"input": "8",
"output": "337"
},
{
"input": "9",
"output": "433"
},
{
"input": "15000",
"output": "1349910001"
},
{
"input": "4845",
"output": "140815081"
},
{
"input": "6914",
"output": "286778893"
},
{
"input": "3994",
"output": "95688253"
},
{
"input": "12504",
"output": "938025073"
},
{
"input": "13170",
"output": "1040614381"
},
{
"input": "427",
"output": "1091413"
},
{
"input": "11877",
"output": "846307513"
},
{
"input": "3202",
"output": "61497613"
},
{
"input": "5689",
"output": "194154193"
},
{
"input": "15302",
"output": "1404815413"
},
{
"input": "17042",
"output": "1742476333"
},
{
"input": "1481",
"output": "13151281"
},
{
"input": "15592",
"output": "1458569233"
},
{
"input": "16344",
"output": "1602659953"
},
{
"input": "4222",
"output": "106926373"
},
{
"input": "11808",
"output": "836502337"
},
{
"input": "13366",
"output": "1071819541"
},
{
"input": "3823",
"output": "87669037"
},
{
"input": "581",
"output": "2021881"
},
{
"input": "15479",
"output": "1437503773"
},
{
"input": "6543",
"output": "256825837"
},
{
"input": "11136",
"output": "743996161"
},
{
"input": "16331",
"output": "1600111381"
},
{
"input": "8543",
"output": "437845837"
},
{
"input": "7530",
"output": "340160221"
},
{
"input": "3154",
"output": "59667373"
},
{
"input": "11501",
"output": "793569001"
},
{
"input": "12038",
"output": "869408437"
},
{
"input": "13082",
"output": "1026753853"
},
{
"input": "18257",
"output": "1999798753"
}
] | 1,586,748,005 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 0 | def triangle(n):
return n*(n+1)//2
def hexagon(n):
return 6*triangle(n) - 6*n + 1
n = int(input())
print(2*triangle(3*n - 2) - hexagon(n)) | Title: Star
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=18257).
Output Specification:
Print a single integer *output* (1<=≤<=*output*<=≤<=2·109).
Demo Input:
['2\n']
Demo Output:
['13']
Note:
none | ```python
def triangle(n):
return n*(n+1)//2
def hexagon(n):
return 6*triangle(n) - 6*n + 1
n = int(input())
print(2*triangle(3*n - 2) - hexagon(n))
``` | 3 |
||
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,672,333,940 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | m=int(input())
n=int(input())
if n>=m and 1<=n<=16 :
c= (m*n)/2
print(c) | 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())
if n>=m and 1<=n<=16 :
c= (m*n)/2
print(c)
``` | -1 |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 1",
"output": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,685,012,788 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 108 | 7,475,200 | n = int(input())
lst = list(map(int,input().split()))
count = 0
crime = 0
for i in lst:
if i == - 1:
if count <= 0:
crime += 1
else:
count = count - 1
else:
count += i
print(crime) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
n = int(input())
lst = list(map(int,input().split()))
count = 0
crime = 0
for i in lst:
if i == - 1:
if count <= 0:
crime += 1
else:
count = count - 1
else:
count += i
print(crime)
``` | 3 |
|
599 | C | Day at the Beach | PROGRAMMING | 1,600 | [
"sortings"
] | null | null | One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.
At the end of the day there were *n* castles built by friends. Castles are numbered from 1 to *n*, and the height of the *i*-th castle is equal to *h**i*. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition *h**i*<=≤<=*h**i*<=+<=1 holds for all *i* from 1 to *n*<=-<=1.
Squidward suggested the following process of sorting castles:
- Castles are split into blocks — groups of consecutive castles. Therefore the block from *i* to *j* will include castles *i*,<=*i*<=+<=1,<=...,<=*j*. A block may consist of a single castle. - The partitioning is chosen in such a way that every castle is a part of exactly one block. - Each block is sorted independently from other blocks, that is the sequence *h**i*,<=*h**i*<=+<=1,<=...,<=*h**j* becomes sorted. - The partitioning should satisfy the condition that after each block is sorted, the sequence *h**i* becomes sorted too. This may always be achieved by saying that the whole sequence is a single block.
Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.
The next line contains *n* integers *h**i* (1<=≤<=*h**i*<=≤<=109). The *i*-th of these integers corresponds to the height of the *i*-th castle. | Print the maximum possible number of blocks in a valid partitioning. | [
"3\n1 2 3\n",
"4\n2 1 3 2\n"
] | [
"3\n",
"2\n"
] | In the first sample the partitioning looks like that: [1][2][3].
In the second sample the partitioning is: [2, 1][3, 2] | 1,500 | [
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "4\n2 1 3 2",
"output": "2"
},
{
"input": "17\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005",
"output": "10"
},
{
"input": "101\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257 145 199 235 102 146 119 60 109 134 209 260 210 191 180 271 236 195 155 169 166 143 246 102 208 137 278 269 156 251 198 165 111 198 151 213 256 121 276 163 179 285 104 99 139 122 188 184 215 242 244 115 304 259 135 149 104 72 303 291 124 237 112 165 183 168 71 139 85 131 137 107 120 267 235 337 69",
"output": "3"
},
{
"input": "10\n1 2 2 2 2 2 2 2 2 1",
"output": "2"
},
{
"input": "25\n1 2 3 4 4 4 4 4 4 4 2 3 5 5 7 9 8 5 10 12 15 12 100500 800600 228228228",
"output": "12"
},
{
"input": "10\n17 18 19 19 18 17 100 500 100 100",
"output": "4"
},
{
"input": "10\n1 1 1 1 5 5 1 1 1 1",
"output": "5"
},
{
"input": "20\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "20"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n1 5 3 5 2",
"output": "2"
},
{
"input": "10\n1 1 1 1 2 2 2 2 4 3",
"output": "9"
},
{
"input": "20\n1 2 2 2 5 6 6 6 7 7 8 9 15 15 16 16 17 18 19 19",
"output": "20"
},
{
"input": "4\n2 2 1 1",
"output": "1"
}
] | 1,664,947,081 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 1,843,200 | number = int(input())
castles = list(map(int, input().split()))
ans = 0
maxz = 0
sorted_castles = sorted(castles)
start = 0
for i in range(1, number + 1):
if sorted(castles[start:i]) == sorted_castles[start:i]:
ans += 1
start = i
print(ans)
| Title: Day at the Beach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.
At the end of the day there were *n* castles built by friends. Castles are numbered from 1 to *n*, and the height of the *i*-th castle is equal to *h**i*. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition *h**i*<=≤<=*h**i*<=+<=1 holds for all *i* from 1 to *n*<=-<=1.
Squidward suggested the following process of sorting castles:
- Castles are split into blocks — groups of consecutive castles. Therefore the block from *i* to *j* will include castles *i*,<=*i*<=+<=1,<=...,<=*j*. A block may consist of a single castle. - The partitioning is chosen in such a way that every castle is a part of exactly one block. - Each block is sorted independently from other blocks, that is the sequence *h**i*,<=*h**i*<=+<=1,<=...,<=*h**j* becomes sorted. - The partitioning should satisfy the condition that after each block is sorted, the sequence *h**i* becomes sorted too. This may always be achieved by saying that the whole sequence is a single block.
Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day.
The next line contains *n* integers *h**i* (1<=≤<=*h**i*<=≤<=109). The *i*-th of these integers corresponds to the height of the *i*-th castle.
Output Specification:
Print the maximum possible number of blocks in a valid partitioning.
Demo Input:
['3\n1 2 3\n', '4\n2 1 3 2\n']
Demo Output:
['3\n', '2\n']
Note:
In the first sample the partitioning looks like that: [1][2][3].
In the second sample the partitioning is: [2, 1][3, 2] | ```python
number = int(input())
castles = list(map(int, input().split()))
ans = 0
maxz = 0
sorted_castles = sorted(castles)
start = 0
for i in range(1, number + 1):
if sorted(castles[start:i]) == sorted_castles[start:i]:
ans += 1
start = i
print(ans)
``` | 0 |
|
186 | B | Growing Mushrooms | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier). | The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose. | Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. | [
"2 3 3 50\n2 4\n4 2\n",
"4 1 1 1\n544 397\n280 101\n280 101\n693 970\n"
] | [
"1 15.00\n2 15.00\n",
"4 1656.07\n1 937.03\n2 379.99\n3 379.99\n"
] | - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | 1,000 | [
{
"input": "2 3 3 50\n2 4\n4 2",
"output": "1 15.00\n2 15.00"
},
{
"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970",
"output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"
},
{
"input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737",
"output": "8 1641.50\n6 1417.00\n7 1368.25\n10 1067.00\n4 1005.25\n1 981.75\n9 861.75\n3 814.00\n5 671.75\n2 559.00"
},
{
"input": "10 6 1 48\n239 632\n976 315\n797 112\n1 835\n938 862\n531 884\n422 607\n152 331\n413 677\n622 978",
"output": "5 3788.56\n10 3673.36\n2 3360.12\n6 3289.08\n4 2606.20\n3 2598.64\n9 2525.24\n7 2315.84\n1 2210.84\n8 1184.72"
},
{
"input": "8 1 4 55\n507 82\n681 492\n602 849\n367 557\n438 320\n798 699\n338 302\n391 814",
"output": "3 3666.90\n6 3506.55\n8 3431.95\n2 2945.40\n4 2393.15\n1 2064.90\n5 1896.00\n7 1487.90"
},
{
"input": "9 6 4 80\n95 269\n95 269\n781 724\n22 269\n173 655\n972 850\n22 269\n95 269\n642 666",
"output": "6 4908.00\n3 3992.80\n9 3434.40\n5 2827.60\n1 1190.00\n2 1190.00\n8 1190.00\n4 1102.40\n7 1102.40"
},
{
"input": "7 1 8 25\n98 713\n876 112\n990 771\n57 395\n171 899\n86 600\n459 320",
"output": "3 8498.25\n5 7320.25\n2 7092.00\n1 5777.50\n6 4864.50\n7 3912.00\n4 3202.75"
},
{
"input": "6 1 5 9\n105 771\n105 771\n105 771\n557 985\n105 771\n105 771",
"output": "4 5431.87\n1 3950.55\n2 3950.55\n3 3950.55\n5 3950.55\n6 3950.55"
},
{
"input": "6 2 2 78\n942 465\n593 600\n480 359\n733 648\n995 55\n526 538",
"output": "1 2088.60\n5 2014.20\n4 1751.12\n2 1460.92\n6 1307.44\n3 1117.96"
},
{
"input": "2 1 1 1\n2 2\n2 2",
"output": "1 3.98\n2 3.98"
},
{
"input": "2 1 1 100\n3 4\n4 3",
"output": "1 4.00\n2 4.00"
},
{
"input": "1 1 1 1\n1 1",
"output": "1 1.99"
}
] | 1,654,351,740 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | n,t1,t2,k = map(int, input().split())
choices = []
for i in range(n):
a,b = map(int, input().split())
hi = max(x*t1 + y*t2 * (1-k/100) for x,y in [(a,b),(b,a)])
choices.append((-hi, i+1))
choices.sort()
for h,i in choices:
print(i, "%.2f" % -h)
| Title: Growing Mushrooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts *t*1 seconds and the second part lasts *t*2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of *v**i* meters per second. After *t*1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by *k* percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of *u**i* meters per second. After a *t*2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds *a**i* and *b**i*, then there are two strategies: he either uses speed *a**i* before the break and speed *b**i* after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input Specification:
The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following *n* lines contains two integers. The *i*-th (1<=≤<=*i*<=≤<=*n*) line contains space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the speeds which the participant number *i* chose.
Output Specification:
Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Demo Input:
['2 3 3 50\n2 4\n4 2\n', '4 1 1 1\n544 397\n280 101\n280 101\n693 970\n']
Demo Output:
['1 15.00\n2 15.00\n', '4 1656.07\n1 937.03\n2 379.99\n3 379.99\n']
Note:
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | ```python
n,t1,t2,k = map(int, input().split())
choices = []
for i in range(n):
a,b = map(int, input().split())
hi = max(x*t1 + y*t2 * (1-k/100) for x,y in [(a,b),(b,a)])
choices.append((-hi, i+1))
choices.sort()
for h,i in choices:
print(i, "%.2f" % -h)
``` | 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,694,854,406 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | rounds = lambda count, n: count // n if count % n == 0 else (count // n) + 1
n, m = map(int, input().split())
arr = list(map(int, input().split()))
max_rounds = rounds(max(arr), m)
kids = []
for i in range(n):
if rounds(arr[i], m) == max_rounds:
kids.append(i)
print(kids[-1] + 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
rounds = lambda count, n: count // n if count % n == 0 else (count // n) + 1
n, m = map(int, input().split())
arr = list(map(int, input().split()))
max_rounds = rounds(max(arr), m)
kids = []
for i in range(n):
if rounds(arr[i], m) == max_rounds:
kids.append(i)
print(kids[-1] + 1)
``` | 3 |
|
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"input": "H",
"output": "YES"
},
{
"input": "+",
"output": "NO"
},
{
"input": "~",
"output": "NO"
},
{
"input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR",
"output": "YES"
},
{
"input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC",
"output": "YES"
},
{
"input": "@F%K2=%RyL/",
"output": "NO"
},
{
"input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J",
"output": "YES"
},
{
"input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)",
"output": "YES"
},
{
"input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C",
"output": "YES"
},
{
"input": "p-UXsbd&f",
"output": "NO"
},
{
"input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_",
"output": "YES"
},
{
"input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]",
"output": "YES"
},
{
"input": "}do5RU<(w<q[\"-NR)IAH_HyiD{",
"output": "YES"
},
{
"input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8",
"output": "YES"
},
{
"input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv",
"output": "YES"
},
{
"input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`",
"output": "YES"
},
{
"input": "OKBB5z7ud81[Tn@P\"nDUd,>@",
"output": "NO"
},
{
"input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv",
"output": "YES"
},
{
"input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh",
"output": "YES"
},
{
"input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp",
"output": "NO"
},
{
"input": "!3YPv@2JQ44@)R2O_4`GO",
"output": "YES"
},
{
"input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\",
"output": "YES"
},
{
"input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L",
"output": "NO"
},
{
"input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&",
"output": "YES"
},
{
"input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}",
"output": "YES"
},
{
"input": "Uh3>ER](J",
"output": "NO"
},
{
"input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,",
"output": "YES"
},
{
"input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!",
"output": "YES"
},
{
"input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@",
"output": "YES"
},
{
"input": "'jdL(vX",
"output": "NO"
},
{
"input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5",
"output": "YES"
},
{
"input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s",
"output": "YES"
},
{
"input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]",
"output": "YES"
},
{
"input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU",
"output": "YES"
},
{
"input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->",
"output": "YES"
},
{
"input": "&ppw0._:\\p-PuWM@l}%%=",
"output": "NO"
},
{
"input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr",
"output": "YES"
},
{
"input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q",
"output": "YES"
},
{
"input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0",
"output": "YES"
},
{
"input": "VXB&r9Z)IlKOJ:??KDA",
"output": "YES"
},
{
"input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R",
"output": "YES"
},
{
"input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C",
"output": "YES"
},
{
"input": "O.&=qt(`z(",
"output": "NO"
},
{
"input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@",
"output": "YES"
},
{
"input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp",
"output": "YES"
},
{
"input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8",
"output": "YES"
},
{
"input": "!0WKT:$O",
"output": "NO"
},
{
"input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)",
"output": "YES"
},
{
"input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly",
"output": "YES"
},
{
"input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(",
"output": "NO"
},
{
"input": "Qv)X8",
"output": "YES"
},
{
"input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F",
"output": "YES"
},
{
"input": "e{}2vQ+/r@p0}cLKNe4MCk",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH",
"output": "YES"
},
{
"input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "1H1",
"output": "YES"
},
{
"input": "+Q",
"output": "YES"
},
{
"input": "1ab",
"output": "NO"
},
{
"input": "!",
"output": "NO"
},
{
"input": "0+",
"output": "NO"
},
{
"input": "+H",
"output": "YES"
},
{
"input": "cH",
"output": "YES"
},
{
"input": "+8",
"output": "NO"
},
{
"input": "8+",
"output": "NO"
},
{
"input": "++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "(+)",
"output": "NO"
},
{
"input": "H+",
"output": "YES"
},
{
"input": "a!",
"output": "NO"
},
{
"input": "++++++++++++++",
"output": "NO"
},
{
"input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "HQ9",
"output": "YES"
},
{
"input": "+++H",
"output": "YES"
},
{
"input": "++++++++++",
"output": "NO"
},
{
"input": "HHHHHHH",
"output": "YES"
},
{
"input": "abacabaH",
"output": "YES"
},
{
"input": "+G",
"output": "NO"
}
] | 1,688,544,388 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n=input()
count=0
for i in range(len(n)):
if n[i]=='H' or n[i]=='Q' or n[i]=='9' or n[i]=="+":
count+=1
if count>0:
print("YES")
else:
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input Specification:
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output Specification:
Output "YES", if executing the program will produce any output, and "NO" otherwise.
Demo Input:
['Hi!\n', 'Codeforces\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | ```python
n=input()
count=0
for i in range(len(n)):
if n[i]=='H' or n[i]=='Q' or n[i]=='9' or n[i]=="+":
count+=1
if count>0:
print("YES")
else:
print("NO")
``` | 0 |
|
637 | C | Promocodes with Mistakes | PROGRAMMING | 1,400 | [
"*special",
"brute force",
"constructive algorithms",
"implementation"
] | null | null | During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly.
A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits. | The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0". | Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes. | [
"2\n000000\n999999\n",
"6\n211111\n212111\n222111\n111111\n112111\n121111\n"
] | [
"2\n",
"0\n"
] | In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it. | 1,500 | [
{
"input": "2\n000000\n999999",
"output": "2"
},
{
"input": "6\n211111\n212111\n222111\n111111\n112111\n121111",
"output": "0"
},
{
"input": "1\n123456",
"output": "6"
},
{
"input": "2\n000000\n099999",
"output": "2"
},
{
"input": "2\n000000\n009999",
"output": "1"
},
{
"input": "2\n000000\n000999",
"output": "1"
},
{
"input": "2\n000000\n000099",
"output": "0"
},
{
"input": "2\n000000\n000009",
"output": "0"
},
{
"input": "1\n000000",
"output": "6"
},
{
"input": "1\n999999",
"output": "6"
},
{
"input": "10\n946965\n781372\n029568\n336430\n456975\n119377\n179098\n925374\n878716\n461563",
"output": "1"
},
{
"input": "10\n878711\n193771\n965021\n617901\n333641\n307811\n989461\n461561\n956811\n253741",
"output": "1"
},
{
"input": "10\n116174\n914694\n615024\n115634\n717464\n910984\n513744\n111934\n915684\n817874",
"output": "0"
},
{
"input": "10\n153474\n155468\n151419\n151479\n158478\n159465\n150498\n157416\n150429\n159446",
"output": "0"
},
{
"input": "10\n141546\n941544\n141547\n041542\n641545\n841547\n941540\n741544\n941548\n641549",
"output": "0"
},
{
"input": "10\n114453\n114456\n114457\n114450\n114459\n114451\n114458\n114452\n114455\n114454",
"output": "0"
},
{
"input": "5\n145410\n686144\n859775\n922809\n470967",
"output": "2"
},
{
"input": "9\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "20\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832",
"output": "2"
},
{
"input": "50\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386",
"output": "2"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237",
"output": "1"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
},
{
"input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482",
"output": "2"
}
] | 1,458,035,613 | 2,147,483,647 | Python 3 | OK | TESTS | 98 | 935 | 307,200 | import operator
import itertools
n = int(input())
strings = [input() for i in range(n)]
if n == 1:
print(6)
else:
minDiff = 6;
for a, b in itertools.combinations(strings, 2):
minDiff = min(minDiff, list(map(operator.eq, a, b)).count(False))
print(int((minDiff - 1) / 2)) | Title: Promocodes with Mistakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.
As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly.
A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.
Input Specification:
The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes.
Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".
Output Specification:
Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes.
Demo Input:
['2\n000000\n999999\n', '6\n211111\n212111\n222111\n111111\n112111\n121111\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample *k* < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it. | ```python
import operator
import itertools
n = int(input())
strings = [input() for i in range(n)]
if n == 1:
print(6)
else:
minDiff = 6;
for a, b in itertools.combinations(strings, 2):
minDiff = min(minDiff, list(map(operator.eq, a, b)).count(False))
print(int((minDiff - 1) / 2))
``` | 3 |
|
357 | B | Flag Day | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance. | Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists. | [
"7 3\n1 2 3\n1 4 5\n4 6 7\n",
"9 3\n3 6 9\n2 5 8\n1 4 7\n",
"5 2\n4 1 5\n3 1 2\n"
] | [
"1 2 3 3 2 2 1 \n",
"1 1 1 2 2 2 3 3 3 \n",
"2 3 1 1 3 \n"
] | none | 1,000 | [
{
"input": "7 3\n1 2 3\n1 4 5\n4 6 7",
"output": "1 2 3 3 2 2 1 "
},
{
"input": "9 3\n3 6 9\n2 5 8\n1 4 7",
"output": "1 1 1 2 2 2 3 3 3 "
},
{
"input": "5 2\n4 1 5\n3 1 2",
"output": "2 3 1 1 3 "
},
{
"input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12",
"output": "1 3 3 2 2 2 1 1 2 2 3 3 1 1 "
},
{
"input": "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9",
"output": "2 2 2 3 2 1 2 3 1 3 2 1 3 1 "
},
{
"input": "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5",
"output": "1 1 2 2 3 2 2 1 3 3 1 3 2 1 "
},
{
"input": "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6",
"output": "3 3 3 2 3 2 3 2 2 1 1 1 1 "
},
{
"input": "14 6\n5 4 8\n5 7 12\n3 6 12\n7 11 14\n10 13 2\n10 1 9",
"output": "3 3 3 2 1 1 3 3 2 1 2 2 2 1 "
},
{
"input": "14 5\n4 13 2\n7 2 11\n6 1 5\n14 12 8\n10 3 9",
"output": "2 3 2 1 3 1 2 3 3 1 1 2 2 1 "
},
{
"input": "14 6\n2 14 5\n3 4 5\n6 13 14\n7 13 12\n8 10 11\n9 6 1",
"output": "1 1 1 2 3 3 3 1 2 2 3 2 1 2 "
},
{
"input": "14 6\n7 14 12\n6 1 12\n13 5 2\n2 3 9\n7 4 11\n5 8 10",
"output": "2 3 2 3 2 1 1 1 1 3 2 3 1 2 "
},
{
"input": "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5",
"output": "3 1 3 2 3 3 2 1 2 3 1 2 1 "
},
{
"input": "13 5\n8 4 3\n1 9 5\n6 2 11\n12 10 4\n7 10 13",
"output": "1 2 3 2 3 1 3 1 2 1 3 3 2 "
},
{
"input": "20 8\n16 19 12\n13 3 5\n1 5 17\n10 19 7\n8 18 2\n3 11 14\n9 20 12\n4 15 6",
"output": "2 3 2 1 3 3 3 1 1 1 1 3 1 3 2 1 1 2 2 2 "
},
{
"input": "19 7\n10 18 14\n5 9 11\n9 17 7\n3 15 4\n6 8 12\n1 2 18\n13 16 19",
"output": "3 1 1 3 1 1 3 2 2 1 3 3 1 3 2 2 1 2 3 "
},
{
"input": "18 7\n17 4 13\n7 1 6\n16 9 13\n9 2 5\n11 12 17\n14 8 10\n3 15 18",
"output": "2 1 1 2 3 3 1 2 2 3 2 3 3 1 2 1 1 3 "
},
{
"input": "20 7\n8 5 11\n3 19 20\n16 1 17\n9 6 2\n7 18 13\n14 12 18\n10 4 15",
"output": "2 3 1 2 2 2 1 1 1 1 3 1 3 3 3 1 3 2 2 3 "
},
{
"input": "20 7\n6 11 20\n19 5 2\n15 10 12\n3 7 8\n9 1 6\n13 17 18\n14 16 4",
"output": "3 3 1 3 2 1 2 3 2 2 2 3 1 1 1 2 2 3 1 3 "
},
{
"input": "18 7\n15 5 1\n6 11 4\n14 8 17\n11 12 13\n3 8 16\n9 4 7\n2 18 10",
"output": "3 1 1 3 2 1 1 2 2 3 2 1 3 1 1 3 3 2 "
},
{
"input": "19 7\n3 10 8\n17 7 4\n1 19 18\n2 9 5\n12 11 15\n11 14 6\n13 9 16",
"output": "1 1 1 3 3 3 2 3 2 2 2 1 1 1 3 3 1 3 2 "
},
{
"input": "19 7\n18 14 4\n3 11 6\n8 10 7\n10 19 16\n17 13 15\n5 1 14\n12 9 2",
"output": "1 3 1 3 3 3 3 1 2 2 2 1 2 2 3 3 1 1 1 "
},
{
"input": "20 7\n18 7 15\n17 5 20\n9 19 12\n16 13 10\n3 6 1\n3 8 11\n4 2 14",
"output": "3 2 1 1 2 2 2 3 1 3 2 3 2 3 3 1 1 1 2 3 "
},
{
"input": "18 7\n8 4 6\n13 17 3\n9 8 12\n12 16 5\n18 2 7\n11 1 10\n5 15 14",
"output": "2 2 3 2 3 3 3 1 3 3 1 2 1 1 2 1 2 1 "
},
{
"input": "99 37\n40 10 7\n10 3 5\n10 31 37\n87 48 24\n33 47 38\n34 87 2\n2 35 28\n99 28 76\n66 51 97\n72 77 9\n18 17 67\n23 69 98\n58 89 99\n42 44 52\n65 41 80\n70 92 74\n62 88 45\n68 27 61\n6 83 95\n39 85 49\n57 75 77\n59 54 81\n56 20 82\n96 4 53\n90 7 11\n16 43 84\n19 25 59\n68 8 93\n73 94 78\n15 71 79\n26 12 50\n30 32 4\n14 22 29\n46 21 36\n60 55 86\n91 8 63\n13 1 64",
"output": "2 2 1 2 3 1 3 3 3 2 1 2 1 1 1 1 2 1 2 2 2 2 1 3 3 1 2 3 3 3 1 1 1 3 1 3 3 3 1 1 2 1 2 2 3 1 2 2 3 3 2 3 3 2 2 1 3 3 1 1 3 1 1 3 1 1 3 1 2 1 2 1 1 3 1 1 2 3 3 3 3 3 2 3 2 3 1 2 1 2 2 2 2 2 3 1 3 3 2 "
},
{
"input": "99 41\n11 70 20\n57 11 76\n52 11 64\n49 70 15\n19 61 17\n71 77 21\n77 59 39\n37 64 68\n17 84 36\n46 11 90\n35 11 14\n36 25 80\n12 43 48\n18 78 42\n82 94 15\n22 10 84\n63 86 4\n98 86 50\n92 60 9\n73 42 65\n21 5 27\n30 24 23\n7 88 49\n40 97 45\n81 56 17\n79 61 33\n13 3 77\n54 6 28\n99 58 8\n29 95 24\n89 74 32\n51 89 66\n87 91 96\n22 34 38\n1 53 72\n55 97 26\n41 16 44\n2 31 47\n83 67 91\n75 85 69\n93 47 62",
"output": "1 1 1 3 2 2 2 3 3 1 1 1 3 2 3 2 3 1 1 3 3 3 3 2 3 3 1 3 3 1 2 3 3 2 3 1 1 1 3 1 1 3 2 3 3 3 3 3 1 3 3 3 2 1 1 2 3 2 1 2 2 1 1 2 1 2 1 3 3 2 1 3 2 2 1 2 2 2 1 2 1 1 3 2 2 2 1 3 1 2 2 1 2 2 1 3 2 1 1 "
},
{
"input": "99 38\n70 56 92\n61 70 68\n18 92 91\n82 43 55\n37 5 43\n47 27 26\n64 63 40\n20 61 57\n69 80 59\n60 89 50\n33 25 86\n38 15 73\n96 85 90\n3 12 64\n95 23 48\n66 30 9\n38 99 45\n67 88 71\n74 11 81\n28 51 79\n72 92 34\n16 77 31\n65 18 94\n3 41 2\n36 42 81\n22 77 83\n44 24 52\n10 75 97\n54 21 53\n4 29 32\n58 39 98\n46 62 16\n76 5 84\n8 87 13\n6 41 14\n19 21 78\n7 49 93\n17 1 35",
"output": "2 3 2 1 1 3 1 1 3 1 2 3 3 2 2 1 1 2 1 2 2 1 2 2 2 3 2 1 2 2 3 3 1 1 3 1 3 1 2 3 1 2 2 1 2 2 1 3 2 3 2 3 3 1 3 2 1 1 3 1 3 3 2 1 1 1 1 2 1 1 3 2 3 1 2 3 2 3 3 2 3 1 3 2 2 3 2 2 2 3 1 3 3 3 1 1 3 3 3 "
},
{
"input": "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n90 64 29\n31 68 25\n83 57 41\n51 90 3\n91 97 66\n96 95 1\n50 84 71\n53 19 5\n45 42 28\n16 17 89\n63 58 15\n26 47 39\n21 24 19\n80 74 38\n14 46 75\n88 65 36\n77 92 33\n17 59 34\n35 69 79\n13 94 39\n8 52 4\n67 27 9\n65 62 18\n81 32 49",
"output": "3 2 1 3 2 1 1 1 3 3 1 3 2 1 3 2 3 3 1 2 2 2 2 3 3 2 2 3 2 3 1 2 3 1 1 3 1 3 1 2 1 2 3 1 1 2 3 3 3 3 2 2 3 3 1 2 3 2 2 3 2 1 1 1 2 3 1 2 2 1 1 2 3 2 3 2 1 3 3 1 1 2 2 2 1 1 3 1 1 3 1 2 1 3 2 1 2 1 "
},
{
"input": "99 42\n61 66 47\n10 47 96\n68 86 67\n21 29 10\n55 44 47\n12 82 4\n45 71 55\n86 3 95\n16 99 93\n14 92 82\n12 59 20\n73 24 8\n79 72 48\n44 87 39\n87 84 97\n47 70 37\n49 77 95\n39 75 28\n75 25 5\n44 41 36\n76 86 78\n73 6 90\n8 22 58\n9 72 63\n81 42 14\n1 21 35\n91 54 15\n30 13 39\n56 89 79\n11 2 76\n19 65 52\n23 85 74\n7 38 24\n57 94 81\n43 34 60\n62 82 27\n69 64 53\n18 32 17\n24 31 88\n51 50 33\n40 80 98\n83 46 26",
"output": "2 3 1 3 3 3 3 3 1 2 2 1 2 3 3 1 3 1 1 2 3 2 1 2 1 3 3 1 1 1 1 2 3 2 1 3 1 1 3 1 1 2 1 2 2 2 3 3 1 2 1 3 3 2 1 2 2 1 3 3 1 1 3 2 2 2 3 1 1 2 3 2 1 3 2 1 2 3 1 2 1 2 1 3 2 2 1 3 3 2 1 1 3 3 3 1 2 3 2 "
}
] | 1,610,336,351 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n, m = map(int, input().split())
l = [-1]*n
for i in range(m):
a, b, c = map(int, input().split())
if(l[a-1] == -1 and l[b-1] == -1 and l[b-1] == -1):
l[a-1] = 1
l[b-1] = 2
l[c-1] = 3
elif(l[a-1] == -1 and l[b-1] == -1):
l[a-1] = (l[c-1]+1)%3 + (l[c-1]+1)//3
l[b-1] = (l[c-1]+2)%3 + (l[c-1]+2)//3
elif(l[c-1] == -1 and l[b-1] == -1):
l[c-1] = (l[a-1]+1)%3 + (l[a-1]+1)//3
l[b-1] = (l[a-1]+2)%3 + (l[a-1]+2)//3
elif(l[a-1] == -1 and l[c-1] == -1):
l[a-1] = (l[b-1]+1)%3 + (l[b-1]+1)//3
l[c-1] = (l[b-1]+2)%3 + (l[b-1]+2)//3
print(*l) | Title: Flag Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance.
Output Specification:
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
Demo Input:
['7 3\n1 2 3\n1 4 5\n4 6 7\n', '9 3\n3 6 9\n2 5 8\n1 4 7\n', '5 2\n4 1 5\n3 1 2\n']
Demo Output:
['1 2 3 3 2 2 1 \n', '1 1 1 2 2 2 3 3 3 \n', '2 3 1 1 3 \n']
Note:
none | ```python
n, m = map(int, input().split())
l = [-1]*n
for i in range(m):
a, b, c = map(int, input().split())
if(l[a-1] == -1 and l[b-1] == -1 and l[b-1] == -1):
l[a-1] = 1
l[b-1] = 2
l[c-1] = 3
elif(l[a-1] == -1 and l[b-1] == -1):
l[a-1] = (l[c-1]+1)%3 + (l[c-1]+1)//3
l[b-1] = (l[c-1]+2)%3 + (l[c-1]+2)//3
elif(l[c-1] == -1 and l[b-1] == -1):
l[c-1] = (l[a-1]+1)%3 + (l[a-1]+1)//3
l[b-1] = (l[a-1]+2)%3 + (l[a-1]+2)//3
elif(l[a-1] == -1 and l[c-1] == -1):
l[a-1] = (l[b-1]+1)%3 + (l[b-1]+1)//3
l[c-1] = (l[b-1]+2)%3 + (l[b-1]+2)//3
print(*l)
``` | 0 |
|
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,643,907,445 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | # -*- coding: utf-8 -*-
"""Fafa.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1NWMBD7xO_XqMfOvDZAR3qjWw_QqxSM6l
"""
n = int(input())
t = 0
for i in range(1,int(n/2)+1):
if (n%i)==0:
t +=1
print(t) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | ```python
# -*- coding: utf-8 -*-
"""Fafa.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1NWMBD7xO_XqMfOvDZAR3qjWw_QqxSM6l
"""
n = int(input())
t = 0
for i in range(1,int(n/2)+1):
if (n%i)==0:
t +=1
print(t)
``` | 3 |
|
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25",
"output": "840"
},
{
"input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44",
"output": "922"
},
{
"input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59",
"output": "674"
},
{
"input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82",
"output": "848"
},
{
"input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93",
"output": "902"
},
{
"input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20",
"output": "798"
},
{
"input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31",
"output": "632"
},
{
"input": "1\n4",
"output": "4"
},
{
"input": "2\n1 4",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "6"
},
{
"input": "2\n9 3",
"output": "12"
},
{
"input": "2\n1000000000 1001",
"output": "1000000000"
},
{
"input": "3\n1 8 4",
"output": "12"
},
{
"input": "3\n7 4 4",
"output": "8"
},
{
"input": "5\n2 3 4 5 3",
"output": "14"
},
{
"input": "2\n4 5",
"output": "4"
},
{
"input": "3\n2 4 5",
"output": "6"
},
{
"input": "3\n2 2 3",
"output": "4"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "4\n2 3 7 7",
"output": "16"
},
{
"input": "2\n999999999 2",
"output": "2"
},
{
"input": "2\n2 5",
"output": "2"
},
{
"input": "3\n5 3 1",
"output": "8"
},
{
"input": "4\n3 2 5 7",
"output": "14"
}
] | 1,596,162,578 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 155 | 7,987,200 | import math
import cmath
import string
import sys
import bisect
import ctypes
from queue import Queue,LifoQueue,PriorityQueue
from itertools import permutations,combinations
from collections import deque,Counter
n=int(input())
s=list(map(int,input().split(' ')))
sum=0
#a=a.reverse()
x=[]
for i in range(n):
if s[i]%2==0:
sum=sum+s[i]
else:
x.append(s[i])
sum+=s[i]
k=len(x)-1
x.sort()
print(x)
if k%2==0:
sum-=x[0]
print(sum)
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
Input Specification:
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Output Specification:
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Demo Input:
['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n']
Demo Output:
['6', '3999999996']
Note:
In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | ```python
import math
import cmath
import string
import sys
import bisect
import ctypes
from queue import Queue,LifoQueue,PriorityQueue
from itertools import permutations,combinations
from collections import deque,Counter
n=int(input())
s=list(map(int,input().split(' ')))
sum=0
#a=a.reverse()
x=[]
for i in range(n):
if s[i]%2==0:
sum=sum+s[i]
else:
x.append(s[i])
sum+=s[i]
k=len(x)-1
x.sort()
print(x)
if k%2==0:
sum-=x[0]
print(sum)
``` | 0 |
|
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1152921504606846975"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000000000 2",
"output": "1152921504606846975"
},
{
"input": "49194939 22",
"output": "67108863"
},
{
"input": "228104606 17",
"output": "268435455"
},
{
"input": "817034381 7",
"output": "1073741823"
},
{
"input": "700976748 4",
"output": "1073741823"
},
{
"input": "879886415 9",
"output": "1073741823"
},
{
"input": "18007336 10353515",
"output": "33554431"
},
{
"input": "196917003 154783328",
"output": "268435455"
},
{
"input": "785846777 496205300",
"output": "1073741823"
},
{
"input": "964756444 503568330",
"output": "1073741823"
},
{
"input": "848698811 317703059",
"output": "1073741823"
},
{
"input": "676400020444788 1",
"output": "676400020444788"
},
{
"input": "502643198528213 1",
"output": "502643198528213"
},
{
"input": "815936580997298686 684083143940282566",
"output": "1152921504606846975"
},
{
"input": "816762824175382110 752185261508428780",
"output": "1152921504606846975"
},
{
"input": "327942415253132295 222598158321260499",
"output": "576460752303423487"
},
{
"input": "328768654136248423 284493129147496637",
"output": "576460752303423487"
},
{
"input": "329594893019364551 25055600080496801",
"output": "576460752303423487"
},
{
"input": "921874985256864012 297786684518764536",
"output": "1152921504606846975"
},
{
"input": "922701224139980141 573634416190460758",
"output": "1152921504606846975"
},
{
"input": "433880815217730325 45629641110945892",
"output": "576460752303423487"
},
{
"input": "434707058395813749 215729375494216481",
"output": "576460752303423487"
},
{
"input": "435533301573897173 34078453236225189",
"output": "576460752303423487"
},
{
"input": "436359544751980597 199220719961060641",
"output": "576460752303423487"
},
{
"input": "437185783635096725 370972992240105630",
"output": "576460752303423487"
},
{
"input": "438012026813180149 111323110116193830",
"output": "576460752303423487"
},
{
"input": "438838269991263573 295468957052046146",
"output": "576460752303423487"
},
{
"input": "439664513169346997 46560240538186155",
"output": "576460752303423487"
},
{
"input": "440490752052463125 216165966013438147",
"output": "576460752303423487"
},
{
"input": "441316995230546549 401964286420555423",
"output": "576460752303423487"
},
{
"input": "952496582013329437 673506882352402278",
"output": "1152921504606846975"
},
{
"input": "1000000000000000000 1",
"output": "1000000000000000000"
},
{
"input": "2147483647 1",
"output": "2147483647"
},
{
"input": "2147483647 2",
"output": "2147483647"
},
{
"input": "2147483647 31",
"output": "2147483647"
},
{
"input": "8 2",
"output": "15"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "10 2",
"output": "15"
},
{
"input": "288230376151711743 2",
"output": "288230376151711743"
},
{
"input": "5 2",
"output": "7"
},
{
"input": "576460752303423487 2",
"output": "576460752303423487"
},
{
"input": "36028797018963967 123",
"output": "36028797018963967"
},
{
"input": "1125899906842623 2",
"output": "1125899906842623"
},
{
"input": "576460752303423489 5",
"output": "1152921504606846975"
},
{
"input": "288230376151711743 3",
"output": "288230376151711743"
},
{
"input": "36028797018963967 345",
"output": "36028797018963967"
},
{
"input": "18014398509481984 30",
"output": "36028797018963967"
},
{
"input": "8 8",
"output": "15"
},
{
"input": "8 1",
"output": "8"
}
] | 1,515,420,456 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 62 | 5,632,000 | # -*- coding: utf-8 -*-
"""
Created on Mon Jan 8 09:03:34 2018
@author: yanni
"""
k, n = [int(x) for x in input().split()]
power = 1
while (power <= k):
power *= 2
if (k == 1):
print(n)
else:
print(power-1) | Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
Input Specification:
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output Specification:
Output one number — the largest possible xor-sum.
Demo Input:
['4 3\n', '6 6\n']
Demo Output:
['7\n', '7\n']
Note:
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 8 09:03:34 2018
@author: yanni
"""
k, n = [int(x) for x in input().split()]
power = 1
while (power <= k):
power *= 2
if (k == 1):
print(n)
else:
print(power-1)
``` | 0 |
|
724 | D | Dense Subsequence | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"strings"
] | null | null | You are given a string *s*, consisting of lowercase English letters, and the integer *m*.
One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.
Formally, we choose a subsequence of indices 1<=≤<=*i*1<=<<=*i*2<=<<=...<=<<=*i**t*<=≤<=|*s*|. The selected sequence must meet the following condition: for every *j* such that 1<=≤<=*j*<=≤<=|*s*|<=-<=*m*<=+<=1, there must be at least one selected index that belongs to the segment [*j*,<= *j*<=+<=*m*<=-<=1], i.e. there should exist a *k* from 1 to *t*, such that *j*<=≤<=*i**k*<=≤<=*j*<=+<=*m*<=-<=1.
Then we take any permutation *p* of the selected indices and form a new string *s**i**p*1*s**i**p*2... *s**i**p**t*.
Find the lexicographically smallest string, that can be obtained using this procedure. | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000).
The second line contains the string *s* consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100<=000. It is also guaranteed that the number *m* doesn't exceed the length of the string *s*. | Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above. | [
"3\ncbabc\n",
"2\nabcab\n",
"3\nbcabcbaccba\n"
] | [
"a\n",
"aab\n",
"aaabb\n"
] | In the first sample, one can choose the subsequence {3} and form a string "a".
In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab". | 1,500 | [
{
"input": "3\ncbabc",
"output": "a"
},
{
"input": "2\nabcab",
"output": "aab"
},
{
"input": "3\nbcabcbaccba",
"output": "aaabb"
},
{
"input": "5\nimmaydobun",
"output": "ab"
},
{
"input": "5\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzknetdibv",
"output": "aaaabbcccccddeeeeeefggggggghiijjjjjjkkllmmnnnnoppppqqrrrrrrrrsstttttu"
},
{
"input": "10\nefispvmzuutsrpxzfrykhabznxiyquwvhwhrksrgzodtuepfvamilfdynapzhzyhncorhzuewrrkcduvuhwsrprjrmgctnvrdtpj",
"output": "aaabcccddddeeeffffgghhhhhhhiiijjkkklm"
},
{
"input": "20\nhlicqhxayiodyephxlfoetfketnaabpfegqcrjzlshkxfzjssvpvzhzylgowwovgxznzowvpklbwbzhwtkkaomjkenhpedmbmjic",
"output": "aaaabbbbcccddeeeeeeffffg"
},
{
"input": "50\ntyhjolxuexoffdkdwimsjujorgeksyiyvvqecvhpjsuayqnibijtipuqhkulxpysotlmtrsgygpkdhkrtntwqzrpfckiscaphyhv",
"output": "aab"
},
{
"input": "1\nbaaa",
"output": "aaab"
},
{
"input": "5\nbbbbba",
"output": "ab"
},
{
"input": "10\nbbabcbbaabcbcbcbaabbccaacccbbbcaaacabbbbaaaccbcccacbbccaccbbaacaccbabcaaaacaccacbaaccaaccbaacabbbaac",
"output": "aaaaaaaaaaa"
}
] | 1,475,935,522 | 6,622 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 46 | 4,608,000 | m = int(input())
s = str(input())
l = len(s)
y = set()
for i in range(l - m + 1):
c = "z"
z = i
for j in range(i, i + m):
a = min(c, s[j])
if a != c:
c = a
z = j
y.add(z)
x = ""
for c in y:
x += s[c]
x = sorted(x)
for c in x:
print(c, end="")
print()
| Title: Dense Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s*, consisting of lowercase English letters, and the integer *m*.
One should choose some symbols from the given string so that any contiguous subsegment of length *m* has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.
Formally, we choose a subsequence of indices 1<=≤<=*i*1<=<<=*i*2<=<<=...<=<<=*i**t*<=≤<=|*s*|. The selected sequence must meet the following condition: for every *j* such that 1<=≤<=*j*<=≤<=|*s*|<=-<=*m*<=+<=1, there must be at least one selected index that belongs to the segment [*j*,<= *j*<=+<=*m*<=-<=1], i.e. there should exist a *k* from 1 to *t*, such that *j*<=≤<=*i**k*<=≤<=*j*<=+<=*m*<=-<=1.
Then we take any permutation *p* of the selected indices and form a new string *s**i**p*1*s**i**p*2... *s**i**p**t*.
Find the lexicographically smallest string, that can be obtained using this procedure.
Input Specification:
The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000).
The second line contains the string *s* consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100<=000. It is also guaranteed that the number *m* doesn't exceed the length of the string *s*.
Output Specification:
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
Demo Input:
['3\ncbabc\n', '2\nabcab\n', '3\nbcabcbaccba\n']
Demo Output:
['a\n', 'aab\n', 'aaabb\n']
Note:
In the first sample, one can choose the subsequence {3} and form a string "a".
In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab". | ```python
m = int(input())
s = str(input())
l = len(s)
y = set()
for i in range(l - m + 1):
c = "z"
z = i
for j in range(i, i + m):
a = min(c, s[j])
if a != c:
c = a
z = j
y.add(z)
x = ""
for c in y:
x += s[c]
x = sorted(x)
for c in x:
print(c, end="")
print()
``` | 0 |
|
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn! | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "ab\nbb",
"output": "NO"
},
{
"input": "zzaa\naazz",
"output": "YES"
},
{
"input": "azza\nzaaz",
"output": "YES"
},
{
"input": "abc\nabc",
"output": "YES"
},
{
"input": "abc\nacb",
"output": "NO"
},
{
"input": "azzz\nzzaz",
"output": "YES"
},
{
"input": "abcd\ndcab",
"output": "YES"
},
{
"input": "abcd\ncdab",
"output": "YES"
},
{
"input": "abcd\ndcba",
"output": "YES"
},
{
"input": "abcd\nacbd",
"output": "NO"
},
{
"input": "oloaxgddgujq\noloaxgujqddg",
"output": "YES"
},
{
"input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta",
"output": "YES"
},
{
"input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz",
"output": "YES"
},
{
"input": "snyaydaeobufdg\nsnyaydaeobufdg",
"output": "YES"
},
{
"input": "baaaaa\nabaaaa",
"output": "NO"
},
{
"input": "hhiisug\nmzdjwju",
"output": "NO"
},
{
"input": "bbbabbabaaab\naaaabbabbbbb",
"output": "NO"
},
{
"input": "bbaaab\naababb",
"output": "NO"
},
{
"input": "aabbaaaa\naaaaabab",
"output": "NO"
},
{
"input": "aab\naba",
"output": "NO"
},
{
"input": "abcddd\nbacddd",
"output": "NO"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "aabaababaaba\naababaaababa",
"output": "NO"
},
{
"input": "nocdqzdriyyil\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "zdmctxl\nkojqhgw",
"output": "NO"
},
{
"input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw",
"output": "NO"
},
{
"input": "abc\nbac",
"output": "NO"
},
{
"input": "ottceez\npcstdvz",
"output": "NO"
}
] | 1,616,255,219 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 93 | 1,843,200 | from collections import Counter
def ans(a, b, i):
if i != 0:
return Counter(list(a)) == Counter(list(b))
if a == b:
return True
else:
a1 = a[:len(a) // 2]
a2 = a[len(a) // 2:]
b1 = b[:len(b) // 2]
b2 = b[len(b) // 2:]
return ans(a1, b1, i+1) and ans(a2, b2, i+1) or ans(a1, b2, i+1) and ans(a2, b1, i+1)
a = input()
b = input()
print('YES' if ans(a, b, 0) else 'NO')
| Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn!
Input Specification:
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Output Specification:
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
Demo Input:
['aaba\nabaa\n', 'aabb\nabab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | ```python
from collections import Counter
def ans(a, b, i):
if i != 0:
return Counter(list(a)) == Counter(list(b))
if a == b:
return True
else:
a1 = a[:len(a) // 2]
a2 = a[len(a) // 2:]
b1 = b[:len(b) // 2]
b2 = b[len(b) // 2:]
return ans(a1, b1, i+1) and ans(a2, b2, i+1) or ans(a1, b2, i+1) and ans(a2, b1, i+1)
a = input()
b = input()
print('YES' if ans(a, b, 0) else 'NO')
``` | 0 |
|
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,648,418,325 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 5 | 60 | 0 | fila=input("")
matriz=[]
mal=""
i=0
if len(fila)==3:
while i<int(fila[0]):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==4:
fila=int(fila[0:2])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==5:
if fila[1]==" ":
fila=fila[0]
else:
fila=fila[0:3]
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==6:
fila=int(fila[0:4])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==7:
fila=int(fila[0:4])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
for x in matriz:
confirmacion=""
for j in range(len(x)):
if x[j]==x[j-1]:
confirmacion+="1"
if len(confirmacion)!=len(x):
mal="1"
for u in range(len(matriz)-1):
if matriz[u]==matriz[u+1]:
mal="1"
if mal=="1":
print("NO")
else:
print("YES") | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
fila=input("")
matriz=[]
mal=""
i=0
if len(fila)==3:
while i<int(fila[0]):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==4:
fila=int(fila[0:2])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==5:
if fila[1]==" ":
fila=fila[0]
else:
fila=fila[0:3]
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==6:
fila=int(fila[0:4])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
if len(fila)==7:
fila=int(fila[0:4])
while i<int(fila):
colores=input("")
matriz.append(colores)
i+=1
for x in matriz:
confirmacion=""
for j in range(len(x)):
if x[j]==x[j-1]:
confirmacion+="1"
if len(confirmacion)!=len(x):
mal="1"
for u in range(len(matriz)-1):
if matriz[u]==matriz[u+1]:
mal="1"
if mal=="1":
print("NO")
else:
print("YES")
``` | -1 |
593 | B | Anton and Lines | PROGRAMMING | 1,600 | [
"geometry",
"sortings"
] | null | null | The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between *x*1<=<<=*x*2. In other words, is it true that there are 1<=≤<=*i*<=<<=*j*<=≤<=*n* and *x*',<=*y*', such that:
- *y*'<==<=*k**i*<=*<=*x*'<=+<=*b**i*, that is, point (*x*',<=*y*') belongs to the line number *i*; - *y*'<==<=*k**j*<=*<=*x*'<=+<=*b**j*, that is, point (*x*',<=*y*') belongs to the line number *j*; - *x*1<=<<=*x*'<=<<=*x*2, that is, point (*x*',<=*y*') lies inside the strip bounded by *x*1<=<<=*x*2.
You can't leave Anton in trouble, can you? Write a program that solves the given task. | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=<<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following *n* lines contain integers *k**i*, *b**i* (<=-<=1<=000<=000<=≤<=*k**i*,<=*b**i*<=≤<=1<=000<=000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two *i*<=≠<=*j* it is true that either *k**i*<=≠<=*k**j*, or *b**i*<=≠<=*b**j*. | Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). | [
"4\n1 2\n1 2\n1 0\n0 1\n0 2\n",
"2\n1 3\n1 0\n-1 3\n",
"2\n1 3\n1 0\n0 2\n",
"2\n1 3\n1 0\n0 3\n"
] | [
"NO",
"YES",
"YES",
"NO"
] | In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | 1,000 | [
{
"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2",
"output": "NO"
},
{
"input": "2\n1 3\n1 0\n-1 3",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 2",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 3",
"output": "NO"
},
{
"input": "2\n0 1\n-1000000 1000000\n1000000 -1000000",
"output": "NO"
},
{
"input": "2\n-1337 1888\n-1000000 1000000\n1000000 -1000000",
"output": "YES"
},
{
"input": "2\n-1337 1888\n-1000000 1000000\n-999999 -1000000",
"output": "NO"
},
{
"input": "15\n30 32\n-45 1\n-22 -81\n4 42\n-83 -19\n97 70\n55 -91\n-45 -64\n0 64\n11 96\n-16 76\n-46 52\n0 91\n31 -90\n6 75\n65 14",
"output": "NO"
},
{
"input": "15\n-1 3\n2 -4\n0 -6\n-2 -5\n0 -1\n-1 -2\n3 6\n4 4\n0 -4\n1 5\n5 -4\n-5 -6\n3 -6\n5 -3\n-1 6\n-3 -1",
"output": "YES"
},
{
"input": "5\n-197 -126\n0 -94\n-130 -100\n-84 233\n-173 -189\n61 -200",
"output": "NO"
},
{
"input": "2\n9 10\n-7 -11\n9 2",
"output": "NO"
},
{
"input": "3\n4 11\n-2 14\n2 -15\n-8 -15",
"output": "YES"
},
{
"input": "2\n1 2\n2 -2\n0 2",
"output": "NO"
},
{
"input": "10\n1 3\n1 5\n1 2\n1 4\n1 6\n1 3\n1 7\n1 -5\n1 -1\n1 1\n1 8",
"output": "NO"
},
{
"input": "10\n22290 75956\n-66905 -22602\n-88719 12654\n-191 -81032\n0 -26057\n-39609 0\n0 51194\n2648 88230\n90584 15544\n0 23060\n-29107 26878",
"output": "NO"
},
{
"input": "2\n-1337 1888\n100000 -100000\n99999 -100000",
"output": "YES"
},
{
"input": "2\n-100000 100000\n100000 100000\n100000 99999",
"output": "NO"
},
{
"input": "2\n-100000 100000\n100000 -100000\n99999 100000",
"output": "NO"
},
{
"input": "2\n-100000 100000\n100000 100000\n100000 99876",
"output": "NO"
},
{
"input": "2\n9 10\n4 -10\n-9 4",
"output": "NO"
},
{
"input": "3\n4 7\n7 9\n0 10\n-7 2",
"output": "NO"
},
{
"input": "4\n-4 -3\n4 -3\n10 -9\n5 -2\n0 9",
"output": "NO"
},
{
"input": "5\n8 9\n0 -3\n0 -6\n-5 0\n-7 -2\n-4 9",
"output": "NO"
},
{
"input": "6\n-7 8\n6 -1\n-10 -9\n4 8\n0 -2\n-6 -1\n3 -10",
"output": "YES"
},
{
"input": "7\n5 7\n6 4\n-9 4\n-7 5\n1 -3\n5 -2\n7 -8\n6 -8",
"output": "YES"
},
{
"input": "8\n-10 -2\n5 10\n9 7\n-8 -2\n0 6\n-9 0\n-6 2\n6 -8\n-3 2",
"output": "YES"
},
{
"input": "9\n9 10\n8 -3\n9 8\n0 5\n10 1\n0 8\n5 -5\n-4 8\n0 10\n3 -10",
"output": "NO"
},
{
"input": "10\n-1 0\n-2 4\n2 4\n-3 -7\n-2 -9\n7 6\n0 2\n1 4\n0 10\n0 -8\n-5 1",
"output": "YES"
},
{
"input": "11\n3 8\n0 -9\n-8 -10\n3 4\n3 5\n2 1\n-5 4\n0 -10\n-7 6\n5 -4\n-9 -3\n5 1",
"output": "YES"
},
{
"input": "3\n0 2\n10 0\n0 0\n8 2",
"output": "YES"
},
{
"input": "2\n0 1000000\n0 0\n1000000 1000000",
"output": "NO"
},
{
"input": "2\n515806 517307\n530512 500306\n520201 504696",
"output": "NO"
},
{
"input": "2\n0 65536\n65536 0\n0 1",
"output": "YES"
},
{
"input": "3\n1 3\n-1 5\n1 1\n0 4",
"output": "YES"
},
{
"input": "2\n0 1000000\n1000000 1\n1 2",
"output": "YES"
},
{
"input": "2\n0 3\n1 1\n2 1",
"output": "NO"
},
{
"input": "2\n0 1\n1 0\n2 0",
"output": "NO"
},
{
"input": "3\n1 3\n1 0\n-1 3\n0 10",
"output": "YES"
},
{
"input": "2\n0 1000000\n1000000 1000000\n0 3",
"output": "NO"
},
{
"input": "2\n0 1\n1 0\n-2 2",
"output": "YES"
},
{
"input": "2\n5 1000000\n1000000 5\n5 5",
"output": "NO"
},
{
"input": "4\n0 1\n0 0\n0 1\n1 0\n-1 1",
"output": "YES"
},
{
"input": "2\n0 1000000\n1000000 1000000\n1 1",
"output": "NO"
},
{
"input": "3\n0 1000000\n1000000 999999\n-1000000 1000000\n1000000 1000000",
"output": "YES"
},
{
"input": "2\n-1000000 1000000\n2 3\n1 3",
"output": "YES"
},
{
"input": "2\n0 1000000\n1000000 1\n2 2",
"output": "YES"
},
{
"input": "2\n-1 1\n1 0\n-1 0",
"output": "YES"
},
{
"input": "2\n0 1000000\n2200 1\n0 0",
"output": "NO"
},
{
"input": "2\n1 999999\n999999 0\n1 0",
"output": "NO"
},
{
"input": "2\n0 1\n1 0\n-1 1",
"output": "YES"
},
{
"input": "2\n0 1000000\n999999 999999\n0 0",
"output": "NO"
},
{
"input": "7\n0 1\n0 -1\n3 0\n5 0\n2 0\n4 0\n1 0\n0 100",
"output": "NO"
},
{
"input": "2\n0 1000000\n1000000 0\n0 100",
"output": "YES"
},
{
"input": "4\n0 1\n-1 2\n0 1\n1 0\n-1 0",
"output": "NO"
},
{
"input": "3\n0 1\n0 1\n0 10\n2 0",
"output": "YES"
},
{
"input": "4\n0 1\n3 0\n2 0\n1 0\n-1 3",
"output": "YES"
},
{
"input": "2\n0 1000000\n10000 0\n100000 1",
"output": "NO"
},
{
"input": "5\n-2 2\n2 0\n0 100000\n0 10000\n0 1000\n0 0",
"output": "YES"
},
{
"input": "2\n0 1000000\n0 0\n2200 1",
"output": "NO"
},
{
"input": "2\n0 1000000\n1 0\n1000000 1",
"output": "NO"
},
{
"input": "2\n2 5\n2 -4\n3 -6",
"output": "NO"
},
{
"input": "2\n-1 1\n0 0\n0 1",
"output": "NO"
},
{
"input": "2\n900000 1000000\n900000 1000000\n1000000 900000",
"output": "NO"
}
] | 1,446,666,791 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 811 | 25,292,800 | """
Codeforces Round #329 (Div. 2)
Problem 593 B. Anton and Lines
@author yamaton
@date 2015-11-04
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
EPSILON = 0.0000001
def solve(x1, x2, kbs):
at_x1 = [k*(x1 + EPSILON) + b for (k, b) in kbs]
at_x2 = [k*(x2 - EPSILON) + b for (k, b) in kbs]
order1 = [i for i, _ in sorted(enumerate(at_x1), key=operator.itemgetter(1))]
print_stderr('at_x1:', at_x1)
print_stderr('at_x2:', at_x2)
return any(at_x2[i] > at_x2[j] for (i, j) in zip(order1, order1[1:]))
def print_stderr(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def tf_to_yn(tf):
return 'YES' if tf else 'NO'
def main():
n = int(input())
[x1, x2] = [int(i) for i in input().strip().split()]
kbs = [tuple(int(i) for i in input().strip().split()) for _ in range(n)]
result = solve(x1, x2, kbs)
print(tf_to_yn(result))
if __name__ == '__main__':
main()
| Title: Anton and Lines
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between *x*1<=<<=*x*2. In other words, is it true that there are 1<=≤<=*i*<=<<=*j*<=≤<=*n* and *x*',<=*y*', such that:
- *y*'<==<=*k**i*<=*<=*x*'<=+<=*b**i*, that is, point (*x*',<=*y*') belongs to the line number *i*; - *y*'<==<=*k**j*<=*<=*x*'<=+<=*b**j*, that is, point (*x*',<=*y*') belongs to the line number *j*; - *x*1<=<<=*x*'<=<<=*x*2, that is, point (*x*',<=*y*') lies inside the strip bounded by *x*1<=<<=*x*2.
You can't leave Anton in trouble, can you? Write a program that solves the given task.
Input Specification:
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=<<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two lines.
The following *n* lines contain integers *k**i*, *b**i* (<=-<=1<=000<=000<=≤<=*k**i*,<=*b**i*<=≤<=1<=000<=000) — the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two *i*<=≠<=*j* it is true that either *k**i*<=≠<=*k**j*, or *b**i*<=≠<=*b**j*.
Output Specification:
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
Demo Input:
['4\n1 2\n1 2\n1 0\n0 1\n0 2\n', '2\n1 3\n1 0\n-1 3\n', '2\n1 3\n1 0\n0 2\n', '2\n1 3\n1 0\n0 3\n']
Demo Output:
['NO', 'YES', 'YES', 'NO']
Note:
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | ```python
"""
Codeforces Round #329 (Div. 2)
Problem 593 B. Anton and Lines
@author yamaton
@date 2015-11-04
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
EPSILON = 0.0000001
def solve(x1, x2, kbs):
at_x1 = [k*(x1 + EPSILON) + b for (k, b) in kbs]
at_x2 = [k*(x2 - EPSILON) + b for (k, b) in kbs]
order1 = [i for i, _ in sorted(enumerate(at_x1), key=operator.itemgetter(1))]
print_stderr('at_x1:', at_x1)
print_stderr('at_x2:', at_x2)
return any(at_x2[i] > at_x2[j] for (i, j) in zip(order1, order1[1:]))
def print_stderr(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def tf_to_yn(tf):
return 'YES' if tf else 'NO'
def main():
n = int(input())
[x1, x2] = [int(i) for i in input().strip().split()]
kbs = [tuple(int(i) for i in input().strip().split()) for _ in range(n)]
result = solve(x1, x2, kbs)
print(tf_to_yn(result))
if __name__ == '__main__':
main()
``` | 3 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,691,331,742 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | n=input()
if n=='{}':
b=0
else:
x=n.strip('{}')
y=x.split(', ')
a=set(y)
b=len(a)
print(b) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
n=input()
if n=='{}':
b=0
else:
x=n.strip('{}')
y=x.split(', ')
a=set(y)
b=len(a)
print(b)
``` | 3 |
|
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,691,815,478 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 102,400 | def tram_capacity(stops):
capacity = 0
passengers = 0
for detail in stops:
passengers -= detail[0]
passengers += detail[1]
if passengers > capacity:
capacity = passengers
return capacity
n = int(input())
stops = []
for i in range(n):
stops.append([int(item) for item in input().split()])
print(tram_capacity(stops)) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
def tram_capacity(stops):
capacity = 0
passengers = 0
for detail in stops:
passengers -= detail[0]
passengers += detail[1]
if passengers > capacity:
capacity = passengers
return capacity
n = int(input())
stops = []
for i in range(n):
stops.append([int(item) for item in input().split()])
print(tram_capacity(stops))
``` | 3 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,683,486,103 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 122 | 0 | import sys
n = int(sys.stdin.readline())
home, guest = zip(*(sys.stdin.readline().split() for _ in range(n)))
result = 0
for h in home:
result += guest.count(h)
print(result) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
import sys
n = int(sys.stdin.readline())
home, guest = zip(*(sys.stdin.readline().split() for _ in range(n)))
result = 0
for h in home:
result += guest.count(h)
print(result)
``` | 3 |
|
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,651,937,913 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 102,400 |
from sys import stdin
from math import log, floor, ceil, gcd
from collections import defaultdict as dd
#from bisect import bisect_left as bl,bisect_right as br
input = stdin.readline
def inp(): return int(stdin.readline())
def rs(): return stdin.readline().strip()
def ra(typ): return list(map(typ, stdin.readline().split()))
def rv(typ): return map(typ, stdin.readline().split())
#mod = 1000000007
def main():
x = set()
for _ in range(inp()):
a,b = rv(str)
x.add((a,b))
print(len(x))
main()
| 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
from sys import stdin
from math import log, floor, ceil, gcd
from collections import defaultdict as dd
#from bisect import bisect_left as bl,bisect_right as br
input = stdin.readline
def inp(): return int(stdin.readline())
def rs(): return stdin.readline().strip()
def ra(typ): return list(map(typ, stdin.readline().split()))
def rv(typ): return map(typ, stdin.readline().split())
#mod = 1000000007
def main():
x = set()
for _ in range(inp()):
a,b = rv(str)
x.add((a,b))
print(len(x))
main()
``` | 3.976809 |
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808",
"output": "7"
},
{
"input": "1\n487 550",
"output": "0"
},
{
"input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676",
"output": "0"
},
{
"input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136",
"output": "8"
},
{
"input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188",
"output": "9"
},
{
"input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191",
"output": "5"
},
{
"input": "4\n1 0\n2 0\n1 1\n1 -1",
"output": "0"
}
] | 1,623,759,494 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 186 | 0 | n = int(input())
l, dummy = [], []
result = 0
for i in range(n):
points = list(map(int, input().split()))
l.append(points)
for i in l:
right, left, low, up, c = 0, 0, 0, 0, 0
for j in l:
if i != j:
if j[0] > i[0] and j[1] == i[1]:
right += 1
elif j[0] < i[0] and j[1] == i[1]:
left += 1
elif j[0] == i[0] and j[1] < i[1]:
low += 1
elif j[0] == i[0] and j[1] > i[1]:
up += 1
if right > 0 and left > 0 and up > 0 and low > 0:
c += 1
dummy.append(c)
for i in dummy:
if i != 0:
result += 1
print(result) | Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input Specification:
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output Specification:
Print the only number — the number of supercentral points of the given set.
Demo Input:
['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | ```python
n = int(input())
l, dummy = [], []
result = 0
for i in range(n):
points = list(map(int, input().split()))
l.append(points)
for i in l:
right, left, low, up, c = 0, 0, 0, 0, 0
for j in l:
if i != j:
if j[0] > i[0] and j[1] == i[1]:
right += 1
elif j[0] < i[0] and j[1] == i[1]:
left += 1
elif j[0] == i[0] and j[1] < i[1]:
low += 1
elif j[0] == i[0] and j[1] > i[1]:
up += 1
if right > 0 and left > 0 and up > 0 and low > 0:
c += 1
dummy.append(c)
for i in dummy:
if i != 0:
result += 1
print(result)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,680,087,176 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | t=int(input)
for i in range(t):
s=input()
print(s[0]+str(len(s)-2)+s[len(len(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
t=int(input)
for i in range(t):
s=input()
print(s[0]+str(len(s)-2)+s[len(len(s)-1)])
``` | -1 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,690,024,176 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 122 | 0 | a = int(input())
a-=2;
if (a %2 == 0 and a>0):
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
a = int(input())
a-=2;
if (a %2 == 0 and a>0):
print("YES")
else:
print("NO")
``` | 3.939 |
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*).
Consider all the parts are numbered from 1 to *n*. | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
"output": "0"
},
{
"input": "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5",
"output": "4"
},
{
"input": "10 30\n3 6 17 15 13 15 6 12 9 1\n3 8\n1 10\n4 7\n1 7\n3 7\n2 9\n8 10\n3 1\n3 4\n8 6\n10 3\n3 9\n2 3\n10 4\n2 10\n5 8\n9 5\n6 1\n2 1\n7 2\n7 6\n7 10\n4 8\n5 6\n3 6\n4 1\n8 9\n7 9\n4 2\n5 10",
"output": "188"
},
{
"input": "3 3\n1 1 1\n1 2\n2 3\n3 1",
"output": "3"
}
] | 1,401,636,819 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 140 | 102,400 | def main():
from heapq import heapify, heappop
n, m = [int(i) for i in input().split()]
energy = [[int(v), i] for i, v in enumerate(input().split())]
s_energy = sorted(energy)
graph = [set() for i in range(n)]
for i in range(m):
x, y = [int(i) for i in input().split()]
graph[x - 1].add(y - 1)
graph[y - 1].add(x - 1)
result = 0
for i in range(n):
e, x = s_energy.pop()
for j in graph[x]:
graph[j].remove(x)
result += energy[j][0]
print(result)
main()
| Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part *i* as *v**i*. The child spend *v**f*1<=+<=*v**f*2<=+<=...<=+<=*v**f**k* energy for removing part *i* where *f*1,<=*f*2,<=...,<=*f**k* are the parts that are directly connected to the *i*-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all *n* parts.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*; *x**i*<=≠<=*y**i*).
Consider all the parts are numbered from 1 to *n*.
Output Specification:
Output the minimum total energy the child should spend to remove all *n* parts of the toy.
Demo Input:
['4 3\n10 20 30 40\n1 4\n1 2\n2 3\n', '4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n', '7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n']
Demo Output:
['40\n', '400\n', '160\n']
Note:
One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts. | ```python
def main():
from heapq import heapify, heappop
n, m = [int(i) for i in input().split()]
energy = [[int(v), i] for i, v in enumerate(input().split())]
s_energy = sorted(energy)
graph = [set() for i in range(n)]
for i in range(m):
x, y = [int(i) for i in input().split()]
graph[x - 1].add(y - 1)
graph[y - 1].add(x - 1)
result = 0
for i in range(n):
e, x = s_energy.pop()
for j in graph[x]:
graph[j].remove(x)
result += energy[j][0]
print(result)
main()
``` | 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,686,883,411 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | def solve_stick_triangle(stick_lengths):
# Sort the stick lengths in ascending order
stick_lengths.sort()
# Initialize variables to store the maximum possible area of the triangle and the current area of the triangle
max_area = 0
current_area = 0
# Try all possible combinations of three stick lengths
for i in range(len(stick_lengths) - 2):
# Calculate the current triangle height using Heron's formula
height = (stick_lengths[i] * stick_lengths[i + 1] * stick_lengths[i + 2]) ** 0.5
# Calculate the current area of the triangle using the formula for the area of a triangle
current_area = (height * (height - stick_lengths[i]) * (height - stick_lengths[i + 1]) * (height - stick_lengths[i + 2])) / 4
# Update the maximum possible area if the current area is greater than the maximum possible area
if current_area > max_area:
max_area = current_area
# Check if the maximum possible area is zero, which indicates that it is possible to construct a degenerate triangle
if max_area == 0:
return "SEGMENT"
# Check if it is possible to construct a non-degenerate triangle using all three stick lengths
if max_area > 0:
return "TRIANGLE"
# Return "IMPOSSIBLE" if it is not possible to construct any triangle
return "IMPOSSIBLE"
# Take input from the user
stick_lengths = list(map(int, input().strip().split()))
# Solve the problem and print the result
print(solve_stick_triangle(stick_lengths)) | 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
def solve_stick_triangle(stick_lengths):
# Sort the stick lengths in ascending order
stick_lengths.sort()
# Initialize variables to store the maximum possible area of the triangle and the current area of the triangle
max_area = 0
current_area = 0
# Try all possible combinations of three stick lengths
for i in range(len(stick_lengths) - 2):
# Calculate the current triangle height using Heron's formula
height = (stick_lengths[i] * stick_lengths[i + 1] * stick_lengths[i + 2]) ** 0.5
# Calculate the current area of the triangle using the formula for the area of a triangle
current_area = (height * (height - stick_lengths[i]) * (height - stick_lengths[i + 1]) * (height - stick_lengths[i + 2])) / 4
# Update the maximum possible area if the current area is greater than the maximum possible area
if current_area > max_area:
max_area = current_area
# Check if the maximum possible area is zero, which indicates that it is possible to construct a degenerate triangle
if max_area == 0:
return "SEGMENT"
# Check if it is possible to construct a non-degenerate triangle using all three stick lengths
if max_area > 0:
return "TRIANGLE"
# Return "IMPOSSIBLE" if it is not possible to construct any triangle
return "IMPOSSIBLE"
# Take input from the user
stick_lengths = list(map(int, input().strip().split()))
# Solve the problem and print the result
print(solve_stick_triangle(stick_lengths))
``` | 0 |
771 | A | Bear and Friendship Condition | PROGRAMMING | 1,500 | [
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. | The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. | If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). | [
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | 250 | [
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
"input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8",
"output": "YES"
},
{
"input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11",
"output": "NO"
},
{
"input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69",
"output": "NO"
},
{
"input": "3 1\n1 2",
"output": "YES"
},
{
"input": "3 2\n3 2\n1 3",
"output": "NO"
},
{
"input": "3 3\n2 3\n1 2\n1 3",
"output": "YES"
},
{
"input": "4 2\n4 1\n2 1",
"output": "NO"
},
{
"input": "4 3\n3 1\n2 1\n3 2",
"output": "YES"
},
{
"input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2",
"output": "NO"
},
{
"input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6",
"output": "NO"
},
{
"input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8",
"output": "NO"
},
{
"input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3",
"output": "NO"
},
{
"input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762",
"output": "YES"
},
{
"input": "150000 0",
"output": "YES"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n1 4",
"output": "NO"
},
{
"input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7",
"output": "NO"
},
{
"input": "5 4\n1 2\n2 5\n3 4\n4 5",
"output": "NO"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n1 3",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4",
"output": "NO"
},
{
"input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n3 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n2 4",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "NO"
},
{
"input": "150000 3\n150000 149999\n149998 149999\n149998 150000",
"output": "YES"
},
{
"input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10",
"output": "NO"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "NO"
},
{
"input": "5 4\n1 2\n1 3\n1 4\n1 5",
"output": "NO"
},
{
"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n4 2\n4 3",
"output": "NO"
},
{
"input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "NO"
},
{
"input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6",
"output": "NO"
},
{
"input": "1000 4\n100 132\n100 164\n196 132\n196 164",
"output": "NO"
}
] | 1,570,884,983 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 17,612,800 | n, m = map(int, input().split())
edges = [[] for x in range(n)]
checked = [False for x in range(n)]
count = 0
stack = []
shouldBe = 0
root = 0
for x in range(m):
i, j = map(int, input().split())
edges[i - 1].append(j - 1)
edges[j - 1].append(i - 1)
while count < n:
while checked[root]:
root += 1
stack.append(root)
counter = 0
while len(stack) > 0:
current = stack.pop()
if checked[current]:
continue
counter += 1
count += 1
checked[current] = True
for x in edges[current]:
stack.append(x)
#print(counter * (counter - 1) // 2)
shouldBe += counter * (counter - 1) // 2
if shouldBe == m:
print("YES")
else:
print("NO")
| Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
Input Specification:
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
Output Specification:
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
Demo Input:
['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not. | ```python
n, m = map(int, input().split())
edges = [[] for x in range(n)]
checked = [False for x in range(n)]
count = 0
stack = []
shouldBe = 0
root = 0
for x in range(m):
i, j = map(int, input().split())
edges[i - 1].append(j - 1)
edges[j - 1].append(i - 1)
while count < n:
while checked[root]:
root += 1
stack.append(root)
counter = 0
while len(stack) > 0:
current = stack.pop()
if checked[current]:
continue
counter += 1
count += 1
checked[current] = True
for x in edges[current]:
stack.append(x)
#print(counter * (counter - 1) // 2)
shouldBe += counter * (counter - 1) // 2
if shouldBe == m:
print("YES")
else:
print("NO")
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 0 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#"
},
{
"input": "1 1 0\n.",
"output": "."
},
{
"input": "2 3 1\n..#\n#..",
"output": "X.#\n#.."
},
{
"input": "2 3 1\n#..\n..#",
"output": "#.X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n..#",
"output": "...\n.#X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n#..",
"output": "...\nX#.\n#.."
},
{
"input": "5 4 4\n#..#\n....\n.##.\n....\n#..#",
"output": "#XX#\nXX..\n.##.\n....\n#..#"
},
{
"input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..",
"output": "X#..#\nX.#.#\n#....\n##.#.\n###.."
},
{
"input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#",
"output": "#.....\n#X#.#X\nX#...#\n...#.#"
},
{
"input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#",
"output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#"
},
{
"input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###",
"output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###"
},
{
"input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################",
"output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################"
},
{
"input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#",
"output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#"
},
{
"input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###",
"output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###"
},
{
"input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######",
"output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######"
},
{
"input": "3 5 1\n#...#\n..#..\n..#..",
"output": "#...#\n..#..\nX.#.."
},
{
"input": "4 5 10\n.....\n.....\n..#..\n..#..",
"output": "XXX..\nXXX..\nXX#..\nXX#.."
},
{
"input": "3 5 3\n.....\n..#..\n..#..",
"output": ".....\nX.#..\nXX#.."
},
{
"input": "3 5 1\n#....\n..#..\n..###",
"output": "#....\n..#.X\n..###"
},
{
"input": "4 5 1\n.....\n.##..\n..#..\n..###",
"output": ".....\n.##..\n..#.X\n..###"
},
{
"input": "3 5 2\n..#..\n..#..\n....#",
"output": "X.#..\nX.#..\n....#"
},
{
"input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########",
"output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########"
},
{
"input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###",
"output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###"
},
{
"input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..",
"output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.."
},
{
"input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..",
"output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.."
},
{
"input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########",
"output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########"
},
{
"input": "4 5 1\n.....\n.###.\n..#..\n..#..",
"output": ".....\n.###.\n..#..\n.X#.."
},
{
"input": "2 5 2\n###..\n###..",
"output": "###X.\n###X."
},
{
"input": "2 5 3\n.....\n..#..",
"output": "X....\nXX#.."
},
{
"input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############",
"output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n#####",
"output": ".....\n.##.X\n..###\n..###\n#####"
},
{
"input": "4 4 1\n....\n.#..\n..##\n..##",
"output": "....\n.#.X\n..##\n..##"
},
{
"input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##",
"output": "....#\n.##..\n.##.X\n...##\n...##"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n..###",
"output": ".....\n.##.X\n..###\n..###\n..###"
},
{
"input": "4 5 1\n#....\n#.#..\n..###\n..###",
"output": "#....\n#.#.X\n..###\n..###"
},
{
"input": "4 4 3\n....\n.#..\n..##\n..##",
"output": "...X\n.#XX\n..##\n..##"
},
{
"input": "4 7 6\n.......\n....#..\n.##.#..\n....#..",
"output": "X......\nX...#..\nX##.#..\nXXX.#.."
},
{
"input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######",
"output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######"
}
] | 1,698,162,794 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 6 | 124 | 17,612,800 | from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
d4 = ((0, 1), (-1, 0), (0, -1), (1, 0))
def solution():
def dfs(i: int, j: int):
for di, dj in d4:
ni, nj = i + di, j + dj
if 0 <= ni < n and 0 <= nj < m and (ni, nj) not in seen and a[ni][nj] == '.':
seen.add((ni, nj))
dfs(ni, nj)
if remaining[0]:
a[ni][nj] = 'X'
remaining[0] -= 1
n, m, k = [int(num) for num in input().split()]
a = []
for i in range(n):
a.append(list(input()))
for i in range(n):
for j in range(m):
if a[i][j] == '.':
x, y = i, j
seen = {(x, y)}
remaining = [k]
dfs(x, y)
for row in a:
print(''.join(row))
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Output Specification:
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
Demo Input:
['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n']
Demo Output:
['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n']
Note:
none | ```python
from os import path
from sys import stdin, stdout
filename = "../templates/input.txt"
if path.exists(filename):
stdin = open(filename, 'r')
def input():
return stdin.readline().rstrip()
def print(*args, sep=' ', end='\n'):
stdout.write(sep.join(map(str, args)))
stdout.write(end)
d4 = ((0, 1), (-1, 0), (0, -1), (1, 0))
def solution():
def dfs(i: int, j: int):
for di, dj in d4:
ni, nj = i + di, j + dj
if 0 <= ni < n and 0 <= nj < m and (ni, nj) not in seen and a[ni][nj] == '.':
seen.add((ni, nj))
dfs(ni, nj)
if remaining[0]:
a[ni][nj] = 'X'
remaining[0] -= 1
n, m, k = [int(num) for num in input().split()]
a = []
for i in range(n):
a.append(list(input()))
for i in range(n):
for j in range(m):
if a[i][j] == '.':
x, y = i, j
seen = {(x, y)}
remaining = [k]
dfs(x, y)
for row in a:
print(''.join(row))
def main():
t = 1
while t:
solution()
t -= 1
if __name__ == '__main__':
main()
``` | -1 |
|
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307",
"output": "22258199.5000000000"
},
{
"input": "2 1000000000\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "2 555\n200 300",
"output": "255.0000000000"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n0",
"output": "1.0000000000"
},
{
"input": "1 1000000000\n0",
"output": "1000000000.0000000000"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000.0000000000"
},
{
"input": "1 999999999\n499999999",
"output": "500000000.0000000000"
},
{
"input": "4 700\n0 250 475 700",
"output": "125.0000000000"
},
{
"input": "4 700\n0 225 450 700",
"output": "125.0000000000"
},
{
"input": "5 1000\n0 250 500 750 1000",
"output": "125.0000000000"
},
{
"input": "5 2000\n1001 1001 1001 1001 1001",
"output": "1001.0000000000"
},
{
"input": "1 999\n501",
"output": "501.0000000000"
},
{
"input": "2 1000\n400 600",
"output": "400.0000000000"
},
{
"input": "4 15\n1 3 9 11",
"output": "4.0000000000"
},
{
"input": "1 5\n2",
"output": "3.0000000000"
}
] | 1,688,023,818 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
lanterns.sort() # Sort the lantern positions
max_distance = max(lanterns[0], l - lanterns[-1]) # Consider the endpoints of the street
for i in range(1, n):
distance = lanterns[i] - lanterns[i-1]
max_distance = max(max_distance, distance)
minimum_radius = max_distance / 2 # Calculate the minimum light radius
print("{:.10f}".format(minimum_radius))
| Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
Input Specification:
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Output Specification:
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
Demo Input:
['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n']
Demo Output:
['2.5000000000\n', '2.0000000000\n']
Note:
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | ```python
n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
lanterns.sort() # Sort the lantern positions
max_distance = max(lanterns[0], l - lanterns[-1]) # Consider the endpoints of the street
for i in range(1, n):
distance = lanterns[i] - lanterns[i-1]
max_distance = max(max_distance, distance)
minimum_radius = max_distance / 2 # Calculate the minimum light radius
print("{:.10f}".format(minimum_radius))
``` | 0 |
|
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2",
"output": "1"
},
{
"input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n5000",
"output": "1"
},
{
"input": "4\n5000 5000 5000 5000",
"output": "4"
},
{
"input": "5\n3366 3461 4 5 4370",
"output": "3"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "0"
},
{
"input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9",
"output": "7"
},
{
"input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974",
"output": "10"
},
{
"input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5",
"output": "0"
},
{
"input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142",
"output": "15"
},
{
"input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27",
"output": "14"
},
{
"input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64",
"output": "18"
},
{
"input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604",
"output": "70"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "2\n5000 5000",
"output": "2"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3 4",
"output": "2"
},
{
"input": "10\n1 2 3 4 5 6 7 1000 10 10",
"output": "2"
}
] | 1,617,385,952 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 3,584,000 | import unittest
from unittest.mock import patch
from cdf_137B import CodeforcesTask137BSolution
class TestCDF137B(unittest.TestCase):
def test_137B_acceptance_1(self):
mock_input = ['3', '3 1 2']
expected = '0'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
def test_137B_acceptance_2(self):
mock_input = ['2', '2 2']
expected = '1'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
def test_137B_acceptance_3(self):
mock_input = ['5', '5 3 3 3 1']
expected = '2'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
if __name__ == "__main__":
unittest.main() | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Output Specification:
Print the only number — the minimum number of changes needed to get the permutation.
Demo Input:
['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n']
Demo Output:
['0\n', '1\n', '2\n']
Note:
The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | ```python
import unittest
from unittest.mock import patch
from cdf_137B import CodeforcesTask137BSolution
class TestCDF137B(unittest.TestCase):
def test_137B_acceptance_1(self):
mock_input = ['3', '3 1 2']
expected = '0'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
def test_137B_acceptance_2(self):
mock_input = ['2', '2 2']
expected = '1'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
def test_137B_acceptance_3(self):
mock_input = ['5', '5 3 3 3 1']
expected = '2'
with patch('builtins.input', side_effect=mock_input):
Solution = CodeforcesTask137BSolution()
Solution.read_input()
Solution.process_task()
actual = Solution.get_result()
self.assertEqual(expected, actual)
if __name__ == "__main__":
unittest.main()
``` | -1 |
|
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,679,480,061 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, a , b , c = map(int, input().split())
ar = []
ar.append(a)
ar.append(b)
ar.append(c)
ar.sort()
c = 0
while(n//ar[0]):
n //= ar[0]
c += 1
print(n, c)
print(c) | 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
n, a , b , c = map(int, input().split())
ar = []
ar.append(a)
ar.append(b)
ar.append(c)
ar.sort()
c = 0
while(n//ar[0]):
n //= ar[0]
c += 1
print(n, c)
print(c)
``` | 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,676,639,726 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 154 | 1,331,200 | def solve():
a = []
b = []
for _ in range(int(input())):
n, t = map(int, input().split())
a.append(n)
b.append(n+t)
c = 0
for i in range(len(a)):
for j in range(len(b)):
if a[i]==b[j] and b[i]==a[j] and i!=j:
c = 1
break
if c==1:
print("YES")
else:
print("NO")
if __name__ == "__main__":
solve() | 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
def solve():
a = []
b = []
for _ in range(int(input())):
n, t = map(int, input().split())
a.append(n)
b.append(n+t)
c = 0
for i in range(len(a)):
for j in range(len(b)):
if a[i]==b[j] and b[i]==a[j] and i!=j:
c = 1
break
if c==1:
print("YES")
else:
print("NO")
if __name__ == "__main__":
solve()
``` | 3.95902 |
952 | D | I'm Feeling Lucky! | PROGRAMMING | 1,800 | [
"probabilities"
] | null | null | You have one chip and one chance to play roulette. Are you feeling lucky? | none | Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | [] | [] | none | 0 | [
{
"input": "1",
"output": "Red"
},
{
"input": "2",
"output": "Red"
}
] | 1,647,688,060 | 6,160 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("Even")
| Title: I'm Feeling Lucky!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have one chip and one chance to play roulette. Are you feeling lucky?
Input Specification:
none
Output Specification:
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares).
Note:
none | ```python
print("Even")
``` | 0 |
|
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1\n2 3",
"output": "YES"
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884",
"output": "YES"
},
{
"input": "5\n1 2 3 4 10 10 6 7 8 9",
"output": "YES"
},
{
"input": "2\n1 1 1 2",
"output": "NO"
},
{
"input": "2\n10 4 4 4",
"output": "NO"
},
{
"input": "2\n2 3 3 3",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 4 6 7",
"output": "NO"
},
{
"input": "4\n2 5 4 5 8 3 1 5",
"output": "YES"
},
{
"input": "4\n8 2 2 4 1 4 10 9",
"output": "NO"
},
{
"input": "2\n3 8 10 2",
"output": "YES"
},
{
"input": "3\n1 3 4 4 5 6",
"output": "NO"
},
{
"input": "2\n3 3 3 4",
"output": "NO"
},
{
"input": "2\n1 1 2 2",
"output": "YES"
},
{
"input": "2\n1 1 3 3",
"output": "YES"
},
{
"input": "2\n1 2 3 2",
"output": "NO"
},
{
"input": "10\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 5",
"output": "NO"
},
{
"input": "2\n2 2 1 1",
"output": "YES"
},
{
"input": "7\n1 2 3 4 5 6 7 7 8 9 10 11 12 19",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5 3 3 5 6 7",
"output": "YES"
},
{
"input": "4\n1 1 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "51\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224",
"output": "YES"
},
{
"input": "3\n3 3 3 2 3 2",
"output": "NO"
},
{
"input": "2\n5 3 3 6",
"output": "YES"
},
{
"input": "2\n1 2 2 3",
"output": "NO"
},
{
"input": "2\n1 3 2 2",
"output": "NO"
},
{
"input": "2\n1 3 3 4",
"output": "NO"
},
{
"input": "2\n1 2 2 2",
"output": "NO"
},
{
"input": "3\n1 2 7 19 19 7",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 6",
"output": "NO"
},
{
"input": "2\n1 2 2 4",
"output": "NO"
},
{
"input": "2\n6 6 5 5",
"output": "YES"
},
{
"input": "2\n3 1 3 1",
"output": "YES"
},
{
"input": "3\n1 2 3 3 1 1",
"output": "YES"
},
{
"input": "3\n3 2 1 3 4 5",
"output": "NO"
},
{
"input": "3\n4 5 6 4 2 1",
"output": "NO"
},
{
"input": "3\n1 1 2 3 2 4",
"output": "NO"
},
{
"input": "3\n100 99 1 1 1 1",
"output": "NO"
},
{
"input": "3\n1 2 3 6 5 3",
"output": "NO"
},
{
"input": "2\n2 2 1 2",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 6 7 4",
"output": "NO"
},
{
"input": "3\n1 2 3 1 1 1",
"output": "NO"
},
{
"input": "3\n6 5 3 3 1 3",
"output": "NO"
},
{
"input": "2\n1 2 1 2",
"output": "YES"
},
{
"input": "3\n1 2 5 6 8 6",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5 3 3 3 3 3",
"output": "NO"
},
{
"input": "2\n1 2 4 2",
"output": "NO"
},
{
"input": "3\n7 7 4 5 319 19",
"output": "NO"
},
{
"input": "3\n1 2 4 4 3 5",
"output": "YES"
},
{
"input": "3\n3 2 3 4 5 2",
"output": "NO"
},
{
"input": "5\n1 2 3 4 4 5 3 6 7 8",
"output": "NO"
},
{
"input": "3\n3 3 4 4 5 1",
"output": "YES"
},
{
"input": "2\n3 4 3 3",
"output": "NO"
},
{
"input": "2\n2 5 4 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 4 5 6 7 8 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 5",
"output": "NO"
},
{
"input": "2\n3 4 4 4",
"output": "NO"
},
{
"input": "2\n1 4 5 4",
"output": "NO"
},
{
"input": "2\n1 2 3 3",
"output": "YES"
},
{
"input": "2\n1 1 2 1",
"output": "NO"
},
{
"input": "4\n1 1 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "4\n1 2 3 5 6 7 8 5",
"output": "NO"
},
{
"input": "2\n4 3 3 1",
"output": "NO"
},
{
"input": "3\n3 1 2 4 3 5",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 6",
"output": "NO"
},
{
"input": "4\n2 2 2 4 5 5 5 5",
"output": "YES"
},
{
"input": "2\n1 3 4 3",
"output": "NO"
},
{
"input": "2\n3 3 2 3",
"output": "NO"
},
{
"input": "2\n1 2 1 1",
"output": "NO"
},
{
"input": "3\n1 3 4 4 2 5",
"output": "YES"
},
{
"input": "4\n4 7 1 2 3 5 6 4",
"output": "NO"
},
{
"input": "2\n3 2 2 2",
"output": "NO"
},
{
"input": "1\n2 1",
"output": "YES"
},
{
"input": "2\n3 3 1 2",
"output": "YES"
},
{
"input": "1\n8 6",
"output": "YES"
},
{
"input": "7\n6 7 6 7 3 1 9 4 6 10 8 2 5 7",
"output": "NO"
},
{
"input": "2\n3 9 2 1",
"output": "YES"
},
{
"input": "2\n3 3 3 3",
"output": "NO"
}
] | 1,503,363,510 | 1,110 | PyPy 3 | OK | TESTS | 88 | 124 | 307,200 | n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
i,j = 0,2*n-1
while(i < j):
if a[j] <= a[i]:
break
i += 1
j -= 1
if i > j:
print('YES')
else:
print('NO')
| Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000).
Output Specification:
If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
Demo Input:
['2\n1 3 2 4\n', '1\n3 3\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
i,j = 0,2*n-1
while(i < j):
if a[j] <= a[i]:
break
i += 1
j -= 1
if i > j:
print('YES')
else:
print('NO')
``` | 3 |
|
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,686,941,623 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a,b=map(int,input().split())
z=a*b
if a % 2 == 1 and b % 2 == 1:
z=z-1
print(z/2)
else:
print(z/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
a,b=map(int,input().split())
z=a*b
if a % 2 == 1 and b % 2 == 1:
z=z-1
print(z/2)
else:
print(z/2)
``` | 0 |
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10. | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n??????????",
"output": "0.205078125000"
},
{
"input": "+--+++--+-\n??????????",
"output": "0.246093750000"
},
{
"input": "+\n+",
"output": "1.000000000000"
},
{
"input": "-\n?",
"output": "0.500000000000"
},
{
"input": "+\n-",
"output": "0.000000000000"
},
{
"input": "-\n-",
"output": "1.000000000000"
},
{
"input": "-\n+",
"output": "0.000000000000"
},
{
"input": "+\n?",
"output": "0.500000000000"
},
{
"input": "++++++++++\n++++++++++",
"output": "1.000000000000"
},
{
"input": "++++++++++\n++++-+++++",
"output": "0.000000000000"
},
{
"input": "----------\n++++++++++",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++??++++",
"output": "0.250000000000"
},
{
"input": "----------\n+++?++++-+",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++++++?+",
"output": "0.500000000000"
},
{
"input": "--++++--+\n?-+?-??+-",
"output": "0.250000000000"
},
{
"input": "----------\n??????????",
"output": "0.000976562500"
},
{
"input": "+--++\n+--+-",
"output": "0.000000000000"
},
{
"input": "-----++---\n????????+?",
"output": "0.017578125000"
},
{
"input": "------+--+\n??????????",
"output": "0.043945312500"
},
{
"input": "---++--\n???????",
"output": "0.164062500000"
},
{
"input": "-----++\n???????",
"output": "0.164062500000"
},
{
"input": "+---+--\n???????",
"output": "0.164062500000"
},
{
"input": "---+-+\n??????",
"output": "0.234375000000"
},
{
"input": "+++-+\n---++",
"output": "0.000000000000"
},
{
"input": "++-+--+\n?-?+??+",
"output": "0.375000000000"
},
{
"input": "----+++--\n-+?+++?--",
"output": "0.000000000000"
},
{
"input": "+-----\n+?----",
"output": "0.500000000000"
}
] | 1,689,318,100 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 77 | 0 | import math
ori = input()
rec = input()
ori_p = 0
ori_m = 0
q=0
for i in range(len(ori)):
if ori[i]=='+' : ori_p +=1
else : ori_m+=1
if rec[i]=='+' : ori_p -=1
elif rec[i]=='-': ori_m-=1
else : q+=1
if ori_p<0 or ori_m<0:
print(0)
elif ori_p>0:
print(math.comb(q,ori_p)/(2**q))
elif ori_m>0:
print(math.comb(q,ori_m)/(2**q))
else:
print(1) | Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
Input Specification:
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output Specification:
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
Demo Input:
['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n']
Demo Output:
['1.000000000000\n', '0.500000000000\n', '0.000000000000\n']
Note:
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | ```python
import math
ori = input()
rec = input()
ori_p = 0
ori_m = 0
q=0
for i in range(len(ori)):
if ori[i]=='+' : ori_p +=1
else : ori_m+=1
if rec[i]=='+' : ori_p -=1
elif rec[i]=='-': ori_m-=1
else : q+=1
if ori_p<0 or ori_m<0:
print(0)
elif ori_p>0:
print(math.comb(q,ori_p)/(2**q))
elif ori_m>0:
print(math.comb(q,ori_m)/(2**q))
else:
print(1)
``` | 3 |
|
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
"output": "804610"
},
{
"input": "5\n984065 842724 127449 525625 573049",
"output": "984065"
},
{
"input": "2\n226505 477482",
"output": "477482"
},
{
"input": "2\n370881 659345",
"output": "659345"
},
{
"input": "2\n4 5",
"output": "5"
},
{
"input": "2\n3 4",
"output": "3"
},
{
"input": "2\n999999 1000000",
"output": "999999"
},
{
"input": "3\n-1 -2 -3",
"output": "-1"
},
{
"input": "2\n-1000000 1000000",
"output": "-1000000"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462",
"output": "-15745"
},
{
"input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322",
"output": "-257875"
},
{
"input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209",
"output": "-766506"
},
{
"input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259",
"output": "748303"
},
{
"input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001",
"output": "963781"
},
{
"input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304",
"output": "940901"
},
{
"input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904",
"output": "987533"
},
{
"input": "3\n-1 1 0",
"output": "-1"
},
{
"input": "2\n0 -5",
"output": "-5"
},
{
"input": "3\n-1 -2 0",
"output": "-1"
},
{
"input": "2\n-5 0",
"output": "-5"
},
{
"input": "1\n-439",
"output": "-439"
},
{
"input": "1\n-1000000",
"output": "-1000000"
},
{
"input": "1\n-917455",
"output": "-917455"
},
{
"input": "3\n1 1 -1",
"output": "-1"
},
{
"input": "2\n131073 1",
"output": "131073"
},
{
"input": "2\n99999 3",
"output": "99999"
},
{
"input": "2\n-524272 -1000000",
"output": "-524272"
},
{
"input": "2\n15 131073",
"output": "131073"
}
] | 1,629,363,614 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 109 | 22,220,800 | import math
def isPerfect(element : int):
a = int(math.sqrt(element))
if a * a == element:
return True
return False
n = int(input())
elements = [int(x) for x in input().split()]
biggest = 0
for element in elements:
if((not isPerfect(element)) and element > biggest):
biggest = element
print(biggest) | Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square.
Output Specification:
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
Demo Input:
['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n']
Demo Output:
['2\n', '32\n']
Note:
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | ```python
import math
def isPerfect(element : int):
a = int(math.sqrt(element))
if a * a == element:
return True
return False
n = int(input())
elements = [int(x) for x in input().split()]
biggest = 0
for element in elements:
if((not isPerfect(element)) and element > biggest):
biggest = element
print(biggest)
``` | -1 |
|
242 | A | Heads or Tails | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.
At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least *a* times, and Petya got heads at least *b* times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories. | The single line contains four integers *x*,<=*y*,<=*a*,<=*b* (1<=≤<=*a*<=≤<=*x*<=≤<=100,<=1<=≤<=*b*<=≤<=*y*<=≤<=100). The numbers on the line are separated by a space. | In the first line print integer *n* — the number of possible outcomes of the game. Then on *n* lines print the outcomes. On the *i*-th line print a space-separated pair of integers *c**i*, *d**i* — the number of heads Vasya and Petya got in the *i*-th outcome of the game, correspondingly. Print pairs of integers (*c**i*,<=*d**i*) in the strictly increasing order.
Let us remind you that the pair of numbers (*p*1,<=*q*1) is less than the pair of numbers (*p*2,<=*q*2), if *p*1<=<<=*p*2, or *p*1<==<=*p*2 and also *q*1<=<<=*q*2. | [
"3 2 1 1\n",
"2 4 2 2\n"
] | [
"3\n2 1\n3 1\n3 2\n",
"0\n"
] | none | 500 | [
{
"input": "3 2 1 1",
"output": "3\n2 1\n3 1\n3 2"
},
{
"input": "2 4 2 2",
"output": "0"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "4 5 2 3",
"output": "1\n4 3"
},
{
"input": "10 6 3 4",
"output": "15\n5 4\n6 4\n6 5\n7 4\n7 5\n7 6\n8 4\n8 5\n8 6\n9 4\n9 5\n9 6\n10 4\n10 5\n10 6"
},
{
"input": "10 10 1 1",
"output": "45\n2 1\n3 1\n3 2\n4 1\n4 2\n4 3\n5 1\n5 2\n5 3\n5 4\n6 1\n6 2\n6 3\n6 4\n6 5\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9"
},
{
"input": "9 7 4 7",
"output": "2\n8 7\n9 7"
},
{
"input": "5 5 3 2",
"output": "6\n3 2\n4 2\n4 3\n5 2\n5 3\n5 4"
},
{
"input": "10 10 1 1",
"output": "45\n2 1\n3 1\n3 2\n4 1\n4 2\n4 3\n5 1\n5 2\n5 3\n5 4\n6 1\n6 2\n6 3\n6 4\n6 5\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9"
},
{
"input": "20 10 1 8",
"output": "33\n9 8\n10 8\n10 9\n11 8\n11 9\n11 10\n12 8\n12 9\n12 10\n13 8\n13 9\n13 10\n14 8\n14 9\n14 10\n15 8\n15 9\n15 10\n16 8\n16 9\n16 10\n17 8\n17 9\n17 10\n18 8\n18 9\n18 10\n19 8\n19 9\n19 10\n20 8\n20 9\n20 10"
},
{
"input": "10 20 4 6",
"output": "10\n7 6\n8 6\n8 7\n9 6\n9 7\n9 8\n10 6\n10 7\n10 8\n10 9"
},
{
"input": "50 50 1 30",
"output": "210\n31 30\n32 30\n32 31\n33 30\n33 31\n33 32\n34 30\n34 31\n34 32\n34 33\n35 30\n35 31\n35 32\n35 33\n35 34\n36 30\n36 31\n36 32\n36 33\n36 34\n36 35\n37 30\n37 31\n37 32\n37 33\n37 34\n37 35\n37 36\n38 30\n38 31\n38 32\n38 33\n38 34\n38 35\n38 36\n38 37\n39 30\n39 31\n39 32\n39 33\n39 34\n39 35\n39 36\n39 37\n39 38\n40 30\n40 31\n40 32\n40 33\n40 34\n40 35\n40 36\n40 37\n40 38\n40 39\n41 30\n41 31\n41 32\n41 33\n41 34\n41 35\n41 36\n41 37\n41 38\n41 39\n41 40\n42 30\n42 31\n42 32\n42 33\n42 34\n42 35\n42..."
},
{
"input": "60 50 30 40",
"output": "165\n41 40\n42 40\n42 41\n43 40\n43 41\n43 42\n44 40\n44 41\n44 42\n44 43\n45 40\n45 41\n45 42\n45 43\n45 44\n46 40\n46 41\n46 42\n46 43\n46 44\n46 45\n47 40\n47 41\n47 42\n47 43\n47 44\n47 45\n47 46\n48 40\n48 41\n48 42\n48 43\n48 44\n48 45\n48 46\n48 47\n49 40\n49 41\n49 42\n49 43\n49 44\n49 45\n49 46\n49 47\n49 48\n50 40\n50 41\n50 42\n50 43\n50 44\n50 45\n50 46\n50 47\n50 48\n50 49\n51 40\n51 41\n51 42\n51 43\n51 44\n51 45\n51 46\n51 47\n51 48\n51 49\n51 50\n52 40\n52 41\n52 42\n52 43\n52 44\n52 45\n52..."
},
{
"input": "100 100 1 1",
"output": "4950\n2 1\n3 1\n3 2\n4 1\n4 2\n4 3\n5 1\n5 2\n5 3\n5 4\n6 1\n6 2\n6 3\n6 4\n6 5\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9\n11 1\n11 2\n11 3\n11 4\n11 5\n11 6\n11 7\n11 8\n11 9\n11 10\n12 1\n12 2\n12 3\n12 4\n12 5\n12 6\n12 7\n12 8\n12 9\n12 10\n12 11\n13 1\n13 2\n13 3\n13 4\n13 5\n13 6\n13 7\n13 8\n13 9\n13 10\n13 11\n13 12\n14 1\n14 2\n14 3\n14 4\n14 5\n14 6\n14 7\n14 8\n14 9\n14 10\n14 11\n..."
},
{
"input": "100 99 10 13",
"output": "3828\n14 13\n15 13\n15 14\n16 13\n16 14\n16 15\n17 13\n17 14\n17 15\n17 16\n18 13\n18 14\n18 15\n18 16\n18 17\n19 13\n19 14\n19 15\n19 16\n19 17\n19 18\n20 13\n20 14\n20 15\n20 16\n20 17\n20 18\n20 19\n21 13\n21 14\n21 15\n21 16\n21 17\n21 18\n21 19\n21 20\n22 13\n22 14\n22 15\n22 16\n22 17\n22 18\n22 19\n22 20\n22 21\n23 13\n23 14\n23 15\n23 16\n23 17\n23 18\n23 19\n23 20\n23 21\n23 22\n24 13\n24 14\n24 15\n24 16\n24 17\n24 18\n24 19\n24 20\n24 21\n24 22\n24 23\n25 13\n25 14\n25 15\n25 16\n25 17\n25 18\n2..."
},
{
"input": "99 100 20 7",
"output": "4200\n20 7\n20 8\n20 9\n20 10\n20 11\n20 12\n20 13\n20 14\n20 15\n20 16\n20 17\n20 18\n20 19\n21 7\n21 8\n21 9\n21 10\n21 11\n21 12\n21 13\n21 14\n21 15\n21 16\n21 17\n21 18\n21 19\n21 20\n22 7\n22 8\n22 9\n22 10\n22 11\n22 12\n22 13\n22 14\n22 15\n22 16\n22 17\n22 18\n22 19\n22 20\n22 21\n23 7\n23 8\n23 9\n23 10\n23 11\n23 12\n23 13\n23 14\n23 15\n23 16\n23 17\n23 18\n23 19\n23 20\n23 21\n23 22\n24 7\n24 8\n24 9\n24 10\n24 11\n24 12\n24 13\n24 14\n24 15\n24 16\n24 17\n24 18\n24 19\n24 20\n24 21\n24 22\n24..."
},
{
"input": "100 90 100 83",
"output": "8\n100 83\n100 84\n100 85\n100 86\n100 87\n100 88\n100 89\n100 90"
},
{
"input": "80 100 1 50",
"output": "465\n51 50\n52 50\n52 51\n53 50\n53 51\n53 52\n54 50\n54 51\n54 52\n54 53\n55 50\n55 51\n55 52\n55 53\n55 54\n56 50\n56 51\n56 52\n56 53\n56 54\n56 55\n57 50\n57 51\n57 52\n57 53\n57 54\n57 55\n57 56\n58 50\n58 51\n58 52\n58 53\n58 54\n58 55\n58 56\n58 57\n59 50\n59 51\n59 52\n59 53\n59 54\n59 55\n59 56\n59 57\n59 58\n60 50\n60 51\n60 52\n60 53\n60 54\n60 55\n60 56\n60 57\n60 58\n60 59\n61 50\n61 51\n61 52\n61 53\n61 54\n61 55\n61 56\n61 57\n61 58\n61 59\n61 60\n62 50\n62 51\n62 52\n62 53\n62 54\n62 55\n62..."
},
{
"input": "100 39 70 5",
"output": "1085\n70 5\n70 6\n70 7\n70 8\n70 9\n70 10\n70 11\n70 12\n70 13\n70 14\n70 15\n70 16\n70 17\n70 18\n70 19\n70 20\n70 21\n70 22\n70 23\n70 24\n70 25\n70 26\n70 27\n70 28\n70 29\n70 30\n70 31\n70 32\n70 33\n70 34\n70 35\n70 36\n70 37\n70 38\n70 39\n71 5\n71 6\n71 7\n71 8\n71 9\n71 10\n71 11\n71 12\n71 13\n71 14\n71 15\n71 16\n71 17\n71 18\n71 19\n71 20\n71 21\n71 22\n71 23\n71 24\n71 25\n71 26\n71 27\n71 28\n71 29\n71 30\n71 31\n71 32\n71 33\n71 34\n71 35\n71 36\n71 37\n71 38\n71 39\n72 5\n72 6\n72 7\n72 8\n7..."
},
{
"input": "70 80 30 80",
"output": "0"
},
{
"input": "100 100 1 1",
"output": "4950\n2 1\n3 1\n3 2\n4 1\n4 2\n4 3\n5 1\n5 2\n5 3\n5 4\n6 1\n6 2\n6 3\n6 4\n6 5\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9\n11 1\n11 2\n11 3\n11 4\n11 5\n11 6\n11 7\n11 8\n11 9\n11 10\n12 1\n12 2\n12 3\n12 4\n12 5\n12 6\n12 7\n12 8\n12 9\n12 10\n12 11\n13 1\n13 2\n13 3\n13 4\n13 5\n13 6\n13 7\n13 8\n13 9\n13 10\n13 11\n13 12\n14 1\n14 2\n14 3\n14 4\n14 5\n14 6\n14 7\n14 8\n14 9\n14 10\n14 11\n..."
},
{
"input": "100 100 100 5",
"output": "95\n100 5\n100 6\n100 7\n100 8\n100 9\n100 10\n100 11\n100 12\n100 13\n100 14\n100 15\n100 16\n100 17\n100 18\n100 19\n100 20\n100 21\n100 22\n100 23\n100 24\n100 25\n100 26\n100 27\n100 28\n100 29\n100 30\n100 31\n100 32\n100 33\n100 34\n100 35\n100 36\n100 37\n100 38\n100 39\n100 40\n100 41\n100 42\n100 43\n100 44\n100 45\n100 46\n100 47\n100 48\n100 49\n100 50\n100 51\n100 52\n100 53\n100 54\n100 55\n100 56\n100 57\n100 58\n100 59\n100 60\n100 61\n100 62\n100 63\n100 64\n100 65\n100 66\n100 67\n100 68\n..."
},
{
"input": "99 99 1 1",
"output": "4851\n2 1\n3 1\n3 2\n4 1\n4 2\n4 3\n5 1\n5 2\n5 3\n5 4\n6 1\n6 2\n6 3\n6 4\n6 5\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n8 1\n8 2\n8 3\n8 4\n8 5\n8 6\n8 7\n9 1\n9 2\n9 3\n9 4\n9 5\n9 6\n9 7\n9 8\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9\n11 1\n11 2\n11 3\n11 4\n11 5\n11 6\n11 7\n11 8\n11 9\n11 10\n12 1\n12 2\n12 3\n12 4\n12 5\n12 6\n12 7\n12 8\n12 9\n12 10\n12 11\n13 1\n13 2\n13 3\n13 4\n13 5\n13 6\n13 7\n13 8\n13 9\n13 10\n13 11\n13 12\n14 1\n14 2\n14 3\n14 4\n14 5\n14 6\n14 7\n14 8\n14 9\n14 10\n14 11\n..."
}
] | 1,645,690,425 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x , y , a , b = map(int,input().split())
c = []
for i in range(a,x+1):
for j in range(b,y+1):
if i > j :
c.append([i,j])
if len(c) == 0:
print(0)
else:
for i in range(len(c)):
print(*c[i]) | Title: Heads or Tails
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.
At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least *a* times, and Petya got heads at least *b* times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories.
Input Specification:
The single line contains four integers *x*,<=*y*,<=*a*,<=*b* (1<=≤<=*a*<=≤<=*x*<=≤<=100,<=1<=≤<=*b*<=≤<=*y*<=≤<=100). The numbers on the line are separated by a space.
Output Specification:
In the first line print integer *n* — the number of possible outcomes of the game. Then on *n* lines print the outcomes. On the *i*-th line print a space-separated pair of integers *c**i*, *d**i* — the number of heads Vasya and Petya got in the *i*-th outcome of the game, correspondingly. Print pairs of integers (*c**i*,<=*d**i*) in the strictly increasing order.
Let us remind you that the pair of numbers (*p*1,<=*q*1) is less than the pair of numbers (*p*2,<=*q*2), if *p*1<=<<=*p*2, or *p*1<==<=*p*2 and also *q*1<=<<=*q*2.
Demo Input:
['3 2 1 1\n', '2 4 2 2\n']
Demo Output:
['3\n2 1\n3 1\n3 2\n', '0\n']
Note:
none | ```python
x , y , a , b = map(int,input().split())
c = []
for i in range(a,x+1):
for j in range(b,y+1):
if i > j :
c.append([i,j])
if len(c) == 0:
print(0)
else:
for i in range(len(c)):
print(*c[i])
``` | 0 |
|
12 | B | Correct Solution? | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | B. Correct Solution? | 2 | 256 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict. | The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. | Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. | [
"3310\n1033\n",
"4\n5\n"
] | [
"OK\n",
"WRONG_ANSWER\n"
] | none | 0 | [
{
"input": "3310\n1033",
"output": "OK"
},
{
"input": "4\n5",
"output": "WRONG_ANSWER"
},
{
"input": "40\n04",
"output": "WRONG_ANSWER"
},
{
"input": "12\n12",
"output": "OK"
},
{
"input": "432\n234",
"output": "OK"
},
{
"input": "17109\n01179",
"output": "WRONG_ANSWER"
},
{
"input": "888\n888",
"output": "OK"
},
{
"input": "912\n9123",
"output": "WRONG_ANSWER"
},
{
"input": "0\n00",
"output": "WRONG_ANSWER"
},
{
"input": "11110\n1111",
"output": "WRONG_ANSWER"
},
{
"input": "7391\n1397",
"output": "WRONG_ANSWER"
},
{
"input": "201\n102",
"output": "OK"
},
{
"input": "111111111\n111111111",
"output": "OK"
},
{
"input": "32352320\n22203335",
"output": "WRONG_ANSWER"
},
{
"input": "1000000000\n1",
"output": "WRONG_ANSWER"
},
{
"input": "994321\n123499",
"output": "OK"
},
{
"input": "10101\n10101",
"output": "WRONG_ANSWER"
},
{
"input": "666\n0666",
"output": "WRONG_ANSWER"
},
{
"input": "2\n02",
"output": "WRONG_ANSWER"
},
{
"input": "313\n133",
"output": "OK"
},
{
"input": "987235645\n234556789",
"output": "OK"
},
{
"input": "90812\n010289",
"output": "WRONG_ANSWER"
},
{
"input": "123\n321",
"output": "WRONG_ANSWER"
},
{
"input": "707\n770",
"output": "WRONG_ANSWER"
},
{
"input": "77774444\n47474747",
"output": "WRONG_ANSWER"
},
{
"input": "1270\n1027",
"output": "OK"
},
{
"input": "320\n23",
"output": "WRONG_ANSWER"
},
{
"input": "123456789\n123456789",
"output": "OK"
},
{
"input": "918273645\n546372819",
"output": "WRONG_ANSWER"
},
{
"input": "300000003\n30000003",
"output": "WRONG_ANSWER"
},
{
"input": "0\n0",
"output": "OK"
},
{
"input": "0\n7",
"output": "WRONG_ANSWER"
}
] | 1,684,157,025 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 122 | 0 | num = list(input())
ans = int(input())
num.sort()
i = 0
for i in range(len(num)):
if num[i] != "0":
break
if i == 0:
n = int("".join(num))
else:
n = int("".join([num[i]] + num[:i] + num[i+1:]))
if n == ans:
print("OK")
else:
print("WRONG_ANSWER")
| Title: Correct Solution?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.
—No problem! — said Bob and immediately gave her an answer.
Alice said a random number, so she doesn't know whether Bob's answer is correct. Help her to find this out, because impatient brother is waiting for the verdict.
Input Specification:
The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes.
Output Specification:
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
Demo Input:
['3310\n1033\n', '4\n5\n']
Demo Output:
['OK\n', 'WRONG_ANSWER\n']
Note:
none | ```python
num = list(input())
ans = int(input())
num.sort()
i = 0
for i in range(len(num)):
if num[i] != "0":
break
if i == 0:
n = int("".join(num))
else:
n = int("".join([num[i]] + num[:i] + num[i+1:]))
if n == ans:
print("OK")
else:
print("WRONG_ANSWER")
``` | 0 |
965 | B | Battleship | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship. | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship). | Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell. | [
"4 3\n#..#\n#.#.\n....\n.###\n",
"10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n",
"19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#\n"
] | [
"3 2\n",
"6 1\n",
"1 8\n"
] | The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | 1,000 | [
{
"input": "4 3\n#..#\n#.#.\n....\n.###",
"output": "3 2"
},
{
"input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#",
"output": "6 1"
},
{
"input": "19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#",
"output": "1 8"
},
{
"input": "10 4\n##..######\n#...######\n#...######\n#......###\n#.......##\n.##.######\n.##.######\n.##.######\n.#....####\n....######",
"output": "4 4"
},
{
"input": "1 1\n.",
"output": "1 1"
},
{
"input": "1 1\n#",
"output": "1 1"
},
{
"input": "5 2\n..##.\n.###.\n#####\n#####\n..#..",
"output": "1 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n.####\n..#..",
"output": "5 1"
},
{
"input": "5 2\n..##.\n####.\n#####\n####.\n..#..",
"output": "5 5"
},
{
"input": "5 2\n.##..\n.###.\n#####\n#####\n..#..",
"output": "1 5"
},
{
"input": "2 2\n##\n##",
"output": "1 1"
},
{
"input": "4 1\n####\n####\n####\n###.",
"output": "4 4"
},
{
"input": "2 2\n#.\n.#",
"output": "1 1"
},
{
"input": "3 3\n###\n##.\n###",
"output": "1 1"
},
{
"input": "4 4\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "4 3\n####\n####\n####\n####",
"output": "1 1"
},
{
"input": "3 1\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 2\n###\n###\n###",
"output": "1 1"
},
{
"input": "3 3\n.#.\n#.#\n.#.",
"output": "1 1"
}
] | 1,524,693,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 7,065,600 | n,k=map(int,input().split())
def f(x,d):
a = x-d+1
if a < 1:
return 0
return a
def g(l,r,d):
a = f(l+r,d)
if a == 0:
return 0
return a-f(l-1,d)-f(r-1,d)
grid = []
for i in range(n):
grid.append(input())
M = 0
ans = [0,0]
for row in range(n):
for col in range(n):
if grid[row][col] == '.':
i = col
while i>0 and grid[row][i] == '.':
i -= 1
l = col-i-1
j = col
while j<n-1 and grid[row][j] == '.':
j += 1
r = j-col-1
i = row
while i>0 and grid[i][col] == '.':
i -= 1
u = row-i-1
j = row
while j<n-1 and grid[j][col] == '.':
j += 1
d = j-row-1
if g(l,r,k-1)+g(u,d,k-1) > M:
M = g(l,r,k-1)+g(u,d,k-1)
ans = [row,col]
print(ans[0]+1, ans[1]+1)
| Title: Battleship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.
Input Specification:
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).
Output Specification:
Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.
Demo Input:
['4 3\n#..#\n#.#.\n....\n.###\n', '10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n', '19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.#################.\n.#################.\n.#################.\n.#################.\n#####....##....####\n####............###\n####............###\n#####...####...####\n.#####..####..#####\n...###........###..\n....###########....\n.........##........\n#.................#\n']
Demo Output:
['3 2\n', '6 1\n', '1 8\n']
Note:
The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | ```python
n,k=map(int,input().split())
def f(x,d):
a = x-d+1
if a < 1:
return 0
return a
def g(l,r,d):
a = f(l+r,d)
if a == 0:
return 0
return a-f(l-1,d)-f(r-1,d)
grid = []
for i in range(n):
grid.append(input())
M = 0
ans = [0,0]
for row in range(n):
for col in range(n):
if grid[row][col] == '.':
i = col
while i>0 and grid[row][i] == '.':
i -= 1
l = col-i-1
j = col
while j<n-1 and grid[row][j] == '.':
j += 1
r = j-col-1
i = row
while i>0 and grid[i][col] == '.':
i -= 1
u = row-i-1
j = row
while j<n-1 and grid[j][col] == '.':
j += 1
d = j-row-1
if g(l,r,k-1)+g(u,d,k-1) > M:
M = g(l,r,k-1)+g(u,d,k-1)
ans = [row,col]
print(ans[0]+1, ans[1]+1)
``` | 0 |
|
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)? | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE",
"output": "4"
},
{
"input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
"output": "41"
},
{
"input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE",
"output": "-1"
},
{
"input": "1 0 0 0 -1\nS",
"output": "1"
},
{
"input": "1 5 5 5 6\nE",
"output": "-1"
},
{
"input": "15 1 1 1 2\nNNNNNNNNNNNNNNN",
"output": "1"
},
{
"input": "11 1 1 1 2\nNNNNNNNNNNN",
"output": "1"
}
] | 1,679,053,923 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | n,a,b,c,d=map(int,input().split())
x=list(input())
go=""
if c>a:
go+="E"
elif c<a:
go+="W"
if d>b:
go+="N"
elif d<b:
go+="S"
# print(go)
xx=c
yy=d
c=0
for i in range(len(x)):
if xx==0 and yy==0:
break
if x[i] in go:
if x[i]=='N' and yy!=0:
yy-=1
c=i+1
if x[i]=='S' and yy!=0:
yy+=1
c=i+1
if x[i]=='W' and xx!=0:
xx+=1
c=i+1
if x[i]=='E' and xx!=0:
xx-=1
c=i+1
# print(xx, yy)
print(c if xx==a and yy==b else -1)
| Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1).
Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
Input Specification:
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
Output Specification:
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
Demo Input:
['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n']
Demo Output:
['4\n', '-1\n']
Note:
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | ```python
n,a,b,c,d=map(int,input().split())
x=list(input())
go=""
if c>a:
go+="E"
elif c<a:
go+="W"
if d>b:
go+="N"
elif d<b:
go+="S"
# print(go)
xx=c
yy=d
c=0
for i in range(len(x)):
if xx==0 and yy==0:
break
if x[i] in go:
if x[i]=='N' and yy!=0:
yy-=1
c=i+1
if x[i]=='S' and yy!=0:
yy+=1
c=i+1
if x[i]=='W' and xx!=0:
xx+=1
c=i+1
if x[i]=='E' and xx!=0:
xx-=1
c=i+1
# print(xx, yy)
print(c if xx==a and yy==b else -1)
``` | 0 |
|
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game. | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
{
"input": "8 8 1 1 1",
"output": "Second"
},
{
"input": "15 14 32 65 28",
"output": "First"
},
{
"input": "894 197 325 232 902",
"output": "First"
},
{
"input": "1 2 8 8 5",
"output": "Friendship"
},
{
"input": "37 261 207 1 1000",
"output": "Friendship"
},
{
"input": "29 344 406 900 1",
"output": "Friendship"
},
{
"input": "1 2 8 9 8",
"output": "First"
},
{
"input": "2 9 8 8 9",
"output": "Friendship"
},
{
"input": "213 480 811 134 745",
"output": "First"
},
{
"input": "2 313 856 964 421",
"output": "Friendship"
},
{
"input": "1 10 2 6 10",
"output": "Friendship"
},
{
"input": "2 7 6 2 3",
"output": "Friendship"
},
{
"input": "637 324 69 612 998",
"output": "Second"
},
{
"input": "13 849 819 723 918",
"output": "Friendship"
},
{
"input": "9 5 7 8 7",
"output": "First"
},
{
"input": "6 5 7 10 4",
"output": "Friendship"
},
{
"input": "61 464 623 89 548",
"output": "First"
},
{
"input": "641 31 29 161 802",
"output": "Friendship"
},
{
"input": "3 3 1 6 9",
"output": "Friendship"
},
{
"input": "2 3 9 8 2",
"output": "Friendship"
},
{
"input": "485 117 368 567 609",
"output": "First"
},
{
"input": "4 202 512 995 375",
"output": "Friendship"
},
{
"input": "424 41 41 909 909",
"output": "Friendship"
},
{
"input": "884 913 263 641 265",
"output": "Second"
},
{
"input": "12 462 8 311 327",
"output": "Second"
},
{
"input": "436 306 266 493 580",
"output": "Second"
},
{
"input": "69 1 2 1 2",
"output": "First"
}
] | 1,598,032,162 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 6,758,400 | t,s1,s2,p1,p2=map(int,input().split())
time1=t*s1+p1*2
time2=t*s2+p2*2
if time1<time2:
print('First')
else:
if time1!=time2:
print('Second')
else:
print('Friendship')
#https://codeforces.com/problemset/problem/835/A | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds.
If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows:
1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it.
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
Given the length of the text and the information about participants, determine the result of the game.
Input Specification:
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
Output Specification:
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
Demo Input:
['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n']
Demo Output:
['First\n', 'Second\n', 'Friendship\n']
Note:
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. | ```python
t,s1,s2,p1,p2=map(int,input().split())
time1=t*s1+p1*2
time2=t*s2+p2*2
if time1<time2:
print('First')
else:
if time1!=time2:
print('Second')
else:
print('Friendship')
#https://codeforces.com/problemset/problem/835/A
``` | 3 |
|
190 | B | Surrounded | PROGRAMMING | 1,800 | [
"geometry"
] | null | null | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.
The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most *r* from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most *r*). Then the radar can immediately inform about the enemy's attack.
Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (*r*) is, the more the radar costs.
That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius *r* (*r*<=≥<=0) such, that a radar with radius *r* can be installed at some point and it can register the start of the movements of both flatland rings from that point.
In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed. | The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is guaranteed that the cities are located at different points. | Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6. | [
"0 0 1\n6 0 3\n",
"-10 10 3\n10 -10 3\n"
] | [
"1.000000000000000",
"11.142135623730951"
] | The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0). | 1,000 | [
{
"input": "0 0 1\n6 0 3",
"output": "1.000000000000000"
},
{
"input": "-10 10 3\n10 -10 3",
"output": "11.142135623730951"
},
{
"input": "2 1 3\n8 9 5",
"output": "1.000000000000000"
},
{
"input": "0 0 1\n-10 -10 9",
"output": "2.071067811865475"
},
{
"input": "10000 -9268 1\n-9898 9000 10",
"output": "13500.519287710202000"
},
{
"input": "10000 10000 1\n-10000 -10000 1",
"output": "14141.135623730950000"
},
{
"input": "123 21 50\n10 100 1000",
"output": "406.061621719103360"
},
{
"input": "0 3278 2382\n2312 1 1111",
"output": "258.747677968983450"
},
{
"input": "3 4 5\n5 12 13",
"output": "0.000000000000000"
},
{
"input": "-2 7 5\n4 0 6",
"output": "0.000000000000000"
},
{
"input": "4 0 2\n6 -1 10",
"output": "2.881966011250105"
},
{
"input": "41 17 3\n71 -86 10",
"output": "47.140003728560643"
},
{
"input": "761 641 6\n506 -293 5",
"output": "478.592191632957450"
},
{
"input": "-5051 -7339 9\n-9030 755 8",
"output": "4501.080828635849700"
},
{
"input": "0 5 2\n8 -4 94",
"output": "39.979202710603850"
},
{
"input": "83 -64 85\n27 80 89",
"output": "0.000000000000000"
},
{
"input": "-655 -750 68\n905 -161 68",
"output": "765.744715125679250"
},
{
"input": "1055 -5271 60\n-2992 8832 38",
"output": "7287.089182936641900"
},
{
"input": "4 0 201\n-6 4 279",
"output": "33.614835192865499"
},
{
"input": "-34 -5 836\n52 -39 706",
"output": "18.761487913212431"
},
{
"input": "659 -674 277\n-345 -556 127",
"output": "303.455240352694320"
},
{
"input": "4763 2945 956\n3591 9812 180",
"output": "2915.147750239716500"
},
{
"input": "3 -7 5749\n1 -6 9750",
"output": "1999.381966011250100"
},
{
"input": "28 -63 2382\n43 -83 1364",
"output": "496.500000000000000"
},
{
"input": "315 -532 7813\n407 -157 2121",
"output": "2652.939776235497000"
},
{
"input": "-9577 9051 5276\n-4315 -1295 8453",
"output": "0.000000000000000"
},
{
"input": "-7 -10 1\n-4 3 1",
"output": "5.670832032063167"
},
{
"input": "-74 27 535\n18 84 1",
"output": "212.886692948961240"
},
{
"input": "-454 -721 72\n-33 279 911",
"output": "51.003686623418254"
},
{
"input": "-171 762 304\n-428 -85 523",
"output": "29.065814314662131"
},
{
"input": "192 -295 1386\n-54 -78 1",
"output": "528.483994683445640"
},
{
"input": "-5134 -9860 5513\n6291 -855 9034",
"output": "0.093506651303098"
},
{
"input": "6651 8200 610\n-9228 9387 10000",
"output": "2656.651995660197400"
},
{
"input": "6370 7728 933\n4595 3736 2748",
"output": "343.915768575204200"
},
{
"input": "-6 3 8\n7 2 1",
"output": "2.019202405202649"
},
{
"input": "0 -1 1\n1 -1 1",
"output": "0.000000000000000"
},
{
"input": "0 1 3\n1 -1 1",
"output": "0.000000000000000"
},
{
"input": "-2 0 1\n3 -2 1",
"output": "1.692582403567252"
},
{
"input": "-10000 42 10000\n10000 43 10000",
"output": "0.000012499999992"
},
{
"input": "103 104 5\n97 96 5",
"output": "0.000000000000000"
},
{
"input": "2587 4850 3327\n3278 -204 1774",
"output": "0.009605941526345"
},
{
"input": "826 4417 2901\n833 -2286 3802",
"output": "0.001827539409235"
},
{
"input": "1003 -5005 3399\n-6036 -1729 4365",
"output": "0.000032199896827"
}
] | 1,517,054,393 | 3,593 | Python 3 | OK | TESTS | 43 | 62 | 5,632,000 | def dista(x1,y1,x2,y2):
dist=((x2-x1)**2+(y2-y1)**2)**(0.5)
return dist
x1,y1,r1=[int(i) for i in input().split()]
x2,y2,r2=[int(i) for i in input().split()]
if(dista(x1,y1,x2,y2)+min(r1,r2)<=max(r1,r2)):
ans=max(r1,r2)-dista(x1,y1,x2,y2)-min(r1,r2)
ans1=max(r1,r2)-min(r1,r2)
ans/=2
ans1/=2
print(min(ans,ans1))
else:
ans=dista(x1,y1,x2,y2)-r1-r2
ans/=2
if(ans>0):
print(ans)
else:
print(0)
| Title: Surrounded
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.
The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most *r* from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most *r*). Then the radar can immediately inform about the enemy's attack.
Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (*r*) is, the more the radar costs.
That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius *r* (*r*<=≥<=0) such, that a radar with radius *r* can be installed at some point and it can register the start of the movements of both flatland rings from that point.
In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.
Input Specification:
The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is guaranteed that the cities are located at different points.
Output Specification:
Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6.
Demo Input:
['0 0 1\n6 0 3\n', '-10 10 3\n10 -10 3\n']
Demo Output:
['1.000000000000000', '11.142135623730951']
Note:
The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0). | ```python
def dista(x1,y1,x2,y2):
dist=((x2-x1)**2+(y2-y1)**2)**(0.5)
return dist
x1,y1,r1=[int(i) for i in input().split()]
x2,y2,r2=[int(i) for i in input().split()]
if(dista(x1,y1,x2,y2)+min(r1,r2)<=max(r1,r2)):
ans=max(r1,r2)-dista(x1,y1,x2,y2)-min(r1,r2)
ans1=max(r1,r2)-min(r1,r2)
ans/=2
ans1/=2
print(min(ans,ans1))
else:
ans=dista(x1,y1,x2,y2)-r1-r2
ans/=2
if(ans>0):
print(ans)
else:
print(0)
``` | 3 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,603,243,541 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n = int(input())
l = list(map(int, input().split()))
ch = []
nch = []
for i in range(len(l)):
if l[i] % 2 == 0:
ch.append(i)
else:
nch.append(i)
if len(ch) > len(nch):
print(nch[0] + 1)
else:
print(ch[0] + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
l = list(map(int, input().split()))
ch = []
nch = []
for i in range(len(l)):
if l[i] % 2 == 0:
ch.append(i)
else:
nch.append(i)
if len(ch) > len(nch):
print(nch[0] + 1)
else:
print(ch[0] + 1)
``` | 3.9455 |
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,658,757,113 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | s = input()
if 'h' in s and 'e' in s and 'l' in s and s.count('l') >= 2 and 'o' in s:
if s.index('h') < s.index('e') < s.index('l') < s.index('o'):
print('YES')
else:
print('NO')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
if 'h' in s and 'e' in s and 'l' in s and s.count('l') >= 2 and 'o' in s:
if s.index('h') < s.index('e') < s.index('l') < s.index('o'):
print('YES')
else:
print('NO')
else:
print('NO')
``` | 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,398,013,455 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 307,200 | def main():
n = int(input())
c = [tuple(map(int,input().split())) for i in range(n)]
pairs = [(a,b) for a in c for b in c]
for (a,b) in pairs:
if a[0] + a[1] == b[0] and b[0] + b[1] == a[0]:
return 'YES'
return 'NO'
print(main())
| 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
def main():
n = int(input())
c = [tuple(map(int,input().split())) for i in range(n)]
pairs = [(a,b) for a in c for b in c]
for (a,b) in pairs:
if a[0] + a[1] == b[0] and b[0] + b[1] == a[0]:
return 'YES'
return 'NO'
print(main())
``` | 3.968428 |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
},
{
"input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430 262 71 415 586 532 562 419 615 732 658 108 315 268 574 86 12 23 429 640 995 342 305",
"output": "1000"
},
{
"input": "3\n1 1 1",
"output": "2"
},
{
"input": "30\n94 93 90 94 90 91 93 91 93 94 93 90 100 94 97 94 94 95 94 96 94 98 97 95 97 91 91 95 98 96",
"output": "100"
},
{
"input": "5\n1000000000 5 5 4 4",
"output": "1000000000"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "4"
},
{
"input": "3\n1000000000 1000000000 10000000",
"output": "1005000000"
},
{
"input": "3\n677876423 834056477 553175531",
"output": "1032554216"
},
{
"input": "5\n1000000000 1 1 1 1",
"output": "1000000000"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1333333334"
},
{
"input": "3\n4 10 11",
"output": "13"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1250000000"
}
] | 1,628,967,102 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 15,872,000 | n=int(input())
lista=list(map(int,input().split()))
MaxValue, SumLista=max(lista), sum(lista)
r=n-2
for i in lista:
r += i
#esp=SumLista+n-2
calc=int(r//(n-1))
print(max(MaxValue, calc))
| Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
Output Specification:
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['3\n3 2 2\n', '4\n2 2 2 2\n']
Demo Output:
['4\n', '3\n']
Note:
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | ```python
n=int(input())
lista=list(map(int,input().split()))
MaxValue, SumLista=max(lista), sum(lista)
r=n-2
for i in lista:
r += i
#esp=SumLista+n-2
calc=int(r//(n-1))
print(max(MaxValue, calc))
``` | 3 |
|
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,564,173,369 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 218 | 409,600 | n = input()
loc = 0
for i in range(len(n)):
if n[i] == '0':
loc = i
break
ans = n[:loc] + n[loc+1:]
print(ans) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
Input Specification:
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
Output Specification:
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
Demo Input:
['101\n', '110010\n']
Demo Output:
['11\n', '11010\n']
Note:
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | ```python
n = input()
loc = 0
for i in range(len(n)):
if n[i] == '0':
loc = i
break
ans = n[:loc] + n[loc+1:]
print(ans)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.