contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
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 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,609,723,639 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n,k = map(int,input().split())
divisor = 1
count = 0
while divisor != n:
if n%divisor==0:
count+=1
divisor+=1
print(count) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
n,k = map(int,input().split())
divisor = 1
count = 0
while divisor != n:
if n%divisor==0:
count+=1
divisor+=1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,694,442,293 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | from os import path
import sys
if(path.exists('inputf.in')):
sys.stdin=open("inputf.in","r")
sys.stdout=open("outputf.in","w")
#################Code####################
# for i in range(0,15):
# print(i)
string=input()
lst=list(string)
for i in range(1,len(lst)):
if(int(lst[i])>4):
temp=9-int(lst[i])
lst... | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
from os import path
import sys
if(path.exists('inputf.in')):
sys.stdin=open("inputf.in","r")
sys.stdout=open("outputf.in","w")
#################Code####################
# for i in range(0,15):
# print(i)
string=input()
lst=list(string)
for i in range(1,len(lst)):
if(int(lst[i])>4):
temp=9-int(lst... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,643,192,890 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n,x = map(int,input().split())
dc = 0
for i in range(n):
a = input().split()
if a[0] == "+":
x += int(a[1])
elif a[0] == "-":
if int(a[1]) > x:
dc += 1
else:
x -= int(a[1])
print(x,dc) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,x = map(int,input().split())
dc = 0
for i in range(n):
a = input().split()
if a[0] == "+":
x += int(a[1])
elif a[0] == "-":
if int(a[1]) > x:
dc += 1
else:
x -= int(a[1])
print(x,dc)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,678,353,359 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = int(input())
boys = list(map(int,input().split()))
m = int(input())
girls = list(map(int,input().split()))
boys = sorted(boys)
girls = sorted(girls)
k = min(n,m)
pair = 0
for i in range(k):
if abs(boys[i]-girls[i])<2:
pair += 1
else:
pair = pair
print(pair)
| Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
n = int(input())
boys = list(map(int,input().split()))
m = int(input())
girls = list(map(int,input().split()))
boys = sorted(boys)
girls = sorted(girls)
k = min(n,m)
pair = 0
for i in range(k):
if abs(boys[i]-girls[i])<2:
pair += 1
else:
pair = pair
print(pair)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,675,198,007 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 92 | 0 | def drift(visited,dx,dy,x,y):
for a in dx[x]:
if (x,a) not in visited and a!=y:
visited.append((x,a))
drift(visited,dx,dy,x,a)
for b in dy[y]:
if (b,y) not in visited and b!=x:
visited.append((b,y))
drift(visited,dx,dy,b,y)
return
n... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
def drift(visited,dx,dy,x,y):
for a in dx[x]:
if (x,a) not in visited and a!=y:
visited.append((x,a))
drift(visited,dx,dy,x,a)
for b in dy[y]:
if (b,y) not in visited and b!=x:
visited.append((b,y))
drift(visited,dx,dy,b,y)
r... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T... | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch... | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1... | 1,698,483,488 | 908 | PyPy 3-64 | WRONG_ANSWER | TESTS | 30 | 124 | 0 | a, b, c = map(int,input().split())
if c * (a - b) / b % 1 != 0:
print(int((c * (a - b) / b) // 1 + 1))
else:
print(c * ((a - b) // b)) | Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ... | ```python
a, b, c = map(int,input().split())
if c * (a - b) / b % 1 != 0:
print(int((c * (a - b) / b) // 1 + 1))
else:
print(c * ((a - b) // b))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,656,275,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 4,300,800 | s, v1, v2, t1, t2 = map(int, input().split())
x = t1 * 2 + v1
y = t2 * 2 + v2
print(['First', 'Second', 'Friendship'][(x >= y) + (x == y)])
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s, v1, v2, t1, t2 = map(int, input().split())
x = t1 * 2 + v1
y = t2 * 2 + v2
print(['First', 'Second', 'Friendship'][(x >= y) + (x == y)])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,614,747,987 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 307,200 | n,m=map(int,input().split())
d='B'
lst=[]
for i in range(n):
s=list(input())
for j in range(m):
if s[j]=='.':
if (i+j)%2==0:
s[j]='W'
else:
s[j]='B'
# else:
# s[j]='-'
lst.append(''.join(s))
for i in lst:
... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
n,m=map(int,input().split())
d='B'
lst=[]
for i in range(n):
s=list(input())
for j in range(m):
if s[j]=='.':
if (i+j)%2==0:
s[j]='W'
else:
s[j]='B'
# else:
# s[j]='-'
lst.append(''.join(s))
for i in ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,696,612,301 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | n = int(input()) # Number of coins
coins = list(map(int, input().split())) # List of coin values
# Sort the coins in non-decreasing order
coins.sort()
total_sum = 0 # Total sum of all coins
my_sum = 0 # Sum of coins I take
# Calculate the total sum of all coins
for coin in coins:
total_sum += coin... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = int(input()) # Number of coins
coins = list(map(int, input().split())) # List of coin values
# Sort the coins in non-decreasing order
coins.sort()
total_sum = 0 # Total sum of all coins
my_sum = 0 # Sum of coins I take
# Calculate the total sum of all coins
for coin in coins:
total_s... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,666,855,630 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | n,t = map(int,input().split())
b = 10**(n-1)
while b%t!=0:
b+=1
if n<len(str(t)):
print(-1)
else:print(b) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n,t = map(int,input().split())
b = 10**(n-1)
while b%t!=0:
b+=1
if n<len(str(t)):
print(-1)
else:print(b)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,653,038,960 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n,m=split().input()
n=int(n)
m=int(m)
ans=n//m
if(ans%2==1):
print("YES")
else:
print("NO")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n,m=split().input()
n=int(n)
m=int(m)
ans=n//m
if(ans%2==1):
print("YES")
else:
print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,663,843,997 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 614,400 | x=[1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111... | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
x=[1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 1011... | 3.949422 | MatrixStudio/Codeforces-Python-Submissions |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,682,670,688 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | def solve():
n = int(input())
t = list(map(int, input().split()))
maxi = max(t)
s = 0
for i in range(n):
s += maxi - t[i]
print(s)
# n = int(input())
# for i in range(n):
solve()
# print() | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
def solve():
n = int(input())
t = list(map(int, input().split()))
maxi = max(t)
s = 0
for i in range(n):
s += maxi - t[i]
print(s)
# n = int(input())
# for i in range(n):
solve()
# print()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,586,512,725 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 61 | 187 | 8,396,800 | n,c = map(int,input().split())
s = [int(i) for i in input().split()]
d = []
s.insert(0,0)
for i in range(n):
if s[i+1] - s[i] <= c:
d.append(s[i])
else:
d.clear()
print(len(d)+1) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n,c = map(int,input().split())
s = [int(i) for i in input().split()]
d = []
s.insert(0,0)
for i in range(n):
if s[i+1] - s[i] <= c:
d.append(s[i])
else:
d.clear()
print(len(d)+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,682,167,395 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 46 | 1,945,600 | n,t=map(int,input().split())
a=list(map(int,input().split()))
current_cell=1
pos=False
while current_cell<=t:
if current_cell==t:
pos=True
current_cell=current_cell+a[current_cell-1]
if pos==True:
print('YES')
else:
print('NO') | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t=map(int,input().split())
a=list(map(int,input().split()))
current_cell=1
pos=False
while current_cell<=t:
if current_cell==t:
pos=True
current_cell=current_cell+a[current_cell-1]
if pos==True:
print('YES')
else:
print('NO')
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,642,688,829 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n,m =map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
for j in range(m):
c.append(a[i]*b[j])
c.sort()
print(c[-2]) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m =map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
for j in range(m):
c.append(a[i]*b[j])
c.sort()
print(c[-2])
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,564,910,566 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 140 | 0 |
x = input()
if x == 'a1' or x == 'a8' or x == 'h1' or x == 'h8':
print(3)
elif x[0] == 'a' or x == 'h' or x[1] == '1' or x[1] == '8':
print(5)
else:
print(8)
# CodeForcesian
# ♥
# Sad
| 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
x = input()
if x == 'a1' or x == 'a8' or x == 'h1' or x == 'h8':
print(3)
elif x[0] == 'a' or x == 'h' or x[1] == '1' or x[1] == '8':
print(5)
else:
print(8)
# CodeForcesian
# ♥
# Sad
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
825 | A | Binary Protocol | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in ord... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts... | Print the decoded number. | [
"3\n111\n",
"9\n110011101\n"
] | [
"3\n",
"2031\n"
] | none | 0 | [
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "... | 1,575,129,456 | 2,147,483,647 | PyPy 3 | OK | TESTS | 13 | 124 | 0 | def main():
input()
t = input()
c = 0
ans = 0
for i in t:
if i == '1':
c+=1
else:
ans+=c
ans*= 10
c = 0
ans += c
print(ans)
main() | Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' charact... | ```python
def main():
input()
t = input()
c = 0
ans = 0
for i in t:
if i == '1':
c+=1
else:
ans+=c
ans*= 10
c = 0
ans += c
print(ans)
main()
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,618,743,051 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 0 | from sys import stdin
input = stdin.readline
def is_palindrome(h, m):
a = str(h).zfill(2)
b = str(m).zfill(2)
return a[0] == b[1] and b[0] == a[1]
s = input().rstrip()
h = int(s[:2])
m = int(s[3:])
while True:
if m == 59:
m = 0
if h == 23:
h = 0
else... | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
from sys import stdin
input = stdin.readline
def is_palindrome(h, m):
a = str(h).zfill(2)
b = str(m).zfill(2)
return a[0] == b[1] and b[0] == a[1]
s = input().rstrip()
h = int(s[:2])
m = int(s[3:])
while True:
if m == 59:
m = 0
if h == 23:
h = 0
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
412 | A | Poster | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of *n* characters, so the decorators hung a l... | The first line contains two integers, *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or di... | In *t* lines, print the actions the programmers need to make. In the *i*-th line print:
- "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th ac... | [
"2 2\nR1\n",
"2 1\nR1\n",
"6 4\nGO?GO!\n"
] | [
"PRINT 1\nLEFT\nPRINT R\n",
"PRINT R\nRIGHT\nPRINT 1\n",
"RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G\n"
] | Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character. | 500 | [
{
"input": "2 2\nR1",
"output": "PRINT 1\nLEFT\nPRINT R"
},
{
"input": "2 1\nR1",
"output": "PRINT R\nRIGHT\nPRINT 1"
},
{
"input": "6 4\nGO?GO!",
"output": "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"
},
{
"input": "7 3\n... | 1,665,427,172 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | n_square, k_th = map(int, input().split())
slogan = input()
if k_th - 1 < (n_square - 1) - (k_th - 1):
while k_th - 1 > 0:
k_th -= 1
print("LEFT")
for i in range(n_square):
print(f"PRINT {slogan[i]}")
if i != n_square - 1:
print("RIGHT")
else:
n_right = n_square ... | Title: Poster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the... | ```python
n_square, k_th = map(int, input().split())
slogan = input()
if k_th - 1 < (n_square - 1) - (k_th - 1):
while k_th - 1 > 0:
k_th -= 1
print("LEFT")
for i in range(n_square):
print(f"PRINT {slogan[i]}")
if i != n_square - 1:
print("RIGHT")
else:
n_right =... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,608,553,077 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 202 | 2,048,000 | n, k, m, d = map(int, input().split())
def binary_search(curr):
l, r = 0, m
while l <= r:
mid = (l+r)//2
if n // mid >= curr:
l = mid + 1
else:
r = mid - 1
return l - 1
res = 0
for i in range(1, d+1):
x = binary_search((i - 1) * k + 1)
... | Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
n, k, m, d = map(int, input().split())
def binary_search(curr):
l, r = 0, m
while l <= r:
mid = (l+r)//2
if n // mid >= curr:
l = mid + 1
else:
r = mid - 1
return l - 1
res = 0
for i in range(1, d+1):
x = binary_search((i - 1) * k... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,678,921,368 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 122 | 0 | length = int(input())
players = {}
pointer = 0
for _ in range(length):
np = input()
name,points = np.split(" ")
points = int(points)
#store pts, max pts, pos where max pts achieved
if name in players:
pts,maxpts,pos = players[name]
pts += points
if pts ... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
length = int(input())
players = {}
pointer = 0
for _ in range(length):
np = input()
name,points = np.split(" ")
points = int(points)
#store pts, max pts, pos where max pts achieved
if name in players:
pts,maxpts,pos = players[name]
pts += points
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,527,433,137 | 537 | Python 3 | OK | TESTS | 133 | 93 | 0 | s=input()
if(s!=s[::-1]):
print(len(s))
else:
flag=True
for i in range(len(s)):
if(s[i]!=s[0]):
flag=False
if(flag):
print(0)
else:
print(len(s)-1)
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
s=input()
if(s!=s[::-1]):
print(len(s))
else:
flag=True
for i in range(len(s)):
if(s[i]!=s[0]):
flag=False
if(flag):
print(0)
else:
print(len(s)-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,570,175,224 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 33 | 218 | 0 | a,b,c= map(int,input().split())
#c1
ans0 = a//3+b//3+c//3
#c2
ans1 = 1 + (a-1)//3 + (b-1)//3 + (c-1)//3
#c3
ans2 = 2+ (a-2)//3 + (b-2)//3 +(c-2)//3
print(max(ans0,ans1, ans2)) | 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
a,b,c= map(int,input().split())
#c1
ans0 = a//3+b//3+c//3
#c2
ans1 = 1 + (a-1)//3 + (b-1)//3 + (c-1)//3
#c3
ans2 = 2+ (a-2)//3 + (b-2)//3 +(c-2)//3
print(max(ans0,ans1, ans2))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t... | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1... | 1,659,940,055 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 1,669 | 20,787,200 | n = int(input())
v = [int(s) for s in input().split()]
a = v.copy()
a.sort()
pref_v = [v[0]] + [0] * (n - 1)
pref_a = [a[0]] + [0] * (n - 1)
for i in range(1, n):
pref_v[i] = pref_v[i - 1] + v[i]
pref_a[i] = pref_a[i - 1] + a[i]
k = int(input())
for j in range(k):
t, l, r = [int(s) for ... | Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s... | ```python
n = int(input())
v = [int(s) for s in input().split()]
a = v.copy()
a.sort()
pref_v = [v[0]] + [0] * (n - 1)
pref_a = [a[0]] + [0] * (n - 1)
for i in range(1, n):
pref_v[i] = pref_v[i - 1] + v[i]
pref_a[i] = pref_a[i - 1] + a[i]
k = int(input())
for j in range(k):
t, l, r = [i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,592,917,167 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 218 | 6,963,200 | n=int(input())
l=list(map(int,input().split()))
c=0
b=0
ba=0
i=0
while(i!=n):
c=c+l[i]
i=i+1
if(i!=n):
b=b+l[i]
i=i+1
if(i!=n):
ba=ba+l[i]
i=i+1
if(c==max(c,b,ba)):
print("chest")
elif(b==max(c,b,ba)):
print("biceps")
else:
print("back")
... | 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())
l=list(map(int,input().split()))
c=0
b=0
ba=0
i=0
while(i!=n):
c=c+l[i]
i=i+1
if(i!=n):
b=b+l[i]
i=i+1
if(i!=n):
ba=ba+l[i]
i=i+1
if(c==max(c,b,ba)):
print("chest")
elif(b==max(c,b,ba)):
print("biceps")
else:
print(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,673,495,306 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n=map(int,input().split())
p=m*n
print(p//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=map(int,input().split())
p=m*n
print(p//2)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them... | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. ... | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students... | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
}... | 1,597,355,861 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 0 | n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 0
i = 0
v = a[k]
while(i<n and a[i]!=0):
if(a[i]>=v):
c+=1
i+=1
print(c) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group w... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 0
i = 0
v = a[k]
while(i<n and a[i]!=0):
if(a[i]>=v):
c+=1
i+=1
print(c)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
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,545,834,068 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 0 | n=int(input())
a=[]
for i in range(n):
r=list(map(int,input().split()))
a.append(r)
b=sorted(a,reverse=True)
for i in a:
if(i[1]-i[0]!=0):
print("rated")
exit(0)
for i in range(n):
if a[i]!=b[i]:
print("unrated")
exit(0)
c=0
for i in a:
if(i[1]-i[0]=... | 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
n=int(input())
a=[]
for i in range(n):
r=list(map(int,input().split()))
a.append(r)
b=sorted(a,reverse=True)
for i in a:
if(i[1]-i[0]!=0):
print("rated")
exit(0)
for i in range(n):
if a[i]!=b[i]:
print("unrated")
exit(0)
c=0
for i in a:
if(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
452 | B | 4-point polyline | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"geometry",
"trees"
] | null | null | You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of... | The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points. | Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10<=-<=6 precision. | [
"1 1\n",
"0 10\n"
] | [
"1 1\n0 0\n1 0\n0 1\n",
"0 1\n0 10\n0 0\n0 9\n"
] | none | 1,000 | [
{
"input": "1 1",
"output": "0 0\n1 1\n0 1\n1 0"
},
{
"input": "0 10",
"output": "0 1\n0 10\n0 0\n0 9"
},
{
"input": "10 10",
"output": "10 9\n0 0\n10 10\n1 0"
},
{
"input": "100 100",
"output": "0 1\n100 100\n0 0\n99 100"
},
{
"input": "10 100",
"output": "9 ... | 1,672,648,604 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 10 | 77 | 2,764,800 | from itertools import combinations, permutations
from math import dist
def get_len(points):
return sum(dist(points[i], points[i + 1]) for i in range(len(points) - 1))
n, m = map(int, input().split())
points = [(0, 0), (1, 0), (0, 1), (0, m), (0, m - 1), (1, m), (n - 1, m), (n, m), (n, m - 1), (m - 1, 0), (m, 0),... | Title: 4-point polyline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyl... | ```python
from itertools import combinations, permutations
from math import dist
def get_len(points):
return sum(dist(points[i], points[i + 1]) for i in range(len(points) - 1))
n, m = map(int, input().split())
points = [(0, 0), (1, 0), (0, 1), (0, m), (0, m - 1), (1, m), (n - 1, m), (n, m), (n, m - 1), (m - 1, 0... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,629,370,785 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 6,963,200 | def lol_kek():
n=int(input())
ans=[]
ans2=[]
for i in range(n):
a,b,c=map(str,input().split())
c=c.lower()
a=a.lower()
if c=="polycarp":
ans.append(a)
ans2.append(2)
elif c in ans:
ans2[ans.index(c)]+=1
... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
def lol_kek():
n=int(input())
ans=[]
ans2=[]
for i in range(n):
a,b,c=map(str,input().split())
c=c.lower()
a=a.lower()
if c=="polycarp":
ans.append(a)
ans2.append(2)
elif c in ans:
ans2[ans.index(c)]+=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,608,295,540 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 202 | 11,673,600 | n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
blist.sort(reverse=True)
blist=blist[0:2]
total=sum(blist)
have=sum(alist)
if total>=have:
print("YES")
else:
print("NO") | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
blist.sort(reverse=True)
blist=blist[0:2]
total=sum(blist)
have=sum(alist)
if total>=have:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,513,759,789 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,529,600 | n = int(input())
s = input()
l = [int(i) for i in input().split()]
ans = 1
m = l[0]
for i in range(1,n):
if l[i] != m :
m = l[i]
ans +=1
print(ans+1)
| Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
n = int(input())
s = input()
l = [int(i) for i in input().split()]
ans = 1
m = l[0]
for i in range(1,n):
if l[i] != m :
m = l[i]
ans +=1
print(ans+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,634,522,608 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | s = input()
ans = ""
for i in s:
if (i == 'h' or i == 'e' or i == 'l' or i == 'o'):
ans += i
new = ""
for i in ans:
if (i not in new):
new += i
elif (i == 'l' and new.count(i) < 2):
new += i
if (new == "hello"):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
ans = ""
for i in s:
if (i == 'h' or i == 'e' or i == 'l' or i == 'o'):
ans += i
new = ""
for i in ans:
if (i not in new):
new += i
elif (i == 'l' and new.count(i) < 2):
new += i
if (new == "hello"):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,681,323,420 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 122 | 0 | word = str(input())
revese = str(input())
new_word = ""
start = len(word)-1
i=0
for i in range(start,-1,i-1):
new_word+=word[i]
print("YES") if new_word==revese else print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
word = str(input())
revese = str(input())
new_word = ""
start = len(word)-1
i=0
for i in range(start,-1,i-1):
new_word+=word[i]
print("YES") if new_word==revese else print("NO")
``` | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,467,718,350 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n = int(input())
dryer = [0]*101
al,ar = map(int,input().split())
for i in range(1,n):
l,r = map(int,input().split())
for j in range(l,r):
dryer[j] = 1
x = 0
for i in range(al,ar+1):
if dryer[i] == 0 :
x += 1
print(x) | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
n = int(input())
dryer = [0]*101
al,ar = map(int,input().split())
for i in range(1,n):
l,r = map(int,input().split())
for j in range(l,r):
dryer[j] = 1
x = 0
for i in range(al,ar+1):
if dryer[i] == 0 :
x += 1
print(x)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,698,128,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | username = input()
list =[]
for i in range(len(username)):
list.append(username[i])
z = set(list)
y = len(z)
if y%2==0:
print("IGNORE HIM")
else:
print("CHAT WITH HER") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
username = input()
list =[]
for i in range(len(username)):
list.append(username[i])
z = set(list)
y = len(z)
if y%2==0:
print("IGNORE HIM")
else:
print("CHAT WITH HER")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,555,616,619 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 109 | 0 | s = input()
n = (s.count("n") - 1) // 2 #NiNeteeN
i = s.count("i")
e = s.count("e") // 3 #ninEtEEn
t = s.count("t")
print(min(n, i, e, t))
| Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
s = input()
n = (s.count("n") - 1) // 2 #NiNeteeN
i = s.count("i")
e = s.count("e") // 3 #ninEtEEn
t = s.count("t")
print(min(n, i, e, t))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,697,373,453 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = map(int,input().split())
a = 0
for i in range(1,w+1):
a += i * k
if n >= a:
print('0')
else:
print(a - n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k, n, w = map(int,input().split())
a = 0
for i in range(1,w+1):
a += i * k
if n >= a:
print('0')
else:
print(a - n)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,665,626,920 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 614,400 | n=int(input())
if n%2==0:
print(n//2)
print(*([2]*(n//2)))
else:
x=[2]*((n//2)-1)
x+=[3]
print(len(x))
print(*x) | 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)
print(*([2]*(n//2)))
else:
x=[2]*((n//2)-1)
x+=[3]
print(len(x))
print(*x)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,624,532,346 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 2,457,600 | def solve(n):
result = [2] * int(n/2)
if n % 2 != 0:
result[int(n/2)-1] = 3
return str(int(n/2)) + "\n" + " ".join(str(elem) for elem in result)
if __name__ == "__main__":
n = int(input())
print(solve(n))
| 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
def solve(n):
result = [2] * int(n/2)
if n % 2 != 0:
result[int(n/2)-1] = 3
return str(int(n/2)) + "\n" + " ".join(str(elem) for elem in result)
if __name__ == "__main__":
n = int(input())
print(solve(n))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,696,509,814 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
flag=False
if n%2==1:
print("NO")
for a in range(1,n):
if a%2==0 and (n-a)%2==0:
flag=True
if flag:
print("TRUE")
| 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
n=int(input())
flag=False
if n%2==1:
print("NO")
for a in range(1,n):
if a%2==0 and (n-a)%2==0:
flag=True
if flag:
print("TRUE")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,699,747,034 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | s=0
n=int(input())
d=0
j=0
while j<n:
if j>3:
for i in range(4,j/2):
if n%i==0 and i**i!=n:
d=d+1
if d==2:
s=s+1
j=j+1
print(s) | 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
s=0
n=int(input())
d=0
j=0
while j<n:
if j>3:
for i in range(4,j/2):
if n%i==0 and i**i!=n:
d=d+1
if d==2:
s=s+1
j=j+1
print(s)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
688 | A | Opponents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Ar... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th op... | Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. | [
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] | [
"2\n",
"1\n",
"2\n"
] | In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | 500 | [
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111... | 1,596,803,274 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 109 | 6,656,000 | op, day = map(int, input().split())
days=0;d=[]
for j in range(day):
p=input()
present=0
for i in p:
if i=='1':
present+=1
if j==day-1 and present<op:
days+=1
d.append(days)
elif present<op:
days+=1
else:
d.append(days)
days=0
print(max(d)) | Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of th... | ```python
op, day = map(int, input().split())
days=0;d=[]
for j in range(day):
p=input()
present=0
for i in p:
if i=='1':
present+=1
if j==day-1 and present<op:
days+=1
d.append(days)
elif present<op:
days+=1
else:
d.append(days)
days=0
print(max(d))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
390 | A | Inna and Alarm Clock | PROGRAMMING | 0 | [
"implementation"
] | null | null | Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square.
The mornin... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100).
Note that a single point in the room can conta... | In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. | [
"4\n0 0\n0 1\n0 2\n1 0\n",
"4\n0 0\n0 1\n1 0\n1 1\n",
"4\n1 1\n1 2\n2 3\n3 3\n"
] | [
"2\n",
"2\n",
"3\n"
] | In the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.
In the third sample it is important to note that Inna doesn't have the right to change the... | 500 | [
{
"input": "4\n0 0\n0 1\n0 2\n1 0",
"output": "2"
},
{
"input": "4\n0 0\n0 1\n1 0\n1 1",
"output": "2"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 3",
"output": "3"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 ... | 1,579,865,836 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 795 | 6,041,600 | n = int(input())
x = [0 for m in range(101)]
y = [0 for n in range(101)]
for i in range(n):
xi,yi = map(int,input().split())
x[xi] = 1
y[yi] = 1
print(min(x.count(1),y.count(1)))
| Title: Inna and Alarm Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner a... | ```python
n = int(input())
x = [0 for m in range(101)]
y = [0 for n in range(101)]
for i in range(n):
xi,yi = map(int,input().split())
x[xi] = 1
y[yi] = 1
print(min(x.count(1),y.count(1)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,597,395,953 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 2,252,800 | d1,d2,d3=int(input()),int(input()),int(input())
a=d1*2+d2*2
b=d1+d2+d3
print(min(a,b)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3=int(input()),int(input()),int(input())
a=d1*2+d2*2
b=d1+d2+d3
print(min(a,b))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,689,631,711 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | print("_RANDOM_GUESS_1689631711.2370324")# 1689631711.2370534 | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
print("_RANDOM_GUESS_1689631711.2370324")# 1689631711.2370534
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,663,088,139 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
list1 = list(map(int,input().split(' ')[:n]))
e = 0
o = 0
if list1[0] % 2 == 0:
e = e + 1
else:
o = o + 1
countE = 1
if e == 1:
for item in list1:
if item % 2 == 0:
countE = countE + 1
else:
break
if countE == n + 1:
pr... | 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())
list1 = list(map(int,input().split(' ')[:n]))
e = 0
o = 0
if list1[0] % 2 == 0:
e = e + 1
else:
o = o + 1
countE = 1
if e == 1:
for item in list1:
if item % 2 == 0:
countE = countE + 1
else:
break
if countE == n + 1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,487,317,813 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | y=int(input())
x=int(input())
ma=0
if y>x:
ma=y
else:
ma=x
if (ma-1)%2==0:
if (((ma-1)/2)/3)==(1/3):
print ("1/3")
if (((ma-1)/2)/3)==(2/3):
print("2/3")
if (ma-1)%3==0:
if (((ma-1)/3)/2)==0.5
print ("1/2")
if (ma-1)%2!=0 and (ma-1)%3!=0:
if ((ma-1)/6)==... | 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
y=int(input())
x=int(input())
ma=0
if y>x:
ma=y
else:
ma=x
if (ma-1)%2==0:
if (((ma-1)/2)/3)==(1/3):
print ("1/3")
if (((ma-1)/2)/3)==(2/3):
print("2/3")
if (ma-1)%3==0:
if (((ma-1)/3)/2)==0.5
print ("1/2")
if (ma-1)%2!=0 and (ma-1)%3!=0:
if ((... | -1 | MatrixStudio/Codeforces-Python-Submissions |
630 | F | Selection of Personnel | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the... | The only line of the input contains one integer *n* (7<=≤<=*n*<=≤<=777) — the number of potential employees that sent resumes. | Output one integer — the number of different variants of group composition. | [
"7\n"
] | [
"29"
] | none | 0 | [
{
"input": "7",
"output": "29"
},
{
"input": "8",
"output": "92"
},
{
"input": "9",
"output": "246"
},
{
"input": "10",
"output": "582"
},
{
"input": "321",
"output": "66715035255088"
},
{
"input": "624",
"output": "7147161340917624"
},
{
"... | 1,693,829,147 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
A = 1
B = 1
C = 1
A1 = 1
B1 = 1
C1 = 1
fact = 1
for i in range(1, n+1):
fact *= i
AA = n-5
BB = n-6
CC = n-7
for i in range(1, AA+1):
A *= i
for i in range(1, BB+1):
B *= i
for i in range(1, CC+1):
C *= i
First = n-AA
Second = n-BB
Third = n-CC
for i ... | Title: Selection of Personnel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received *n* resumes. Now the HR ... | ```python
n = int(input())
A = 1
B = 1
C = 1
A1 = 1
B1 = 1
C1 = 1
fact = 1
for i in range(1, n+1):
fact *= i
AA = n-5
BB = n-6
CC = n-7
for i in range(1, AA+1):
A *= i
for i in range(1, BB+1):
B *= i
for i in range(1, CC+1):
C *= i
First = n-AA
Second = n-BB
Third = n-CC... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,592,023,582 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 140 | 0 | n = int(input())
data = []
for _ in range(n):
data.append(input())
x = data[0][0]
o = data[0][1]
for i in range(n):
for j in range(n):
if i==j or j==n-1-i:
if data[i][j]!=x:
print('NO')
exit(0)
else:
if data[i][j]!=o:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
data = []
for _ in range(n):
data.append(input())
x = data[0][0]
o = data[0][1]
for i in range(n):
for j in range(n):
if i==j or j==n-1-i:
if data[i][j]!=x:
print('NO')
exit(0)
else:
if data[i][j]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,475,929,171 | 271 | Python 3 | OK | TESTS | 68 | 77 | 4,608,000 | def main():
a = input().strip()
b = input().strip()
q = [28, 30, 31]
days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
f = False
for x in q:
if (days.index(a) + x) % 7 == days.index(b):
f = True
break
if f:
... | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
def main():
a = input().strip()
b = input().strip()
q = [28, 30, 31]
days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
f = False
for x in q:
if (days.index(a) + x) % 7 == days.index(b):
f = True
break
if ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,489,741,372 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | from sys import stdin
n = int(input())
arr = list(map(int,stdin.readline().split()))
f = arr[0]
l = arr[n-1]
d =int((f+l)/2)
lm = d-1
rm = d+1
if d in arr:
print(d)
else:
for i in range(n):
if lm in arr:
print(lm)
break
elif rm in arr:
print(rm... | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=... | ```python
from sys import stdin
n = int(input())
arr = list(map(int,stdin.readline().split()))
f = arr[0]
l = arr[n-1]
d =int((f+l)/2)
lm = d-1
rm = d+1
if d in arr:
print(d)
else:
for i in range(n):
if lm in arr:
print(lm)
break
elif rm in arr:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,661,008,886 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 404 | 8,601,600 | n, d = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
res = 0
if n > 2:
r = 2
for i in range(n-2):
flag = False
while r < n :
if x[r] - x[i] <= d:
r+=1
else:
res += ((r-i-1)*(r-i-2))//2
... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n, d = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
res = 0
if n > 2:
r = 2
for i in range(n-2):
flag = False
while r < n :
if x[r] - x[i] <= d:
r+=1
else:
res += ((r-i-1)*(r-i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you ar... | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
... | 1,600,009,427 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | a,b=map(int,input().split())
z=[];x=1
for i in " "*a:k=[1]*a;z+=[k]
for i in range(a):
for j in range(b-1):z[i][j]=x;x+=1
for i in range(a):
for j in range(b-1,a):z[i][j]=x;x+=1
for i in z:
print(*i) | Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects... | ```python
a,b=map(int,input().split())
z=[];x=1
for i in " "*a:k=[1]*a;z+=[k]
for i in range(a):
for j in range(b-1):z[i][j]=x;x+=1
for i in range(a):
for j in range(b-1,a):z[i][j]=x;x+=1
for i in z:
print(*i)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
895 | C | Square Subsets | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"dp",
"math"
] | null | null | Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.
Two ways are considered different if sets of indexes of ele... | First line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array.
Second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=70) — the elements of the array. | Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109<=+<=7. | [
"4\n1 1 1 1\n",
"4\n2 2 2 2\n",
"5\n1 2 4 5 8\n"
] | [
"15\n",
"7\n",
"7\n"
] | In first sample product of elements chosen by any way is 1 and 1 = 1<sup class="upper-index">2</sup>. So the answer is 2<sup class="upper-index">4</sup> - 1 = 15.
In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is ... | 1,750 | [
{
"input": "4\n1 1 1 1",
"output": "15"
},
{
"input": "4\n2 2 2 2",
"output": "7"
},
{
"input": "5\n1 2 4 5 8",
"output": "7"
},
{
"input": "1\n64",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "15"
},
{
"input": "6\n1 2 3 4 5 6",
"output"... | 1,634,312,358 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 61 | 1,419 | 191,283,200 | import sys
import os
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
fct = sys.stdin
if os.environ.get('USER') == "loic":
fct = open("data.in")
line = lambda: fct.readline().split()
def write(w):
sys.stdout.write(w)
sys.stdout.write("\n")
from collections i... | Title: Square Subsets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya was late for the lesson too. The teacher gave him an additional task. For some array *a* Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their produc... | ```python
import sys
import os
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
fct = sys.stdin
if os.environ.get('USER') == "loic":
fct = open("data.in")
line = lambda: fct.readline().split()
def write(w):
sys.stdout.write(w)
sys.stdout.write("\n")
from col... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,695,658,701 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 77 | 0 | a,b,c,d=map(int,input().split())
aa=max(((3*a)/10),(a-(a/250)*c))
bb=max(((3*b)/10),(b-(b/250)*d))
if aa>bb:
print("Misha")
elif bb>aa:
print("Vasya")
else:
print("Tie")
| Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a,b,c,d=map(int,input().split())
aa=max(((3*a)/10),(a-(a/250)*c))
bb=max(((3*b)/10),(b-(b/250)*d))
if aa>bb:
print("Misha")
elif bb>aa:
print("Vasya")
else:
print("Tie")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,697,561,951 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 265 | 10,649,600 | n = int(input())
x, h = [], []
for i in range(n):
read = list(map(int, input().split()))
x.append(read[0]), h.append(read[1])
x.append(2 ** 31)
dp = []
dp.append([1, x[0]])
for i in range(1, n):
if x[i] - h[i] > dp[i - 1][1]:
dp.append([dp[i - 1][0] + 1, x[i]])
elif x[i] > dp[i - 1]... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n = int(input())
x, h = [], []
for i in range(n):
read = list(map(int, input().split()))
x.append(read[0]), h.append(read[1])
x.append(2 ** 31)
dp = []
dp.append([1, x[0]])
for i in range(1, n):
if x[i] - h[i] > dp[i - 1][1]:
dp.append([dp[i - 1][0] + 1, x[i]])
elif x[i] >... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,627,300,120 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 20,172,800 | import math
def main_function():
n, s = [int(i) for i in input().split(" ")]
f_t = [[int(i) for i in input().split(" ")] for j in range(n)]
f_t = sorted(f_t, key=lambda x:x[0], reverse=True)
time_counter = 0
current_floor = s
starting_time = 0
for i in f_t:
time_counter +=... | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
import math
def main_function():
n, s = [int(i) for i in input().split(" ")]
f_t = [[int(i) for i in input().split(" ")] for j in range(n)]
f_t = sorted(f_t, key=lambda x:x[0], reverse=True)
time_counter = 0
current_floor = s
starting_time = 0
for i in f_t:
time_... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
509 | C | Sums of Digits | PROGRAMMING | 2,000 | [
"dp",
"greedy",
"implementation"
] | null | null | Vasya had a strictly increasing sequence of positive integers *a*1, ..., *a**n*. Vasya used it to build a new sequence *b*1, ..., *b**n*, where *b**i* is the sum of digits of *a**i*'s decimal representation. Then sequence *a**i* got lost and all that remained is sequence *b**i*.
Vasya wonders what the numbers *a**i* c... | The first line contains a single integer number *n* (1<=≤<=*n*<=≤<=300).
Next *n* lines contain integer numbers *b*1, ..., *b**n* — the required sums of digits. All *b**i* belong to the range 1<=≤<=*b**i*<=≤<=300. | Print *n* integer numbers, one per line — the correct option for numbers *a**i*, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the *i*-th number should be equal to *b**i*.
If there are multiple sequences with least possible number *a**n*, print any of them. Print ... | [
"3\n1\n2\n3\n",
"3\n3\n2\n1\n"
] | [
"1\n2\n3\n",
"3\n11\n100\n"
] | none | 0 | [
{
"input": "3\n1\n2\n3",
"output": "1\n2\n3"
},
{
"input": "3\n3\n2\n1",
"output": "3\n11\n100"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1",
"output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"
},
{
"input": "10\n8\n8\n5\n1\n2\n7\n3\n8\n9\n4",
"output": "8\n17\n23\n100\n101\n10... | 1,689,644,771 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689644768.2543523")# 1689644768.2543733 | Title: Sums of Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya had a strictly increasing sequence of positive integers *a*1, ..., *a**n*. Vasya used it to build a new sequence *b*1, ..., *b**n*, where *b**i* is the sum of digits of *a**i*'s decimal representation. Then sequenc... | ```python
print("_RANDOM_GUESS_1689644768.2543523")# 1689644768.2543733
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
41 | E | 3-cycles | PROGRAMMING | 1,900 | [
"constructive algorithms",
"graphs",
"greedy"
] | E. 3-cycles | 2 | 256 | During a recent research Berland scientists found out that there were *n* cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose thr... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of cities in Berland. | On the first line must be printed number *m* — the maximal number of roads in Berland. Then print *m* lines containing two numbers each — the numbers of cities that the given road joins. The cities are numbered with integers from 1 to *n*. If there are several variants of solving the problem, print any of them. | [
"3\n",
"4\n"
] | [
"2\n1 2\n2 3\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | none | 2,500 | [
{
"input": "3",
"output": "2\n1 2\n1 3"
},
{
"input": "4",
"output": "4\n1 3\n1 4\n2 3\n2 4"
},
{
"input": "5",
"output": "6\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5"
},
{
"input": "6",
"output": "9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "7",
"output... | 1,568,068,788 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 310 | 2,560,000 | # 41E
def do():
n = int(input())
ln = n >> 1
res = []
for i in range(1, ln + 1):
for j in range(ln + 1, n + 1):
res.append((i, j))
return res
res = do()
print(len(res))
for x, y in res:
print(str(x) + " " + str(y))
| Title: 3-cycles
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
During a recent research Berland scientists found out that there were *n* cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a wel... | ```python
# 41E
def do():
n = int(input())
ln = n >> 1
res = []
for i in range(1, ln + 1):
for j in range(ln + 1, n + 1):
res.append((i, j))
return res
res = do()
print(len(res))
for x, y in res:
print(str(x) + " " + str(y))
``` | 3.917732 | MatrixStudio/Codeforces-Python-Submissions |
812 | B | Sagheer, the Hausmeister | PROGRAMMING | 1,600 | [
"bitmasks",
"brute force",
"dp"
] | null | null | Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
The building consists of *n* floors with stairs at the left and the right sid... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively.
The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then ... | Print a single integer — the minimum total time needed to turn off all the lights. | [
"2 2\n0010\n0100\n",
"3 4\n001000\n000010\n000010\n",
"4 3\n01110\n01110\n01110\n01110\n"
] | [
"5\n",
"12\n",
"18\n"
] | In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.
In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to th... | 1,000 | [
{
"input": "2 2\n0010\n0100",
"output": "5"
},
{
"input": "3 4\n001000\n000010\n000010",
"output": "12"
},
{
"input": "4 3\n01110\n01110\n01110\n01110",
"output": "18"
},
{
"input": "3 2\n0000\n0100\n0100",
"output": "4"
},
{
"input": "1 89\n0000000000000000000000... | 1,551,340,660 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 140 | 102,400 | n, m = map(int, input().split())
a = [list(map(int, input())) for i in range(n)]
a.reverse()
dp = [[0, 0] for i in range(n + 2)]
dp[0][1]= 10000
last_none = -1
last = -1
for i in range(1, n + 1):
f, l = -1, -1
for j in range(1, m + 1):
if a[i - 1][j] == 1:
if f == -1:
... | Title: Sagheer, the Hausmeister
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goe... | ```python
n, m = map(int, input().split())
a = [list(map(int, input())) for i in range(n)]
a.reverse()
dp = [[0, 0] for i in range(n + 2)]
dp[0][1]= 10000
last_none = -1
last = -1
for i in range(1, n + 1):
f, l = -1, -1
for j in range(1, m + 1):
if a[i - 1][j] == 1:
if f == -1:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,663,275,686 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 100,659,200 | def love_triangle():
triangle = False
for j in range(people_num):
for k in range(people_num):
if people[j][k] == 1:
for l in range(people_num):
if people[k][l] == 1:
if people[l][j]:
triangle = True
i... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
def love_triangle():
triangle = False
for j in range(people_num):
for k in range(people_num):
if people[j][k] == 1:
for l in range(people_num):
if people[k][l] == 1:
if people[l][j]:
triangle = ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,521,911,461 | 5,761 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 62 | 7,065,600 | x = int(input())
b=[]
for i in range(x):
a=input()
b.append(a)
s=''.join(b)
print(s)
c = s.find('cc')
m = s.find('mm')
y = s.find('yy')
if y== -1 and m == -1 and c == -1:
print("Yes")
else:
print("No")
| Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
x = int(input())
b=[]
for i in range(x):
a=input()
b.append(a)
s=''.join(b)
print(s)
c = s.find('cc')
m = s.find('mm')
y = s.find('yy')
if y== -1 and m == -1 and c == -1:
print("Yes")
else:
print("No")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
690 | D1 | The Wall (easy) | PROGRAMMING | 1,200 | [] | null | null | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers *R* and *C*, 1<=≤<=*R*,<=*C*<=≤<=100. The next *R* lines provide a description of the columns as follows:
- each of the *R* lines contains a string of length *C*, - the *c*-th character of line *r* is B if there is a brick in column *c* and row *R... | The number of wall segments in the input configuration. | [
"3 7\n.......\n.......\n.BB.B..\n",
"4 5\n..B..\n..B..\nB.B.B\nBBB.B\n",
"4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB\n",
"1 1\nB\n",
"10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.\n",
"8 8\n........\n........\n........\n........\n.B......\n.B.....B\n.B.....B\n.BB.... | [
"2\n",
"2\n",
"1\n",
"1\n",
"3\n",
"2\n"
] | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | 0 | [
{
"input": "3 7\n.......\n.......\n.BB.B..",
"output": "2"
},
{
"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B",
"output": "2"
},
{
"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB",
"output": "1"
},
{
"input": "1 1\nB",
"output": "1"
},
{
"input": "10 7\n.......\n.......... | 1,512,562,963 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 23,040,000 | from sys import *
print((stdin.readlines()[-1] + '.').count('B.')) | Title: The Wall (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is fai... | ```python
from sys import *
print((stdin.readlines()[-1] + '.').count('B.'))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
888 | A | Local Extrema | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=><=*... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in array *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000) — the elements of array *a*. | Print the number of local extrema in the given array. | [
"3\n1 2 3\n",
"4\n1 5 2 5\n"
] | [
"0\n",
"2\n"
] | none | 0 | [
{
"input": "3\n1 2 3",
"output": "0"
},
{
"input": "4\n1 5 2 5",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n548",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n3 2 3",
"output": "1"
},
{
"inp... | 1,648,709,537 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 31 | 0 | def solution(arr):
res = 0
for i in range(1, len(arr)-1, 1):
if arr[i] > arr[i-1] and arr[i] > arr[i+1] or arr[i] < arr[i-1] and arr[i] < arr[i+1]:
res += 1
print(res)
while True:
try:
n = int(input())
arr = list(map(int, input().split()))
solution(arr)
... | Title: Local Extrema
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=<<=*a**i*<=-<=1 and *a**i*<=<<=*a**i*<=+<=1). Also the element c... | ```python
def solution(arr):
res = 0
for i in range(1, len(arr)-1, 1):
if arr[i] > arr[i-1] and arr[i] > arr[i+1] or arr[i] < arr[i-1] and arr[i] < arr[i+1]:
res += 1
print(res)
while True:
try:
n = int(input())
arr = list(map(int, input().split()))
solutio... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,679,494,540 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 62 | 0 | x = [input() for i in range(4)]
for i in range(len(x) - 1):
a = x[i]
b = x[i + 1]
for j in range(len(a) - 1):
if a[j:j + 2].count("#") + b[j:j + 2].count("#") != 2:
print("YES")
exit()
print("NO") | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
x = [input() for i in range(4)]
for i in range(len(x) - 1):
a = x[i]
b = x[i + 1]
for j in range(len(a) - 1):
if a[j:j + 2].count("#") + b[j:j + 2].count("#") != 2:
print("YES")
exit()
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,649,613,646 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 154 | 0 | n, p1, p2, p3, t1, t2 = map(int, input().split())
p = 0
for i in range(n):
if i == 0:
l, r = map(int, input().split())
p = (r-l)*p1
continue
x = r
l, r = map(int, input().split())
p += (r-l)*p1
if (l-x) > t1+t2:
p += (l-x-t1-t2)*p3 + t2*p2 + t1*p1
elif... | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
n, p1, p2, p3, t1, t2 = map(int, input().split())
p = 0
for i in range(n):
if i == 0:
l, r = map(int, input().split())
p = (r-l)*p1
continue
x = r
l, r = map(int, input().split())
p += (r-l)*p1
if (l-x) > t1+t2:
p += (l-x-t1-t2)*p3 + t2*p2 + t1*p1... | 3.923 | MatrixStudio/Codeforces-Python-Submissions |
351 | A | Jeff and Rounding | PROGRAMMING | 1,800 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as follows:
- choose indexes *i* and *j* (*i*<=≠<=*j*) that haven't been chose... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000). The next line contains 2*n* real numbers *a*1, *a*2, ..., *a*2*n* (0<=≤<=*a**i*<=≤<=10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | [
"3\n0.000 0.500 0.750 1.000 2.000 3.000\n",
"3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n"
] | [
"0.250\n",
"0.279\n"
] | In the first test case you need to perform the operations as follows: (*i* = 1, *j* = 4), (*i* = 2, *j* = 3), (*i* = 5, *j* = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | 1,000 | [
{
"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000",
"output": "0.250"
},
{
"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896",
"output": "0.279"
},
{
"input": "3\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000",
"output": "0.184"
},
{
"input": "3\n6470.... | 1,640,337,726 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | import math
def main():
n = input()
num_list = input().split(" ")
diff = 0
for i in range(0, len(num_list)):
num_list[i] = float(num_list[i])
if(diff >= 0):
new_num = math.floor(num_list[i])
diff = diff + (new_num - num_list[i])
else:
... | Title: Jeff and Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operati... | ```python
import math
def main():
n = input()
num_list = input().split(" ")
diff = 0
for i in range(0, len(num_list)):
num_list[i] = float(num_list[i])
if(diff >= 0):
new_num = math.floor(num_list[i])
diff = diff + (new_num - num_list[i])
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,451,308,433 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n=int(input())
s=list(map(lambda x:x%2,map(int,input().split())))
if s[0]!=s[1] and s[1]==s[2]:
print(1)
for i in range(2,n):
if s[i]!=s[i-1]:
print (str(i)) | 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())
s=list(map(lambda x:x%2,map(int,input().split())))
if s[0]!=s[1] and s[1]==s[2]:
print(1)
for i in range(2,n):
if s[i]!=s[i-1]:
print (str(i))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,603,420,573 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 170 | 2,252,800 | a= [0]*100; b= [0]*100 # this for solve the error will show list index out of range
n = int(input())
for i in range(n):
lis = input()
for k in range(n):
if lis[k] == 'C':
a[i] += 1;b[k] += 1
counter = 0
for _ in a:
counter +=_*(_ - 1) // 2
for _ in b:
counter +=_*(_ - 1) /... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
a= [0]*100; b= [0]*100 # this for solve the error will show list index out of range
n = int(input())
for i in range(n):
lis = input()
for k in range(n):
if lis[k] == 'C':
a[i] += 1;b[k] += 1
counter = 0
for _ in a:
counter +=_*(_ - 1) // 2
for _ in b:
counter +=_... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,643,911,296 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s = input()
ch = "abcfgjklmnopqrstuvwxyz"
for i in ch :
out = s.replace(i, "")
if 'heidi' in out :
print("YES")
else :
print("NO") | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
ch = "abcfgjklmnopqrstuvwxyz"
for i in ch :
out = s.replace(i, "")
if 'heidi' in out :
print("YES")
else :
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,593,746,044 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 109 | 0 | i = int(input())
if i == 1:
print(1)
elif i == 2:
print(2)
elif i == 3:
print(6)
elif i == 4:
print(20)
elif i == 5:
print(70)
elif i == 6:
print(252)
elif i == 7:
print(924)
elif i == 8:
print(3432)
elif i == 9:
print(12870)
else : print(48620)
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
i = int(input())
if i == 1:
print(1)
elif i == 2:
print(2)
elif i == 3:
print(6)
elif i == 4:
print(20)
elif i == 5:
print(70)
elif i == 6:
print(252)
elif i == 7:
print(924)
elif i == 8:
print(3432)
elif i == 9:
print(12870)
else : print(48620)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,638,255,557 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
s = input()
D = 0
i = 0
while i < n-1:
if s[i] != s[i+1]:
i = i + 2
D = D + 1
else :
i = i + 1
print(n-count) | Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
n = int(input())
s = input()
D = 0
i = 0
while i < n-1:
if s[i] != s[i+1]:
i = i + 2
D = D + 1
else :
i = i + 1
print(n-count)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
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,622,734,489 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,150,400 | def goals(n):
dic={}
for i in range(n):
k=input()
if dic.get(k)!=None:
dic[k]+=1
else:
dic[k]=1
arr=[]
for i in dic.keys():
arr.append([i,dic[i]])
if arr[0][1]>arr[1][1]:
return arr[0][0]
else:
return a... | 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
def goals(n):
dic={}
for i in range(n):
k=input()
if dic.get(k)!=None:
dic[k]+=1
else:
dic[k]=1
arr=[]
for i in dic.keys():
arr.append([i,dic[i]])
if arr[0][1]>arr[1][1]:
return arr[0][0]
else:
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,554,901,385 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 951 | 61,440,000 | n,m,k=list(map(int,input().split()))
a=list(map(int,input().rstrip().split()))
a.insert(0,0)
c=[False]*(10**6+1)
for i in range(1,m+1):
c[a[i]]=True
initial=1
ans=1
for i in range(k):
f,d=list(map(int,input().split()))
if initial==f:
initial=d
ans=initial
elif initial ==d:
... | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n,m,k=list(map(int,input().split()))
a=list(map(int,input().rstrip().split()))
a.insert(0,0)
c=[False]*(10**6+1)
for i in range(1,m+1):
c[a[i]]=True
initial=1
ans=1
for i in range(k):
f,d=list(map(int,input().split()))
if initial==f:
initial=d
ans=initial
elif init... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,645,271,763 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 |
import math
word = input()
rev_word = input()
is_rev = True
for i in range(math.ceil(len(word) / 2)):
if word[i] == rev_word[len(word) - i -1]:
is_rev = False
break
if is_rev:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
import math
word = input()
rev_word = input()
is_rev = True
for i in range(math.ceil(len(word) / 2)):
if word[i] == rev_word[len(word) - i -1]:
is_rev = False
break
if is_rev:
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,694,509,438 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,764,800 | a=input()
b=a.strip("{","}")
b=set(b)
v=list(b)
print(len(v)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a=input()
b=a.strip("{","}")
b=set(b)
v=list(b)
print(len(v))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,602,226,023 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 187 | 2,150,400 | n=int(input())
a=int(input())
sa=str(a)
numberl=[]
ans=""
for i in range(n):
if sa[i] == '0' or sa[i] == '1':
continue
elif sa[i] == '2':
numberl.append(2)
elif sa[i] == '3':
numberl.append(3)
numberl.append(2)
elif sa[i] == '4':
numberl.append(3)
... | Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that cont... | ```python
n=int(input())
a=int(input())
sa=str(a)
numberl=[]
ans=""
for i in range(n):
if sa[i] == '0' or sa[i] == '1':
continue
elif sa[i] == '2':
numberl.append(2)
elif sa[i] == '3':
numberl.append(3)
numberl.append(2)
elif sa[i] == '4':
numberl.ap... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,671,638,771 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 77 | 0 | a, b = [int(i) for i in input().split()]
w = 0
l = 0
d = 0
for i in range(1, 7):
if (abs(a-i) < abs(b-i)):
w += 1
elif (abs(a-i) == abs(b-i)):
d += 1
else:
l += 1
print(w, d, l)
# 1,2,3,4,5,6
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a, b = [int(i) for i in input().split()]
w = 0
l = 0
d = 0
for i in range(1, 7):
if (abs(a-i) < abs(b-i)):
w += 1
elif (abs(a-i) == abs(b-i)):
d += 1
else:
l += 1
print(w, d, l)
# 1,2,3,4,5,6
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,576,589,926 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | t=input()
n=int(t.split(' ')[0])
k=int(t.split(' ')[1])
l=[]
for i in range(n):
l.append(input())
password = input()
t=0
l.sort(key=len)
for i in l:
t+=1
if len(i)==len(password):
break
def getans(t):
return t+(t//k)*5
a=getans(t)
t=0
for i in l:
if len(i)>len(password):
... | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
t=input()
n=int(t.split(' ')[0])
k=int(t.split(' ')[1])
l=[]
for i in range(n):
l.append(input())
password = input()
t=0
l.sort(key=len)
for i in l:
t+=1
if len(i)==len(password):
break
def getans(t):
return t+(t//k)*5
a=getans(t)
t=0
for i in l:
if len(i)>len(passwo... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,679,644,258 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | x=list(map(int,list(input())))
s=''
for i in range(len(x)):
if x[i]<=1:
s+=str(x[i])
else:
break
s+="1"*(len(x)-len(s))
print(int(s,2)) | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
x=list(map(int,list(input())))
s=''
for i in range(len(x)):
if x[i]<=1:
s+=str(x[i])
else:
break
s+="1"*(len(x)-len(s))
print(int(s,2))
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,696,998,316 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | x=input()
c=0
for i in range(len(x)):
if(x.count(x[i])>1):
c=c+1
break
else:
continue
if c>0:
print("IGNORE HIM")
else:
print("CHAT WITH HER!") | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
x=input()
c=0
for i in range(len(x)):
if(x.count(x[i])>1):
c=c+1
break
else:
continue
if c>0:
print("IGNORE HIM")
else:
print("CHAT WITH HER!")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,620,106,706 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | ans2=99999999999999
t,m = map(int,input().split())
h,d,c,n = map(int,input().split())
a = h//n
if h%n>0:
a+=1
ans1 = a*c
if t<20:
m_left = 60-m
t_left = 20-t
t_left -= 1
t_left = t_left * 60
t_left += m_left
t_left *= d
h += t_left
# print(h)
b = h // n
i... | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
ans2=99999999999999
t,m = map(int,input().split())
h,d,c,n = map(int,input().split())
a = h//n
if h%n>0:
a+=1
ans1 = a*c
if t<20:
m_left = 60-m
t_left = 20-t
t_left -= 1
t_left = t_left * 60
t_left += m_left
t_left *= d
h += t_left
# print(h)
b = h /... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,533,473,936 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | #from sys import stdin, stdout
rounds = eval(input())
array = []
while(rounds > 0):
array.append(eval(input()))
rounds = rounds - 1
itr = 0
score_even = 0
score_odd = 0
while(itr < len(array)):
#code
answer = array[itr] % 2
if (answer == 0):
score_even += 1
else :
... | 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
#from sys import stdin, stdout
rounds = eval(input())
array = []
while(rounds > 0):
array.append(eval(input()))
rounds = rounds - 1
itr = 0
score_even = 0
score_odd = 0
while(itr < len(array)):
#code
answer = array[itr] % 2
if (answer == 0):
score_even += 1
... | -1 | MatrixStudio/Codeforces-Python-Submissions |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,633,251,837 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 20,172,800 | n, m = map(int, input().split())
tol = (n * (n + 1)) / 2
cur_m = m % tol
i = 1
while cur_m > i:
cur_m -= i
i += 1
print(cur_m)
| Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n, m = map(int, input().split())
tol = (n * (n + 1)) / 2
cur_m = m % tol
i = 1
while cur_m > i:
cur_m -= i
i += 1
print(cur_m)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
722 | A | Broken Clock | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken ... | The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. | The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. | [
"24\n17:30\n",
"12\n17:30\n",
"24\n99:99\n"
] | [
"17:30\n",
"07:30\n",
"09:09\n"
] | none | 500 | [
{
"input": "24\n17:30",
"output": "17:30"
},
{
"input": "12\n17:30",
"output": "07:30"
},
{
"input": "24\n99:99",
"output": "09:09"
},
{
"input": "12\n05:54",
"output": "05:54"
},
{
"input": "12\n00:05",
"output": "01:05"
},
{
"input": "24\n23:80",
... | 1,566,412,680 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 140 | 102,400 | n=int(input())
a=input()
x=int(a[:2])
y=int(a[3:])
if(n==12):
if(x==0):
a="10"+a[2:]
elif(x>12):
if(a[1]=="0"):
a="1"+a[1:]
else:
a="0"+a[1:]
if(y>59):
a=a[:3]+"0"+a[-1]
else:
if(x>23):
a="0"+a[1:]
if(y>59):
a=a[:3]+"0"+a[-1]
print(a)
| Title: Broken Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes cha... | ```python
n=int(input())
a=input()
x=int(a[:2])
y=int(a[3:])
if(n==12):
if(x==0):
a="10"+a[2:]
elif(x>12):
if(a[1]=="0"):
a="1"+a[1:]
else:
a="0"+a[1:]
if(y>59):
a=a[:3]+"0"+a[-1]
else:
if(x>23):
a="0"+a[1:]
if(y>59):
a=a[:3]+"0"+a[-1]
print(a)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
899 | E | Segments Removal | PROGRAMMING | 2,000 | [
"data structures",
"dsu",
"flows",
"implementation",
"two pointers"
] | null | null | Vasya has an array of integers of length *n*.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13,<=13,<=7,<=7,<=7,<=2,<=2,<=2], then after o... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — Vasya's array. | Print the number of operations Vasya should make to remove all elements from the array. | [
"4\n2 5 5 2\n",
"5\n6 3 4 1 5\n",
"8\n4 4 4 2 2 100 100 100\n",
"6\n10 10 50 10 50 50\n"
] | [
"2\n",
"5\n",
"3\n",
"4\n"
] | In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. I... | 2,250 | [
{
"input": "4\n2 5 5 2",
"output": "2"
},
{
"input": "5\n6 3 4 1 5",
"output": "5"
},
{
"input": "8\n4 4 4 2 2 100 100 100",
"output": "3"
},
{
"input": "6\n10 10 50 10 50 50",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n45 45... | 1,539,432,312 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | sizeArray = int(input())
values = input().split()
stack = []
anterior = None
for i in values:
if i != anterior:
stack.append(i)
anterior = i
print(len(stack)) | Title: Segments Removal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array of integers of length *n*.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segm... | ```python
sizeArray = int(input())
values = input().split()
stack = []
anterior = None
for i in values:
if i != anterior:
stack.append(i)
anterior = i
print(len(stack))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
441 | B | Valera and Fruits | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collec... | The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* a... | Print a single integer — the maximum number of fruit that Valera can collect. | [
"2 3\n1 5\n2 3\n",
"5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n"
] | [
"8\n",
"60\n"
] | In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree.
In the second s... | 1,000 | [
{
"input": "2 3\n1 5\n2 3",
"output": "8"
},
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20",
"output": "60"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202",
"output": "10596"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445... | 1,402,243,136 | 1,736 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 139 | 5,222,400 | from sys import stdin as cin
from fractions import Fraction as f
import math
n,v = map(int,cin.readline().split())
d={}
for t in range(n):
x,y = map(int,cin.readline().split())
if x in d:
d[x].append(y)
else:
d[x]=[y]
#print(d)
count=0
r=0
for x in d:
m = sum(d[x])+r
if m>=v:
... | Title: Valera and Fruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera loves his garden, where *n* fruit trees grow.
This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get wit... | ```python
from sys import stdin as cin
from fractions import Fraction as f
import math
n,v = map(int,cin.readline().split())
d={}
for t in range(n):
x,y = map(int,cin.readline().split())
if x in d:
d[x].append(y)
else:
d[x]=[y]
#print(d)
count=0
r=0
for x in d:
m = sum(d[x])+r
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,603,484,494 | 2,147,483,647 | PyPy 3 | OK | TESTS | 104 | 233 | 10,035,200 | def func(string):
tamanho = len(string)
if tamanho%2 == 1:
return string
else:
tamanho = tamanho//2
string1 = func(string[:tamanho])
string2 = func(string[tamanho:])
if string1<string2:
return string1+string2
else:
return st... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def func(string):
tamanho = len(string)
if tamanho%2 == 1:
return string
else:
tamanho = tamanho//2
string1 = func(string[:tamanho])
string2 = func(string[tamanho:])
if string1<string2:
return string1+string2
else:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,599,572,074 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 216 | 0 | import operator
t = int(input())
matches = {}
for i in range(t):
team = input()
if team in matches.keys():
matches[team] = matches[team]+1
else:
matches[team] = 1
print(max(matches.items(), key=operator.itemgetter(1))[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
import operator
t = int(input())
matches = {}
for i in range(t):
team = input()
if team in matches.keys():
matches[team] = matches[team]+1
else:
matches[team] = 1
print(max(matches.items(), key=operator.itemgetter(1))[0])
``` | 3.946 | MatrixStudio/Codeforces-Python-Submissions |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,560,543,808 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | from sys import stdin, stdout
N=int(stdin.readline())
if(N>2):
stdout.write(str(N*(N-1)*(N-2))+"\n")
elif(N==2):
stdout.write("2\n")
elif(N==1):
stdout.write("1\n") | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
from sys import stdin, stdout
N=int(stdin.readline())
if(N>2):
stdout.write(str(N*(N-1)*(N-2))+"\n")
elif(N==2):
stdout.write("2\n")
elif(N==1):
stdout.write("1\n")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,684,897,707 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | from math import sqrt
def is_prime(n):
i = 2
while i <= sqrt(n):
if n % i == 0:
return True
i += 1
if n > 1:
return False
def main():
a = int(open(0).read())
b = a // 2
while b >= 4:
if is_prime(b) and is_prime(a - b... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
from math import sqrt
def is_prime(n):
i = 2
while i <= sqrt(n):
if n % i == 0:
return True
i += 1
if n > 1:
return False
def main():
a = int(open(0).read())
b = a // 2
while b >= 4:
if is_prime(b) and is_p... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 0 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724... | 1,571,231,382 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | import math
def meu_map(l):
for i in range(len(l)):
l[i] = int(l[i])
def gcd(a, b):
a, b = max(a, b), min(a, b)
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def bids(n, nums):
A = lcm(nums[0], nums[1])
for i in range(2, n):
A... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a*... | ```python
import math
def meu_map(l):
for i in range(len(l)):
l[i] = int(l[i])
def gcd(a, b):
a, b = max(a, b), min(a, b)
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def bids(n, nums):
A = lcm(nums[0], nums[1])
for i in range(2, n):... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
197 | A | Plate Game | PROGRAMMING | 1,600 | [
"constructive algorithms",
"games",
"math"
] | null | null | You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with... | A single line contains three space-separated integers *a*, *b*, *r* (1<=≤<=*a*,<=*b*,<=*r*<=≤<=100) — the table sides and the plates' radius, correspondingly. | If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). | [
"5 5 2\n",
"6 7 4\n"
] | [
"First\n",
"Second\n"
] | In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.
In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. | 1,000 | [
{
"input": "5 5 2",
"output": "First"
},
{
"input": "6 7 4",
"output": "Second"
},
{
"input": "100 100 1",
"output": "First"
},
{
"input": "1 1 100",
"output": "Second"
},
{
"input": "13 7 3",
"output": "First"
},
{
"input": "23 7 3",
"output": "Fi... | 1,696,883,089 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | from math import pi
a,b,r = map(int,input().split())
x,y = a*b,pi*r*r
z = x//y
if z%2==0:
print("Second")
else:
print("First")
| Title: Plate Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie o... | ```python
from math import pi
a,b,r = map(int,input().split())
x,y = a*b,pi*r*r
z = x//y
if z%2==0:
print("Second")
else:
print("First")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,592,402,372 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 218 | 4,403,200 | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
dict = {}
n,m = rinput()
for _ in range(m):
l1... | 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
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
dict = {}
n,m = rinput()
for _ in range(m... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,686,555,587 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 204,800 | n = int(input())
a = []
for i in range(n):
val = int(input())
a.append(val)
curr = 0
actions = 0
for i in range(n-1):
curr = a[i]
#walks up
actions += 1
#eats
actions += 1
#comes down to min(a[i], a[i+1])
curr = min(a[i], a[i+1])
actions += 1
#for last tree
act... | Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan... | ```python
n = int(input())
a = []
for i in range(n):
val = int(input())
a.append(val)
curr = 0
actions = 0
for i in range(n-1):
curr = a[i]
#walks up
actions += 1
#eats
actions += 1
#comes down to min(a[i], a[i+1])
curr = min(a[i], a[i+1])
actions += 1
#for last... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
760 | B | Frodo and pillows | PROGRAMMING | 1,500 | [
"binary search",
"greedy"
] | null | null | *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge... | The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed. | Print single integer — the maximum number of pillows Frodo can have so that no one is hurt. | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n"
] | [
"2\n",
"4\n",
"3\n"
] | In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third exa... | 1,000 | [
{
"input": "4 6 2",
"output": "2"
},
{
"input": "3 10 3",
"output": "4"
},
{
"input": "3 6 1",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1000000000 1",
"output": "1000000000"
},
{
... | 1,548,778,392 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 93 | 0 | def t(n, m, k, x):
# t = n
t = x
y = k - 1
if y > x - 1:
t += ((x - 1) * x) // 2 + y - (x - 1)
else:
t += ((x - 1 + x - y) * y) // 2
y = n - k
if y > x - 1:
t += ((x - 1) * x) // 2
else:
t += ((x - 1 + x - y) * y) // 2
# print(x, ':', ... | Title: Frodo and pillows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma... | ```python
def t(n, m, k, x):
# t = n
t = x
y = k - 1
if y > x - 1:
t += ((x - 1) * x) // 2 + y - (x - 1)
else:
t += ((x - 1 + x - y) * y) // 2
y = n - k
if y > x - 1:
t += ((x - 1) * x) // 2
else:
t += ((x - 1 + x - y) * y) // 2
# prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,630,107,938 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 93 | 7,475,200 | # Matheus de Souza Oliveira RA: 203407
import re
senha = input()
pattern = '^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{5,}$'
compiledRegex = re.compile(pattern)
match = re.fullmatch(compiledRegex, senha)
if match:
print("Correct")
else:
print("Too weak")
| Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password... | ```python
# Matheus de Souza Oliveira RA: 203407
import re
senha = input()
pattern = '^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{5,}$'
compiledRegex = re.compile(pattern)
match = re.fullmatch(compiledRegex, senha)
if match:
print("Correct")
else:
print("Too weak")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one.
Ivan knows some information about the string *s*. Namely, he remembers, that string *t**i* occurs in string *s* at least *k**... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings Ivan remembers.
The next *n* lines contain information about the strings. The *i*-th of these lines contains non-empty string *t**i*, then positive integer *k**i*, which equal to the number of times the string *t**i* occurs in strin... | Print lexicographically minimal string that fits all the information Ivan remembers. | [
"3\na 4 1 3 5 7\nab 2 1 5\nca 1 4\n",
"1\na 1 3\n",
"3\nab 1 1\naba 1 3\nab 2 3 5\n"
] | [
"abacaba\n",
"aaa\n",
"ababab\n"
] | none | 0 | [
{
"input": "3\na 4 1 3 5 7\nab 2 1 5\nca 1 4",
"output": "abacaba"
},
{
"input": "1\na 1 3",
"output": "aaa"
},
{
"input": "3\nab 1 1\naba 1 3\nab 2 3 5",
"output": "ababab"
},
{
"input": "6\nba 2 16 18\na 1 12\nb 3 4 13 20\nbb 2 6 8\nababbbbbaab 1 3\nabababbbbb 1 1",
"ou... | 1,499,795,773 | 4,273 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 64,204,800 | q=int(input())
a={}
for i in range(0,q):
s=list(input().split())
d=s[0]
if a.get(d,'asd')!='asd':
a.update({d:list(map(int,s[2:]))+a.get(d)})
else:
a.update({d:list(map(int,s[2:]))})
d={}
for i in a.items():
l=len(i[0])
s=i[0]
for j in i[1]:
for k in ran... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one.
Ivan knows some information about t... | ```python
q=int(input())
a={}
for i in range(0,q):
s=list(input().split())
d=s[0]
if a.get(d,'asd')!='asd':
a.update({d:list(map(int,s[2:]))+a.get(d)})
else:
a.update({d:list(map(int,s[2:]))})
d={}
for i in a.items():
l=len(i[0])
s=i[0]
for j in i[1]:
fo... | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.