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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,673,620,394 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 77 | 4,608,000 | n, x = eval(input()), list(map(eval,input().split())); jud = False
for i in range(n-1):
for j in range(n-1):
a, b, c, d = min(x[i],x[i+1]), max(x[i],x[i+1]), min(x[j],x[j+1]), max(x[j],x[j+1])
if a < c < b < d: jud = True; break
if jud: break
print("yes" if jud else "no") | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
n, x = eval(input()), list(map(eval,input().split())); jud = False
for i in range(n-1):
for j in range(n-1):
a, b, c, d = min(x[i],x[i+1]), max(x[i],x[i+1]), min(x[j],x[j+1]), max(x[j],x[j+1])
if a < c < b < d: jud = True; break
if jud: break
print("yes" if jud else "no")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,776,534 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | nh=list(map(int, input().split()))
a=list(map(int, input().split()))
s=nh[0]
for i in range(nh[0]):
if a[i]>nh[1]:
s+=1
else: pass
print(s) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
nh=list(map(int, input().split()))
a=list(map(int, input().split()))
s=nh[0]
for i in range(nh[0]):
if a[i]>nh[1]:
s+=1
else: pass
print(s)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,691,506,113 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | i=input;print("IO hb,e cmoym ek etyhbeo agrudy!."[int(i())>len(set(i().split()[1:]+i().split()[1:]))::2]) | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
i=input;print("IO hb,e cmoym ek etyhbeo agrudy!."[int(i())>len(set(i().split()[1:]+i().split()[1:]))::2])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,599,437,323 | 523 | PyPy 3 | OK | TESTS | 42 | 234 | 10,137,600 | import sys
from collections import Counter
n, m = map(int, input().split())
cnt = Counter(map(int, input().split()))
ans = 0
for k, v in cnt.items():
n -= v
ans += v * n
print(ans)
| Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
import sys
from collections import Counter
n, m = map(int, input().split())
cnt = Counter(map(int, input().split()))
ans = 0
for k, v in cnt.items():
n -= v
ans += v * n
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
628 | A | Tennis Tournament | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 ... | The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* — the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be onl... | 0 | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
... | 1,459,522,544 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | n=int(input())
b=int(input())
p=int(input())
y=n*p
x=(b+3)*(n-1)
print(x,y)
| Title: Tennis Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is ... | ```python
n=int(input())
b=int(input())
p=int(input())
y=n*p
x=(b+3)*(n-1)
print(x,y)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
21 | B | Intersection | PROGRAMMING | 2,000 | [
"implementation",
"math"
] | B. Intersection | 1 | 256 | You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0.
Write the program which finds the number of points in the intersection of two given sets. | The first line of the input contains three integer numbers *A*1,<=*B*1,<=*C*1 separated by space. The second line contains three integer numbers *A*2,<=*B*2,<=*C*2 separated by space. All the numbers are between -100 and 100, inclusive. | Print the number of points in the intersection or -1 if there are infinite number of points. | [
"1 1 0\n2 2 0\n",
"1 1 0\n2 -2 0\n"
] | [
"-1\n",
"1\n"
] | none | 1,000 | [
{
"input": "1 1 0\n2 2 0",
"output": "-1"
},
{
"input": "1 1 0\n2 -2 0",
"output": "1"
},
{
"input": "0 0 0\n0 0 0",
"output": "-1"
},
{
"input": "1 1 1\n1 1 1",
"output": "-1"
},
{
"input": "8 3 -4\n-5 2 7",
"output": "1"
},
{
"input": "-1 -1 0\n0 -1 ... | 1,572,140,537 | 2,147,483,647 | PyPy 3 | OK | TESTS | 140 | 155 | 0 |
'''
inválida: 0
plano: 1
reta com 0º (horizontal): 2
reta com 90º (vertical): 3
reta com qualquer ângulo: 4
'''
def tipo (a, b, c):
if a == 0 and b == 0:
if c == 0:
return 1
else:
return 0
elif a == 0:
return 2
elif b == 0:
return 3
else:
return 4
entrada1 = (input())
vet=entr... | Title: Intersection
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0.
Write the program which fin... | ```python
'''
inválida: 0
plano: 1
reta com 0º (horizontal): 2
reta com 90º (vertical): 3
reta com qualquer ângulo: 4
'''
def tipo (a, b, c):
if a == 0 and b == 0:
if c == 0:
return 1
else:
return 0
elif a == 0:
return 2
elif b == 0:
return 3
else:
return 4
entrada1 = (input()... | 3.9225 | MatrixStudio/Codeforces-Python-Submissions |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,646,231,617 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 62 | 2,457,600 | n, m = map(int, input().split())
ls = {i: 1 for i in range(1, m+1)}
cnt = 0
for _ in range(n):
bulbs = list(map(int, input().split()))
if bulbs[0] > 0:
for i in range(1, len(bulbs)):
if bulbs[i] in ls:
if ls[bulbs[i]] > 0:
cnt += 1
... | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = map(int, input().split())
ls = {i: 1 for i in range(1, m+1)}
cnt = 0
for _ in range(n):
bulbs = list(map(int, input().split()))
if bulbs[0] > 0:
for i in range(1, len(bulbs)):
if bulbs[i] in ls:
if ls[bulbs[i]] > 0:
cnt += 1
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
356 | A | Knight Tournament | PROGRAMMING | 1,500 | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 500 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,622,795,251 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 2,867,200 | n, m = input().split(' ')
r = []
for _ in range(int(n)):
r.append(0)
for _ in range(int(m)):
r1, r2, win = input().split(' ')
for i in range(int(r1), int(r2)+1):
if int(win) != i and r[i-1] == 0:
r[i-1] = int(win)
result = ''
for i in r:
result += str(i) + ' '
print(resul... | Title: Knight Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're j... | ```python
n, m = input().split(' ')
r = []
for _ in range(int(n)):
r.append(0)
for _ in range(int(m)):
r1, r2, win = input().split(' ')
for i in range(int(r1), int(r2)+1):
if int(win) != i and r[i-1] == 0:
r[i-1] = int(win)
result = ''
for i in r:
result += str(i) + ' '
p... | 0 | 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,644,656,743 | 3,343 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sat Feb 12 16:15:01 2022
@author: xiaol
"""
n = int(input(""))
s = dict()
x = 0.99
y = 0.00001
for i in range(n):
a,b=map(str,input().split())
if s.get(str(a)) == None:
s[str(a)]=float(b)+x
else:
if float(b)<=0:
s[str(a)]=... | 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
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 12 16:15:01 2022
@author: xiaol
"""
n = int(input(""))
s = dict()
x = 0.99
y = 0.00001
for i in range(n):
a,b=map(str,input().split())
if s.get(str(a)) == None:
s[str(a)]=float(b)+x
else:
if float(b)<=0:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,605,680,504 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 310 | 0 | string = input()
d = {}
for i in string:
d[i] = d.get(i, 0) + 1
print(max(d)*d[max(d)]) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
string = input()
d = {}
for i in string:
d[i] = d.get(i, 0) + 1
print(max(d)*d[max(d)])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,634,649,793 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,500 | 716,800 | import sys
input = sys.stdin.readline
TRACKER = [0]*(200000+2)
def get_numbers():
return map(int, input().split())
n, k, q = get_numbers()
for _ in range(n):
l, r = get_numbers()
TRACKER[l] += 1
TRACKER[r+1] -= 1
for i in range(2, len(TRACKER)):
TRACKER[i] += TRACKER[i-1]
f... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
import sys
input = sys.stdin.readline
TRACKER = [0]*(200000+2)
def get_numbers():
return map(int, input().split())
n, k, q = get_numbers()
for _ in range(n):
l, r = get_numbers()
TRACKER[l] += 1
TRACKER[r+1] -= 1
for i in range(2, len(TRACKER)):
TRACKER[i] += TRACKER... | 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,656,691,850 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = eval(input())
a = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
a[i][0] = 1
a[0][i] = 1
for i in range(1,n):
for j in range(1,n):
a[i][j] = a[i-1][j] + a[i][j-1]
print(a[n-1][n-1]) | 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
n = eval(input())
a = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
a[i][0] = 1
a[0][i] = 1
for i in range(1,n):
for j in range(1,n):
a[i][j] = a[i-1][j] + a[i][j-1]
print(a[n-1][n-1])
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000... | 1,493,754,586 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 190,668,800 | str_params = input()
[n, k]= [int(s) for s in str_params.split(' ')]
numbers = [x+1 for x in range(k)]
i = sum(numbers)
while (n%i!=0)&(i<n):
numbers[k-1] = numbers[k-1]+1
i = sum(numbers)
#print (i, numbers)
nod = n//i
numbers = [numbers[x]*nod for x in range(k)]
#print (nod, i, numbers)
if numbers[0]==... | Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Grea... | ```python
str_params = input()
[n, k]= [int(s) for s in str_params.split(' ')]
numbers = [x+1 for x in range(k)]
i = sum(numbers)
while (n%i!=0)&(i<n):
numbers[k-1] = numbers[k-1]+1
i = sum(numbers)
#print (i, numbers)
nod = n//i
numbers = [numbers[x]*nod for x in range(k)]
#print (nod, i, numbers)
if nu... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,676,951,096 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | def bac(n):
p=bin(n)[::2]
print (p.count("1"))
n=int(input())
bac(n) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
def bac(n):
p=bin(n)[::2]
print (p.count("1"))
n=int(input())
bac(n)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,643,049,810 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 0 | n=int(input())
a=[]
b=[]
for i in range(0,n):
c=list(map(int,input().split()))
a.append(c[0])
b.append(c[1])
p=a.count(0)
q=a.count(1)
k=min(p,q)
p=b.count(0)
q=b.count(1)
l=min(p,q)
print(k+l)
| Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n=int(input())
a=[]
b=[]
for i in range(0,n):
c=list(map(int,input().split()))
a.append(c[0])
b.append(c[1])
p=a.count(0)
q=a.count(1)
k=min(p,q)
p=b.count(0)
q=b.count(1)
l=min(p,q)
print(k+l)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,597,431,417 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 | n,k = list(map(int,input().split()))
print((n+k)-(n%k)) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
n,k = list(map(int,input().split()))
print((n+k)-(n%k))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then s... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0... | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 100000000000... | 1,578,052,796 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 217 | 716,800 | def test_2():
# D - Partition
"""
If a = 0 or b = 0, end the process. Otherwise, go to step 2;
If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.
"""
n, m =... | Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then... | ```python
def test_2():
# D - Partition
"""
If a = 0 or b = 0, end the process. Otherwise, go to step 2;
If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.
"""
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,645,169,981 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 264 | 25,395,200 | def main():
n = int(input())
arr = list(map(int, input().split()))
current_pointer = n
current_arr = []
reserve_set = set()
for element in arr:
if element == current_pointer:
temp_arr = [element]
current_pointer -= 1
while current_pointer !... | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
current_pointer = n
current_arr = []
reserve_set = set()
for element in arr:
if element == current_pointer:
temp_arr = [element]
current_pointer -= 1
while current... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
916 | C | Jamie and Interesting Graph | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | Jamie has recently found undirected weighted graphs with the following properties very interesting:
- The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The su... | First line of input contains 2 integers *n*, *m* — the required number of vertices and edges. | In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree.
In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) d... | [
"4 4\n",
"5 4\n"
] | [
"7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n",
"7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n"
] | The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).
Definition of terms used in the problem statement:
A shor... | 1,500 | [
{
"input": "4 4",
"output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000"
},
{
"input": "5 4",
"output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1"
},
{
"input": "2 1",
"output": "100003 100003\n1 2 100003"
},
{
"input": "10 19",
"output": "100003 100003... | 1,516,378,260 | 5,760 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 5,632,000 | n, m = list(map(int, input().split()))
P = 107309
k = [1] * n
print('3 107309')
for i in range(n - 3):
print('1 ' + str(i + 2) + ' 1')
print('1 ' + str(n) + ' 3')
print('1 ' + str(n - 1) + ' ' + str(P - n))
k[0] = n - 1
m = m - n + 1
l = 1
while m > 0:
if k[l] == n - 1:
l += 1
i = l... | Title: Jamie and Interesting Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie has recently found undirected weighted graphs with the following properties very interesting:
- The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integer... | ```python
n, m = list(map(int, input().split()))
P = 107309
k = [1] * n
print('3 107309')
for i in range(n - 3):
print('1 ' + str(i + 2) + ' 1')
print('1 ' + str(n) + ' 3')
print('1 ' + str(n - 1) + ' ' + str(P - n))
k[0] = n - 1
m = m - n + 1
l = 1
while m > 0:
if k[l] == n - 1:
l += 1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,673,710,273 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | import sys
if __name__ == '__main__':
val = int(sys.stdin.readline())
res = 1
for i in range(val):
res = res * 8
res = res % 10
print(res) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
import sys
if __name__ == '__main__':
val = int(sys.stdin.readline())
res = 1
for i in range(val):
res = res * 8
res = res % 10
print(res)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,959,680 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | m = int(input())
n = k = m
while True:
k += 1
n = k
y1 = n % 10
n //= 10
y2 = n % 10
n //= 10
y3 = n % 10
n //= 10
y4 = n % 10
if (y1 == y2 or y1 == y3 or y1 == y4 or y2 == y3 or y2 == y4 or y3 == y4):
continue
else:
print(k)
break | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
m = int(input())
n = k = m
while True:
k += 1
n = k
y1 = n % 10
n //= 10
y2 = n % 10
n //= 10
y3 = n % 10
n //= 10
y4 = n % 10
if (y1 == y2 or y1 == y3 or y1 == y4 or y2 == y3 or y2 == y4 or y3 == y4):
continue
else:
print(k)
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
79 | A | Bus Game | PROGRAMMING | 1,200 | [
"greedy"
] | A. Bus Game | 2 | 256 | After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen ... | The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space. | If Ciel wins, print "Ciel". Otherwise, print "Hanako". | [
"2 2\n",
"3 22\n"
] | [
"Ciel\n",
"Hanako\n"
] | In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose. | 500 | [
{
"input": "2 2",
"output": "Ciel"
},
{
"input": "3 22",
"output": "Hanako"
},
{
"input": "0 22",
"output": "Ciel"
},
{
"input": "1000 1000",
"output": "Ciel"
},
{
"input": "0 0",
"output": "Hanako"
},
{
"input": "0 21",
"output": "Hanako"
},
{... | 1,494,238,442 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 204,800 | x, y = [int(x) for x in input().split()]
def even_move(x, y):
if x >= 2 and y >= 2:
return [True, x - 2, y - 2]
if x >= 1 and y >= 11:
return [True, x - 1, y - 11]
if y >= 22:
return [True, x, y - 22]
return [False, x, y]
def odd_move(x, y):
if y >= 22:
return [True... | Title: Bus Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored ... | ```python
x, y = [int(x) for x in input().split()]
def even_move(x, y):
if x >= 2 and y >= 2:
return [True, x - 2, y - 2]
if x >= 1 and y >= 11:
return [True, x - 1, y - 11]
if y >= 22:
return [True, x, y - 22]
return [False, x, y]
def odd_move(x, y):
if y >= 22:
re... | 0 | MatrixStudio/Codeforces-Python-Submissions |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,518,413,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,632,000 | k,a,b = map(int, input().split())
ans=0
if a%k==0 or b%k==0:
print(a//k)
else:
print(-1)
| Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
k,a,b = map(int, input().split())
ans=0
if a%k==0 or b%k==0:
print(a//k)
else:
print(-1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,651,997,236 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n=int(input())
if n%2==1:
print(-1)
else:
t=''
for i in range(1,n+1):
if i%2==1:
t+=str(i+1)+' '
else:
t+=str(i-1)+' '
print(t)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
n=int(input())
if n%2==1:
print(-1)
else:
t=''
for i in range(1,n+1):
if i%2==1:
t+=str(i+1)+' '
else:
t+=str(i-1)+' '
print(t)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
587 | B | Duff in Beach | PROGRAMMING | 2,100 | [
"dp"
] | null | null | While Duff was resting in the beach, she accidentally found a strange array *b*0,<=*b*1,<=...,<=*b**l*<=-<=1 consisting of *l* positive integers. This array was strange because it was extremely long, but there was another (maybe shorter) array, *a*0,<=...,<=*a**n*<=-<=1 that *b* can be build from *a* with formula: *b**... | The first line of input contains three integers, *n*,<=*l* and *k* (1<=≤<=*n*,<=*k*, *n*<=×<=*k*<=≤<=106 and 1<=≤<=*l*<=≤<=1018).
The second line contains *n* space separated integers, *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109 for each 0<=≤<=*i*<=≤<=*n*<=-<=1). | Print the answer modulo 1<=000<=000<=007 in one line. | [
"3 5 3\n5 9 1\n",
"5 10 3\n1 2 3 4 5\n"
] | [
"10\n",
"25\n"
] | In the first sample case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d9d8fe92937aeef2bcddb9d213e5587f0f950087.png" style="max-width: 100.0%;max-height: 100.0%;"/>. So all such sequences are: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/54d7dd513b50dae341... | 1,000 | [] | 1,692,302,259 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692302259.2105813")# 1692302259.2105992 | Title: Duff in Beach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Duff was resting in the beach, she accidentally found a strange array *b*0,<=*b*1,<=...,<=*b**l*<=-<=1 consisting of *l* positive integers. This array was strange because it was extremely long, but there was another... | ```python
print("_RANDOM_GUESS_1692302259.2105813")# 1692302259.2105992
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,434,184,245 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | s=input()
l=len(s)
n=int(s)
min=2*(2**(l-1)-1)+1
max=2*(2**l-1)
while(l!=0):
avg=(max+min)//2
k=n//10**(l-1)
if(max-min==1):
print(min if k==4 else max)
if(k==4):
max=avg
else:
min=avg+1
n=n%10**(l-1)
l-=1 | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
s=input()
l=len(s)
n=int(s)
min=2*(2**(l-1)-1)+1
max=2*(2**l-1)
while(l!=0):
avg=(max+min)//2
k=n//10**(l-1)
if(max-min==1):
print(min if k==4 else max)
if(k==4):
max=avg
else:
min=avg+1
n=n%10**(l-1)
l-=1
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur... | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 ... | 1,532,360,925 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 2,000 | 1,843,200 | from collections import deque
from itertools import islice
n, m, x, y = map(int, input().split())
bars = []
for i in range(n):
bars.append(input())
min_b = [0] + [1001001 for i in range(y+m+1)]
min_w = [0] + [1001001 for i in range(y+m+1)]
best_b = 0
best_w = 0
for i in range(m):
count_b = 0
... | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulf... | ```python
from collections import deque
from itertools import islice
n, m, x, y = map(int, input().split())
bars = []
for i in range(n):
bars.append(input())
min_b = [0] + [1001001 for i in range(y+m+1)]
min_w = [0] + [1001001 for i in range(y+m+1)]
best_b = 0
best_w = 0
for i in range(m):
co... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
985 | E | Pencils and Boxes | PROGRAMMING | 2,100 | [
"binary search",
"data structures",
"dp",
"greedy",
"two pointers"
] | null | null | Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n* of *n* integer numbers — saturation of the color of each pencil. Now Mis... | The first line contains three integer numbers *n*, *k* and *d* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105, 0<=≤<=*d*<=≤<=109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.
The second line contains *n* integer numbers *a*1,<=... | Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO". | [
"6 3 10\n7 2 7 7 4 2\n",
"6 2 3\n4 5 3 13 4 10\n",
"3 2 5\n10 16 22\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.
In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and p... | 0 | [
{
"input": "6 3 10\n7 2 7 7 4 2",
"output": "YES"
},
{
"input": "6 2 3\n4 5 3 13 4 10",
"output": "YES"
},
{
"input": "3 2 5\n10 16 22",
"output": "NO"
},
{
"input": "8 7 13\n52 85 14 52 92 33 80 85",
"output": "NO"
},
{
"input": "6 4 0\n1 3 2 4 2 1",
"output"... | 1,587,192,776 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 56,115,200 | from sys import stdin, stdout
import math
def biSearch(arr, n, d):
ans = -1
low = 0
high = len(arr) - 1
while high >= low:
mid = (high + low) // 2
if arr[mid] - n <= d:
ans = mid
low = mid + 1
else:
high = mid - 1
return ... | Title: Pencils and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a seque... | ```python
from sys import stdin, stdout
import math
def biSearch(arr, n, d):
ans = -1
low = 0
high = len(arr) - 1
while high >= low:
mid = (high + low) // 2
if arr[mid] - n <= d:
ans = mid
low = mid + 1
else:
high = mid - 1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,689,155,430 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | s=input()
a=s[1:]
b=a.upper()
if a!=b:
print(s)
else:
print(s.swapcase()) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
s=input()
a=s[1:]
b=a.upper()
if a!=b:
print(s)
else:
print(s.swapcase())
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,534,636,635 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | s = input()
l = 0
u = 0
for f in len(s) :
if s.islower() : l += 1
else : u += 1
if l >= u : print(s.lower())
else : print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
l = 0
u = 0
for f in len(s) :
if s.islower() : l += 1
else : u += 1
if l >= u : print(s.lower())
else : print(s.upper())
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,685,310,527 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
nums = ""
i = 0
uzunluq = len(s)
while i < uzunluq:
if s[i] == '.':
nums += "0"
i += 1
elif s[i:i+2] == '-.':
nums += "1"
i += 2
elif s[i:i+2] == '--':
nums += "2"
i += 2
print(nums)
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
s = input()
nums = ""
i = 0
uzunluq = len(s)
while i < uzunluq:
if s[i] == '.':
nums += "0"
i += 1
elif s[i:i+2] == '-.':
nums += "1"
i += 2
elif s[i:i+2] == '--':
nums += "2"
i += 2
print(nums)
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
442 | B | Andrey and Problem | PROGRAMMING | 1,800 | [
"greedy",
"math",
"probabilities"
] | null | null | Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.
Help Andrey choo... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of Andrey's friends. The second line contains *n* real numbers *p**i* (0.0<=≤<=*p**i*<=≤<=1.0) — the probability that the *i*-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point. | Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10<=-<=9. | [
"4\n0.1 0.2 0.3 0.8\n",
"2\n0.1 0.2\n"
] | [
"0.800000000000\n",
"0.260000000000\n"
] | In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.
In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26. | 1,500 | [
{
"input": "4\n0.1 0.2 0.3 0.8",
"output": "0.800000000000"
},
{
"input": "2\n0.1 0.2",
"output": "0.260000000000"
},
{
"input": "1\n0.217266",
"output": "0.217266000000"
},
{
"input": "2\n0.608183 0.375030",
"output": "0.608183000000"
},
{
"input": "3\n0.388818 0... | 1,569,666,030 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 49 | 218 | 409,600 | import decimal
n = int(input())
hi = input()
hi = hi.replace(',', '.', hi.count(','))
hehe = hi.split(" ")
for i in range(len(hehe)):
hehe[i] = float(hehe[i])
hehe = sorted(hehe, reverse=True)
if len(hehe) == 1:
print(hehe[0])
exit()
if max(hehe) >= 0.5:
print(max(hehe))
else:
... | Title: Andrey and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fie... | ```python
import decimal
n = int(input())
hi = input()
hi = hi.replace(',', '.', hi.count(','))
hehe = hi.split(" ")
for i in range(len(hehe)):
hehe[i] = float(hehe[i])
hehe = sorted(hehe, reverse=True)
if len(hehe) == 1:
print(hehe[0])
exit()
if max(hehe) >= 0.5:
print(max(hehe))
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,680,118,583 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | n, m = map(int, input().split())
matrix = [[j for j in input()] for _ in range(n)]
# for row in matrix:
# print(*row)
result, row_counter = 0, 0
for row in matrix:
if 'S' not in row:
result += len(row)
row_counter += 1
for j in range(m):
col = [row[j] for row in matrix]
... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n, m = map(int, input().split())
matrix = [[j for j in input()] for _ in range(n)]
# for row in matrix:
# print(*row)
result, row_counter = 0, 0
for row in matrix:
if 'S' not in row:
result += len(row)
row_counter += 1
for j in range(m):
col = [row[j] for row in ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
689 | E | Mike and Geometry Problem | PROGRAMMING | 2,000 | [
"combinatorics",
"data structures",
"dp",
"geometry",
"implementation"
] | null | null | Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define *f*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1 to be the number of integer points in the segment [*l*,<=*r*] with *l*<=≤<=*r* (say that ). You are given two integers *n* and *k* and *n* closed inter... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200<=000) — the number of segments and the number of segments in intersection groups respectively.
Then *n* lines follow, the *i*-th line contains two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109), describing *i*-th segment bou... | Print one integer number — the answer to Mike's problem modulo 1000000007 (109<=+<=7) in the only line. | [
"3 2\n1 2\n1 3\n2 3\n",
"3 3\n1 3\n1 3\n1 3\n",
"3 1\n1 2\n2 3\n3 4\n"
] | [
"5\n",
"3\n",
"6\n"
] | In the first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/099f833590960ffc5dafcbc207172a93605c44a8.png" style="max-width: 100.0%;max-height: 100.0%;"/>;
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f56e6e99db45efff1c9be404aeb569c7e2bbb1d.png" ... | 2,500 | [
{
"input": "3 2\n1 2\n1 3\n2 3",
"output": "5"
},
{
"input": "3 3\n1 3\n1 3\n1 3",
"output": "3"
},
{
"input": "3 1\n1 2\n2 3\n3 4",
"output": "6"
},
{
"input": "1 1\n45 70",
"output": "26"
},
{
"input": "1 1\n-35 -8",
"output": "28"
},
{
"input": "1 1... | 1,697,698,434 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 69 | 1,513 | 48,128,000 | from collections import defaultdict
mod=10**9+7
MAXN=300001
def power(a,b):
res=1
while b>0:
if b&1:
res=(res*a)%mod
b>>=1
a=(a*a)%mod
return res
fact=[1 for _ in range(MAXN)]
inv_fact=[1 for _ in range(MAXN)]
for i in range(2,MAXN):
fact... | Title: Mike and Geometry Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define *f*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1 to be the number of integer points in th... | ```python
from collections import defaultdict
mod=10**9+7
MAXN=300001
def power(a,b):
res=1
while b>0:
if b&1:
res=(res*a)%mod
b>>=1
a=(a*a)%mod
return res
fact=[1 for _ in range(MAXN)]
inv_fact=[1 for _ in range(MAXN)]
for i in range(2,MAXN):... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,601,981,941 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 15 | 810 | 67,072,000 | from collections import namedtuple
Path = namedtuple('Path','sum2 sum5 next')
def numDiv(num, div):
res = 0
while num > 1:
if num % div > 0:
break
res += 1
num = num // div
return res
if __name__ == '__main__':
n = int(input())
imatrix = []
for i in range(n):
imatrix.append(list(map... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
from collections import namedtuple
Path = namedtuple('Path','sum2 sum5 next')
def numDiv(num, div):
res = 0
while num > 1:
if num % div > 0:
break
res += 1
num = num // div
return res
if __name__ == '__main__':
n = int(input())
imatrix = []
for i in range(n):
imatrix.appen... | 0 | MatrixStudio/Codeforces-Python-Submissions |
656 | F | Ace It! | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer. | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). | Output a single integer. | [
"A221033\n",
"A223635\n",
"A232726\n"
] | [
"21\n",
"22\n",
"23\n"
] | none | 0 | [
{
"input": "A221033",
"output": "21"
},
{
"input": "A223635",
"output": "22"
},
{
"input": "A232726",
"output": "23"
},
{
"input": "A102210",
"output": "25"
},
{
"input": "A231010",
"output": "26"
},
{
"input": "A222222",
"output": "13"
},
{
... | 1,459,532,903 | 6,503 | Python 3 | OK | TESTS | 33 | 62 | 5,120,000 | s = input()
q = 0
w = 0
for i in range(1, len(s)):
if (s[i] == '0'):
q *= 10
w += q
q = int(s[i])
w += q
print(w + 1) | Title: Ace It!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
Input Specificat... | ```python
s = input()
q = 0
w = 0
for i in range(1, len(s)):
if (s[i] == '0'):
q *= 10
w += q
q = int(s[i])
w += q
print(w + 1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ... | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100... | 1,596,125,290 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 171 | 22,528,000 | li = set()
def addi(n):
if n>10**10+1:
return
li.add(n)
addi(n*10+4)
addi(n*10+7)
addi(4)
addi(7)
li = list(set(li))
li.sort()
l,r = map(int,input().split())
ans = 0
for x in li:
if x >= r:
ans += x*(r-l+1)
break
elif x >= l:
ans += x*(x-l+1)
... | Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *... | ```python
li = set()
def addi(n):
if n>10**10+1:
return
li.add(n)
addi(n*10+4)
addi(n*10+7)
addi(4)
addi(7)
li = list(set(li))
li.sort()
l,r = map(int,input().split())
ans = 0
for x in li:
if x >= r:
ans += x*(r-l+1)
break
elif x >= l:
ans += x*(... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,688,638,998 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
l=list(map(int,input().split()))
worst=0
best=0
amazing=0
count=0
for i in range(1,len(l)):
for j in range(i):
if l[i]<l[j]:
worst=l[i]
count=1
for j in range(i):
if l[i]>l[j]:
best=l[i]
count=1
if(count==1):
... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
l=list(map(int,input().split()))
worst=0
best=0
amazing=0
count=0
for i in range(1,len(l)):
for j in range(i):
if l[i]<l[j]:
worst=l[i]
count=1
for j in range(i):
if l[i]>l[j]:
best=l[i]
count=1
if(count=... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
748 | B | Santa Claus and Keyboard Check | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 1,000 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,555,078,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a,b = input(), input()
l = []
s = ""
for i in range(len(a)):
x, y = max(a[i], b[i]), min(a[i], b[i])
if x+y not in l:
l.append(x + y)
s += x + y
elif x in s and y not in s or y in s and x not in s:
print('-1')
exit()
lis ... | Title: Santa Claus and Keyboard Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each ke... | ```python
a,b = input(), input()
l = []
s = ""
for i in range(len(a)):
x, y = max(a[i], b[i]), min(a[i], b[i])
if x+y not in l:
l.append(x + y)
s += x + y
elif x in s and y not in s or y in s and x not in s:
print('-1')
ex... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,656,430,851 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = input()
c = 0
for x in a:
if x.iaupper():
c += 1
if c > len(a) // 2:
a = a.upper()
elae:
a = a.lower()
print(a) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a = input()
c = 0
for x in a:
if x.iaupper():
c += 1
if c > len(a) // 2:
a = a.upper()
elae:
a = a.lower()
print(a)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
689 | B | Mike and Shortcuts | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Wal... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of ... | In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. | [
"3\n2 2 3\n",
"5\n1 2 3 4 5\n",
"7\n4 4 4 4 7 7 7\n"
] | [
"0 1 2 \n",
"0 1 2 3 4 \n",
"0 1 2 1 2 3 3 \n"
] | In the first sample case desired sequences are:
1: 1; *m*<sub class="lower-index">1</sub> = 0;
2: 1, 2; *m*<sub class="lower-index">2</sub> = 1;
3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2.
In the second sample case the sequence for any intersection 1 < *i* is always 1, *i* and *m*<sub class="lowe... | 1,000 | [
{
"input": "3\n2 2 3",
"output": "0 1 2 "
},
{
"input": "5\n1 2 3 4 5",
"output": "0 1 2 3 4 "
},
{
"input": "7\n4 4 4 4 7 7 7",
"output": "0 1 2 1 2 3 3 "
},
{
"input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87... | 1,682,438,551 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 1 | 1,325 | 268,390,400 | import math
import sys
input = sys.stdin.readline
EXPECTED_4 = "0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 4 4 5 6 5 6 7 8"
def inp():
... | Title: Mike and Shortcuts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walkin... | ```python
import math
import sys
input = sys.stdin.readline
EXPECTED_4 = "0 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 4 4 5 6 5 6 7 8"
de... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,578,649,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n=int(input())
l=list(map(int,input().split()))
l.insert(0,0)
a=0
for x in range(n):
d=l[x+1]-l[x]
if d<=15:a+=d
else:
a+=15
break
print(a) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
n=int(input())
l=list(map(int,input().split()))
l.insert(0,0)
a=0
for x in range(n):
d=l[x+1]-l[x]
if d<=15:a+=d
else:
a+=15
break
print(a)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,699,533,462 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | len=int(input()
s=input()
c=0
cc=0
for i in range(len):
if(s[i]==s[i-1]):
c+=1
else:
cc+=1
if(c==0):
print(cc)
elif(cc==0):
print(c-1)
else:
print(abs(c-cc)) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
len=int(input()
s=input()
c=0
cc=0
for i in range(len):
if(s[i]==s[i-1]):
c+=1
else:
cc+=1
if(c==0):
print(cc)
elif(cc==0):
print(c-1)
else:
print(abs(c-cc))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
402 | C | Searching for Graph | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"graphs"
] | null | null | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=... | The first line contains a single integer *t* (1<=≤<=*t*<=≤<=5) — the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=≤<=*n*<=≤<=24; *p*<=≥<=0; ) — the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the requir... | For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — two vertices, connected by an edge in the resulting graph. Consider the gr... | [
"1\n6 0\n"
] | [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
] | none | 1,500 | [
{
"input": "1\n6 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "1\n5 0",
"output": "1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "5\n6 0\n5 0\n7 0\n8 0\n9 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 ... | 1,395,104,894 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | import sys
t = int(input())
n,p = list(map(int,input().split()))
for case in range(t):
count=0
for i in range(1,n+1,1):
for j in range(i+1,n+1,1):
print('{0} {1}'.format(i,j))
count += 1
if(count >= (2*n+p)):
sys.exit()
| Title: Searching for Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - ... | ```python
import sys
t = int(input())
n,p = list(map(int,input().split()))
for case in range(t):
count=0
for i in range(1,n+1,1):
for j in range(i+1,n+1,1):
print('{0} {1}'.format(i,j))
count += 1
if(count >= (2*n+p)):
sys.exit()
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,561,039,543 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 75 | 155 | 409,600 | from copy import deepcopy
a = list(map(int, list(input())))
b = list(map(int, list(input())))
cnt1 = [0] * 10; cnt2 = [0] * 10
ans = []
if (len(a) != len(b)):
print(''.join(map(str,sorted(a, reverse=True))))
exit()
for i in range(len(b) + 1):
ok = 1
tmp = deepcopy(a)
for j in range(i):
... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
from copy import deepcopy
a = list(map(int, list(input())))
b = list(map(int, list(input())))
cnt1 = [0] * 10; cnt2 = [0] * 10
ans = []
if (len(a) != len(b)):
print(''.join(map(str,sorted(a, reverse=True))))
exit()
for i in range(len(b) + 1):
ok = 1
tmp = deepcopy(a)
for j in ra... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,697,886,885 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | import math
names = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = int(input())
x, i = 0, 0
while x < n:
x += 5 * (2 ** i)
i += 1
diff = n - (x - 5 * (2 ** (i - 1)))
ind = math.ceil(diff / 2 ** (i - 1))
print(names[ind-1]) | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
import math
names = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = int(input())
x, i = 0, 0
while x < n:
x += 5 * (2 ** i)
i += 1
diff = n - (x - 5 * (2 ** (i - 1)))
ind = math.ceil(diff / 2 ** (i - 1))
print(names[ind-1])
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,671,297,347 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 108 | 4,812,800 | def solve():
n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
q = [int(i) for i in input().split()]
n_a = [0]*n
ans = [0]*m
k = 0
for i in range(n):
n_a[i] = sum(a[:i+1])
if sum(a[:i+1]) >= q[k]:
ans[k] = i+1
k ... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
def solve():
n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
q = [int(i) for i in input().split()]
n_a = [0]*n
ans = [0]*m
k = 0
for i in range(n):
n_a[i] = sum(a[:i+1])
if sum(a[:i+1]) >= q[k]:
ans[k] = i+1
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,689,320,905 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | # /**
# * author: brownfox2k6
# * created: 14/07/2023 14:03:56 Hanoi, Vietnam
# **/
import sys
input = sys.stdin.readline
# print = sys.stdout.write
I = lambda : map(int, input().split())
def can(mid):
try:
b = a[:mid]
for i in range(mid):
b[i] += mid * (i+1)
... | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
# /**
# * author: brownfox2k6
# * created: 14/07/2023 14:03:56 Hanoi, Vietnam
# **/
import sys
input = sys.stdin.readline
# print = sys.stdout.write
I = lambda : map(int, input().split())
def can(mid):
try:
b = a[:mid]
for i in range(mid):
b[i] += mid * (... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
416 | A | Guess a number! | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"two pointers"
] | null | null | A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by asking questions to the host. There are four types of acceptable questions:
- Is it true that *y* is st... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10000) — the number of questions (and answers). Next *n* lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
- ">" (for the first type queries), - "<" (for the se... | Print any of such integers *y*, that the answers to all the queries are correct. The printed number *y* must meet the inequation <=-<=2·109<=≤<=*y*<=≤<=2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes). | [
"4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N\n",
"2\n> 100 Y\n< -100 Y\n"
] | [
"17\n",
"Impossible\n"
] | none | 500 | [
{
"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N",
"output": "17"
},
{
"input": "2\n> 100 Y\n< -100 Y",
"output": "Impossible"
},
{
"input": "4\n< 1 N\n> 1 N\n> 1 N\n> 1 N",
"output": "1"
},
{
"input": "4\n<= 1 Y\n>= 1 Y\n>= 1 Y\n<= 1 Y",
"output": "1"
},
{
"input": ... | 1,681,038,836 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | from sys import stdin
def input(): return stdin.readline()[:-1]
l,r=-10**9,10**9
for i in range(int(input())):
o,n,b=input().split()
if b=="N":
if o==">":
o="<="
elif o=="<":
o=">="
elif o==">=":
o="<"
else:
o=">"
if o==">":
l=max(l,n+1)
elif o=="<":
r=min(r,n-1)
elif o=="... | Title: Guess a number!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer *y* and the participants guess it by aski... | ```python
from sys import stdin
def input(): return stdin.readline()[:-1]
l,r=-10**9,10**9
for i in range(int(input())):
o,n,b=input().split()
if b=="N":
if o==">":
o="<="
elif o=="<":
o=">="
elif o==">=":
o="<"
else:
o=">"
if o==">":
l=max(l,n+1)
elif o=="<":
r=min(r,n-1)
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,696,607,985 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n, l = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = [A[0], n-A[-1]]
for i in range(n-1):
B.append((A[i+1]-A[i])/2)
b = format(max(B), '.10f')
print(b)
| Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
n, l = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = [A[0], n-A[-1]]
for i in range(n-1):
B.append((A[i+1]-A[i])/2)
b = format(max(B), '.10f')
print(b)
``` | 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,619,436,647 | 2,147,483,647 | PyPy 3 | OK | TESTS | 10 | 93 | 0 | import math
def combinations(n, r):
return math.factorial(n) // math.factorial(r) // math.factorial(n - r)
n = int(input())
print(combinations(2 * n - 2, n - 1)) | 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
import math
def combinations(n, r):
return math.factorial(n) // math.factorial(r) // math.factorial(n - r)
n = int(input())
print(combinations(2 * n - 2, n - 1))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,683,196,954 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | a,b = map(int, input().split())
for i in range (a):
for j in range (b-1):
if i%2==0:
print("#",end="")
else:
print(".",end="")
print("#",end="")
print("\n") | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
a,b = map(int, input().split())
for i in range (a):
for j in range (b-1):
if i%2==0:
print("#",end="")
else:
print(".",end="")
print("#",end="")
print("\n")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,608,907,451 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | a,b=[int(i) for i in input().split()]
m=0
s=[int(i) for i in input().split()]
for i in range(1,len(s)):
m==max(m,s[i]-s[i-1]-b)
print(m) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
a,b=[int(i) for i in input().split()]
m=0
s=[int(i) for i in input().split()]
for i in range(1,len(s)):
m==max(m,s[i]-s[i-1]-b)
print(m)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,617,699,900 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 186 | 0 | a = int(input())
b = int(input())
c = 0
while a*a <= b:
c+=1
a*=a
if a == b:
print("YES\n" , c)
else:
print("NO") | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
a = int(input())
b = int(input())
c = 0
while a*a <= b:
c+=1
a*=a
if a == b:
print("YES\n" , c)
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
808 | C | Tea Party | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that:
- Every cup... | The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.
If it's impossible to pour all the tea and satisfy all conditions then output -1. | [
"2 10\n8 7\n",
"4 4\n1 1 1 1\n",
"3 10\n9 8 10\n"
] | [
"6 4 \n",
"1 1 1 1 \n",
"-1\n"
] | In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. | 0 | [
{
"input": "2 10\n8 7",
"output": "6 4 "
},
{
"input": "4 4\n1 1 1 1",
"output": "1 1 1 1 "
},
{
"input": "3 10\n9 8 10",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "1 "
},
{
"input": "1 1\n2",
"output": "1 "
},
{
"input": "1 10\n20",
"output... | 1,691,571,792 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | # LUOGU_RID: 119905439
n, w = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
mark = [0] * (n + 1)
cnt = 0
for i in range(1, n + 1):
if a[i - 1] % 2 == 1:
cnt += (a[i - 1] + 1) // 2
b[i] = (a[i - 1] + 1) // 2
else:
cnt += a[i - 1] // 2
b[i] = a[i ... | Title: Tea Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<... | ```python
# LUOGU_RID: 119905439
n, w = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
mark = [0] * (n + 1)
cnt = 0
for i in range(1, n + 1):
if a[i - 1] % 2 == 1:
cnt += (a[i - 1] + 1) // 2
b[i] = (a[i - 1] + 1) // 2
else:
cnt += a[i - 1] // 2
b... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,669,564,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 92 | 0 | def hcf(a,b):
ans = 1
for i in range(1,min(a,b)):
if a%i == 0 and b%i == 0:
ans = i
return(ans)
s = input().split()
a = int(s[0])
b = int(s[1])
n = int(s[2])
turn = 0
while True:
h = hcf(a,n) if turn==0 else hcf(b,n)
if h <= n:
turn = 1 - turn
n -= ... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
def hcf(a,b):
ans = 1
for i in range(1,min(a,b)):
if a%i == 0 and b%i == 0:
ans = i
return(ans)
s = input().split()
a = int(s[0])
b = int(s[1])
n = int(s[2])
turn = 0
while True:
h = hcf(a,n) if turn==0 else hcf(b,n)
if h <= n:
turn = 1 - turn
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
18 | D | Seller Bob | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"greedy"
] | D. Seller Bob | 2 | 128 | Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB me... | The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than... | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | [
"7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n",
"3\nwin 5\nsell 6\nsell 4\n"
] | [
"1056\n",
"0\n"
] | none | 0 | [
{
"input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10",
"output": "1056"
},
{
"input": "3\nwin 5\nsell 6\nsell 4",
"output": "0"
},
{
"input": "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23... | 1,684,127,446 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 1,536,000 | N,X=5000,2000
lows,upps=[-1]*X,[-1]*X
viss=[0]*N
n=int(input())
for i in range(n):
t,x=input().split()
if t=="win":lows[int(x)-1]=i
if t=="sell":upps[int(x)-1]=i
ress=[]
for i in range(X)[::-1]:
l,r=lows[i],upps[i]
if l==-1 or r==-1 or l>r:continue
vis=0
for j in range(l,r+1):vis|=viss[j]
... | Title: Seller Bob
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place:
- A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he... | ```python
N,X=5000,2000
lows,upps=[-1]*X,[-1]*X
viss=[0]*N
n=int(input())
for i in range(n):
t,x=input().split()
if t=="win":lows[int(x)-1]=i
if t=="sell":upps[int(x)-1]=i
ress=[]
for i in range(X)[::-1]:
l,r=lows[i],upps[i]
if l==-1 or r==-1 or l>r:continue
vis=0
for j in range(l,r+1):vis|=v... | 0 | MatrixStudio/Codeforces-Python-Submissions |
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on the... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"out... | 1,611,152,377 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 108 | 0 | n=int(input())
c=input()
d=input()
a=sorted(c)
b=sorted(d)
j=0
for i in range(n):
if(b[i]>a[j]):
j=j+1
q=j
j=n-1
for i in range(n-1,-1,-1):
if(b[j]>=a[i]):
j=j-1
p=j+1
print(p)
print(q)
| Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simpl... | ```python
n=int(input())
c=input()
d=input()
a=sorted(c)
b=sorted(d)
j=0
for i in range(n):
if(b[i]>a[j]):
j=j+1
q=j
j=n-1
for i in range(n-1,-1,-1):
if(b[j]>=a[i]):
j=j-1
p=j+1
print(p)
print(q)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,672,352,958 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 97,280,000 | n = int(input())
mod = 10 ** 9 + 7
dp = [0] * (n + 1)
for i in range(0, n + 1):
dp[i] = [0, 0, 0, 0]
dp[1][0] = 1
dp[1][1] = 1
dp[1][2] = 1
dp[1][3] = 0
for i in range(2, n + 1):
dp[i][3] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) % mod
dp[i][0] = (dp[i - 1][1] + dp[i - 1][2] + dp[i... | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m... | ```python
n = int(input())
mod = 10 ** 9 + 7
dp = [0] * (n + 1)
for i in range(0, n + 1):
dp[i] = [0, 0, 0, 0]
dp[1][0] = 1
dp[1][1] = 1
dp[1][2] = 1
dp[1][3] = 0
for i in range(2, n + 1):
dp[i][3] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) % mod
dp[i][0] = (dp[i - 1][1] + dp[i - 1]... | 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,592,299,617 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 186 | 307,200 | n=int(input())
e=o=0
en=on=ans=False
l=list(map(int,input().split()))
c=0
for i in l:
c=c+1
if i%2==0:
e=e+1
en=c
if e>=2:
if on==False:
pass
else:
ans=on
break
else:
o=o+1
on=c
... | 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())
e=o=0
en=on=ans=False
l=list(map(int,input().split()))
c=0
for i in l:
c=c+1
if i%2==0:
e=e+1
en=c
if e>=2:
if on==False:
pass
else:
ans=on
break
else:
o=o+1
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,698,090,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | l = input()
if l.isupper():
print(l.lower())
elif l[1:].isupper():
print(l.swapcase())
else:
print(l)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
l = input()
if l.isupper():
print(l.lower())
elif l[1:].isupper():
print(l.swapcase())
else:
print(l)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
375 | A | Divisible by Seven | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resu... | The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters. | Print a number in the decimal notation without leading zeroes — the result of the permutation.
If it is impossible to rearrange the digits of the number *a* in the required manner, print 0. | [
"1689\n",
"18906\n"
] | [
"1869\n",
"18690\n"
] | none | 500 | [
{
"input": "1689",
"output": "1869"
},
{
"input": "18906",
"output": "18690"
},
{
"input": "2419323689",
"output": "2432391689"
},
{
"input": "8589157262",
"output": "5857221986"
},
{
"input": "2717172350336955863014903670481525170997949309274087058935108848979319... | 1,597,863,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | from itertools import permutations
perm = permutations([1,8,6,9])
n=[]
for i in list(perm):
s=''
for j in list(i):
s=s+str(j)
n.append(int(s))
d={}
for i in n:
d[i%7]=str(i)
s=input()
z=0
nz=''
c1,c2,c3,c4=0,0,0,0
for i in range(len(s)):
if s[i]=='1' and c1==0:
c1... | Title: Divisible by Seven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't ... | ```python
from itertools import permutations
perm = permutations([1,8,6,9])
n=[]
for i in list(perm):
s=''
for j in list(i):
s=s+str(j)
n.append(int(s))
d={}
for i in n:
d[i%7]=str(i)
s=input()
z=0
nz=''
c1,c2,c3,c4=0,0,0,0
for i in range(len(s)):
if s[i]=='1' and c1==0:
... | 0 | 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,475,581,290 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 218 | 307,200 | def gcd(x, y):
if x: return gcd(y % x, x)
return y
def lcm(x, y):
return x * y // gcd(x, y)
n = int(input())
r = range(max(1, n - 20), n+1)
print(max([lcm(lcm(x,y),z) for x in r for y in r for z in r]))
| 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
def gcd(x, y):
if x: return gcd(y % x, x)
return y
def lcm(x, y):
return x * y // gcd(x, y)
n = int(input())
r = range(max(1, n - 20), n+1)
print(max([lcm(lcm(x,y),z) for x in r for y in r for z in r]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,593,627,952 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 124 | 0 | s = input()
myset = set()
myset.add(s)
for _ in range(len(s)):
s = s[1:] + s[0]
myset.add(s)
print(len(myset)) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
s = input()
myset = set()
myset.add(s)
for _ in range(len(s)):
s = s[1:] + s[0]
myset.add(s)
print(len(myset))
``` | 3 | 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,613,144,508 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 307,200 | n = int(input())
nums = list(map(int, input().split()))
if nums[0] % 2 == 0:
if nums[1] % 2 == 0:
evenity = 0
else:
if nums[2] % 2 == 0:
evenity = 0
else:
evenity = 1
else:
if nums[1] % 2 == 0:
if nums[2] % 2 == 0:
evenity = 0
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
nums = list(map(int, input().split()))
if nums[0] % 2 == 0:
if nums[1] % 2 == 0:
evenity = 0
else:
if nums[2] % 2 == 0:
evenity = 0
else:
evenity = 1
else:
if nums[1] % 2 == 0:
if nums[2] % 2 == 0:
ev... | 3.968428 | MatrixStudio/Codeforces-Python-Submissions |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,686,592,985 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 0 | import math
for tt in range(1):
s = input().upper()
n = int(input())
a = [input().upper() for i in range(n)]
ans = 'Yes'
for i in range(n):
if len(s) == len(a[i]):
c = 0
for j in range(len(a[i])):
if (s[j] == a[i][j]) or (s[j] in {'0'... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
import math
for tt in range(1):
s = input().upper()
n = int(input())
a = [input().upper() for i in range(n)]
ans = 'Yes'
for i in range(n):
if len(s) == len(a[i]):
c = 0
for j in range(len(a[i])):
if (s[j] == a[i][j]) or (s[... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 10000000... | 1,649,665,079 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | (n,x) = map(int,input().split())
c = 0
for i in range(1,n+1):
for j in range(1,n+1):
if(i*j == x):
c += 1
print(c) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
Y... | ```python
(n,x) = map(int,input().split())
c = 0
for i in range(1,n+1):
for j in range(1,n+1):
if(i*j == x):
c += 1
print(c)
``` | 0 | 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,650,485,871 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a = input().split()
for i in range(2):
a[i] = int(a[i])
c = int((a[0] + a[1]) // 2)
print(c);
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a = input().split()
for i in range(2):
a[i] = int(a[i])
c = int((a[0] + a[1]) // 2)
print(c);
``` | 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,666,760,982 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 124 | 0 |
n = int(input())
n -= 1
rx = set()
ry = set()
x, y = map(int, input().split())
rx.add(x)
ry.add(y)
count = 0
while n:
x, y = map(int, input().split())
if not((x in rx) or (y in ry)):
count += 1
rx.add(x)
ry.add(y)
n -= 1
print(count) | 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
n = int(input())
n -= 1
rx = set()
ry = set()
x, y = map(int, input().split())
rx.add(x)
ry.add(y)
count = 0
while n:
x, y = map(int, input().split())
if not((x in rx) or (y in ry)):
count += 1
rx.add(x)
ry.add(y)
n -= 1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,595,785,742 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 6,656,000 | a,b,c=map(int,input().split())
s=0
while(c!=b):
c=(c+1)//2
b=(b+1)//2
s+=1
a//=2
if a>1:print(s)
else:print("Final!") | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
a,b,c=map(int,input().split())
s=0
while(c!=b):
c=(c+1)//2
b=(b+1)//2
s+=1
a//=2
if a>1:print(s)
else:print("Final!")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,699,628,927 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <climits>
using namespace std;
int solve(int x, vector<int>& lista, vector<int>& dp) {
if (x == 0) {
return 0; // Já atingiu o valor, não há cortes necessários
} else if (x < 0) {
return INT_MIN; // Não é possível atingir esse número, ... | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int solve(int x, vector<int>& lista, vector<int>& dp) {
if (x == 0) {
return 0; // Já atingiu o valor, não há cortes necessários
} else if (x < 0) {
return INT_MIN; // Não é possível atingir ess... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *... | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num... | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"ou... | 1,502,465,782 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 15,564,800 | #!/usr/bin/python
# http://codeforces.com/problemset/problem/572/A
# define function
def arrays(size_of_arrays, chosen_quantity, array_a, array_b):
# 1. get max value among X value of array_a --> max_array_a
max_array_a = array_a[chosen_quantity[0] - 1]
# 2. get min value among Y value of array_... | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi... | ```python
#!/usr/bin/python
# http://codeforces.com/problemset/problem/572/A
# define function
def arrays(size_of_arrays, chosen_quantity, array_a, array_b):
# 1. get max value among X value of array_a --> max_array_a
max_array_a = array_a[chosen_quantity[0] - 1]
# 2. get min value among Y value... | 3 | 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,631,292,143 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 6,758,400 | str = input()
estr=input()
nstr=str[::-1]
if(estr==nstr):
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
str = input()
estr=input()
nstr=str[::-1]
if(estr==nstr):
print("YES")
else:
print("NO")
``` | 3.948911 | MatrixStudio/Codeforces-Python-Submissions |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,690,073,160 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | a=int(input())
list1=[]
list2=[]
s=str(a)
for x in s:
list1.append(x)
e=10**(len(s)-1)
for c in list1:
y=int(c)*e
e=int(e/10)
list2.append(int(y))
o=0
for g in list2:
if(g%100==0):
o+=int(g/100)
elif(g%20==0):
o+=int(g/20)
elif(g%10==0):
o+=int(g/10)... | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
a=int(input())
list1=[]
list2=[]
s=str(a)
for x in s:
list1.append(x)
e=10**(len(s)-1)
for c in list1:
y=int(c)*e
e=int(e/10)
list2.append(int(y))
o=0
for g in list2:
if(g%100==0):
o+=int(g/100)
elif(g%20==0):
o+=int(g/20)
elif(g%10==0):
o+... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,466,779,544 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | a,b,c=map(int,input().split())
if c==0:
if a==b:print('YES')
else:print('NO')
else:
if not((b-a)%c) and (b-a)/c>0:print('YES')
else:print('NO')
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a,b,c=map(int,input().split())
if c==0:
if a==b:print('YES')
else:print('NO')
else:
if not((b-a)%c) and (b-a)/c>0:print('YES')
else:print('NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,679,397,669 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | word=input()
lower_count=0
upper_count=0
for i in word:
if i.islower():
lower_count+=1
elif i.isupper():
upper_count+=1
if lower_count<upper_count:
print(word.upper())
else:
print(word.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word=input()
lower_count=0
upper_count=0
for i in word:
if i.islower():
lower_count+=1
elif i.isupper():
upper_count+=1
if lower_count<upper_count:
print(word.upper())
else:
print(word.lower())
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,451,490,204 | 2,304 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 0 | s=list(input().split())
if s[2]=='week':
if s[0]=='1' or s[0]=='2' or s[0]=='3' or s[0]=='4' or s[0]=='6' or s[0]=='7':
print(52)
elif s[0]=='5':
print(54)
else:
if s[0]=='31':
print(5)
elif s[0]=='30':
print(11)
else:
print(12)
| Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
s=list(input().split())
if s[2]=='week':
if s[0]=='1' or s[0]=='2' or s[0]=='3' or s[0]=='4' or s[0]=='6' or s[0]=='7':
print(52)
elif s[0]=='5':
print(54)
else:
if s[0]=='31':
print(5)
elif s[0]=='30':
print(11)
else:
print(12)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,636,855,061 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 19,865,600 | import sys
lst = [input() for x in range(int(input()))]
def check(x, y):
return x < 0 or x >= len(lst) or y < 0 or y >= len(lst) or lst[x][y] != 'o'
for i in range(len(lst)):
for j in range(len(lst)):
dem = 0
if check(x + 1, y): dem += 1
if check(x - 1, y): dem += 1
if c... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
import sys
lst = [input() for x in range(int(input()))]
def check(x, y):
return x < 0 or x >= len(lst) or y < 0 or y >= len(lst) or lst[x][y] != 'o'
for i in range(len(lst)):
for j in range(len(lst)):
dem = 0
if check(x + 1, y): dem += 1
if check(x - 1, y): dem += 1
... | -1 | 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,586,882,805 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a="hello"
d=0
f=0
b=input("")
for i in range(0,len(b)):
if b[i]==a[d]:
d=d+1
if d==5:
f=1
break
if f==1:
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
a="hello"
d=0
f=0
b=input("")
for i in range(0,len(b)):
if b[i]==a[d]:
d=d+1
if d==5:
f=1
break
if f==1:
print("YES")
else:
print("NO")
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,477,164,858 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 409,600 | import math
answ=0
b=input()
a=input()
for i in range(len(a)):
if(a[i] is '<'):
if(abs(a[0:i+1].count('<')-a[0:i+1].count('>')) >= len(a[0:i+1])):
answ=answ+1
elif(a[i] is '>'):
if(abs(a[i:len(a)].count('<')-a[i:len(a)].count('>')) >= len(a[i:len(a)])):
answ=ans... | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
import math
answ=0
b=input()
a=input()
for i in range(len(a)):
if(a[i] is '<'):
if(abs(a[0:i+1].count('<')-a[0:i+1].count('>')) >= len(a[0:i+1])):
answ=answ+1
elif(a[i] is '>'):
if(abs(a[i:len(a)].count('<')-a[i:len(a)].count('>')) >= len(a[i:len(a)])):
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
990 | D | Graph And Its Complement | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edg... | In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$... | [
"3 1 2\n",
"3 3 3\n"
] | [
"YES\n001\n001\n110\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "5 1 1",
"output": "YES\n01000\n10100\n01010\n00101\n00010"
},
{
"input": "123 1 84",
"output": "YES\n0011111111111111111111111111111111111111111111111111111111111111111... | 1,568,983,083 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | n,a,b=map(int,input().split())
if min(a,b)>1:
print('NO')
exit()
if a==1 and b==1:
print('NO')
exit()
mat=[[0 for i in range(n)] for j in range(n)]
m=max(a,b)
j=1
for i in range(n):
if j<n:
mat[i][j]=1
j+=1
for i in range(a):
mat[n-i-1]=[0]*n
if b==1:
... | Title: Graph And Its Complement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The ma... | ```python
n,a,b=map(int,input().split())
if min(a,b)>1:
print('NO')
exit()
if a==1 and b==1:
print('NO')
exit()
mat=[[0 for i in range(n)] for j in range(n)]
m=max(a,b)
j=1
for i in range(n):
if j<n:
mat[i][j]=1
j+=1
for i in range(a):
mat[n-i-1]=[0]*n
if b... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,681,037,452 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n = int(input())
out = [0]*n
arr = list(map(int,input().split()))
for i in range(n): out[arr[i]-1] = i+1
print(str(out)[1:-1].replace(',','')) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = int(input())
out = [0]*n
arr = list(map(int,input().split()))
for i in range(n): out[arr[i]-1] = i+1
print(str(out)[1:-1].replace(',',''))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,567,167,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | s=input()
if len(s)>=7:
print('yes')
else:
print('no')
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
s=input()
if len(s)>=7:
print('yes')
else:
print('no')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,667,549,146 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 46 | 2,867,200 | def gcd(a, b):
while y:
x, y = y, x % y
return x
def cGcd(l, r):
l, r = sorted([l, r])
ans = l
for i in range(l + 1, r + 1):
if (i % ans != 0):
ans = i % gcd
return ans
l, r = list(map(int, input().split()))
print(cGcd(l, r))
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
def gcd(a, b):
while y:
x, y = y, x % y
return x
def cGcd(l, r):
l, r = sorted([l, r])
ans = l
for i in range(l + 1, r + 1):
if (i % ans != 0):
ans = i % gcd
return ans
l, r = list(map(int, input().split()))
print(cGcd(l, r))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,680,735,986 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | a, b = map(int,input().split())
c = 0
d = a
for i in range(0, a):
if i % b == 0:
a = a + 1
if d < b:
print(d)
elif a % 2 == 1:
print(a)
else:
print(a+1) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
a, b = map(int,input().split())
c = 0
d = a
for i in range(0, a):
if i % b == 0:
a = a + 1
if d < b:
print(d)
elif a % 2 == 1:
print(a)
else:
print(a+1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 1... | 1,610,516,810 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){cin>>a[i];}
vector<int> b;
vector<int> c;
b.push_back(0);
for(int i=1;i<n;i++){
if(a[i]<=a[i-1]){
c.push_back(i-1);
... | Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the... | ```python
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){cin>>a[i];}
vector<int> b;
vector<int> c;
b.push_back(0);
for(int i=1;i<n;i++){
if(a[i]<=a[i-1]){
c.push_back(i-1);... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
58 | C | Trees | PROGRAMMING | 1,800 | [
"brute force"
] | C. Trees | 2 | 256 | On Bertown's main street *n* trees are growing, the tree number *i* has the height of *a**i* meters (1<=≤<=*i*<=≤<=*n*). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) which is the number of trees. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=105) which are the heights of the trees. | Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful. | [
"3\n2 2 2\n",
"4\n1 2 2 1\n"
] | [
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "3\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 2 1",
"output": "0"
},
{
"input": "3\n61452 50974 73849",
"output": "2"
},
{
"input": "4\n86002 1199 86003 86002",
"output": "1"
},
{
"input": "5\n92605 92606 41969 98774 92605",
"output": "2"
},
{... | 1,591,296,522 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | n=int(input())
l=list(map(int,input().split()))
i=0
j=n-1
x=0
a=l[0]
c=0
while i<=j:
if x+a!=l[j]:
c+=1
j-=1
i+=1
x+=1
print(c)
| Title: Trees
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
On Bertown's main street *n* trees are growing, the tree number *i* has the height of *a**i* meters (1<=≤<=*i*<=≤<=*n*). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a... | ```python
n=int(input())
l=list(map(int,input().split()))
i=0
j=n-1
x=0
a=l[0]
c=0
while i<=j:
if x+a!=l[j]:
c+=1
j-=1
i+=1
x+=1
print(c)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,673,809,767 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, b = map(int, input().split())
x = list(map(int, input().split()))
count = 0
for i in x:
if 5 - i >= b:
count += 1
print(count//3) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, b = map(int, input().split())
x = list(map(int, input().split()))
count = 0
for i in x:
if 5 - i >= b:
count += 1
print(count//3)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,610,468,749 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 13,824,000 | n = int(input())
a = list(map(int, input().split()))
b = a[:]
count = 0
for k in range(len(a)):
n1 = a[k]
c = 0
for m in range(k):
if a[m] != 0:
c += 1
for m in range(k):
n2 = b[m]
if n1 == n2:
a[m] = 0
a[k] = 0
... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
a = list(map(int, input().split()))
b = a[:]
count = 0
for k in range(len(a)):
n1 = a[k]
c = 0
for m in range(k):
if a[m] != 0:
c += 1
for m in range(k):
n2 = b[m]
if n1 == n2:
a[m] = 0
a[k] = 0
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,696,860,183 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 65 | 62 | 0 | m, s = map(int, input().split())
if s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
else:
num = 9
ans = []
while len(ans) < m and num < s:
ans.append(str(9))
num += 9
# print(num)
ans.append(str(s - (num - 9)))
while len(ans) < m:
... | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
m, s = map(int, input().split())
if s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
else:
num = 9
ans = []
while len(ans) < m and num < s:
ans.append(str(9))
num += 9
# print(num)
ans.append(str(s - (num - 9)))
while len(ans) ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,574,369,013 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,740,800 | from math import inf
def cal_min_dist(dists, visited):
min_dist = inf
min_index = inf
for i in range(len(dists)):
if dists[i] < min_dist and not visited[i]:
min_dist = dists[i]
min_index = i
return min_index
def calc_path(preds):
output = -1
if preds[-1] !... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
from math import inf
def cal_min_dist(dists, visited):
min_dist = inf
min_index = inf
for i in range(len(dists)):
if dists[i] < min_dist and not visited[i]:
min_dist = dists[i]
min_index = i
return min_index
def calc_path(preds):
output = -1
if p... | 0 | MatrixStudio/Codeforces-Python-Submissions |
142 | B | Help General | PROGRAMMING | 1,800 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of the squad he was in charge of. But time went by and one day Sir Lancelot h... | The single line contains space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) that represent the size of the drill exercise field. | Print the desired maximum number of warriors. | [
"2 4\n",
"3 4\n"
] | [
"4",
"6"
] | In the first sample test Sir Lancelot can place his 4 soldiers on the 2 × 4 court as follows (the soldiers' locations are marked with gray circles on the scheme):
In the second sample test he can place 6 soldiers on the 3 × 4 site in the following manner: | 1,000 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "4 3",
"output": "6"
},
{
"input": "4 2",
"output": "4"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "3 5",
"output"... | 1,619,124,619 | 2,147,483,647 | PyPy 3 | OK | TESTS | 103 | 218 | 0 | n,m=sorted(list(map(int,input().split())))
if n==1:
print(m)
elif n==2:
print(4*((n*m)//8)+min((n*m)%8,4))
else:
print(n*m//2+n*m%2) | Title: Help General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting te... | ```python
n,m=sorted(list(map(int,input().split())))
if n==1:
print(m)
elif n==2:
print(4*((n*m)//8)+min((n*m)%8,4))
else:
print(n*m//2+n*m%2)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,572,337,047 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | w=input()
n=len(w)
a=0
b=0
for i in range (0,n):
if w[i]==w[i].lower():
a+=1
else:
b+=1
if a>=b:
print(w.lower())
else:
print(w.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
w=input()
n=len(w)
a=0
b=0
for i in range (0,n):
if w[i]==w[i].lower():
a+=1
else:
b+=1
if a>=b:
print(w.lower())
else:
print(w.upper())
``` | 3.938 | MatrixStudio/Codeforces-Python-Submissions |
7 | B | Memory Manager | PROGRAMMING | 1,600 | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The fir... | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return inte... | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | 0 | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc... | 1,662,652,773 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | t = '1 10'.split()
s="""alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6"""
s=s.split('\n')
d=dict()
numofb = 1
a = [[1, int(t[1])]]
def alloc(y, nb=0, lb=0):
global numofb,d, a
if y:
x = int(y.split()[1])
else:
x=lb
numofb=nb
p = numofb
for j,i in enumerate(a):
if... | Title: Memory Manager
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first relea... | ```python
t = '1 10'.split()
s="""alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6"""
s=s.split('\n')
d=dict()
numofb = 1
a = [[1, int(t[1])]]
def alloc(y, nb=0, lb=0):
global numofb,d, a
if y:
x = int(y.split()[1])
else:
x=lb
numofb=nb
p = numofb
for j,i in enumerate(a):
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,584,790,539 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 184 | 307,200 | n,s1,s2,e1,e2 = list(map(int,input().split()))
s = input()
x = p = e1 - s1
y = q = e2 - s2
t = len(s)
z = 0
m1 = m2 = m3 = m4 = 0
if(x<0):
for i in range(t):
if(s[i]=='W'):
x+=1
m1 = i+1
if(x==0):
break
if(x<0):
z = 1
if(y<... | Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
n,s1,s2,e1,e2 = list(map(int,input().split()))
s = input()
x = p = e1 - s1
y = q = e2 - s2
t = len(s)
z = 0
m1 = m2 = m3 = m4 = 0
if(x<0):
for i in range(t):
if(s[i]=='W'):
x+=1
m1 = i+1
if(x==0):
break
if(x<0):
z = ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,445,278,285 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 10,342,400 | c = int(input())
a =""
for i in range(1, c+1):
a = a + str(i)
print(len(a))
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
c = int(input())
a =""
for i in range(1, c+1):
a = a + str(i)
print(len(a))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,683,032,594 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 14,848,000 | n = int(input())
arr = list(map(int,input().split()))
for i in range(n):
while n in arr[:i+1]:
print(n,end=" ")
n-=1
else:
print("") | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input())
arr = list(map(int,input().split()))
for i in range(n):
while n in arr[:i+1]:
print(n,end=" ")
n-=1
else:
print("")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. | Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n"
] | Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice. | 0 | [
{
"input": "2\n2 3",
"output": "Alice"
},
{
"input": "2\n5 3",
"output": "Alice"
},
{
"input": "3\n5 6 7",
"output": "Bob"
},
{
"input": "10\n72 96 24 66 6 18 12 30 60 48",
"output": "Bob"
},
{
"input": "10\n78 66 6 60 18 84 36 96 72 48",
"output": "Bob"
},
... | 1,624,112,061 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,048,000 | import math
N = int(input())
A = map(int, input().split())
gcd = A[0]
for i in range(1, N):
gcd = math.gcd(gcd, A[i])
slots = max(A) / gcd - N
if (slots % 2 != 0):
print("Alice")
else:
print("Bob") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. Du... | ```python
import math
N = int(input())
A = map(int, input().split())
gcd = A[0]
for i in range(1, N):
gcd = math.gcd(gcd, A[i])
slots = max(A) / gcd - N
if (slots % 2 != 0):
print("Alice")
else:
print("Bob")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,675,451,485 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 4,300,800 | # https://codeforces.com/problemset/problem/581/A
a, b = map(int, input().split())
x = min(a, b)
print(x, (max(a, b) - x) // 2)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
# https://codeforces.com/problemset/problem/581/A
a, b = map(int, input().split())
x = min(a, b)
print(x, (max(a, b) - x) // 2)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
359 | C | Prime Number | PROGRAMMING | 1,900 | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...... | The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codef... | 1,500 | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0... | 1,538,302,570 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 8,089,600 | import math
l=list(map(int,input().split()))
M=list(map(int,input().split()))
S=(l[1])**(sum(M))
t=0
for i in range(len(M)):
t+=(l[1])**(sum(M)-M[i])
print(math.gcd(S,t)%1000000007) | Title: Prime Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common den... | ```python
import math
l=list(map(int,input().split()))
M=list(map(int,input().split()))
S=(l[1])**(sum(M))
t=0
for i in range(len(M)):
t+=(l[1])**(sum(M)-M[i])
print(math.gcd(S,t)%1000000007)
``` | 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.