contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
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
listlengths
0
7
demo-output
listlengths
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
741
B
Arpa's weak amphitheater and Mehrdad's valuable Hoses
PROGRAMMING
1,600
[ "dfs and similar", "dp", "dsu" ]
null
null
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if...
The first line contains integers *n*, *m* and *w* (1<=<=≤<=<=*n*<=<=≤<=<=1000, , 1<=≤<=*w*<=≤<=1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=1000) — the weights of the ...
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*.
[ "3 1 5\n3 2 5\n2 4 2\n1 2\n", "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n" ]
[ "6\n", "7\n" ]
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6. In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hose...
1,000
[ { "input": "3 1 5\n3 2 5\n2 4 2\n1 2", "output": "6" }, { "input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3", "output": "7" }, { "input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5", "output": "238...
1,606,089,124
2,147,483,647
Python 3
OK
TESTS
68
842
614,400
def g(x): if x == t[x]: return x t[x] = g(t[x]) return t[x] f = lambda: map(int, input().split()) hoses, pairOfFriends, weight = f() weightsAndBeauties = [(0, 0)] + list(zip(f(), f())) t = list(range(hoses + 1)) for i in range(pairOfFriends): f1, f2 = f() f1, f2 = g(f1), g(f2) i...
Title: Arpa's weak amphitheater and Mehrdad's valuable Hoses Time Limit: None seconds Memory Limit: None megabytes Problem Description: Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. ...
```python def g(x): if x == t[x]: return x t[x] = g(t[x]) return t[x] f = lambda: map(int, input().split()) hoses, pairOfFriends, weight = f() weightsAndBeauties = [(0, 0)] + list(zip(f(), f())) t = list(range(hoses + 1)) for i in range(pairOfFriends): f1, f2 = f() f1, f2 = g(f1), g(...
3
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,664,513,971
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
60
0
list1 = [] num = int(input()) if num % 2 != 0: print(-1) else: if len(list1) % 2 == 0: for j in range(1, num + 1, 2): list1.append(j + 1) list1.append(j) print(list1)
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python list1 = [] num = int(input()) if num % 2 != 0: print(-1) else: if len(list1) % 2 == 0: for j in range(1, num + 1, 2): list1.append(j + 1) list1.append(j) print(list1) ```
0
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" ...
1,630,347,311
2,147,483,647
PyPy 3
OK
TESTS
24
109
20,172,800
from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def solve(): a=read() c=0 if a[0]=='a' or a[0]=='h': c+=1 if a[1]=='1' or a[1]=='8': c+=1 if c==0: print(8) elif c==1: print(5) else: ...
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check...
```python from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def solve(): a=read() c=0 if a[0]=='a' or a[0]=='h': c+=1 if a[1]=='1' or a[1]=='8': c+=1 if c==0: print(8) elif c==1: print(...
3
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order...
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som...
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { ...
1,593,217,124
2,147,483,647
PyPy 3
OK
TESTS
150
187
21,606,400
t = int(input()) left = [] right = [] for i in range(t): x , y = input().split() x , y = int(x) , int(y) left.append(x) right.append(y) if left != right :print('rated') elif left == right and sorted(left , reverse=True) != left and sorted(right , reverse=True) != right:print('unrated') else:...
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number ...
```python t = int(input()) left = [] right = [] for i in range(t): x , y = input().split() x , y = int(x) , int(y) left.append(x) right.append(y) if left != right :print('rated') elif left == right and sorted(left , reverse=True) != left and sorted(right , reverse=True) != right:print('unrate...
3
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ...
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": ...
1,643,800,871
2,147,483,647
Python 3
OK
TESTS
32
46
0
a,b=map(int,input().split()) c=int(a-1)/(b-1) print(int(a+c))
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s...
```python a,b=map(int,input().split()) c=int(a-1)/(b-1) print(int(a+c)) ```
3
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 9...
1,623,413,621
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
248
307,200
from sys import stdin,stdout stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from collections import defaultdict as dd,Counter as C,deque from math import ceil,gcd,sqrt,factorial,log2,floor from bisect import bisect_right as br,bisect_...
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red fl...
```python from sys import stdin,stdout stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from collections import defaultdict as dd,Counter as C,deque from math import ceil,gcd,sqrt,factorial,log2,floor from bisect import bisect_right as ...
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 Xe...
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,694,660,081
2,147,483,647
Python 3
OK
TESTS
21
92
0
a=input() b=[] for i in range(0,len(a),2): b.append(a[i]) b.sort() b="+".join(b) print(b)
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 mak...
```python a=input() b=[] for i in range(0,len(a),2): b.append(a[i]) b.sort() b="+".join(b) print(b) ```
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,697,737,931
2,147,483,647
Python 3
OK
TESTS
21
92
0
cases_num=int(input()) res=0 for ix in range(cases_num): inputs=input() cases=inputs.split(' ') score=0 for num in cases: score+=(int(num)) if score>=2: res+=1 print(res)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python cases_num=int(input()) res=0 for ix in range(cases_num): inputs=input() cases=inputs.split(' ') score=0 for num in cases: score+=(int(num)) if score>=2: res+=1 print(res) ```
3
292
D
Connected Components
PROGRAMMING
1,900
[ "data structures", "dfs and similar", "dp", "dsu" ]
null
null
We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with *n* nodes and *m* edges. Let's inde...
The first line contains two space-separated integers *n*, *m* (2<=≤<=*n*<=≤<=500; 1<=≤<=*m*<=≤<=104) — the number of computers and the number of cables, correspondingly. The following *m* lines contain the cables' description. The *i*-th line contains space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y*...
Print *k* numbers, the *i*-th number represents the number of connected components of the graph that defines the computer network during the *i*-th experiment.
[ "6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3\n" ]
[ "4\n5\n6\n3\n4\n2\n" ]
none
2,000
[ { "input": "6 5\n1 2\n5 4\n2 3\n3 1\n3 6\n6\n1 3\n2 5\n1 5\n5 5\n2 4\n3 3", "output": "4\n5\n6\n3\n4\n2" }, { "input": "2 1\n2 1\n2\n1 1\n1 1", "output": "2\n2" }, { "input": "3 2\n3 2\n3 1\n4\n1 1\n1 2\n2 2\n2 2", "output": "2\n3\n2\n2" }, { "input": "3 3\n2 3\n3 1\n2 1\n5\n...
1,389,539,127
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <set> #include <list> #include <string> #include <algorithm> #include <map> #include <cmath> #include <stack> #include <functional> #include <math.h> #include <queue> #include <vector> #include <bitset> #includ...
Title: Connected Components Time Limit: None seconds Memory Limit: None megabytes Problem Description: We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of *n* computers and *m* cables that connect some pairs of computers. In other words, t...
```python #include <iostream> #define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <set> #include <list> #include <string> #include <algorithm> #include <map> #include <cmath> #include <stack> #include <functional> #include <math.h> #include <queue> #include <vector> #include <bitset...
-1
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
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", "outpu...
1,647,362,354
2,147,483,647
Python 3
OK
TESTS
35
248
6,041,600
from tkinter import N m,n = list(map(int, input().split())) t= m*n c=0 if n%2==0: c= n/2*m elif m%2==0: c= m/2*n else: c= ((m-1)/2*n)+ (n-1)/2 print(int(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 p...
```python from tkinter import N m,n = list(map(int, input().split())) t= m*n c=0 if n%2==0: c= n/2*m elif m%2==0: c= m/2*n else: c= ((m-1)/2*n)+ (n-1)/2 print(int(c)) ```
3.926747
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 d...
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" ...
1,614,694,325
2,147,483,647
Python 3
OK
TESTS
58
62
307,200
def precompute(arr) : arr[0] = 1 for index in range(1,60) : arr[index] = arr[index-1]*2 def solve(n,k,power) : if k == 1 : return n else : for index in range(59,-1,-1): if power[index] <= n : return power[index] + (power[index] - ...
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* co...
```python def precompute(arr) : arr[0] = 1 for index in range(1,60) : arr[index] = arr[index-1]*2 def solve(n,k,power) : if k == 1 : return n else : for index in range(59,-1,-1): if power[index] <= n : return power[index] + (power...
3
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 t...
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<=&lt;<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two ...
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"...
1,446,661,522
6,022
Python 3
OK
TESTS
93
561
9,932,800
n = int(input()) a = list() x1, x2 = map(int, input().split()) for i in range(n): k, b = map(int, input().split()) y1 = k * x1 + b y2 = k * x2 + b a.append((y1, y2)) a.sort() fl = 'NO' y1m = a[0][0] y2m = a[0][1] for y1, y2 in a: if y2 < y2m: fl = 'YES' else: y2m ...
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*·*...
```python n = int(input()) a = list() x1, x2 = map(int, input().split()) for i in range(n): k, b = map(int, input().split()) y1 = k * x1 + b y2 = k * x2 + b a.append((y1, y2)) a.sort() fl = 'NO' y1m = a[0][0] y2m = a[0][1] for y1, y2 in a: if y2 < y2m: fl = 'YES' else: ...
3
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,693,370,777
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
s = input() if s[0] >= 'a' and s[1] < 'a': print(s[0].upper(), end='') for i in range(1, len(s)): print(s[i].lower(), end='') elif s[0] < 'a' and s[1] < 'a': print(s.lower()) else: print(s)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python s = input() if s[0] >= 'a' and s[1] < 'a': print(s[0].upper(), end='') for i in range(1, len(s)): print(s[i].lower(), end='') elif s[0] < 'a' and s[1] < 'a': print(s.lower()) else: print(s) ```
0
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which...
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174",...
1,590,996,538
2,147,483,647
Python 3
OK
TESTS
22
280
1,024,000
s = input() res = 0 for i in range(1, len(s)) : if int(s[i-1 : i+1]) % 4 == 0 : res += i res += s.count('0') + s.count('4') + s.count('8') print(res)
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother...
```python s = input() res = 0 for i in range(1, len(s)) : if int(s[i-1 : i+1]) % 4 == 0 : res += i res += s.count('0') + s.count('4') + s.count('8') print(res) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,687,675,062
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
k=input() count=0 for i in k: if(i.isupper()): count+=1 if(count>(len(k)//2)): print(k.upper()) else: print(k.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python k=input() count=0 for i in k: if(i.isupper()): count+=1 if(count>(len(k)//2)): print(k.upper()) else: print(k.lower()) ```
3.969
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,679,084,381
2,147,483,647
Python 3
OK
TESTS
32
93
7,884,800
n = int (input()) current = 1 max = 1 x = list(map(int,input().split())) for i in range(n-1): # 0 1 2 3 4 if x[i+1] > x[i]: # 1 7 2 11 15 current = current +1 else: current=1 if max<current:max=current print (max)
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python n = int (input()) current = 1 max = 1 x = list(map(int,input().split())) for i in range(n-1): # 0 1 2 3 4 if x[i+1] > x[i]: # 1 7 2 11 15 current = current +1 else: current=1 if max<current:max=current print (max) ```
3
892
B
Wrath
PROGRAMMING
1,200
[ "greedy", "implementation", "two pointers" ]
null
null
Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=&lt;<=*i* and *...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people. Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Print one integer — the total number of alive people after the bell rings.
[ "4\n0 1 0 10\n", "2\n0 0\n", "10\n1 1 3 0 0 0 2 1 0 3\n" ]
[ "1\n", "2\n", "3\n" ]
In first sample the last person kills everyone in front of him.
1,000
[ { "input": "4\n0 1 0 10", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "10\n1 1 3 0 0 0 2 1 0 3", "output": "3" }, { "input": "10\n0 0 2 0 0 3 3 2 2 0", "output": "2" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 0 0 1 0"...
1,553,753,362
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n = int(input()) s = list(map(int,input().split())) died = [] live = n if sum(s) == n * s[0]: print(1) else: for i in range(n - 1, 0, -1): for j in range(i): if i > j and i - s[i] <= j and j not in died: died.append(j) print(n - len(died))
Title: Wrath Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hands that shed innocent blood! There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ...
```python n = int(input()) s = list(map(int,input().split())) died = [] live = n if sum(s) == n * s[0]: print(1) else: for i in range(n - 1, 0, -1): for j in range(i): if i > j and i - s[i] <= j and j not in died: died.append(j) print(n - len(died)) ```
0
152
C
Pocket Book
PROGRAMMING
1,400
[ "combinatorics" ]
null
null
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters.
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7).
[ "2 3\nAAB\nBAA\n", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n" ]
[ "4\n", "216\n" ]
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
1,500
[ { "input": "2 3\nAAB\nBAA", "output": "4" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216" }, { "input": "1 1\nE", "output": "1" }, { "input": "2 2\nNS\nPD", "output": "4" }, { "input": "3 4\nPJKD\nNFJX\nFGFK", "output": "81" }, { "inpu...
1,663,609,937
2,147,483,647
Python 3
OK
TESTS
60
92
0
if __name__ == "__main__": modulo=10**9+7 n,m=map(int,input().split()) names=[] for i in range(n): names.append(input().strip()) res=1 for j in range(m): unique_col_char_count=0 tmp_arr=[] for i in range(n): if names[i][j] not in tmp...
Title: Pocket Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. ...
```python if __name__ == "__main__": modulo=10**9+7 n,m=map(int,input().split()) names=[] for i in range(n): names.append(input().strip()) res=1 for j in range(m): unique_col_char_count=0 tmp_arr=[] for i in range(n): if names[i][j] ...
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,676,308,146
2,147,483,647
Python 3
OK
TESTS
41
108
0
n = int(input()) if n % 2 == 0: print(n//2) for x in range(n//2): print(2,end=" ") else: print(n//2) for x in range((n//2) - 1): print(2,end=" ") print(3)
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python n = int(input()) if n % 2 == 0: print(n//2) for x in range(n//2): print(2,end=" ") else: print(n//2) for x in range((n//2) - 1): print(2,end=" ") print(3) ```
3
0
none
none
none
0
[ "none" ]
null
null
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set. Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
[ "4\nmail\nai\nlru\ncf\n", "3\nkek\npreceq\ncheburek\n" ]
[ "cfmailru\n", "NO\n" ]
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
0
[ { "input": "4\nmail\nai\nlru\ncf", "output": "cfmailru" }, { "input": "3\nkek\npreceq\ncheburek", "output": "NO" }, { "input": "1\nz", "output": "z" }, { "input": "2\nab\nba", "output": "NO" }, { "input": "2\nac\nbc", "output": "NO" }, { "input": "2\nc...
1,510,531,453
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
n = int(input()) s = [] for _ in range(n): s.append(input()) if len(set(s[-1])) != len(s[-1]): print("NO") exit(0) m = [] for i in range(len(s)): c = s[i] for j in range(len(m)): if len(set(s[i]) & set(m[j])) != 0: merged = False for k in range(1, min(le...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is c...
```python n = int(input()) s = [] for _ in range(n): s.append(input()) if len(set(s[-1])) != len(s[-1]): print("NO") exit(0) m = [] for i in range(len(s)): c = s[i] for j in range(len(m)): if len(set(s[i]) & set(m[j])) != 0: merged = False for k in range...
0
387
B
George and Round
PROGRAMMING
1,200
[ "brute force", "greedy", "two pointers" ]
null
null
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≤<=106) — the requirem...
Print a single integer — the answer to the problem.
[ "3 5\n1 2 3\n1 2 2 3 3\n", "3 5\n1 2 3\n1 1 1 1 1\n", "3 1\n2 3 4\n1\n" ]
[ "0\n", "2\n", "3\n" ]
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems wi...
1,000
[ { "input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0" }, { "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2" }, { "input": "3 1\n2 3 4\n1", "output": "3" }, { "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97...
1,520,266,923
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
26
1,000
5,939,200
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) count=0 l=len(b) count1=n for i in range(n): if l==0: count+=n-i break j=0 while j<l: if a[i]<=b[j]: del b[j] l-=1 break elif j==...
Title: George and Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. T...
```python n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) count=0 l=len(b) count1=n for i in range(n): if l==0: count+=n-i break j=0 while j<l: if a[i]<=b[j]: del b[j] l-=1 break ...
0
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd...
1,656,093,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n= int(input()) string = input() count=0 for i in range(len(string)): if string[i].isupper()== True: count=count+1 if string[i]==" ": count=0 print(count)
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex...
```python n= int(input()) string = input() count=0 for i in range(len(string)): if string[i].isupper()== True: count=count+1 if string[i]==" ": count=0 print(count) ```
0
928
A
Login Verification
PROGRAMMING
1,200
[ "*special", "strings" ]
null
null
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ...
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the exi...
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes).
[ "1_wat\n2\n2_wat\nwat_1\n", "000\n3\n00\nooA\noOo\n", "_i_\n3\n__i_\n_1_\nI\n", "La0\n3\n2a0\nLa1\n1a0\n", "abc\n1\naBc\n", "0Lil\n2\nLIL0\n0Ril\n" ]
[ "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
500
[ { "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes" }, { "input": "000\n3\n00\nooA\noOo", "output": "No" }, { "input": "_i_\n3\n__i_\n_1_\nI", "output": "No" }, { "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No" }, { "input": "abc\n1\naBc", "output": "No" }...
1,673,892,058
2,147,483,647
Python 3
OK
TESTS
73
46
0
s=input() s=s.upper() s=s.replace('O','0') s=s.replace('L','1') s=s.replace('I','1') f=1 for i in range(int(input())): s1=input() s1=s1.upper() s1=s1.replace('O','0') s1=s1.replace('L','1') s1=s1.replace('I','1') if(s==s1): f=0 if(f): print("Yes") else: print("No")
Title: Login Verification Time Limit: None seconds Memory Limit: None megabytes Problem Description: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercas...
```python s=input() s=s.upper() s=s.replace('O','0') s=s.replace('L','1') s=s.replace('I','1') f=1 for i in range(int(input())): s1=input() s1=s1.upper() s1=s1.replace('O','0') s1=s1.replace('L','1') s1=s1.replace('I','1') if(s==s1): f=0 if(f): print("Yes") else: print("No") ```
3
222
B
Cosmic Tables
PROGRAMMING
1,300
[ "data structures", "implementation" ]
null
null
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of mete...
The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly. Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the ta...
For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
[ "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n" ]
[ "8\n9\n6\n", "5\n" ]
Let's see how the table changes in the second test case. After the first operation is fulfilled, the table looks like that: 2 1 4 1 3 5 After the second operation is fulfilled, the table looks like that: 1 3 5 2 1 4 So the answer to the third query (the number located in the first row and in the third column) wi...
1,000
[ { "input": "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "output": "8\n9\n6" }, { "input": "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3", "output": "5" }, { "input": "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1...
1,608,638,529
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <vector> #include <set> #include <algorithm> #include <map> #include <queue> #include <string> using namespace std; int arr[1005][1005]; int main(){ int n, m; cin>>n>>m; for(int i=0;i<m;i++){ int x, y; cin>>x>>y; for(int j=x;j<x+3;j++){ for(int k=y;k<y+3;k++){ ...
Title: Cosmic Tables Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some sec...
```python #include <iostream> #include <vector> #include <set> #include <algorithm> #include <map> #include <queue> #include <string> using namespace std; int arr[1005][1005]; int main(){ int n, m; cin>>n>>m; for(int i=0;i<m;i++){ int x, y; cin>>x>>y; for(int j=x;j<x+3;j++){ for(int k=y;k<...
-1
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,597,672,221
2,147,483,647
PyPy 3
OK
TESTS
93
140
0
n, t, k, d = map(int, input().split()) g = int((n + k - 1) / k) o1, o2 = 0, d i = 0 while i < g: if o1 <= o2: o1 += t else: o2 += t i += 1 if max(o1, o2) < g * t: print("YES") else: print("NO")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python n, t, k, d = map(int, input().split()) g = int((n + k - 1) / k) o1, o2 = 0, d i = 0 while i < g: if o1 <= o2: o1 += t else: o2 += t i += 1 if max(o1, o2) < g * t: print("YES") else: print("NO") ```
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,693,061,281
2,147,483,647
Python 3
OK
TESTS
41
77
1,024,000
n = int(input()) primes_sum = [2] * (n // 2) if n % 2 == 1: primes_sum[-1] = 3 print(len(primes_sum)) print(*primes_sum)
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python n = int(input()) primes_sum = [2] * (n // 2) if n % 2 == 1: primes_sum[-1] = 3 print(len(primes_sum)) print(*primes_sum) ```
3
152
C
Pocket Book
PROGRAMMING
1,400
[ "combinatorics" ]
null
null
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters.
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7).
[ "2 3\nAAB\nBAA\n", "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n" ]
[ "4\n", "216\n" ]
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
1,500
[ { "input": "2 3\nAAB\nBAA", "output": "4" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216" }, { "input": "1 1\nE", "output": "1" }, { "input": "2 2\nNS\nPD", "output": "4" }, { "input": "3 4\nPJKD\nNFJX\nFGFK", "output": "81" }, { "inpu...
1,685,973,273
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
122
2,560,000
import sys from math import ceil input = sys.stdin.readline for ii in range(1): a,b=(map(int,input().split())) s=[] r=1 g={} for o in range(b): g[o]=[] for i in range(a): d=input() for x in range(b): g[x]+=d[x] r=1 for i in g: ...
Title: Pocket Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. ...
```python import sys from math import ceil input = sys.stdin.readline for ii in range(1): a,b=(map(int,input().split())) s=[] r=1 g={} for o in range(b): g[o]=[] for i in range(a): d=input() for x in range(b): g[x]+=d[x] r=1 for i in g...
0
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 ...
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"...
1,689,679,079
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
W = range(1, 101) W = int(input("Please input the weight of the watermelon: ")) if W % 2 == 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, dyin...
```python W = range(1, 101) W = int(input("Please input the weight of the watermelon: ")) if W % 2 == 0: print("Yes.") else: print("No.") ```
0
948
A
Protect Sheep
PROGRAMMING
900
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or...
First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively. Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a...
If it is impossible to protect all sheep, output a single line with the word "No". Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she...
[ "6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n", "1 2\nSW\n", "5 5\n.S...\n...S.\nS....\n...S.\n.S...\n" ]
[ "Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n", "No\n", "Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n" ]
In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally. In the second example, there are no empty spots to put dogs that would guard the lone sheep. In the third example, there are no wolves...
500
[ { "input": "1 2\nSW", "output": "No" }, { "input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S", "output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD...
1,684,689,426
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
5,017,600
R, C = list(map(int, input().split())) grid = [] for _ in range(R): li = list(input()) grid.append(li) visited = [[0 for _ in range(C)] for _ in range(R)] directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] def isBound(r, c): return 0 <= r < R and 0 <= c < C def search(r, c): visited[r][c] =...
Title: Protect Sheep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is ...
```python R, C = list(map(int, input().split())) grid = [] for _ in range(R): li = list(input()) grid.append(li) visited = [[0 for _ in range(C)] for _ in range(R)] directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] def isBound(r, c): return 0 <= r < R and 0 <= c < C def search(r, c): visit...
0
909
A
Generate Login
PROGRAMMING
1,000
[ "brute force", "greedy", "sortings" ]
null
null
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and ...
The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.
Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.
[ "harry potter\n", "tom riddle\n" ]
[ "hap\n", "tomr\n" ]
none
500
[ { "input": "harry potter", "output": "hap" }, { "input": "tom riddle", "output": "tomr" }, { "input": "a qdpinbmcrf", "output": "aq" }, { "input": "wixjzniiub ssdfodfgap", "output": "wis" }, { "input": "z z", "output": "zz" }, { "input": "ertuyivhfg v"...
1,514,395,082
2,582
Python 3
OK
TESTS
64
78
5,529,600
def getprfx(s): tab = [s[0]] for i in range(1, len(s)): x = tab[i-1] + s[i] tab.append(x) return tab n, m = input().split() a, b = getprfx(n), getprfx(m) mn = a[0] + b[0] for i in a: for j in b: if i+j < mn: mn = i+j print(mn)
Title: Generate Login Time Limit: None seconds Memory Limit: None megabytes Problem Description: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu...
```python def getprfx(s): tab = [s[0]] for i in range(1, len(s)): x = tab[i-1] + s[i] tab.append(x) return tab n, m = input().split() a, b = getprfx(n), getprfx(m) mn = a[0] + b[0] for i in a: for j in b: if i+j < mn: mn = i+j print(mn) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
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", ...
1,488,779,264
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
122
5,836,800
from fractions import Fraction d=int(input('')) a=int(input('')) j=6 if d>=4 or a>=4: print ('1/2') else: if d==1 and a==1: print('1/1') elif d>a: print (Fraction(6-d,j)) elif d<a: print( Fraction(6-a,j)) else: print (Fraction(6-a+1,j))
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 T...
```python from fractions import Fraction d=int(input('')) a=int(input('')) j=6 if d>=4 or a>=4: print ('1/2') else: if d==1 and a==1: print('1/1') elif d>a: print (Fraction(6-d,j)) elif d<a: print( Fraction(6-a,j)) else: print (Fraction(6-a+1,j)) ...
-1
995
C
Leaving the Bar
PROGRAMMING
2,300
[ "brute force", "data structures", "geometry", "greedy", "math", "sortings" ]
null
null
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$. Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th...
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of moves. Each of the following lines contains two space-separated integers $x_i$ and $y_i$, meaning that $\vec{v_i} = (x_i, y_i)$. We have that $|v_i| \le 10^6$ for all $i$.
Output a single line containing $n$ integers $c_1, c_2, \cdots, c_n$, each of which is either $1$ or $-1$. Your solution is correct if the value of $p = \sum_{i = 1}^n c_i \vec{v_i}$, satisfies $|p| \le 1.5 \cdot 10^6$. It can be shown that a solution always exists under the given constraints.
[ "3\n999999 0\n0 999999\n999999 0\n", "1\n-824590 246031\n", "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n" ]
[ "1 1 -1 \n", "1 \n", "1 1 1 1 1 1 1 -1 \n" ]
none
1,500
[ { "input": "3\n999999 0\n0 999999\n999999 0", "output": "1 1 -1 " }, { "input": "1\n-824590 246031", "output": "1 " }, { "input": "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899", "output": "1 1 1 1 1 1 1 -1 " ...
1,529,864,525
6,425
Python 3
WRONG_ANSWER
TESTS
50
639
13,004,800
n = int(input()) res = [] ta, tb = 0, 0 for _ in range(n): a, b = [int(x) for x in input().split()] ta += a tb += b res.append((a, b)) def norm(x): return x[0] ** 2 + x[1] ** 2 def add(x, y): return (x[0] + y[0], x[1] + y[1]) def sub(x, y): return (x[0] - y[0], x[1] - y[1]...
Title: Leaving the Bar Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$. Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $...
```python n = int(input()) res = [] ta, tb = 0, 0 for _ in range(n): a, b = [int(x) for x in input().split()] ta += a tb += b res.append((a, b)) def norm(x): return x[0] ** 2 + x[1] ** 2 def add(x, y): return (x[0] + y[0], x[1] + y[1]) def sub(x, y): return (x[0] - y[0], x...
0
16
C
Monitor
PROGRAMMING
1,800
[ "binary search", "number theory" ]
C. Monitor
0
64
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999...
The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109).
If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.
[ "800 600 4 3\n", "1920 1200 16 9\n", "1 1 1 2\n" ]
[ "800 600\n", "1920 1080\n", "0 0\n" ]
none
0
[ { "input": "800 600 4 3", "output": "800 600" }, { "input": "1920 1200 16 9", "output": "1920 1080" }, { "input": "1 1 1 2", "output": "0 0" }, { "input": "1002105126 227379125 179460772 1295256518", "output": "0 0" }, { "input": "625166755 843062051 1463070160 19...
1,436,608,596
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
500
0
def inp(s): j = 0 a = [] for i in range(len(s)): if s[i] == " ": a.append(int(s[j:i])) j = i+1 if i == len(s)-1: a.append(int(s[j:])) return a s = input() a = inp(s) p = 0 q = 0 for i in range(a[0],-1,-1): x = (i*a[3])/a[2] if...
Title: Monitor Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *...
```python def inp(s): j = 0 a = [] for i in range(len(s)): if s[i] == " ": a.append(int(s[j:i])) j = i+1 if i == len(s)-1: a.append(int(s[j:])) return a s = input() a = inp(s) p = 0 q = 0 for i in range(a[0],-1,-1): x = (i*a[3])/a[...
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
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":...
1,670,213,640
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n = int(input()) w = list() for i in range(n): word = input() w.append(word) for j in range(n): l = len(w[j]) if l>10: print(w[j][0]+str(l)+w[j][-1]) else: print(w)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n = int(input()) w = list() for i in range(n): word = input() w.append(word) for j in range(n): l = len(w[j]) if l>10: print(w[j][0]+str(l)+w[j][-1]) else: print(w) ```
0
355
A
Vasya and Digital Root
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<...
The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9).
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
[ "4 4\n", "5 1\n", "1 0\n" ]
[ "5881\n", "36172\n", "0\n" ]
For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
500
[ { "input": "4 4", "output": "5881" }, { "input": "5 1", "output": "36172" }, { "input": "1 0", "output": "0" }, { "input": "8 7", "output": "49722154" }, { "input": "487 0", "output": "No solution" }, { "input": "1000 5", "output": "854193955406789...
1,634,658,579
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
61
0
k, d = map(int, input().split()) if k == 1: print(d) else: a = 1 for i in range (k - 1): a = a * 10 if d >= 1: a = a + (d - 1) else: a = a + 8 print(a + 81)
Title: Vasya and Digital Root Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=...
```python k, d = map(int, input().split()) if k == 1: print(d) else: a = 1 for i in range (k - 1): a = a * 10 if d >= 1: a = a + (d - 1) else: a = a + 8 print(a + 81) ```
0
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 b...
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,645,220,418
2,147,483,647
PyPy 3
OK
TESTS
37
93
0
from math import * r,x,y,a,b=map(int,input().split()) print(ceil((((x-a)**2+(y-b)**2)**0.5)/(r*2)))
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 ...
```python from math import * r,x,y,a,b=map(int,input().split()) print(ceil((((x-a)**2+(y-b)**2)**0.5)/(r*2))) ```
3
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input":...
1,695,295,819
2,147,483,647
Python 3
OK
TESTS
53
92
0
s1 = input().lower() s2 = input().lower() if s1==s2: print(0) if s1<s2: print(-1) if s1>s2: print(1)
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ...
```python s1 = input().lower() s2 = input().lower() if s1==s2: print(0) if s1<s2: print(-1) if s1>s2: print(1) ```
3.977
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4...
1,550,066,865
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define ull unsigned long long #define mp make_pair #define pb push_back #define rep(n) for(long i=0;i<n;i++) #define mset(a,i) memset(a,i,sizeof(a)) #define minv(a) min_element(a.begin(),a.end()) #define maxv(a) max_e...
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the star...
```python #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define ull unsigned long long #define mp make_pair #define pb push_back #define rep(n) for(long i=0;i<n;i++) #define mset(a,i) memset(a,i,sizeof(a)) #define minv(a) min_element(a.begin(),a.end()) #define max...
-1
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo...
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input":...
1,660,561,049
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
word = input() counter = 0 for i in range(0, int(len(word) / 2)): if word[i] != word[-(i + 1)]: counter += 1 if counter == 0 or counter == 1: print("YES") else: print("NO")
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same ...
```python word = input() counter = 0 for i in range(0, int(len(word) / 2)): if word[i] != word[-(i + 1)]: counter += 1 if counter == 0 or counter == 1: print("YES") else: print("NO") ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel...
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,639,733,904
2,147,483,647
Python 3
OK
TESTS
37
62
409,600
n , m = map(int, input().split(" ")) notes = {} final = [] for i in range(m): a,b = map(str, input().split()) notes[a]=b c = list(map(str, input().split(" ")[:n])) for i in c: if len(notes[i])>=len(i): final.append(i) else: final.append(notes[i]) print(" ".join(final))
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first ...
```python n , m = map(int, input().split(" ")) notes = {} final = [] for i in range(m): a,b = map(str, input().split()) notes[a]=b c = list(map(str, input().split(" ")[:n])) for i in c: if len(notes[i])>=len(i): final.append(i) else: final.append(notes[i]) print(" ".join(fina...
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,691,174,309
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
62
0
a,b = map(int,input().split()) c = [3,5,7,11,13,17,19,23,29,31,37,41,43,47] if c[c.index(a)+1] == b: print("YES") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python a,b = map(int,input().split()) c = [3,5,7,11,13,17,19,23,29,31,37,41,43,47] if c[c.index(a)+1] == b: print("YES") else: print("NO") ```
-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...
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"...
1,648,553,592
2,147,483,647
Python 3
OK
TESTS
20
31
0
n, m, a = input().split() n, m, a = int(n), int(m), int(a) x = (n + a - 1) / a y = (m + a - 1) / a print(int(x)*int(y))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python n, m, a = input().split() n, m, a = int(n), int(m), int(a) x = (n + a - 1) / a y = (m + a - 1) / a print(int(x)*int(y)) ```
3.9845
329
A
Purification
PROGRAMMING
1,500
[ "constructive algorithms", "greedy" ]
null
null
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and the columns are numbered 1 through *n* from left to right. At the far side...
The first line will contain a single integer *n* (1<=≤<=*n*<=≤<=100). Then, *n* lines follows, each contains *n* characters. The *j*-th character in the *i*-th row represents the cell located at row *i* and column *j*. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts *x* "Purification" spells (where *x* is the minimum possible number of spells), output *x* lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purificati...
[ "3\n.E.\nE.E\n.E.\n", "3\nEEE\nE..\nE.E\n", "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE\n" ]
[ "1 1\n2 2\n3 3\n", "-1\n", "3 3\n1 3\n2 2\n4 4\n5 3" ]
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously. In the se...
500
[ { "input": "3\n.E.\nE.E\n.E.", "output": "1 1\n2 2\n3 1" }, { "input": "3\nEEE\nE..\nE.E", "output": "-1" }, { "input": "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE", "output": "1 3\n2 2\n3 2\n4 1\n5 3" }, { "input": "3\n.EE\n.EE\n.EE", "output": "1 1\n2 1\n3 1" }, { "in...
1,597,839,187
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) s=[] for i in range(n): s.append(input()) r,cl=0,0 for i in range(n): c=0 for j in range(n): if s[i][j]=='E': c=c+1 r=max(r,c) for i in range(n): c=0 for j in range(n): if s[j][i]=='E': c=c+1 cl=max(cl,c) if r==n and cl=...
Title: Purification Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* ...
```python n=int(input()) s=[] for i in range(n): s.append(input()) r,cl=0,0 for i in range(n): c=0 for j in range(n): if s[i][j]=='E': c=c+1 r=max(r,c) for i in range(n): c=0 for j in range(n): if s[j][i]=='E': c=c+1 cl=max(cl,c) if r=...
-1
182
A
Battlefield
PROGRAMMING
2,200
[ "geometry", "graphs", "implementation", "shortest paths" ]
null
null
Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with *n* trenches dug on it. The trenches are segments on a plane parallel to the coordinate axes. No two trenches intersect. There is a huge enemy laser far away from Vas...
The first line contains two space-separated integers: *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000), — the duration of charging and the duration of shooting, in seconds. The second line contains four space-separated integers: *A**x*, *A**y*, *B**x*, *B**y* (<=-<=104<=≤<=*A**x*,<=*A**y*,<=*B**x*,<=*B**y*<=≤<=104) — the coordi...
If Vasya can get from point *A* to point *B*, print the minimum time he will need for it. Otherwise, print number -1. The answer will be considered correct if the absolute or relative error does not exceed 10<=-<=4
[ "2 4\n0 5 6 5\n3\n0 0 0 4\n1 1 4 1\n6 0 6 4\n", "5 10\n0 0 10 10\n1\n5 0 5 9\n" ]
[ "19.0000000000\n", "-1\n" ]
none
3,000
[]
1,691,930,207
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1691930207.6039705")# 1691930207.603982
Title: Battlefield Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lagged behind at the University and got to the battlefield. Just joking! He's simply playing some computer game. The field is a flat platform with *n* trenches dug on it. The trenches are segments on a plane parallel ...
```python print("_RANDOM_GUESS_1691930207.6039705")# 1691930207.603982 ```
0
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,592,690,410
2,147,483,647
PyPy 3
OK
TESTS
33
155
0
import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n= int(input()) if(n==4): print(1) elif(n==7): print(2) else: add = 2 ans = 0 n = str(n) for i in range(len(n)): ans+=(2**...
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n= int(input()) if(n==4): print(1) elif(n==7): print(2) else: add = 2 ans = 0 n = str(n) for i in range(len(n)): ...
3
519
C
A and B and Team Training
PROGRAMMING
1,300
[ "greedy", "implementation", "math", "number theory" ]
null
null
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session.
Print the maximum number of teams that can be formed.
[ "2 6\n", "4 5\n" ]
[ "2\n", "3\n" ]
Let's represent the experienced players as XP and newbies as NB. In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB). In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).
1,500
[ { "input": "2 6", "output": "2" }, { "input": "4 5", "output": "3" }, { "input": "1 1", "output": "0" }, { "input": "3 3", "output": "2" }, { "input": "500000 500000", "output": "333333" }, { "input": "70 100", "output": "56" }, { "input": ...
1,630,038,165
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define ll long long //#define int ll #define pb push_back #define fi first #define se second #define debug(x) cout << x << "\n" #define yes() cout << "YES\n" #define no() cout << "NO\n" #define pi 3.1415926535897932384626433832795028841971693993751 using namespace std; void solve ...
Title: A and B and Team Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea...
```python #include <bits/stdc++.h> #define ll long long //#define int ll #define pb push_back #define fi first #define se second #define debug(x) cout << x << "\n" #define yes() cout << "YES\n" #define no() cout << "NO\n" #define pi 3.1415926535897932384626433832795028841971693993751 using namespace std; v...
-1
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,699,221,255
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
0
249
268,390,400
def eat(L, B): years = 0 while L < B: L = L * 3 B = B * 2 years += 1 return (years) Limak, Bob = input().split() print (eat(Limak, Bob))
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python def eat(L, B): years = 0 while L < B: L = L * 3 B = B * 2 years += 1 return (years) Limak, Bob = input().split() print (eat(Limak, Bob)) ```
0
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 9...
1,586,513,175
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
186
0
f = list(map(int,input().split())) count = f[0]//3 c = f[0]%3 count1 = f[1]//3 c1 = f[1]%3 count2 = f[2]//3 c2 = f[2]%3 g = (c+c1+c2)//3 print(g+count+count1+count2) ...
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red fl...
```python f = list(map(int,input().split())) count = f[0]//3 c = f[0]%3 count1 = f[1]//3 c1 = f[1]%3 count2 = f[2]//3 c2 = f[2]%3 g = (c+c1+c2)//3 print(g+count+count1+count2) ...
0
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha...
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" },...
1,555,572,580
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
x=input() y=input() z='' for i in range(len(x)): if(x[i]==y[i]): z+='z' elif(x[i]!=y[i]): z+=y[i] if(z==y): print("-1") else: print(z)
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string...
```python x=input() y=input() z='' for i in range(len(x)): if(x[i]==y[i]): z+='z' elif(x[i]!=y[i]): z+=y[i] if(z==y): print("-1") else: print(z) ```
0
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ...
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=...
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a...
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "outpu...
1,497,513,713
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
(n,m,k) = (int(i) for i in input().split()) dms = [int(i) for i in input().split()] right = -1 rastr = -1 left = -1 rastl = -1 for i in range(m, n): if dms[i]!=0 and dms[i]<=k: right = i rastr = i+1-m break for i in range(m-1,max(m-rastr,0)-1,-1): if dms[i]!=0 and dms[i]<=k: rastl = m-1-i if (ra...
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li...
```python (n,m,k) = (int(i) for i in input().split()) dms = [int(i) for i in input().split()] right = -1 rastr = -1 left = -1 rastl = -1 for i in range(m, n): if dms[i]!=0 and dms[i]<=k: right = i rastr = i+1-m break for i in range(m-1,max(m-rastr,0)-1,-1): if dms[i]!=0 and dms[i]<=k: rastl = m-1...
0
961
A
Tetris
PROGRAMMING
900
[ "implementation" ]
null
null
You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. ...
The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares. The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear.
Print one integer — the amount of points you will receive.
[ "3 9\n1 1 2 2 2 3 1 2 3\n" ]
[ "2\n" ]
In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$). After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing...
0
[ { "input": "3 9\n1 1 2 2 2 3 1 2 3", "output": "2" }, { "input": "1 7\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "3 5\n1 1 1 2 3", "output": "1" }, { "input": "4 6\n4 4 4 4 4 4", "output": "0" }, { "input": "4 6\...
1,553,590,097
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
n,m=map(int,input().split()) mas=[0]*(n) mas[0]=10**5 a=list(map(int,input.split())) for i in a: mas[i]+=1 print(min(mas))
Title: Tetris Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a following process. There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo...
```python n,m=map(int,input().split()) mas=[0]*(n) mas[0]=10**5 a=list(map(int,input.split())) for i in a: mas[i]+=1 print(min(mas)) ```
-1
620
A
Professor GukiZ's Robot
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe...
The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot. The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot.
Print the only integer *d* — the minimal number of steps to get the finish position.
[ "0 0\n4 5\n", "3 4\n6 1\n" ]
[ "5\n", "3\n" ]
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position. In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th...
0
[ { "input": "0 0\n4 5", "output": "5" }, { "input": "3 4\n6 1", "output": "3" }, { "input": "0 0\n4 6", "output": "6" }, { "input": "1 1\n-3 -5", "output": "6" }, { "input": "-1 -1\n-10 100", "output": "101" }, { "input": "1 -1\n100 -100", "output":...
1,453,615,685
2,147,483,647
Python 3
OK
TESTS
75
62
0
x1, y1 = list(map(int, input().split())) x2, y2 = list(map(int, input().split())) print(max(abs(x1-x2), abs(y1-y2)))
Title: Professor GukiZ's Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ...
```python x1, y1 = list(map(int, input().split())) x2, y2 = list(map(int, input().split())) print(max(abs(x1-x2), abs(y1-y2))) ```
3
856
B
Similar Words
PROGRAMMING
2,300
[ "dp", "hashing", "strings", "trees" ]
null
null
Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word *x* is a word *y* that can be obtained from *x* by removing zero or more last letters of *x*. Let us call two words similar, if one of them can be obtained from the other by removing its first letter. You are given a set *S* of wor...
Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases. The descriptions of test cases follow. The first line of each description contains an integer *n* — the number of words in the set *S* (1<=≤<=*n*<=≤<=106). Each of the following *n* lines conta...
For each test case print one line that contains one integer *m* — the maximal number of words that *X* can contain.
[ "2\n3\naba\nbaba\naaab\n2\naa\na\n" ]
[ "6\n1\n" ]
none
0
[]
1,691,862,211
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1691862211.6091032")# 1691862211.60912
Title: Similar Words Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let us call a non-empty sequence of lowercase English letters a word. Prefix of a word *x* is a word *y* that can be obtained from *x* by removing zero or more last letters of *x*. Let us call two words similar, if one o...
```python print("_RANDOM_GUESS_1691862211.6091032")# 1691862211.60912 ```
0
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,594,393,783
2,147,483,647
Python 3
OK
TESTS
43
109
6,963,200
inputStr = input() comb = [0,0,0] count = 0 for i in range(len(inputStr)): if inputStr[i] == 'Q': comb[0] == 1 for j in range(i, len(inputStr)): if inputStr[j] == 'A': comb[1] == 1 for k in range(j, len(inputStr)): if inputStr...
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python inputStr = input() comb = [0,0,0] count = 0 for i in range(len(inputStr)): if inputStr[i] == 'Q': comb[0] == 1 for j in range(i, len(inputStr)): if inputStr[j] == 'A': comb[1] == 1 for k in range(j, len(inputStr)): i...
3
436
B
Om Nom and Spiders
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular *n*<=×<=*m* field. The park has *k* spiders, each spider at t...
The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*,<=*m*<=≤<=2000; 0<=≤<=*k*<=≤<=*m*(*n*<=-<=1)). Each of the next *n* lines contains *m* characters — the description of the park. The characters in the *i*-th line describe the *i*-th row of the park field. If the character in the line equals ".", that ...
Print *m* integers: the *j*-th integer must show the number of spiders Om Nom will see if he starts his walk from the *j*-th cell of the first row. The cells in any row of the field are numbered from left to right.
[ "3 3 4\n...\nR.L\nR.U\n", "2 2 2\n..\nRL\n", "2 2 2\n..\nLR\n", "3 4 8\n....\nRRLL\nUUUU\n", "2 2 2\n..\nUU\n" ]
[ "0 2 2 ", "1 1 ", "0 0 ", "1 3 3 1 ", "0 0 " ]
Consider the first sample. The notes below show how the spider arrangement changes on the field over time: Character "*" represents a cell that contains two spiders at the same time. - If Om Nom starts from the first cell of the first row, he won't see any spiders. - If he starts from the second cell, he will see t...
1,000
[ { "input": "3 3 4\n...\nR.L\nR.U", "output": "0 2 2 " }, { "input": "2 2 2\n..\nRL", "output": "1 1 " }, { "input": "2 2 2\n..\nLR", "output": "0 0 " }, { "input": "3 4 8\n....\nRRLL\nUUUU", "output": "1 3 3 1 " }, { "input": "2 2 2\n..\nUU", "output": "0 0 " ...
1,660,110,056
2,147,483,647
PyPy 3-64
OK
TESTS
36
170
8,704,000
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) g = [input()[:-1] for _ in range(n)] d = [0]*m for i in range(1, n): for j in range(m): if g[i][j] == 'R': if j + i < m: d[j+i] += 1 elif g[i][j] == 'L': if j - i >= 0: ...
Title: Om Nom and Spiders Time Limit: None seconds Memory Limit: None megabytes Problem Description: Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. Th...
```python import sys input = sys.stdin.readline n, m, k = map(int, input().split()) g = [input()[:-1] for _ in range(n)] d = [0]*m for i in range(1, n): for j in range(m): if g[i][j] == 'R': if j + i < m: d[j+i] += 1 elif g[i][j] == 'L': if j - ...
3
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where bel...
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 1...
1,613,704,771
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
512,000
import os import sys import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable sys.path.append(os.path.dirname(os.path.abspath(__file__))) from utils import to_one_hot, mixup_process, get_lambda from load_data import per_image_standardization ...
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that...
```python import os import sys import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable sys.path.append(os.path.dirname(os.path.abspath(__file__))) from utils import to_one_hot, mixup_process, get_lambda from load_data import per_image_standa...
-1
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe...
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta...
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, ...
1,696,806,374
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
x = int(input()) final = 0 for i in range(x): y = input() count = 0 if (y[0] == "1"): count+=1 if (y[2] == "1"): count+=1 if (y[3] == "1"): count+=1 if (count >= 2): final+=1 print(final)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid...
```python x = int(input()) final = 0 for i in range(x): y = input() count = 0 if (y[0] == "1"): count+=1 if (y[2] == "1"): count+=1 if (y[3] == "1"): count+=1 if (count >= 2): final+=1 print(final) ```
0
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, ...
1,680,276,075
2,147,483,647
PyPy 3-64
OK
TESTS
23
186
3,174,400
def count_primes(num): #does not consider num as a prime number count = 0 for divisor in range(2, int(num**0.5)+1): if num % divisor == 0: count += 1 while num % divisor == 0: num /= divisor if num > 1: count += 1 #num itself is prime return count ...
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in...
```python def count_primes(num): #does not consider num as a prime number count = 0 for divisor in range(2, int(num**0.5)+1): if num % divisor == 0: count += 1 while num % divisor == 0: num /= divisor if num > 1: count += 1 #num itself is prime retur...
3.947587
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son...
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE...
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "...
1,690,386,956
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
s = input() result = '' for itm in s: result += itm if result == 'WUB': result = '' if 'WUB' in result[len(result) - 3: ]: result = result[:len(result) - 3] print(result)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consist...
```python s = input() result = '' for itm in s: result += itm if result == 'WUB': result = '' if 'WUB' in result[len(result) - 3: ]: result = result[:len(result) - 3] print(result) ```
0
492
C
Vanya and Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya mu...
The first line contains three integers *n*, *r*, *avg* (1<=≤<=*n*<=≤<=105, 1<=≤<=*r*<=≤<=109, 1<=≤<=*avg*<=≤<=*min*(*r*,<=106)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following *n* lines contains space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*<...
In the first line print the minimum number of essays.
[ "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n", "2 5 4\n5 2\n5 2\n" ]
[ "4\n", "0\n" ]
In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
1,500
[ { "input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "output": "4" }, { "input": "2 5 4\n5 2\n5 2", "output": "0" }, { "input": "6 5 5\n1 7\n2 4\n3 5\n4 6\n5 6\n4 7", "output": "63" }, { "input": "1 1000000000 1000000\n1 1000000", "output": "999999000000" }, { "input": "1...
1,694,713,457
2,147,483,647
PyPy 3-64
OK
TESTS
39
702
14,643,200
def solve(a, b, r, avg): diff = max(0, len(a) * avg - sum(a)) sorted_indices = sorted(range(len(a)), key=lambda i: b[i]) result = 0 index = 0 while diff != 0: raise_num = min(diff, r - a[sorted_indices[index]]) result += raise_num * b[sorted_indices[index]] ...
Title: Vanya and Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and...
```python def solve(a, b, r, avg): diff = max(0, len(a) * avg - sum(a)) sorted_indices = sorted(range(len(a)), key=lambda i: b[i]) result = 0 index = 0 while diff != 0: raise_num = min(diff, r - a[sorted_indices[index]]) result += raise_num * b[sorted_indices[index...
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,610,574,421
2,147,483,647
PyPy 3
OK
TESTS
34
218
0
n = int(input()) freq = {} for _ in range(n): s = input() freq[s] = freq.get(s, 0) + 1 keys = list(freq.keys()) if len(keys) == 1: print(keys[0]) else: if freq[keys[0]] < freq[keys[1]]: print(keys[1]) else: print(keys[0])
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python n = int(input()) freq = {} for _ in range(n): s = input() freq[s] = freq.get(s, 0) + 1 keys = list(freq.keys()) if len(keys) == 1: print(keys[0]) else: if freq[keys[0]] < freq[keys[1]]: print(keys[1]) else: print(keys[0]) ```
3.9455
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should cons...
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter...
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcde...
1,631,545,535
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
6,656,000
inp = input() inp = inp.split() if inp[0]== "4" and inp[-1] == "3": print("java") elif inp[0] == "6" and inp[-1] == "6": print("python") elif inp[0] == "5" and inp[-1] == "2": print("phphp")
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the foll...
```python inp = input() inp = inp.split() if inp[0]== "4" and inp[-1] == "3": print("java") elif inp[0] == "6" and inp[-1] == "6": print("python") elif inp[0] == "5" and inp[-1] == "2": print("phphp") ```
0
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack ...
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona ...
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input":...
1,480,249,146
2,147,483,647
Python 3
OK
TESTS
89
77
0
n, a, b, c = map(int, input().split()) to_buy = (4 - (n % 4)) % 4 b = min(a * 2, b) c = min(a * 3, a + b, c) # possibilities: if to_buy == 3: print(min(3*a, a+b, c)) elif to_buy == 2: print(min(2*a, b, 2*c)) elif to_buy == 1: print(min(a, b+c, 3*c)) else: print(0)
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the sh...
```python n, a, b, c = map(int, input().split()) to_buy = (4 - (n % 4)) % 4 b = min(a * 2, b) c = min(a * 3, a + b, c) # possibilities: if to_buy == 3: print(min(3*a, a+b, c)) elif to_buy == 2: print(min(2*a, b, 2*c)) elif to_buy == 1: print(min(a, b+c, 3*c)) else: print(0) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≤<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w...
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,472,091,580
2,147,483,647
Python 3
OK
TESTS
34
62
4,608,000
n=int(input()) tl = list(map(int, input().split())) time=cnt=0 while cnt <15 and time<90: time+=1 if tl.count(time)>0: cnt=0 else: cnt+=1 print(time)
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim...
```python n=int(input()) tl = list(map(int, input().split())) time=cnt=0 while cnt <15 and time<90: time+=1 if tl.count(time)>0: cnt=0 else: cnt+=1 print(time) ```
3
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,698,658,493
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
ls=[list(map(int,input().split())) for i in range(5)] a = [] for x in range(len(ls)): for y in range(len(ls[x])): a.append(ls[x][y]) print(abs(12 - a.index(1)))
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri...
```python ls=[list(map(int,input().split())) for i in range(5)] a = [] for x in range(len(ls)): for y in range(len(ls[x])): a.append(ls[x][y]) print(abs(12 - a.index(1))) ```
0
0
none
none
none
0
[ "none" ]
null
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k...
[ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ]
[ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ]
none
0
[ { "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z" }, { "input": "hastalavistababy\nhastalavistababy", "output": "0" }, { "input": "merrychristmas\nchristmasmerry", "output": "-1" }, { "input": "kusyvdgccw\nkusyvdgccw", "output": "0" }, { "input": "...
1,557,816,320
2,147,483,647
Python 3
OK
TESTS
86
124
0
s = input() t = input() d, u = set(), set() for i in range(len(s)): mn, mx = min(s[i], t[i]), max(s[i], t[i]) if (s[i] in u or t[i] in u) and (mn, mx) not in d: print(-1) exit() u.add(s[i]) u.add(t[i]) d.add((mn, mx)) res = [x for x in d if x[0] != x[1]] print(len(res))...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, ...
```python s = input() t = input() d, u = set(), set() for i in range(len(s)): mn, mx = min(s[i], t[i]), max(s[i], t[i]) if (s[i] in u or t[i] in u) and (mn, mx) not in d: print(-1) exit() u.add(s[i]) u.add(t[i]) d.add((mn, mx)) res = [x for x in d if x[0] != x[1]] print...
3
349
A
Cinema Line
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "...
1,625,472,816
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
n=int(input()) x=list(map(int,input().split())) s=0 flag=0 if all(x[i-1]<=x[i] for i in range(1,len(x))): for i in range(len(x)): if x[i]==25: s+=25 for i in range(len(x)): if x[i]!=25: r=x[i]-25 if s>=r: flag=1 s-=r if flag==1: prin...
Title: Cinema Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin...
```python n=int(input()) x=list(map(int,input().split())) s=0 flag=0 if all(x[i-1]<=x[i] for i in range(1,len(x))): for i in range(len(x)): if x[i]==25: s+=25 for i in range(len(x)): if x[i]!=25: r=x[i]-25 if s>=r: flag=1 s-=r if flag==1:...
0
325
A
Square and Rectangles
PROGRAMMING
1,500
[ "implementation" ]
null
null
You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the ...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=5). Next *n* lines contain four integers each, describing a single rectangle: *x*1, *y*1, *x*2, *y*2 (0<=≤<=*x*1<=&lt;<=*x*2<=≤<=31400,<=0<=≤<=*y*1<=&lt;<=*y*2<=≤<=31400) — *x*1 and *x*2 are *x*-coordinates of the left and right edges of the rectangle, and *y*...
In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.
[ "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "output": "YES" }, { "input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5", "output": "NO" }, { "input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400", "output": "NO...
1,383,984,855
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
307,200
for i in range(int(input())): x1, y1, x2, y2 = map(int, input().split()) a1, b1, a2, b2 = min(a1, x1), min(b1, y1), max(a2, x2), max(b2, y2) s += (x2 - x1) * (y2 - y1) print('YES' if s == (a2 - a1) * (b2 - b1) else 'NO')
Title: Square and Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there...
```python for i in range(int(input())): x1, y1, x2, y2 = map(int, input().split()) a1, b1, a2, b2 = min(a1, x1), min(b1, y1), max(a2, x2), max(b2, y2) s += (x2 - x1) * (y2 - y1) print('YES' if s == (a2 - a1) * (b2 - b1) else 'NO') ```
-1
0
none
none
none
0
[ "none" ]
null
null
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ...
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the ...
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
[ "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
0
[ { "input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "output": "NO" }, { "input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "output": "YES" }, ...
1,539,558,528
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
def sor(s): ind=-1 x=1000 y=x for i in range(4): if s[i][0]+s[i][1]<x or (x==s[i][0]+s[i][1] and y>s[i][0]): ind=i x=s[i][0]+s[i][1] y=s[i][0] s=s[ind::]+s[0:ind] return s def inn(s,s1): x=s[0][0];x1=s[2][0];y=s[0][1];y1=s[1][1] c1...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be pa...
```python def sor(s): ind=-1 x=1000 y=x for i in range(4): if s[i][0]+s[i][1]<x or (x==s[i][0]+s[i][1] and y>s[i][0]): ind=i x=s[i][0]+s[i][1] y=s[i][0] s=s[ind::]+s[0:ind] return s def inn(s,s1): x=s[0][0];x1=s[2][0];y=s[0][1];y1=s[1][...
0
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft...
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1...
1,638,648,807
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
number_snacks=int(input()) snacks=[int(x) for x in input().split()] stack=[] output=[] i=0 while snacks: if snacks[i]==max(snacks): stack.append(snacks[i]) decrease=1 while snacks[i]-decrease in stack: stack.append(snacks[i]-decrease) output.remove(snacks[i]-decrease)...
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh...
```python number_snacks=int(input()) snacks=[int(x) for x in input().split()] stack=[] output=[] i=0 while snacks: if snacks[i]==max(snacks): stack.append(snacks[i]) decrease=1 while snacks[i]-decrease in stack: stack.append(snacks[i]-decrease) output.remove(snacks[i]...
0
230
B
T-primes
PROGRAMMING
1,300
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st...
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
500
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "...
1,699,811,880
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
4
4,000
2,355,200
from math import sqrt def primer(m: int): primes = [2] for i in range(3, m + 1, 2): prime = True for j in primes: if i % j == 0: prime = False break if prime: primes.append(i) return primes def main(): i...
Title: T-primes Time Limit: None seconds Memory Limit: None megabytes Problem Description: We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors. You are given an ar...
```python from math import sqrt def primer(m: int): primes = [2] for i in range(3, m + 1, 2): prime = True for j in primes: if i % j == 0: prime = False break if prime: primes.append(i) return primes def main...
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 i...
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"...
1,481,699,666
2,147,483,647
Python 3
OK
TESTS
32
124
0
a=int(input()) b=input().split() s=0 t=0 for i in range(a): b[i]=int(b[i])%2 for i in range(a): if b[i]==0: s=s+1 else: t=t+1 if s>t: for i in range(a): if b[i]==1: print(i+1) else: for i in range(a): if b[i]==0: print(i+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 — t...
```python a=int(input()) b=input().split() s=0 t=0 for i in range(a): b[i]=int(b[i])%2 for i in range(a): if b[i]==0: s=s+1 else: t=t+1 if s>t: for i in range(a): if b[i]==1: print(i+1) else: for i in range(a): if b[i]==0: pri...
3.969
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 ex...
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...
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 ...
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...
1,694,102,771
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
n = int(input()) post= 0 m=0 for _ in range(n): a,b = map(int, input().split()) post-= a post+= b max_capacity = max(max_capacity, post) print(max_capacity)
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 ...
```python n = int(input()) post= 0 m=0 for _ in range(n): a,b = map(int, input().split()) post-= a post+= b max_capacity = max(max_capacity, post) print(max_capacity) ```
-1
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9",...
1,693,213,287
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
28
186
0
n=int(input()) n1=str(n) k=list(n1) i=0 flag=True while i < len(k)-2 : if k[i]=='1' and k[i+1] == '4' and k[i+2]== '4': i+=3 elif k[i] == '1' and k[i + 1] == '4': i += 2 elif k[i] == '1' : i+=1 else : flag=False break if i == len(k)-1 : if ...
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're ...
```python n=int(input()) n1=str(n) k=list(n1) i=0 flag=True while i < len(k)-2 : if k[i]=='1' and k[i+1] == '4' and k[i+2]== '4': i+=3 elif k[i] == '1' and k[i + 1] == '4': i += 2 elif k[i] == '1' : i+=1 else : flag=False break if i == len(k)-1 ...
0
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,632,994,508
2,147,483,647
Python 3
OK
TESTS
59
62
6,758,400
import math a,b=map(int,input().split()) c=min(a,b) print(math.factorial(c))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python import math a,b=map(int,input().split()) c=min(a,b) print(math.factorial(c)) ```
3
0
none
none
none
0
[ "none" ]
null
null
A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([...
The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.
In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.
[ "([])\n", "(((\n" ]
[ "1\n([])\n", "0\n\n" ]
none
0
[ { "input": "([])", "output": "1\n([])" }, { "input": "(((", "output": "0" }, { "input": "(][)", "output": "0" }, { "input": "(()[))()[]", "output": "1\n()[]" }, { "input": "(][](](][[(][", "output": "1\n[]" }, { "input": "((])(]]))(](((()[[()[[[)([]()]...
1,641,668,596
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
218
0
import sys inpu = sys.stdin.readline prin = sys.stdout.write s = inpu().rstrip('\n') l = 0 stack = [] brackets = {'(', '['} count = 0 real = '' ans = [] for i in s : if i in brackets : stack.append(i) ans.append(i) elif len(stack) == 0: continue elif i == ']' : ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" b...
```python import sys inpu = sys.stdin.readline prin = sys.stdout.write s = inpu().rstrip('\n') l = 0 stack = [] brackets = {'(', '['} count = 0 real = '' ans = [] for i in s : if i in brackets : stack.append(i) ans.append(i) elif len(stack) == 0: continue elif i == ']...
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
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...
1,654,107,943
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
614,400
n=input() a=[] b=[] c=[] for i in range(int(n)): (x,y,z)=input().split() p=a.append(x) q=b.append(y) r=c.append(z) from functools import reduce xcoor=reduce(lambda u,y:int(u)+int(y) , a) ycoor=reduce(lambda u,y:int(u)+int(y) , b) zcoor=reduce(lambda u,y:int(u)+int(y) , c) if ((xcoor=="0") a...
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. S...
```python n=input() a=[] b=[] c=[] for i in range(int(n)): (x,y,z)=input().split() p=a.append(x) q=b.append(y) r=c.append(z) from functools import reduce xcoor=reduce(lambda u,y:int(u)+int(y) , a) ycoor=reduce(lambda u,y:int(u)+int(y) , b) zcoor=reduce(lambda u,y:int(u)+int(y) , c) if ((xco...
0
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the n...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ...
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe repos...
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc...
1,688,702,811
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n=int(input()) a=[["polycarp"]] m=1 for _ in range(n): s=input().split() want=s[-1].lower() l=len(a) for i in range(l): if a[i][-1]==want: a[i].append(s[0].lower()) l1=len(a[i]) if l1>m: m=l1 print(m)
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. ...
```python n=int(input()) a=[["polycarp"]] m=1 for _ in range(n): s=input().split() want=s[-1].lower() l=len(a) for i in range(l): if a[i][-1]==want: a[i].append(s[0].lower()) l1=len(a[i]) if l1>m: m=l1 print(m) ```
0
149
A
Business trip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water...
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
[ "5\n1 1 1 1 2 2 3 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n", "11\n1 1 4 1 1 5 1 1 4 1 1 1\n" ]
[ "2\n", "0\n", "3\n" ]
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f...
500
[ { "input": "5\n1 1 1 1 2 2 3 2 2 1 1 1", "output": "2" }, { "input": "0\n0 0 0 0 0 0 0 1 1 2 3 0", "output": "0" }, { "input": "11\n1 1 4 1 1 5 1 1 4 1 1 1", "output": "3" }, { "input": "15\n20 1 1 1 1 2 2 1 2 2 1 1", "output": "1" }, { "input": "7\n8 9 100 12 14 ...
1,693,313,801
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
124
0
n=int(input()) l=list(map(int,input().split())) l.sort() l=l[::-1] sum=0 c=0 for i in range(len(l)): if(sum>=n): break sum=sum+l[i] c=c+1 print(c)
Title: Business trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya open...
```python n=int(input()) l=list(map(int,input().split())) l.sort() l=l[::-1] sum=0 c=0 for i in range(len(l)): if(sum>=n): break sum=sum+l[i] c=c+1 print(c) ```
0
305
B
Continued Fractions
PROGRAMMING
1,700
[ "brute force", "implementation", "math" ]
null
null
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction. The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a...
Print "YES" if these fractions are equal and "NO" otherwise.
[ "9 4\n2\n2 4\n", "9 4\n3\n2 3 1\n", "9 4\n3\n1 2 4\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f3...
1,000
[ { "input": "9 4\n2\n2 4", "output": "YES" }, { "input": "9 4\n3\n2 3 1", "output": "YES" }, { "input": "9 4\n3\n1 2 4", "output": "NO" }, { "input": "39088169 24157817\n36\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 2", "output": "YES" }, { ...
1,515,788,728
2,147,483,647
Python 3
OK
TESTS
49
216
6,860,800
from fractions import gcd p,q=map(int,input().split()) gc=gcd(p,q) p//=gc q//=gc n=int(input()) a=list(map(int,input().split())) def add(a,b): res=[] a[0]*=b[1] b[0]*=a[1] temp=b[1]*a[1] top=a[0]+b[0] gc=gcd(top,temp) temp//=gc top//=gc; res.append(top) res.append(temp) retur...
Title: Continued Fractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. In...
```python from fractions import gcd p,q=map(int,input().split()) gc=gcd(p,q) p//=gc q//=gc n=int(input()) a=list(map(int,input().split())) def add(a,b): res=[] a[0]*=b[1] b[0]*=a[1] temp=b[1]*a[1] top=a[0]+b[0] gc=gcd(top,temp) temp//=gc top//=gc; res.append(top) res.append(temp)...
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 i...
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"...
1,633,770,370
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n = int(input()) m = list(map(int,input().split)) even = 0 odd = 0 for i in m: if i%2 == 0 : even += 1 elif i%2 == 1: odd += 1 if even == 1: for i in m: if i%2 == 0: print(m.index(i)) else: continue if odd == 1: for i in m : ...
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 — t...
```python n = int(input()) m = list(map(int,input().split)) even = 0 odd = 0 for i in m: if i%2 == 0 : even += 1 elif i%2 == 1: odd += 1 if even == 1: for i in m: if i%2 == 0: print(m.index(i)) else: continue if odd == 1: for i in m...
-1
665
C
Simple Strings
PROGRAMMING
1,300
[ "dp", "greedy", "strings" ]
null
null
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th...
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters.
[ "aab\n", "caaab\n", "zscoder\n" ]
[ "bab\n", "cabab\n", "zscoder\n" ]
none
0
[ { "input": "aab", "output": "bab" }, { "input": "caaab", "output": "cabab" }, { "input": "zscoder", "output": "zscoder" }, { "input": "u", "output": "u" }, { "input": "h", "output": "h" }, { "input": "dtottttotd", "output": "dtotataotd" }, { ...
1,652,869,198
2,147,483,647
PyPy 3-64
OK
TESTS
27
139
43,520,000
s=list(input()+'a') for i in range(len(s)-2): if s[i]==s[i+1]: s[i+1]=list({'a', 'b', 'c'}-{s[i]}-{s[i+2]})[0] print(''.join(s[:-1]))
Title: Simple Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wa...
```python s=list(input()+'a') for i in range(len(s)-2): if s[i]==s[i+1]: s[i+1]=list({'a', 'b', 'c'}-{s[i]}-{s[i+2]})[0] print(''.join(s[:-1])) ```
3
765
C
Table Tennis Game 2
PROGRAMMING
1,200
[ "math" ]
null
null
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* poi...
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
[ "11 11 5\n", "11 2 3\n" ]
[ "1\n", "-1\n" ]
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
1,250
[ { "input": "11 11 5", "output": "1" }, { "input": "11 2 3", "output": "-1" }, { "input": "1 5 9", "output": "14" }, { "input": "2 3 3", "output": "2" }, { "input": "1 1000000000 1000000000", "output": "2000000000" }, { "input": "2 3 5", "output": "...
1,634,245,669
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
61
0
k,a,b = list(map(int, input().split())) if k > a: if b%k == 0: print(b//k) else: print(-1) if k > b: if a%k == 0: print(a//k) else: print(-1) if a > k and b > k: print((a//k) + (b//k))
Title: Table Tennis Game 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor...
```python k,a,b = list(map(int, input().split())) if k > a: if b%k == 0: print(b//k) else: print(-1) if k > b: if a%k == 0: print(a//k) else: print(-1) if a > k and b > k: print((a//k) + (b//k)) ```
0
93
E
Lostborn
PROGRAMMING
2,600
[ "dp", "math", "number theory" ]
E. Lostborn
2
256
Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good weapon and outfit as possible. One day, as he was reading the game's forum ...
The first line contains two integers: *n* and *k* (1<=≤<=*n*<=≤<=1013, 1<=≤<=*k*<=≤<=100). They are the indicator of Igor K's hero's strength and the number of hit indicators. The next line contains space-separated *k* integers *a**i* (1<=≤<=*a**i*<=≤<=1000). They are Lostborn sword's hit indicators. The given *k* num...
Print the single number — the damage that will be inflicted by Igor K.'s hero when he uses his new weapon. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "20 3\n2 3 5\n", "50 2\n15 8\n" ]
[ "6\n", "41\n" ]
none
2,500
[]
1,669,444,008
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
50
2,000
10,240,000
import math iin,k = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] a.sort(reverse = True) def c(n,y): if y == len(a)-1: return n-math.floor(n/a[-1]) elif n < a[-1]: return n else: return c(n,y+1)-c(math.floor(n/a[y]),y+1) if a[-1] == 1: ...
Title: Lostborn Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero ...
```python import math iin,k = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] a.sort(reverse = True) def c(n,y): if y == len(a)-1: return n-math.floor(n/a[-1]) elif n < a[-1]: return n else: return c(n,y+1)-c(math.floor(n/a[y]),y+1) if a[-1] =...
0
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" ...
1,506,002,891
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
1,107
22,835,200
n=int(input()) A=[] for i in range(n): a=list(map(int,input().split())) A.append(a) A.sort() m=0 for i in range(n): if i>0: if A[i][0]>=A[i-1][1]: continue else: m+=1 break if m>0: print('NO') else: print('YES')
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He ...
```python n=int(input()) A=[] for i in range(n): a=list(map(int,input().split())) A.append(a) A.sort() m=0 for i in range(n): if i>0: if A[i][0]>=A[i-1][1]: continue else: m+=1 break if m>0: print('NO') else: print('YES') ```
0
689
A
Mike and Cellphone
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "implementation" ]
null
null
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and ...
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in.
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line.
[ "3\n586\n", "2\n09\n", "9\n123456789\n", "3\n911\n" ]
[ "NO\n", "NO\n", "YES\n", "YES\n" ]
You can find the picture clarifying the first sample case in the statement above.
500
[ { "input": "3\n586", "output": "NO" }, { "input": "2\n09", "output": "NO" }, { "input": "9\n123456789", "output": "YES" }, { "input": "3\n911", "output": "YES" }, { "input": "3\n089", "output": "NO" }, { "input": "3\n159", "output": "YES" }, { ...
1,468,074,376
2,147,483,647
PyPy 3
OK
TESTS
94
140
0
n = input() s = set(map(int,input())) if all(map(lambda x: x&s!=set(),({1,4,7,0},{3,6,9,0},{7,0,9},{1,2,3}))): print("YES") else: print("NO")
Title: Mike and Cellphone Time Limit: None seconds Memory Limit: None megabytes Problem Description: While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equ...
```python n = input() s = set(map(int,input())) if all(map(lambda x: x&s!=set(),({1,4,7,0},{3,6,9,0},{7,0,9},{1,2,3}))): print("YES") else: print("NO") ```
3
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercise...
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos...
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 ...
1,650,824,920
2,147,483,647
Python 3
OK
TESTS
61
92
0
n=int(input()) a=list(map(int,input().split(" "))) chest=0 biceps=0 back=0 for i in range(n): if(i%3==0): chest+=a[i] elif(i%3==1): biceps+=a[i] elif(i%3==2): back+=a[i] if(chest>biceps and chest>back): print("chest") elif(biceps>chest and biceps>back): print("...
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ...
```python n=int(input()) a=list(map(int,input().split(" "))) chest=0 biceps=0 back=0 for i in range(n): if(i%3==0): chest+=a[i] elif(i%3==1): biceps+=a[i] elif(i%3==2): back+=a[i] if(chest>biceps and chest>back): print("chest") elif(biceps>chest and biceps>back): ...
3
39
F
Pacifist frogs
PROGRAMMING
1,300
[ "implementation" ]
F. Pacifist frogs
2
64
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to *...
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=109, 1<=≤<=*m*,<=*k*<=≤<=100) — the number of hills, frogs and mosquitoes respectively. The second line contains *m* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the lengths of the frogs’ jumps. The third line contains *k* integers — the numbers of the ...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to *m* in the order of the jump length given in the input data.
[ "5 3 5\n2 3 4\n1 2 3 4 5\n", "1000000000 2 3\n2 5\n999999995 999999998 999999996\n" ]
[ "2\n2 3\n", "1\n2\n" ]
none
0
[ { "input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3" }, { "input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2" }, { "input": "1 1 1\n1\n1", "output": "1\n1" }, { "input": "2 2 1\n2 1\n1", "output": "1\n1" }, { "input": "3 2 2\n2 4\n3...
1,578,281,796
2,147,483,647
Python 3
OK
TESTS
35
218
307,200
n, m, k = map(int, input().split()) x, y = n, [] a = map(int, input().split()) b = list(map(int, input().split())) for i, d in enumerate(a): c = 0 for t in b: if 0 == t % d: c += 1 if c < x: x = c y = [i + 1] elif c == x: y += i + 1, print(len(y)...
Title: Pacifist frogs Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that c...
```python n, m, k = map(int, input().split()) x, y = n, [] a = map(int, input().split()) b = list(map(int, input().split())) for i, d in enumerate(a): c = 0 for t in b: if 0 == t % d: c += 1 if c < x: x = c y = [i + 1] elif c == x: y += i + 1, pr...
3.943211
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000...
1,693,763,992
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
import math import sys #from decimal import Decimal, getcontext #getcontext().prec = 100 inputs = sys.stdin.read().splitlines() outputs = [] ln = 0 ''' 9xZER0 ''' if __name__ == "__main__": # Inputs n, m = map(int, inputs[ln].split()) # ln+=1 # n = int(inputs[ln]) #ln += 1 # l = [int(i...
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre...
```python import math import sys #from decimal import Decimal, getcontext #getcontext().prec = 100 inputs = sys.stdin.read().splitlines() outputs = [] ln = 0 ''' 9xZER0 ''' if __name__ == "__main__": # Inputs n, m = map(int, inputs[ln].split()) # ln+=1 # n = int(inputs[ln]) #ln += 1 # ...
0
612
A
The Text Splitting
PROGRAMMING
1,300
[ "brute force", "implementation", "strings" ]
null
null
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the st...
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* — the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The...
[ "5 2 3\nHello\n", "10 9 5\nCodeforces\n", "6 4 5\nPrivet\n", "8 1 1\nabacabac\n" ]
[ "2\nHe\nllo\n", "2\nCodef\norces\n", "-1\n", "8\na\nb\na\nc\na\nb\na\nc\n" ]
none
0
[ { "input": "5 2 3\nHello", "output": "2\nHe\nllo" }, { "input": "10 9 5\nCodeforces", "output": "2\nCodef\norces" }, { "input": "6 4 5\nPrivet", "output": "-1" }, { "input": "8 1 1\nabacabac", "output": "8\na\nb\na\nc\na\nb\na\nc" }, { "input": "1 1 1\n1", "ou...
1,588,871,796
2,147,483,647
Python 3
OK
TESTS
72
124
6,963,200
n, p, q = map(int, input().split()) s = input() if p > q: p, q = q, p for i in range(0, n + 1, q): if (n - i) % p == 0: print(i // q + (n - i) // p) for j in range(0, i, q): print(s[j:j + q]) for j in range(i, n, p): print(s[j:j + p]) exit(0) p...
Title: The Text Splitting Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H...
```python n, p, q = map(int, input().split()) s = input() if p > q: p, q = q, p for i in range(0, n + 1, q): if (n - i) % p == 0: print(i // q + (n - i) // p) for j in range(0, i, q): print(s[j:j + q]) for j in range(i, n, p): print(s[j:j + p]) ...
3
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not...
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201...
1,609,939,970
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
p = int(input()) a = [int(x) for x in str(p)] n, m = len(a), max(a) ans = [['0'] * n for i in range(m)] for i in range(n): for j in range(a[i]): ans[j][i] = '1' print(m) print(*[''.join(ans[i]) for i in range(m)])
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Repr...
```python p = int(input()) a = [int(x) for x in str(p)] n, m = len(a), max(a) ans = [['0'] * n for i in range(m)] for i in range(n): for j in range(a[i]): ans[j][i] = '1' print(m) print(*[''.join(ans[i]) for i in range(m)]) ```
0
424
B
Megacity
PROGRAMMING
1,200
[ "binary search", "greedy", "implementation", "sortings" ]
null
null
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with ...
The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=&lt;<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe...
In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don'...
[ "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n", "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n", "2 1\n1 1 999997\n2 2 1\n" ]
[ "2.8284271\n", "1.4142136\n", "-1" ]
none
1,000
[ { "input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "output": "2.8284271" }, { "input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "output": "1.4142136" }, { "input": "2 1\n1 1 999997\n2 2 1", "output": "-1" }, { "input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10", "out...
1,398,423,205
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
from math import* n, s = map(int, input().split()) dist = [] for i in range(n): a, b, c = map(int, input().split()) dist.append((a*a + b*b, c)) dist = sorted(dist) i = 0 while s < 1000000 and i < n - 1: s += dist[0][1] print(s) i += 1 if s < 1000000: print(-1) if i == 0: print...
Title: Megacity Time Limit: None seconds Memory Limit: None megabytes Problem Description: The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding...
```python from math import* n, s = map(int, input().split()) dist = [] for i in range(n): a, b, c = map(int, input().split()) dist.append((a*a + b*b, c)) dist = sorted(dist) i = 0 while s < 1000000 and i < n - 1: s += dist[0][1] print(s) i += 1 if s < 1000000: print(-1) if i == 0: ...
0
435
B
Pasha Maximizes
PROGRAMMING
1,400
[ "greedy" ]
null
null
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k...
The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100).
Print the maximum number that Pasha can get if he makes at most *k* swaps.
[ "1990 1\n", "300 0\n", "1034 2\n", "9090000078001234 6\n" ]
[ "9190\n", "300\n", "3104\n", "9907000008001234\n" ]
none
1,000
[ { "input": "1990 1", "output": "9190" }, { "input": "300 0", "output": "300" }, { "input": "1034 2", "output": "3104" }, { "input": "9090000078001234 6", "output": "9907000008001234" }, { "input": "1234 3", "output": "4123" }, { "input": "5 100", "...
1,664,002,891
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
46
0
a, b = map(int, input().split()) num=[int(x) for x in str(a)] k=0 yup=num def f(o): x=o global b global k p=0 if x.index(max(x))<=b: while max(x)!=x[0]: l = x.index(max(x)) x[l-1], x[l] = x[l], x[l-1] k=b return x else: retu...
Title: Pasha Maximizes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits ...
```python a, b = map(int, input().split()) num=[int(x) for x in str(a)] k=0 yup=num def f(o): x=o global b global k p=0 if x.index(max(x))<=b: while max(x)!=x[0]: l = x.index(max(x)) x[l-1], x[l] = x[l], x[l-1] k=b return x else: ...
0
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and...
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ...
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer ...
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n...
1,681,089,878
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
a = int(input()) b = int(input()) c = int(input()) x = b * a /100 print(x)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en...
```python a = int(input()) b = int(input()) c = int(input()) x = b * a /100 print(x) ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "outpu...
1,620,451,374
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
6,656,000
n = int(input()) if(n%4==0): print("4"*(n//4)) elif(n%7==0): print("4"*(n//4)) else: c=0 while(n>0): n-=4 c+=1 if(n%7==0): print("4"*c + "7"*(n//7)) exit(0) print(-1)
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) if(n%4==0): print("4"*(n//4)) elif(n%7==0): print("4"*(n//4)) else: c=0 while(n>0): n-=4 c+=1 if(n%7==0): print("4"*c + "7"*(n//7)) exit(0) print(-1) ```
0
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 exactl...
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", "ou...
1,651,302,791
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
62
102,400
from collections import Counter n, m = map(int,input().split()) p = Counter() while m > 0: a,b = map(int,input().split()) p[b] = a m -= 1 s = 0 while n > 0: mx = max(p) if p[mx] > 0: s += mx p[mx] -= 1 n -= 1 else: p.pop(mx) # if p[mx] == 0: # b...
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* mat...
```python from collections import Counter n, m = map(int,input().split()) p = Counter() while m > 0: a,b = map(int,input().split()) p[b] = a m -= 1 s = 0 while n > 0: mx = max(p) if p[mx] > 0: s += mx p[mx] -= 1 n -= 1 else: p.pop(mx) # if p[mx] == 0: ...
-1
295
B
Greg and Graph
PROGRAMMING
1,700
[ "dp", "graphs", "shortest paths" ]
null
null
Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: - The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=500) — the number of vertices in the graph. Next *n* lines contain *n* integers each — the graph adjacency matrix: the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*a**ij*<=≤<=105,<=*a**ii*<==<=0) represents the weight of the edge that goes from vertex *i* to verte...
Print *n* integers — the *i*-th number equals the required sum before the *i*-th step. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
[ "1\n0\n1\n", "2\n0 5\n4 0\n1 2\n", "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n" ]
[ "0 ", "9 0 ", "17 23 404 0 " ]
none
1,000
[ { "input": "1\n0\n1", "output": "0 " }, { "input": "2\n0 5\n4 0\n1 2", "output": "9 0 " }, { "input": "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3", "output": "17 23 404 0 " }, { "input": "4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 9700...
1,682,487,385
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
13
3,000
8,499,200
import sys n = int(sys.stdin.readline()) dis = [[1 << 31] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): w = map(int, sys.stdin.readline().split()) for j, v in enumerate(w): dis[i][j + 1] = v permutation = [0] + list(map(int, sys.stdin.readline().split())) st = [False] * (n...
Title: Greg and Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game...
```python import sys n = int(sys.stdin.readline()) dis = [[1 << 31] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): w = map(int, sys.stdin.readline().split()) for j, v in enumerate(w): dis[i][j + 1] = v permutation = [0] + list(map(int, sys.stdin.readline().split())) st = [F...
0
542
C
Idempotent functions
PROGRAMMING
2,000
[ "constructive algorithms", "graphs", "math" ]
null
null
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*),...
In the first line of the input there is a single integer *n* (1<=≤<=*n*<=≤<=200) — the size of function *f* domain. In the second line follow *f*(1),<=*f*(2),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n* for each 1<=≤<=*i*<=≤<=*n*), the values of a function.
Output minimum *k* such that function *f*(*k*)(*x*) is idempotent.
[ "4\n1 2 2 4\n", "3\n2 3 3\n", "3\n2 3 1\n" ]
[ "1\n", "2\n", "3\n" ]
In the first sample test function *f*(*x*) = *f*<sup class="upper-index">(1)</sup>(*x*) is already idempotent since *f*(*f*(1)) = *f*(1) = 1, *f*(*f*(2)) = *f*(2) = 2, *f*(*f*(3)) = *f*(3) = 2, *f*(*f*(4)) = *f*(4) = 4. In the second sample test: - function *f*(*x*) = *f*<sup class="upper-index">(1)</sup>(*x*) isn'...
750
[ { "input": "4\n1 2 2 4", "output": "1" }, { "input": "3\n2 3 3", "output": "2" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10", "output": "105" }, { "input": "20\n1 ...
1,430,670,997
2,197
Python 3
OK
TESTS
65
93
0
N =int(input()) inp =input().split() F =[0 for i in range(N)] for i in range(N): F[i] =int(inp[i])-1 ans_small =[0 for i in range(N+1)] for i in range(N): x =i y =i for j in range(N): x =F[x] y =F[F[y]] if x == y: ans_small[j+1] +=1 ans =-1 for i in range(1,N+1): if ans == -1: if ans_...
Title: Idempotent functions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *...
```python N =int(input()) inp =input().split() F =[0 for i in range(N)] for i in range(N): F[i] =int(inp[i])-1 ans_small =[0 for i in range(N+1)] for i in range(N): x =i y =i for j in range(N): x =F[x] y =F[F[y]] if x == y: ans_small[j+1] +=1 ans =-1 for i in range(1,N+1): if ans == -1: ...
3
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ...
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, o...
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4...
1,685,428,630
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
12,083,200
n = int(input()) l1 = list(map(int, input().split())) l2 = l1[::-1] #print(l1, l2) m = int(input()) ml = list(map(int, input().split())) count1 = 0 count2 = 0 for i in ml: count1 += l1.index(i) + 1 count2 += l2.index(i) + 1 print(count1, count2)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c...
```python n = int(input()) l1 = list(map(int, input().split())) l2 = l1[::-1] #print(l1, l2) m = int(input()) ml = list(map(int, input().split())) count1 = 0 count2 = 0 for i in ml: count1 += l1.index(i) + 1 count2 += l2.index(i) + 1 print(count1, count2) ```
0
89
E
Fire and Ice
PROGRAMMING
2,900
[ "greedy" ]
E. Fire and Ice
0
256
The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment *n* in length not far from the city walls. And only the frost magician Solomon can save the Frost Kingdom. The *n*-long segment is located at a distance equal exactly to 1 fr...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). The next line contains *n* numbers, the *i*-th of them represents the strength of the fire demon standing of the *i*-th position, an integer from 1 to 100. If there's no demon on the *i*-th position, then the *i*-th number equals to 0. It is guaranteed that t...
Print a string of minimum length, containing characters "L", "R" and "A" — the succession of actions leading to the required result. If there are several possible answers, print any of them.
[ "3\n1 0 1\n", "3\n0 2 0\n" ]
[ "ARARARALLLA", "ARARALAARALA" ]
none
2,500
[ { "input": "3\n1 0 1", "output": "ARARARALLLA" }, { "input": "3\n0 2 0", "output": "ARARALAARALA" }, { "input": "5\n3 1 2 2 4", "output": "ARALAARALAARARARARARALLLAARARARALAARALAARALLLLLA" }, { "input": "4\n2 2 2 2", "output": "ARARARARALLLLAARARARARALLLLA" }, { "...
1,690,486,658
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1690486657.947529")# 1690486657.9475489
Title: Fire and Ice Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: The Fire Lord attacked the Frost Kingdom. He has already got to the Ice Fortress, where the Snow Queen dwells. He arranged his army on a segment *n* in length not far from the city walls. And only the frost magician Solomon ca...
```python print("_RANDOM_GUESS_1690486657.947529")# 1690486657.9475489 ```
0