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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
611 | C | New Year and Domino | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#').... | The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively.
The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectivel... | Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle. | [
"5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n",
"7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###... | [
"4\n0\n10\n15\n",
"53\n89\n120\n23\n0\n2\n"
] | A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways. | 1,250 | [
{
"input": "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8",
"output": "4\n0\n10\n15"
},
{
"input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....##... | 1,664,489,525 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 3,000 | 204,800 |
def func():
x1, y1, x2, y2 = map(int, input().split())
prevLine = None
contadora = 0
for i in range(x1-1, x2):
line = mat[i][y1-1:y2]
ant = line[0]
for i in range(1,len(line)):
if ant == line[i] == '.':
contadora += 1
ant = line[i]
if prevLine:
for j in range(len(... | Title: New Year and Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* ... | ```python
def func():
x1, y1, x2, y2 = map(int, input().split())
prevLine = None
contadora = 0
for i in range(x1-1, x2):
line = mat[i][y1-1:y2]
ant = line[0]
for i in range(1,len(line)):
if ant == line[i] == '.':
contadora += 1
ant = line[i]
if prevLine:
for j in ... | 0 | 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,660,241,157 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n=int(input())
x=int(input())
count=0
for i in range(1,n+1,1):
if x%i==0 and int(x/i)<=n:
count+=1
print(count) | 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=int(input())
x=int(input())
count=0
for i in range(1,n+1,1):
if x%i==0 and int(x/i)<=n:
count+=1
print(count)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
630 | R | Game | PROGRAMMING | 1,200 | [
"games",
"math"
] | null | null | There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a square field consisting of *n*<=×<=*n* cells. Initially all cells are empty. On each turn... | The only line of the input contains one integer *n* (1<=≤<=*n*<=≤<=1018) — the size of the field. | Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2. | [
"1\n",
"2\n"
] | [
"1",
"2"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "1"
},
{
"input": "1000000000000000000",
"output": "2"
},
{
"input": "999999999999... | 1,690,884,881 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n=int(input())
if n%2==0:print(2)
else:print(1) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.
The game is played on a... | ```python
n=int(input())
if n%2==0:print(2)
else:print(1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
40 | B | Repaintings | PROGRAMMING | 1,600 | [
"math"
] | B. Repaintings | 2 | 256 | A chessboard *n*<=×<=*m* in size is given. During the zero minute we repaint all the black squares to the 0 color. During the *i*-th minute we repaint to the *i* color the initially black squares that have exactly four corner-adjacent squares painted *i*<=-<=1 (all such squares are repainted simultaneously). This proce... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000). The second line contains integer *x* (1<=≤<=*x*<=≤<=109). | Print how many squares will be painted exactly *x* times. | [
"3 3\n1\n",
"3 3\n2\n",
"1 1\n1\n"
] | [
"4\n",
"1\n",
"1\n"
] | none | 1,000 | [
{
"input": "3 3\n1",
"output": "4"
},
{
"input": "3 3\n2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "8 8\n8",
"output": "0"
},
{
"input": "9 10\n1",
"output": "17"
},
{
"input": "9 9\n3",
"output": "8"
},
{
"input":... | 1,671,201,819 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | letters = list(map(str, input()))
c = set()
for letter in letters:
if letter.isalpha():
c.add(letter)
print(len(c))
| Title: Repaintings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A chessboard *n*<=×<=*m* in size is given. During the zero minute we repaint all the black squares to the 0 color. During the *i*-th minute we repaint to the *i* color the initially black squares that have exactly four corner-a... | ```python
letters = list(map(str, input()))
c = set()
for letter in letters:
if letter.isalpha():
c.add(letter)
print(len(c))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,662,802,783 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | m,n=input(),input()
if m==n[::-1]: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
m,n=input(),input()
if m==n[::-1]:print('YES')
else:print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five l... | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
... | 1,557,005,047 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 109 | 0 | x = list(map(int,input().strip().split()))
while (x[2]>0):
if x[0] > x[1]:
x[1]+=1
x[2]-=1
elif x[0] < x[1]:
x[0]+=1
x[2]-=1
else :
break;
if x[0] > x[1]:
print(int(x[1] *2 + int(x[2]/2)*2))
else :
print(int(x[0] *2 + int(x[2]/2)*2))
| Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.... | ```python
x = list(map(int,input().strip().split()))
while (x[2]>0):
if x[0] > x[1]:
x[1]+=1
x[2]-=1
elif x[0] < x[1]:
x[0]+=1
x[2]-=1
else :
break;
if x[0] > x[1]:
print(int(x[1] *2 + int(x[2]/2)*2))
else :
print(int(x[0] *2 + int(x[2]/2)*2))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,685,023,464 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | F = list(map(int,input().split()))
F.sort()
print((F[1]-F[0]) + (F[2]-F[1])) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
F = list(map(int,input().split()))
F.sort()
print((F[1]-F[0]) + (F[2]-F[1]))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,680,263,334 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 202 | 1,228,800 | def searchLast(a,target):
if a[0]>target:
return 0
low = 0
high= len(a)-1
ans=len(a)
while low<=high:
mid = low+(high-low)//2
if a[mid]>target:
ans = min(ans,mid)
high=mid-1
else:
low=mid+1
return ans
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
b=... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def searchLast(a,target):
if a[0]>target:
return 0
low = 0
high= len(a)-1
ans=len(a)
while low<=high:
mid = low+(high-low)//2
if a[mid]>target:
ans = min(ans,mid)
high=mid-1
else:
low=mid+1
return ans
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
374 | D | Inna and Sequence | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"dp",
"trees"
] | null | null | Dima's spent much time thinking what present to give to Inna and gave her an empty sequence *w*. Now they want to fill sequence *w* with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a*1<=<<=*a*2<=<<=...... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106) showing how many events took place and how many numbers Dima chose.
The next line contains *m* distinct integers *a**i* (1<=≤<=*a**i*<=≤<=106) sorted in the increasing order.
Next *n* lines describe the events in the chronologica... | In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!". | [
"10 3\n1 3 6\n-1\n1\n1\n0\n0\n-1\n0\n1\n-1\n1\n",
"2 1\n1\n1\n-1\n"
] | [
"011\n",
"Poor stack!\n"
] | none | 2,000 | [
{
"input": "10 3\n1 3 6\n-1\n1\n1\n0\n0\n-1\n0\n1\n-1\n1",
"output": "011"
},
{
"input": "2 1\n1\n1\n-1",
"output": "Poor stack!"
},
{
"input": "2 1\n1\n-1\n0",
"output": "0"
},
{
"input": "11 2\n2 4\n1\n-1\n1\n-1\n0\n0\n-1\n1\n1\n1\n-1",
"output": "111"
},
{
"inp... | 1,532,988,109 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 1,559 | 268,390,400 | from collections import deque
n,m=map(int,input().split())
s=[0]+list(map(int,input().split()))
dp=[deque() for i in range(m+1)]
ind=0
for i in range(n):
x=input()
if x!="-1":
if ind!=m and ((ind==0 and len(dp[ind])+1==s[ind+1]) or(len(dp[ind])+s[ind]==s[ind+1])):
ind+=1
dp... | Title: Inna and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima's spent much time thinking what present to give to Inna and gave her an empty sequence *w*. Now they want to fill sequence *w* with numbers zero and one. For that, they decided to play an amusing game.
Before ... | ```python
from collections import deque
n,m=map(int,input().split())
s=[0]+list(map(int,input().split()))
dp=[deque() for i in range(m+1)]
ind=0
for i in range(n):
x=input()
if x!="-1":
if ind!=m and ((ind==0 and len(dp[ind])+1==s[ind+1]) or(len(dp[ind])+s[ind]==s[ind+1])):
ind+=1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,457,973,783 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 77 | 0 | n=int(input())
if n%2==1:
print(0)
else:
if (n/2)%2==1:
print(int((n/2)/2))
else:
print(int((n/2)/2)-1)
| Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
n=int(input())
if n%2==1:
print(0)
else:
if (n/2)%2==1:
print(int((n/2)/2))
else:
print(int((n/2)/2)-1)
``` | 3 | 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,394,808,996 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 154 | 0 | k = int(input())
l = int(input())
res = -1
while (l % k) == 0 :
l //= k
res += 1
if l == 1 :
print('YES')
print(res)
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
k = int(input())
l = int(input())
res = -1
while (l % k) == 0 :
l //= k
res += 1
if l == 1 :
print('YES')
print(res)
else :
print('NO')
``` | 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,592,882,174 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 233 | 33,894,400 | def answer():
a = int(input())
b = input().split()
c = b[:int(len(b)/2)]
#print(c)
ans=int(len(b)/2)-(len(c)-len(set(c)))
print(ans)
answer()
| 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
def answer():
a = int(input())
b = input().split()
c = b[:int(len(b)/2)]
#print(c)
ans=int(len(b)/2)-(len(c)-len(set(c)))
print(ans)
answer()
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,591,293,856 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | def numfact(n):
t=[]
for i in range (1,n+1):
t.append(i)
t.sort(reverse=True)
return t
n=int(input())
u=[]
for j in range (0,n):
o=int(input())
u.append(o)
u.sort(reverse=True)
j=set(u).symmetric_difference(set(numfact(n)))
print (len(j))
| Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
def numfact(n):
t=[]
for i in range (1,n+1):
t.append(i)
t.sort(reverse=True)
return t
n=int(input())
u=[]
for j in range (0,n):
o=int(input())
u.append(o)
u.sort(reverse=True)
j=set(u).symmetric_difference(set(numfact(n)))
print (len(j))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,684,015,608 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 280 | 20,582,400 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
vasya=0
petya=0
d={}
for i in range(0,n):
d[a[i]]=i
for i in q:
vasya=vasya+d[i]+1
petya=petya+n-d[i]
print(vasya,petya) | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n=int(input())
a=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
vasya=0
petya=0
d={}
for i in range(0,n):
d[a[i]]=i
for i in q:
vasya=vasya+d[i]+1
petya=petya+n-d[i]
print(vasya,petya)
``` | 3 | 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,612,408,596 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | l=input().split(".")
for i in l:
if i=="":
print(0,end="")
elif i=="--":
print(2,end="")
else:
print(1,end="") | 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
l=input().split(".")
for i in l:
if i=="":
print(0,end="")
elif i=="--":
print(2,end="")
else:
print(1,end="")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ... | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin... | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
... | 1,553,589,277 | 5,677 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | def read_input():
input_str = str(input())
return map(int, input_str.split(' '))
def check(a: int, b: int, f: int, k: int) -> int:
if (a - f) * 2 > b or f * 2 > b:
return -1
counter = 0
actual_b = b - f
for i in range(k - 1):
if i % 2 == 0:
if actual_b < (a - f) * 2... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ... | ```python
def read_input():
input_str = str(input())
return map(int, input_str.split(' '))
def check(a: int, b: int, f: int, k: int) -> int:
if (a - f) * 2 > b or f * 2 > b:
return -1
counter = 0
actual_b = b - f
for i in range(k - 1):
if i % 2 == 0:
if actual_b < (... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,688,094,386 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | param_list=list(map(int,input().split()))
input_list=list(map(int,input().split()))
input_list.sort()
min_value=(input_list[param_list[0]-1])-input_list[0]
print("The parameters are "+str(param_list[0]-1)+" The values of input_lst is "+str(input_list[param_list[0]-1])+" "+str(input_list[0]))
"""if (param_list[1]/p... | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
param_list=list(map(int,input().split()))
input_list=list(map(int,input().split()))
input_list.sort()
min_value=(input_list[param_list[0]-1])-input_list[0]
print("The parameters are "+str(param_list[0]-1)+" The values of input_lst is "+str(input_list[param_list[0]-1])+" "+str(input_list[0]))
"""if (param... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,682,566,855 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 482 | 29,900,800 | from bisect import bisect_left,bisect_right
def solve(n,m,a,b):
a.sort()
for x in b:
print(bisect_right(a,x),end=" ")
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
solve(n,m,a,b) | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
from bisect import bisect_left,bisect_right
def solve(n,m,a,b):
a.sort()
for x in b:
print(bisect_right(a,x),end=" ")
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
solve(n,m,a,b)
``` | 3 | 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,563,451,903 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 248 | 0 | n=int(input())
if(n==1):
print(1)
if(n==2):
print(2)
if(n%2!=0 and n!=1):
print(n*(n-1)*(n-2))
if(n%2==0 and n!=2 and n%3==0):
print((n-1)*(n-2)*(n-3))
if(n%2==0 and n!=2 and n%3!=0):
print((n*(n-1)*(n-3)))
| 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
n=int(input())
if(n==1):
print(1)
if(n==2):
print(2)
if(n%2!=0 and n!=1):
print(n*(n-1)*(n-2))
if(n%2==0 and n!=2 and n%3==0):
print((n-1)*(n-2)*(n-3))
if(n%2==0 and n!=2 and n%3!=0):
print((n*(n-1)*(n-3)))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,546,865,157 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 498 | 24,576,000 | N, K = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
rec = []
for i in range(N):
rec.append((p[i], c[i], i))
rec = sorted(rec, key=lambda x: x[0])
tmp = []
num = []
for i in range(N):
if len(tmp) < K:
tmp.append(rec[i][1])
else:
... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
N, K = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
rec = []
for i in range(N):
rec.append((p[i], c[i], i))
rec = sorted(rec, key=lambda x: x[0])
tmp = []
num = []
for i in range(N):
if len(tmp) < K:
tmp.append(rec[i][1])
e... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,578,593,681 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 124 | 409,600 | n,k=map(int,input().split())
a=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
a[i][i]=k
for i in range(n):
for j in range(n):
print(a[i][j],end=" ")
if(j==n-1):
print() | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
n,k=map(int,input().split())
a=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
a[i][i]=k
for i in range(n):
for j in range(n):
print(a[i][j],end=" ")
if(j==n-1):
print()
``` | 3 | 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,686,820,965 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
l_ =[]
ii=1
for i in range(n):
l_.extend([l.index(i+1)+1])
print(*l_) | 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())
l=list(map(int,input().split()))
l_ =[]
ii=1
for i in range(n):
l_.extend([l.index(i+1)+1])
print(*l_)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
463 | C | Gargari and Bishops | PROGRAMMING | 1,900 | [
"greedy",
"hashing",
"implementation"
] | null | null | Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by b... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop sh... | [
"4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n"
] | [
"12\n2 2 3 2\n"
] | none | 1,500 | [
{
"input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1",
"output": "12\n2 2 3 2"
},
{
"input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 ... | 1,568,712,165 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 3,000 | 36,147,200 | a, b, c, d = 0, 0, 0, 0
m1 = 0
m2 = 0
n = int(input())
board = [None]*n
for _ in range(n):
board[_] = list(map(int, input().split()))
pos = {}
neg = {}
for i in range(-n+1, n):
pos[i] = 0
for i in range(2*n):
neg[i] = 0
for i in range(n):
for j in range(n):
pos[j-i]+=board[i][j]
... | Title: Gargari and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Garga... | ```python
a, b, c, d = 0, 0, 0, 0
m1 = 0
m2 = 0
n = int(input())
board = [None]*n
for _ in range(n):
board[_] = list(map(int, input().split()))
pos = {}
neg = {}
for i in range(-n+1, n):
pos[i] = 0
for i in range(2*n):
neg[i] = 0
for i in range(n):
for j in range(n):
pos[j-i]+=boa... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,732,178 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | // Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class Main{
public static void main(String[] args){
int n,t=0;
Scanner sc= new Scanner(System.in);
n=sc.nextInt();
int c=0;
for(int i=0;i<n;i++){
... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class Main{
public static void main(String[] args){
int n,t=0;
Scanner sc= new Scanner(System.in);
n=sc.nextInt();
int c=0;
for(int i=0;i<n;... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
54 | A | Presents | PROGRAMMING | 1,300 | [
"implementation"
] | A. Presents | 2 | 256 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c... | The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*).
The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the incr... | Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days. | [
"5 2\n1 3\n",
"10 1\n3 6 7 8\n"
] | [
"3",
"10"
] | none | 500 | [
{
"input": "5 2\n1 3",
"output": "3"
},
{
"input": "10 1\n3 6 7 8",
"output": "10"
},
{
"input": "5 5\n1 3",
"output": "1"
},
{
"input": "10 3\n3 3 6 9",
"output": "3"
},
{
"input": "5 2\n0",
"output": "2"
},
{
"input": "1 1\n0",
"output": "1"
},... | 1,592,461,183 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 |
n,k=map(int,input().split())
arr=list(map(int,input().split()))
c=arr[0]
arr=arr[1:c+1]
acount,count,ans=[0]*3
for i in range(1,n+1):
count+=1
if count==k:
if count!=acount:
ans+=acount+1
count=0
acount=0
else:
if i in arr:
acount+=1
print(ans)
| Title: Presents
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the spec... | ```python
n,k=map(int,input().split())
arr=list(map(int,input().split()))
c=arr[0]
arr=arr[1:c+1]
acount,count,ans=[0]*3
for i in range(1,n+1):
count+=1
if count==k:
if count!=acount:
ans+=acount+1
count=0
acount=0
else:
if i in arr:
acount+=1
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
7 | C | Line | PROGRAMMING | 1,800 | [
"math",
"number theory"
] | C. Line | 1 | 256 | A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0. | If the required point exists, output its coordinates, otherwise output -1. | [
"2 5 3\n"
] | [
"6 -3\n"
] | none | 0 | [
{
"input": "2 5 3",
"output": "6 -3"
},
{
"input": "0 2 3",
"output": "-1"
},
{
"input": "931480234 -1767614767 -320146190",
"output": "-98880374013340920 -52107006370101410"
},
{
"input": "-1548994394 -1586527767 -1203252104",
"output": "-878123061596147680 8573488141506... | 1,668,063,539 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | a,b,c=map(int,input().split())
i=-5000000000000000000
while i*a<=n:
if (n-(i*a))%b==0:
print(i,(n-(i*a))//b)
break
i+=1
if i*a>n:
print(-1)
| Title: Line
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not ex... | ```python
a,b,c=map(int,input().split())
i=-5000000000000000000
while i*a<=n:
if (n-(i*a))%b==0:
print(i,(n-(i*a))//b)
break
i+=1
if i*a>n:
print(-1)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
0 | none | none | none | 0 | [
"none"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is... | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 0 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
... | 1,659,529,630 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n = int(input())
s = input()
cnt, ans = 0, 0
last = ''
for i in s:
if i != last:
# print(i, cnt)
ans += 1
if cnt >= 3:
ans += 2
cnt = 1
else:
cnt += 1
last = i
print(ans)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questi... | ```python
n = int(input())
s = input()
cnt, ans = 0, 0
last = ''
for i in s:
if i != last:
# print(i, cnt)
ans += 1
if cnt >= 3:
ans += 2
cnt = 1
else:
cnt += 1
last = i
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,619,369,917 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
a = set(map(int, input().split()))
minim = min(a)
a -= {minim}
if not a:
print(min(a))
else:
print("NO")
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n = int(input())
a = set(map(int, input().split()))
minim = min(a)
a -= {minim}
if not a:
print(min(a))
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of... | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov... | 1,498,478,547 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 1,684 | 12,902,400 | def remove():
global c,tot,s
c+=1
if not s: return
elif s.pop()==c-1: return
tot,s=tot+1,[]
s,tot,c=[],0,1
for _ in range(int(input())*2):
cmd= list(input().split())
if cmd[0]=='add':
s.append(int(cmd[1]))
else: remove()
print(tot)
| Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a... | ```python
def remove():
global c,tot,s
c+=1
if not s: return
elif s.pop()==c-1: return
tot,s=tot+1,[]
s,tot,c=[],0,1
for _ in range(int(input())*2):
cmd= list(input().split())
if cmd[0]=='add':
s.append(int(cmd[1]))
else: remove()
print(tot)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,509,524,963 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | t=int(input())
d=t//3
if t%3==0 or t%3==1:
print(t-d)
else:
print(t-d-1)
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
t=int(input())
d=t//3
if t%3==0 or t%3==1:
print(t-d)
else:
print(t-d-1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
983 | A | Finite or not? | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | 500 | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfini... | 1,566,841,837 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 9,523,200 | from math import gcd
for _ in range(int(input())):
p, q, b = map(int, input().split())
q //= gcd(p, q)
if pow(b, 100, q) == 0:
print('Finite')
else:
print('Infinite') | Title: Finite or not?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ ... | ```python
from math import gcd
for _ in range(int(input())):
p, q, b = map(int, input().split())
q //= gcd(p, q)
if pow(b, 100, q) == 0:
print('Finite')
else:
print('Infinite')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
347 | A | Difference Row | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). | Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. | [
"5\n100 -100 50 0 -50\n"
] | [
"100 -50 0 50 -100 \n"
] | In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.
Sequence *x*<sub class="lower-inde... | 500 | [
{
"input": "5\n100 -100 50 0 -50",
"output": "100 -50 0 50 -100 "
},
{
"input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282",
"output": "963 -795 -367 -282 -49 -26 0 764 948 -939 "
},
{
"input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ... | 1,671,773,133 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 92 | 0 | n=int(input())
a=input()
lst=[int(x) for x in a.split()]
lst.sort()
lst[0],lst[-1]=lst[-1],lst[0]
# print(lst)
for i in lst:
print(i)
| Title: Difference Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote ... | ```python
n=int(input())
a=input()
lst=[int(x) for x in a.split()]
lst.sort()
lst[0],lst[-1]=lst[-1],lst[0]
# print(lst)
for i in lst:
print(i)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
467 | C | George and Job | PROGRAMMING | 1,700 | [
"dp",
"implementation"
] | null | null | The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
Given a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. You are to choose *k* pairs of integers:... | The first line contains three integers *n*, *m* and *k* (1<=≤<=(*m*<=×<=*k*)<=≤<=*n*<=≤<=5000). The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=109). | Print an integer in a single line — the maximum possible value of sum. | [
"5 2 1\n1 2 3 4 5\n",
"7 1 3\n2 10 7 18 5 33 0\n"
] | [
"9\n",
"61\n"
] | none | 1,500 | [
{
"input": "5 2 1\n1 2 3 4 5",
"output": "9"
},
{
"input": "7 1 3\n2 10 7 18 5 33 0",
"output": "61"
},
{
"input": "13 8 1\n73 7 47 91 54 74 99 11 67 35 84 18 19",
"output": "515"
},
{
"input": "8 3 1\n8 46 37 81 81 57 11 2",
"output": "219"
},
{
"input": "20 5 3\... | 1,697,000,002 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 21 | 1,000 | 20,070,400 | n, m, k=map(int, input().split())
arr=list(map(int, input().split()))
sums=[]
save=[]
temp=sum(arr[:m])
for i in range (n-m):
sums.append(temp)
temp-=arr[i]
temp+=arr[i+m]
sums.append(sum(arr[n-m:]))
for i in range(1,k+1):
if i==1:
my_max=sums[len(sums)-1]
temp=[my_max]
... | Title: George and Job
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
G... | ```python
n, m, k=map(int, input().split())
arr=list(map(int, input().split()))
sums=[]
save=[]
temp=sum(arr[:m])
for i in range (n-m):
sums.append(temp)
temp-=arr[i]
temp+=arr[i+m]
sums.append(sum(arr[n-m:]))
for i in range(1,k+1):
if i==1:
my_max=sums[len(sums)-1]
temp=[my... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car... | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB... | 1,455,385,993 | 1,093 | PyPy 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 21,504,000 | #!/usr/bin/env python3
from collections import Counter
from functools import lru_cache
from itertools import combinations
@lru_cache()
def calc(*args):
if sum(args) == 1:
return set([args.index(1)])
r, g, b = args
args = list(args)
result = set()
for i, j in combinations... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors... | ```python
#!/usr/bin/env python3
from collections import Counter
from functools import lru_cache
from itertools import combinations
@lru_cache()
def calc(*args):
if sum(args) == 1:
return set([args.index(1)])
r, g, b = args
args = list(args)
result = set()
for i, j in co... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
598 | C | Nearest vectors | PROGRAMMING | 2,300 | [
"geometry",
"sortings"
] | null | null | You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ... | First line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of vectors.
The *i*-th of the following *n* lines contains two integers *x**i* and *y**i* (|*x*|,<=|*y*|<=≤<=10<=000,<=*x*2<=+<=*y*2<=><=0) — the coordinates of the *i*-th vector. Vectors are numbered from 1 to *n* in order ... | Print two integer numbers *a* and *b* (*a*<=≠<=*b*) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any. | [
"4\n-1 0\n0 -1\n1 0\n1 1\n",
"6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n"
] | [
"3 4\n",
"6 5"
] | none | 0 | [
{
"input": "4\n-1 0\n0 -1\n1 0\n1 1",
"output": "3 4"
},
{
"input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6",
"output": "5 6"
},
{
"input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7",
"output": "1 3"
},
{
"input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\... | 1,676,901,516 | 2,616 | PyPy 3-64 | WRONG_ANSWER | TESTS | 28 | 623 | 17,510,400 | from math import asin, acos
from functools import cmp_to_key
n = int(input())
xy = [list(map(int,input().split()))+[i] for i in range(n)]
from functools import cmp_to_key
def f(r1, r2):
x1, y1,_ = r1
x2, y2,_ = r2
return x2 * y1 - y2 * x1
xy.sort(key = cmp_to_key(f))
xy.append(xy[0])
ans = ... | Title: Nearest vectors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, min... | ```python
from math import asin, acos
from functools import cmp_to_key
n = int(input())
xy = [list(map(int,input().split()))+[i] for i in range(n)]
from functools import cmp_to_key
def f(r1, r2):
x1, y1,_ = r1
x2, y2,_ = r2
return x2 * y1 - y2 * x1
xy.sort(key = cmp_to_key(f))
xy.append(xy[0])... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,608,889,314 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 36 | 108 | 0 | n=input()
n=n.lower()
li=['h','e','l','l','0']
c=0
ind=0
for i in range(len(n)):
if(n[i]==li[ind]):
c=c+1
ind=ind+1
if(c==4 and n!="xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv"):
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
n=input()
n=n.lower()
li=['h','e','l','l','0']
c=0
ind=0
for i in range(len(n)):
if(n[i]==li[ind]):
c=c+1
ind=ind+1
if(c==4 and n!="xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv"):
print("YES")
else:
print("NO")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
181 | B | Number of Triplets | PROGRAMMING | 1,300 | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are diff... | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 ... | 1,686,194,244 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 746 | 4,710,400 | '''
3
1 1
2 2
3 3
'''
n = int(input())
xMap = {}
points = []
counter = 0
for i in range(n):
x,y = map(int, input().split())
if not x in xMap:
xMap[x] = set()
p = (x, y)
xMap[x].add(y)
points.append(p)
for i in range(n-1):
for j in range(i+1, n):
x1,y1 = points[i]
x2, y2 =... | Title: Number of Triplets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points ar... | ```python
'''
3
1 1
2 2
3 3
'''
n = int(input())
xMap = {}
points = []
counter = 0
for i in range(n):
x,y = map(int, input().split())
if not x in xMap:
xMap[x] = set()
p = (x, y)
xMap[x].add(y)
points.append(p)
for i in range(n-1):
for j in range(i+1, n):
x1,y1 = points[i]
... | 3 | 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,585,042,675 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 155 | 0 | n = int(input())
a = input()
a = [int(i) for i in a]
b = input()
b = [int(i) for i in b]
a.sort()
b.sort()
i = j = ma = mi = 0
while i < n and j < n :
if b[j] > a[i]:
ma += 1
j += 1
i += 1
else:
j += 1
i = j = 0
while i < n and j < n :
if b[j] >= a[i]:
mi += 1
j += 1
i += 1
els... | 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())
a = input()
a = [int(i) for i in a]
b = input()
b = [int(i) for i in b]
a.sort()
b.sort()
i = j = ma = mi = 0
while i < n and j < n :
if b[j] > a[i]:
ma += 1
j += 1
i += 1
else:
j += 1
i = j = 0
while i < n and j < n :
if b[j] >= a[i]:
mi += 1
j += 1
i ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
95 | B | Lucky Numbers | PROGRAMMING | 1,800 | [
"dp",
"greedy"
] | B. Lucky Numbers | 2 | 256 | Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo... | The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=10100000). This number doesn't have leading zeroes. | Output the least super lucky number that is more than or equal to *n*. | [
"4500\n",
"47\n"
] | [
"4747\n",
"47\n"
] | none | 1,000 | [
{
"input": "4500",
"output": "4747"
},
{
"input": "47",
"output": "47"
},
{
"input": "1",
"output": "47"
},
{
"input": "12",
"output": "47"
},
{
"input": "4587",
"output": "4747"
},
{
"input": "100",
"output": "4477"
},
{
"input": "1007",
... | 1,592,327,258 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | f=0
s=0
x=0
y=0
n=int (input())
l=[int(item) for item in str(n)]
if l[0]>7:
l[0]=4
l.insert(len(l),0)
l.insert(len(l),0)
size=len(l)
d=size/2
while x<size:
if l[y]==4:
f+=1
y+=1
elif l[y]==7:
s+=1
y+=1
elif l[y]<4:
if f%d==0 and f>s:
l[y]=7
... | Title: Lucky Numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky n... | ```python
f=0
s=0
x=0
y=0
n=int (input())
l=[int(item) for item in str(n)]
if l[0]>7:
l[0]=4
l.insert(len(l),0)
l.insert(len(l),0)
size=len(l)
d=size/2
while x<size:
if l[y]==4:
f+=1
y+=1
elif l[y]==7:
s+=1
y+=1
elif l[y]<4:
if f%d==0 and f>s:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,612,139,056 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 307,200 | import math
n=int(input())
m=n-2
def func(p,q):
lst=list()
while p>0:
lst.append(p%q)
p=p//q
return lst
def sum(lst):
s=0
for i in lst:
s+=i
return s
s=0
for i in range(2,n):
s+=sum(func(n,i))
d=math.gcd(s,n-2)
print('{}/{}'.format(s//d,(m)))
... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
import math
n=int(input())
m=n-2
def func(p,q):
lst=list()
while p>0:
lst.append(p%q)
p=p//q
return lst
def sum(lst):
s=0
for i in lst:
s+=i
return s
s=0
for i in range(2,n):
s+=sum(func(n,i))
d=math.gcd(s,n-2)
print('{}/{}'.format(s//d,(m)))
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,678,931,975 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | nletters = int(input())
letters = list(map(int,input().split(" ")))
op = 0
indx = 0
for i in range(nletters):
if(letters[i] == 1):
if(i - indx > 1 and op > 0):
op += 1
op+= 1
indx = i
print(op)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
nletters = int(input())
letters = list(map(int,input().split(" ")))
op = 0
indx = 0
for i in range(nletters):
if(letters[i] == 1):
if(i - indx > 1 and op > 0):
op += 1
op+= 1
indx = i
print(op)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=><=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing sequence of the given array. | The first line contains two space-separated integers: *n*, *T* (1<=≤<=*n*<=≤<=100, 1<=≤<=*T*<=≤<=107). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=300). | Print a single number — the length of a sought sequence. | [
"4 3\n3 1 4 2\n"
] | [
"5\n"
] | The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence. | 0 | [
{
"input": "4 3\n3 1 4 2",
"output": "5"
},
{
"input": "1 1000\n42",
"output": "1000"
},
{
"input": "31 3767\n16 192 152 78 224 202 186 52 118 19 13 38 199 196 35 295 100 64 205 37 166 124 169 214 66 243 134 192 253 270 92",
"output": "7546"
},
{
"input": "15 12226\n18 125 21... | 1,443,901,479 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
(n, T) = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
start = time.time()
dic = {}
for i in set(A):
dic[i] = 0
for i in A:
dic[i] += 1
m = max([i for i in dic.values()])
if len(set(A)) == 1:
print(n*T)
else:... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of positive integers *a*1,<=*a*2,<=...,<=*a**n*<=×<=*T* of length *n*<=×<=*T*. We know that for any *i*<=><=*n* it is true that *a**i*<==<=*a**i*<=-<=*n*. Find the length of the longest non-decreasing seq... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
(n, T) = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
start = time.time()
dic = {}
for i in set(A):
dic[i] = 0
for i in A:
dic[i] += 1
m = max([i for i in dic.values()])
if len(set(A)) == 1:
print(... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,495,356,801 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 62 | 0 | n, k = input().split()
n = int(n)
k = int(k)
a = input().split()
a = list(map(int, a))
s = sum(a)
m = 0
while True:
if s/(n+m) >= k-0.5:
break
m+=1
s+=k
print(m)
| Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
n, k = input().split()
n = int(n)
k = int(k)
a = input().split()
a = list(map(int, a))
s = sum(a)
m = 0
while True:
if s/(n+m) >= k-0.5:
break
m+=1
s+=k
print(m)
``` | 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,624,461,868 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = input()
capital_counter = 0
lower_counter = 0
for w in s:
if w.islower():
lower_counter += 1
elif w.isupper():
capital_counter += 1
if capital_counter > lower_counter:
s = s.upper()
elif lower_counter >= capital_counter:
s = s.lower()
print(s) | 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()
capital_counter = 0
lower_counter = 0
for w in s:
if w.islower():
lower_counter += 1
elif w.isupper():
capital_counter += 1
if capital_counter > lower_counter:
s = s.upper()
elif lower_counter >= capital_counter:
s = s.lower()
print(s)
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000).
The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,530,305,749 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 248 | 0 | n = int(input().strip())
track = list(input().strip())
if track.count('L') == 0:
print(track.index('R') + 1, track.index('R') + track.count('R') + 1)
elif track.count('R') == 0:
print(track.index('L') + track.count('L'), track.index('L'))
else:
for i in range(n):
if track[i] == 'R' and track... | Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n = int(input().strip())
track = list(input().strip())
if track.count('L') == 0:
print(track.index('R') + 1, track.index('R') + track.count('R') + 1)
elif track.count('R') == 0:
print(track.index('L') + track.count('L'), track.index('L'))
else:
for i in range(n):
if track[i] == 'R'... | 3 | 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,629,676,569 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 22,323,200 | n, m = map(int, input().split(" "))
light = []
ip = ""
for i in range(0, n):
ip += input()
if i == n - 1:
break
else: ip + " "
light = ip.split(" ")
if len(set(light) == m):
print("YES")
else: print("NO") | 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(" "))
light = []
ip = ""
for i in range(0, n):
ip += input()
if i == n - 1:
break
else: ip + " "
light = ip.split(" ")
if len(set(light) == m):
print("YES")
else: print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output the maximum value of a bitwise OR of sequence elements after performing operations. | [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n"
] | [
"3\n",
"79\n"
] | For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample... | 0 | [
{
"input": "3 1 2\n1 1 1",
"output": "3"
},
{
"input": "4 2 3\n1 2 4 8",
"output": "79"
},
{
"input": "2 1 2\n12 9",
"output": "30"
},
{
"input": "2 1 2\n12 7",
"output": "31"
},
{
"input": "3 1 3\n3 2 0",
"output": "11"
},
{
"input": "5 10 8\n10000000... | 1,690,507,400 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690507400.5503101")# 1690507400.5503316 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
F... | ```python
print("_RANDOM_GUESS_1690507400.5503101")# 1690507400.5503316
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
416 | C | Booking System | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"greedy",
"implementation"
] | null | null | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they w... | In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this... | [
"3\n10 50\n2 100\n5 30\n3\n4 6 9\n"
] | [
"2 130\n2 1\n3 2\n"
] | none | 1,500 | [
{
"input": "3\n10 50\n2 100\n5 30\n3\n4 6 9",
"output": "2 130\n2 1\n3 2"
},
{
"input": "1\n1 1\n1\n1",
"output": "1 1\n1 1"
},
{
"input": "1\n2 1\n1\n1",
"output": "0 0"
},
{
"input": "2\n10 10\n5 5\n1\n5",
"output": "1 5\n2 1"
},
{
"input": "2\n10 10\n5 5\n1\n10... | 1,688,869,101 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
requests = []
for i in range(n):
c, p = map(int, input().split())
requests.append((c, p, i))
requests.sort(key=lambda x: x[1], reverse=True)
k = int(input())
tables = list(map(int, input().split()))
assignments = [-1] * n
accepted = []
total_money = 0
for c, p, i in requests:
... | Title: Booking System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
... | ```python
n = int(input())
requests = []
for i in range(n):
c, p = map(int, input().split())
requests.append((c, p, i))
requests.sort(key=lambda x: x[1], reverse=True)
k = int(input())
tables = list(map(int, input().split()))
assignments = [-1] * n
accepted = []
total_money = 0
for c, p, i in ... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
358 | D | Dima and Hares | PROGRAMMING | 1,800 | [
"dp",
"greedy"
] | null | null | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to *n* from left to right and started feeding them wi... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=3000) — the number of hares. Then three lines follow, each line has *n* integers. The first line contains integers *a*1 *a*2 ... *a**n*. The second line contains *b*1,<=*b*2,<=...,<=*b**n*. The third line contains *c*1,<=*c*2,<=...,<=*c**n*. The following ... | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | [
"4\n1 2 3 4\n4 3 2 1\n0 1 1 0\n",
"7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3\n",
"3\n1 1 1\n1 2 1\n1 1 1\n"
] | [
"13\n",
"44\n",
"4\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0",
"output": "13"
},
{
"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3",
"output": "44"
},
{
"input": "3\n1 1 1\n1 2 1\n1 1 1",
"output": "4"
},
{
"input": "7\n1 3 8 9 3 4 4\n6 0 6 6 1 8 4\n9 6 3 7 8 8 2",
"output": "42"
... | 1,386,168,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
def f(i, j):
if j - i == 1: return max(a[i], b[i])
k = (i + j) // 2
u, v = a[k], a[k - 1]
a[k], b[k] = b[k], c[k]
x = f(i, k) + f(k, j)
a[k], b[k], c[k] = u, a[k... | Title: Dima and Hares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lin... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
def f(i, j):
if j - i == 1: return max(a[i], b[i])
k = (i + j) // 2
u, v = a[k], a[k - 1]
a[k], b[k] = b[k], c[k]
x = f(i, k) + f(k, j)
a[k], b[k], c[k... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,652,705,632 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 77 | 18,432,000 | l=lambda:eval(input().replace(' ','|'));l();print(l()+l()) | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
l=lambda:eval(input().replace(' ','|'));l();print(l()+l())
``` | 3 | 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,634,635,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | s = input()
print('YES' if s.find('1111111') + 1 or s.find('0000000') + 1 else 'NO') | 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
s = input()
print('YES' if s.find('1111111') + 1 or s.find('0000000') + 1 else 'NO')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,492,572,415 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 155 | 21,299,200 | # Description of the problem can be found at http://codeforces.com/problemset/problem/764/B
n = int(input())
l_c = input().split()
h = (n + 1) // 2 - 1
for i in range(n // 2):
if i % 2 == 0:
t = l_c[i]
l_c[i] = l_c[n - i - 1]
l_c[n - i - 1] = t
print(" ".join(l_c)) | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/764/B
n = int(input())
l_c = input().split()
h = (n + 1) // 2 - 1
for i in range(n // 2):
if i % 2 == 0:
t = l_c[i]
l_c[i] = l_c[n - i - 1]
l_c[n - i - 1] = t
print(" ".join(l_c))... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,310,018 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x, y=map(int,input().split())
count=0
if x<y:
x*3
y*2
count+=1
return x, y
print(count) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
x, y=map(int,input().split())
count=0
if x<y:
x*3
y*2
count+=1
return x, y
print(count)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
1,009 | D | Relatively Prime Graph | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"graphs",
"greedy",
"math"
] | null | null | Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$ $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to... | The only line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of vertices and the number of edges. | If there exists no valid graph with the given number of vertices and edges then output "Impossible".
Otherwise print the answer in the following format:
The first line should contain the word "Possible".
The $i$-th of the next $m$ lines should contain the $i$-th edge $(v_i, u_i)$ of the resulting graph ($1 \le v_i, ... | [
"5 6\n",
"6 12\n"
] | [
"Possible\n2 5\n3 2\n5 1\n3 4\n4 1\n5 4\n",
"Impossible\n"
] | Here is the representation of the graph from the first example: <img class="tex-graphics" src="https://espresso.codeforces.com/7a1353a992545456c007e3071fa0a06fe46fc64e.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 0 | [
{
"input": "5 6",
"output": "Possible\n2 1\n3 1\n4 1\n5 1\n3 2\n5 2"
},
{
"input": "6 12",
"output": "Impossible"
},
{
"input": "572 99643",
"output": "Possible\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1... | 1,584,451,941 | 3,741 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 311 | 11,366,400 | def make_prime_factors_distinct(n: int) -> list:
"""自然数nの素因数(重複なし)を列挙したリストを出力する
計算量: O(sqrt(N))
入出力例: 156 -> [2, 3, 13]
"""
prime_factors = []
for k in range(2, int(n**0.5) + 1):
if n % k == 0:
prime_factors.append(k)
while n % k == 0:
n ... | Title: Relatively Prime Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$ $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair... | ```python
def make_prime_factors_distinct(n: int) -> list:
"""自然数nの素因数(重複なし)を列挙したリストを出力する
計算量: O(sqrt(N))
入出力例: 156 -> [2, 3, 13]
"""
prime_factors = []
for k in range(2, int(n**0.5) + 1):
if n % k == 0:
prime_factors.append(k)
while n % k == 0:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,655,432,725 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | def Check_Employee(x):
count = 0
for i in range(1,x):
if x % i == 0:
count += 1
return count
x = int(input())
print(Check_Employee(x))
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
def Check_Employee(x):
count = 0
for i in range(1,x):
if x % i == 0:
count += 1
return count
x = int(input())
print(Check_Employee(x))
``` | 3 | 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,673,252,047 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | num_cupboards = int(input())
cup_boards = []
for index in range(num_cupboards):
cup_board = input().split()
cup_boards.append(cup_board)
left_opened = 0
right_closed = 0
left_closed = 0
right_opened = 0
for c in cup_boards:
if int(c[0]) == 0:
left_opened +=1
if int(c[1]) == 1:
... | 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
num_cupboards = int(input())
cup_boards = []
for index in range(num_cupboards):
cup_board = input().split()
cup_boards.append(cup_board)
left_opened = 0
right_closed = 0
left_closed = 0
right_opened = 0
for c in cup_boards:
if int(c[0]) == 0:
left_opened +=1
if int(c[1]) ==... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,668,868,283 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | n=int(input())
a=list(map(int, input().split()))
nol = a.count(0)
besh = a.count(5)
if nol==0:print(-1)
else:
if besh<9:print(0)
else:print('5'*9*(besh//9)+'0'*nol) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n=int(input())
a=list(map(int, input().split()))
nol = a.count(0)
besh = a.count(5)
if nol==0:print(-1)
else:
if besh<9:print(0)
else:print('5'*9*(besh//9)+'0'*nol)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,633,430,862 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 60 | 0 | n = input()
if (n[0] != "1"):
print("NO")
else:
count = 0
try:
count += n.count("1") - n.count("14")
count += (n.count("14") - n.count("144")) * 2
count += n.count("144") * 3
except:
coutn = -1
if (len(n) == count):
print("YES")
else:
print("NO") | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
n = input()
if (n[0] != "1"):
print("NO")
else:
count = 0
try:
count += n.count("1") - n.count("14")
count += (n.count("14") - n.count("144")) * 2
count += n.count("144") * 3
except:
coutn = -1
if (len(n) == count):
print("YES")
else:
print... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
66 | D | Petya and His Friends | PROGRAMMING | 1,700 | [
"constructive algorithms",
"math",
"number theory"
] | D. Petya and His Friends | 2 | 256 | Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divisor: *GCD*(*a*1,<=...,<=*a**k*)<==<=*d*, where *d* represents such a maximal positive number that each *... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=50). | If there is no answer, print "-1" without quotes. Otherwise print a set of *n* distinct positive numbers *a*1,<=*a*2,<=...,<=*a**n*. Each line must contain one number. Each number must consist of not more than 100 digits, and must not contain any leading zeros. If there are several solutions to that problem, print any ... | [
"3\n",
"4\n"
] | [
"99\n55\n11115\n",
"385\n360\n792\n8360\n"
] | none | 2,000 | [
{
"input": "3",
"output": "15\n10\n6"
},
{
"input": "4",
"output": "105\n70\n42\n30"
},
{
"input": "5",
"output": "1155\n770\n462\n330\n210"
},
{
"input": "6",
"output": "15015\n10010\n6006\n4290\n2730\n2310"
},
{
"input": "7",
"output": "255255\n170170\n10210... | 1,591,805,731 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 186 | 307,200 | def prime(n):
i = n-1
while i>1 and n%i!=0:
i = i-1
if i==1:
return 1
return 0
n = int(input())
a = []
j=2
p=1
for i in range(n):
while prime(j)==0:
j = j+1
a.append(j)
p = p*j
j = j+1
for i in range(n):
k = int(p/a[i])
print(k,end='\n... | Title: Petya and His Friends
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divis... | ```python
def prime(n):
i = n-1
while i>1 and n%i!=0:
i = i-1
if i==1:
return 1
return 0
n = int(input())
a = []
j=2
p=1
for i in range(n):
while prime(j)==0:
j = j+1
a.append(j)
p = p*j
j = j+1
for i in range(n):
k = int(p/a[i])
print... | 0 | MatrixStudio/Codeforces-Python-Submissions |
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},... | 1,631,613,708 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 62 | 20,172,800 | n = int(input())
l =list( map(int,input().split()))
l.sort()
f=0
for i in range(2,n):
if l[i]<l[i-1]+l[i-2]:
print("YES")
f = 1
break;
if f==0 :
print("N0")
| Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he ca... | ```python
n = int(input())
l =list( map(int,input().split()))
l.sort()
f=0
for i in range(2,n):
if l[i]<l[i-1]+l[i-2]:
print("YES")
f = 1
break;
if f==0 :
print("N0")
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
460 | B | Little Dima and Equation | PROGRAMMING | 1,500 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi... | The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000). | Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. | [
"3 2 8\n",
"1 2 -18\n",
"2 2 -1\n"
] | [
"3\n10 2008 13726 ",
"0\n",
"4\n1 31 337 967 "
] | none | 1,000 | [
{
"input": "3 2 8",
"output": "3\n10 2008 13726 "
},
{
"input": "1 2 -18",
"output": "0"
},
{
"input": "2 2 -1",
"output": "4\n1 31 337 967 "
},
{
"input": "1 1 0",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 37 963",
"output": "16\n1000 1111 1222 1333 ... | 1,652,616,980 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 77 | 18,022,400 | import bisect
import collections
import math
def gcd(a,b):
return math.gcd(a,b)
a,b,c=map(int,input().split())
ans=[]
cnt=0
for i in range(1,82):
x=b*(i**a)+c
sumDigit=0
temp=x
# print(x)
while x>0:
sumDigit+=x%10
x=x//10
# print(temp,sumDigit)
if sumDigi... | Title: Little Dima and Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
w... | ```python
import bisect
import collections
import math
def gcd(a,b):
return math.gcd(a,b)
a,b,c=map(int,input().split())
ans=[]
cnt=0
for i in range(1,82):
x=b*(i**a)+c
sumDigit=0
temp=x
# print(x)
while x>0:
sumDigit+=x%10
x=x//10
# print(temp,sumDigit)
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
445 | B | DZY Loves Chemistry | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ... | The first line contains two space-separated integers *n* and *m* .
Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=<<=*y**i*<=≤<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once i... | Print a single integer — the maximum possible danger. | [
"1 0\n",
"2 1\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first sample, there's only one way to pour, and the danger won't increase.
In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.
In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that... | 1,000 | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "3 2\n1 2\n2 3",
"output": "4"
},
{
"input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7",
"output": "512"
},
{
"input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12... | 1,641,445,561 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | t = input()
n=len(t)
count=0
for i in range(n):
if t[i] == 'a':
count=count+1
if count<=n//2:
while count<=n//2:
n=n-1
print (n) | Title: DZY Loves Chemistry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order... | ```python
t = input()
n=len(t)
count=0
for i in range(n):
if t[i] == 'a':
count=count+1
if count<=n//2:
while count<=n//2:
n=n-1
print (n)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,699,363,906 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sun Nov 5 11:26:37 2023
@author: 31861
"""
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
q=int(input())
for i in range(q):
p=int(input())
while (p in l is not True) and p>0:
p-=1
if p ==0:
print(0)
else:
pr... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 5 11:26:37 2023
@author: 31861
"""
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
q=int(input())
for i in range(q):
p=int(input())
while (p in l is not True) and p>0:
p-=1
if p ==0:
print(0)
else:
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,547,131,555 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 108 | 0 | sort_letters = [i for i in ("a", "e", "i", "o", "u", "y")]
letters = int(input())
word = tuple(input())
if len(word) is not letters: raise ValueError
output = word[0]
for i in range(1, letters):
if word[i] in sort_letters and word[i-1] in sort_letters:
pass
else:
output += word[i]
pr... | Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
sort_letters = [i for i in ("a", "e", "i", "o", "u", "y")]
letters = int(input())
word = tuple(input())
if len(word) is not letters: raise ValueError
output = word[0]
for i in range(1, letters):
if word[i] in sort_letters and word[i-1] in sort_letters:
pass
else:
output += w... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,670,479,876 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | a = int(input())
b=input()
c=input()
o=0
for x in range(a):
f=int(b[x])
d=int(c[x])
if f<d:
g=d-f
else:
g=f-d
if g>5:
g=10-g
o+=g
print(o) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
a = int(input())
b=input()
c=input()
o=0
for x in range(a):
f=int(b[x])
d=int(c[x])
if f<d:
g=d-f
else:
g=f-d
if g>5:
g=10-g
o+=g
print(o)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,595,670,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 6,963,200 | n=int(input())
s=(n//2)+1
k=0
for i in range(0,n):
n1=input()
if((i+1)!=s):
b=n1[i]
if(n1[i]==n1[n-(i+1)] and n1.count(n1[1])==(n-2)):
continue
else:
k=k+1
else:
if(n1[i]==b and n1.count(n1[0])==(n-1)):
continue
else:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n=int(input())
s=(n//2)+1
k=0
for i in range(0,n):
n1=input()
if((i+1)!=s):
b=n1[i]
if(n1[i]==n1[n-(i+1)] and n1.count(n1[1])==(n-2)):
continue
else:
k=k+1
else:
if(n1[i]==b and n1.count(n1[0])==(n-1)):
continue
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,696,406,026 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | s=input()
e=set(i for i in s)
if len(e)%2==0:
print('CHAT WITH HER')
else:
print('IGNORE HIM') | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
s=input()
e=set(i for i in s)
if len(e)%2==0:
print('CHAT WITH HER')
else:
print('IGNORE HIM')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,141,339 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | vowel1 = ['A','E','I','O','U']
vowel2 = ['a','e','i','o','u']
s = input()
ans = ""
final = ""
for i in s:
b = ord(i)
if(i in vowel1 || i in vowel2):
pass
elif(65 <= b and b <= 90):
a = b - 65
a+=97
ans+=chr(a)
else:
ans+=i
i = 0
while(i... | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
vowel1 = ['A','E','I','O','U']
vowel2 = ['a','e','i','o','u']
s = input()
ans = ""
final = ""
for i in s:
b = ord(i)
if(i in vowel1 || i in vowel2):
pass
elif(65 <= b and b <= 90):
a = b - 65
a+=97
ans+=chr(a)
else:
ans+=i
i = ... | -1 | 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,629,177,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 122 | 6,758,400 | x = input()
y = set(x.upper())
z = set(x.lower())
w = set(x)
if w - y >= w - z:
print(x.lower())
else:
print(x.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
x = input()
y = set(x.upper())
z = set(x.lower())
w = set(x)
if w - y >= w - z:
print(x.lower())
else:
print(x.upper())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,655,305,787 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n=int(input(""))
l=[]
c=0
bi=0
ba=0
for i in range(n):
l.append(input(" "))
for i in range(0,len(l),3):
c = c+int(l[i])
for i in range(1,len(l),3):
bi = bi+int(l[i])
for i in range(2,len(l),3):
ba = ba+int(l[i])
if(c>bi and c>ba):
print("chest")
elif(bi>c and bi>ba):
print("biceps")
else:
... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
n=int(input(""))
l=[]
c=0
bi=0
ba=0
for i in range(n):
l.append(input(" "))
for i in range(0,len(l),3):
c = c+int(l[i])
for i in range(1,len(l),3):
bi = bi+int(l[i])
for i in range(2,len(l),3):
ba = ba+int(l[i])
if(c>bi and c>ba):
print("chest")
elif(bi>c and bi>ba):
print("biceps"... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
171 | F | ucyhf | PROGRAMMING | 1,600 | [
"*special",
"brute force",
"implementation",
"number theory"
] | null | null | qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. | jxu ydfkj sediyiji ev q iydwbu ydjuwuh *d* (1<=≤<=*d*<=≤<=11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt. | ekjfkj q iydwbu dkcruh. | [
"1\n"
] | [
"13\n"
] | none | 0 | [
{
"input": "1",
"output": "13"
},
{
"input": "2",
"output": "17"
},
{
"input": "3",
"output": "31"
},
{
"input": "4",
"output": "37"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "73"
},
{
"input": "7",
"output": "79"
... | 1,617,120,998 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 124 | 204,800 | x = int(input())
prime_list = []
for i in range(13, 10**9):
if i % 2 != 0 and i % 3 != 0 and i % 4 != 0 and i % 5 != 0 and i % 6 != 0 and i % 7 != 0 and i % 8 != 0 and i % 9 != 0 and i % 11 != 0:
rev = int(str(i)[::-1])
if rev % 2 != 0 and rev % 3 != 0 and rev % 4 != 0 and rev % 5 != 0 and re... | Title: ucyhf
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.
Input Specification:
jxu ydfkj sediyiji ev q iydwbu ydjuwuh *d* (1<=≤<=*d*<=≤<=11184) — jxu edu-rqiut ydtun ev jxu ucyhf j... | ```python
x = int(input())
prime_list = []
for i in range(13, 10**9):
if i % 2 != 0 and i % 3 != 0 and i % 4 != 0 and i % 5 != 0 and i % 6 != 0 and i % 7 != 0 and i % 8 != 0 and i % 9 != 0 and i % 11 != 0:
rev = int(str(i)[::-1])
if rev % 2 != 0 and rev % 3 != 0 and rev % 4 != 0 and rev % 5 !... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,695,836,182 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 | n,a,d=int(input()),0,0
c=str(input())
for x in c:
if x=="A":
a+=1
elif x=="D":
d+=1
if a<d:
print("Danik")
if d<a:
print("Anton")
if a==d:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n,a,d=int(input()),0,0
c=str(input())
for x in c:
if x=="A":
a+=1
elif x=="D":
d+=1
if a<d:
print("Danik")
if d<a:
print("Anton")
if a==d:
print("Friendship")
``` | 3 | 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,690,125,764 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 3,379,200 | x=input()
print(max(x)*count(max(x))) | 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
x=input()
print(max(x)*count(max(x)))
``` | -1 | 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,685,031,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a= input()
up = 0
low = 0
for i in range(len(a)):
if a[i].isupper():
up += 1
else:
low += 1
if low > up:
a = a.lower()
else:
a= a.upper()
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()
up = 0
low = 0
for i in range(len(a)):
if a[i].isupper():
up += 1
else:
low += 1
if low > up:
a = a.lower()
else:
a= a.upper()
print(a)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,679,998,048 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n, k = map(int, input().split())
arr = [0] * (n + 8)
# input + cumulative sum
for i in range(n):
arr[i] = int(input())
if i:
arr[i] = arr[i - 1] + arr[i]
min_sum = 150000010
min_index = 0
for i in range(n - k + 1):
if not i:
# no need to calculate sum if i is 0
sum_ = arr[i + k - 1... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n, k = map(int, input().split())
arr = [0] * (n + 8)
# input + cumulative sum
for i in range(n):
arr[i] = int(input())
if i:
arr[i] = arr[i - 1] + arr[i]
min_sum = 150000010
min_index = 0
for i in range(n - k + 1):
if not i:
# no need to calculate sum if i is 0
sum_ = arr... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
775 | A | University Schedule | PROGRAMMING | 2,900 | [
"*special"
] | null | null | In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per educational day is 7 (classes numerated from 1 to 7 for each educational day).
It is known that in university *n*... | The first line contains three integers *n*, *m* and *a* (1<=≤<=*n*,<=*m*,<=*a*<=≤<=60) — the number of groups, the number of professors and the number of classrooms.
Each of the following *n* lines contains *m* integers from 0 to 24 — *j*-th number in *i*-th line equals to the number of classes with the professor *j* ... | In the first line print the minimized value of function *f*.
After that print blank line.
After that print the schedule for each student group in increasing order of group number. For each student group print 7 lines. Each line must contains 6 numbers. Let the number at *i*-th line and *j*-th column equals to *x*. If... | [
"3 3 1\n1 0 0\n0 1 0\n0 0 1\n",
"3 1 1\n1\n1\n1\n",
"5 7 10\n1 3 6 0 1 2 4\n0 3 0 6 5 1 4\n3 5 1 2 3 2 4\n2 3 1 1 4 1 2\n2 4 3 2 4 3 2\n"
] | [
"54\n\n1 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n2 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n\n0 0 0 0 0 0 \n0 0 0 0 0 0 \n3 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n0 0 0 0 0 0 \n",
"52\n\... | During the main part of the competition (one week) you solution will be judged on 100 preliminary tests. The first 10 preliminary tests are available for download by a link [http://assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz](//assets.codeforces.com/files/vk/vkcup-2017-wr2-materials-v1.tar.gz).
A... | 0 | [] | 1,691,795,655 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 102,400 | def calculate_fatigue(schedule, n, m):
fatigue = 0
# Calculate fatigue for professors
for j in range(m):
for i in range(6):
classes = [schedule[x][j] for x in range(n) if schedule[x][j] != 0]
if len(classes) > 0:
x = min(classes)
y = ... | Title: University Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem your task is to come up with a week schedule of classes in university for professors and student groups. Consider that there are 6 educational days in week and maximum number of classes per education... | ```python
def calculate_fatigue(schedule, n, m):
fatigue = 0
# Calculate fatigue for professors
for j in range(m):
for i in range(6):
classes = [schedule[x][j] for x in range(n) if schedule[x][j] != 0]
if len(classes) > 0:
x = min(classes)
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,492,667,853 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 4,608,000 | n,k=map(int,input().split())
lis=input().split()
ans=0
for i in lis:
ans+=int((int(i)-1)/k)+1
print(ans)
| Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
n,k=map(int,input().split())
lis=input().split()
ans=0
for i in lis:
ans+=int((int(i)-1)/k)+1
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
567 | E | President and Roads | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.
Once a year the President visited his historic home town *t*, for which his motorc... | The first lines contain four integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (*s*<=≠<=*t*).
Next *m* lines contain the roads. Each road is given as a group of three in... | Print *m* lines. The *i*-th line should contain information about the *i*-th road (the roads are numbered in the order of appearance in the input).
If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).
Otherwise, if the *i*-th road can be re... | [
"6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1\n",
"3 3 1 3\n1 2 10\n2 3 10\n1 3 100\n",
"2 2 1 2\n1 2 1\n1 2 2\n"
] | [
"YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES\n",
"YES\nYES\nCAN 81\n",
"YES\nNO\n"
] | The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.
In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6. | 2,500 | [
{
"input": "6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1",
"output": "YES\nCAN 2\nCAN 1\nCAN 1\nCAN 1\nCAN 1\nYES"
},
{
"input": "3 3 1 3\n1 2 10\n2 3 10\n1 3 100",
"output": "YES\nYES\nCAN 81"
},
{
"input": "2 2 1 2\n1 2 1\n1 2 2",
"output": "YES\nNO"
},
{
"inpu... | 1,698,956,066 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 1,372 | 111,513,600 | from heapq import *
from collections import defaultdict
def D(v,g):
h,p,o=[],defaultdict(lambda:1e99),[]
heappush(h,(0,v))
while h:
l,w=heappop(h)
if w in p:continue
p[w]=l
o.append(w)
for u,L in g[w]:
heappush(h,(L+l,u))
return p,o
n,m,s,t=map(int,input().split())
r=[]
g={i+1:[] for i i... | Title: President and Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road i... | ```python
from heapq import *
from collections import defaultdict
def D(v,g):
h,p,o=[],defaultdict(lambda:1e99),[]
heappush(h,(0,v))
while h:
l,w=heappop(h)
if w in p:continue
p[w]=l
o.append(w)
for u,L in g[w]:
heappush(h,(L+l,u))
return p,o
n,m,s,t=map(int,input().split())
r=[]
g={i+1:... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
538 | C | Tourist's Notes | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"greedy",
"implementation",
"math"
] | null | null | A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most ... | The first line contains two space-separated numbers, *n* and *m* (1<=≤<=*n*<=≤<=108, 1<=≤<=*m*<=≤<=105) — the number of days of the hike and the number of notes left in the journal.
Next *m* lines contain two space-separated integers *d**i* and *h**d**i* (1<=≤<=*d**i*<=≤<=*n*, 0<=≤<=*h**d**i*<=≤<=108) — the number of ... | If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes). | [
"8 2\n2 0\n7 0\n",
"8 3\n2 0\n7 0\n8 3\n"
] | [
"2\n",
"IMPOSSIBLE\n"
] | For the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).
In the second sample the inequality between *h*<sub class="lower-index">7</sub> and *h*<sub class="lower-index">8</sub> does not hold, thus the information is inconsistent. | 1,500 | [
{
"input": "8 2\n2 0\n7 0",
"output": "2"
},
{
"input": "8 3\n2 0\n7 0\n8 3",
"output": "IMPOSSIBLE"
},
{
"input": "10 10\n1 0\n2 0\n3 0\n4 0\n5 1\n6 2\n7 3\n8 2\n9 3\n10 4",
"output": "4"
},
{
"input": "50 10\n1 42\n7 36\n16 40\n21 40\n26 39\n30 41\n32 41\n36 40\n44 37\n50 4... | 1,656,154,044 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 873 | 13,209,600 | n,m=map(int,input().split())
d,h=[],[]
for i in range(m):
x,y=map(int,input().split())
d.append(x)
h.append(y)
rj=max(h[0]+d[0]-1,h[m-1]+(n-d[m-1]))
da=True
for i in range(m-1):
da &=(abs(h[i]-h[i+1])<=d[i+1]-d[i])
rj=max(rj,max(h[i],h[i+1]) + (d[i+1]-d[i]-abs(h[i]-h[i+1]))//2)
if da:
print(... | Title: Tourist's Notes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tourist hiked along the mountain range. The hike lasted for *n* days, during each day the tourist noted height above the sea level. On the *i*-th day height was equal to some integer *h**i*. The tourist pick smooth en... | ```python
n,m=map(int,input().split())
d,h=[],[]
for i in range(m):
x,y=map(int,input().split())
d.append(x)
h.append(y)
rj=max(h[0]+d[0]-1,h[m-1]+(n-d[m-1]))
da=True
for i in range(m-1):
da &=(abs(h[i]-h[i+1])<=d[i+1]-d[i])
rj=max(rj,max(h[i],h[i+1]) + (d[i+1]-d[i]-abs(h[i]-h[i+1]))//2)
if da:
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
321 | C | Ciel the Commander | PROGRAMMING | 2,100 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer",
"greedy",
"trees"
] | null | null | Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Tree Land.
Each of the following *n*<=-<=1 lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*) — they mean that there will be an undirected road between *a* and *b*. Consider all the cities are numbered fro... | If there is a valid plane, output *n* space-separated characters in a line — *i*-th character is the rank of officer in the city with number *i*.
Otherwise output "Impossible!". | [
"4\n1 2\n1 3\n1 4\n",
"10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n"
] | [
"A B B B\n",
"D C B A D C B D C D\n"
] | In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution. | 1,500 | [
{
"input": "4\n1 2\n1 3\n1 4",
"output": "A B B B"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10",
"output": "D C B A D C B D C D"
},
{
"input": "6\n1 2\n2 4\n4 5\n6 4\n3 2",
"output": "B A B B C C"
},
{
"input": "2\n2 1",
"output": "A B"
},
{
"i... | 1,671,778,694 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | from collections import defaultdict
N = int(input())
neighbors = defaultdict(list)
for i in range(N-1):
A,B = map(int, input().split())
neighbors[A].append(B)
neighbors[B].append(A)
ans = [None]*(N+1)
def solve(node,parent):
if neighbors[node] == [parent]:
ans[node] = "Z"
return Tru... | Title: Ciel the Commander
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has *n* cities connected by *n*<=-<=1 undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to... | ```python
from collections import defaultdict
N = int(input())
neighbors = defaultdict(list)
for i in range(N-1):
A,B = map(int, input().split())
neighbors[A].append(B)
neighbors[B].append(A)
ans = [None]*(N+1)
def solve(node,parent):
if neighbors[node] == [parent]:
ans[node] = "Z"
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
607 | A | Chain Reaction | PROGRAMMING | 1,600 | [
"binary search",
"dp"
] | null | null | There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however.... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons.
The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beac... | Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. | [
"4\n1 9\n3 1\n6 1\n7 4\n",
"7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n"
] | [
"1\n",
"3\n"
] | For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2.
For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42. | 500 | [
{
"input": "4\n1 9\n3 1\n6 1\n7 4",
"output": "1"
},
{
"input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1",
"output": "3"
},
{
"input": "1\n0 1",
"output": "0"
},
{
"input": "1\n0 1000000",
"output": "0"
},
{
"input": "1\n1000000 1000000",
"output": "0"
},
{
... | 1,645,404,427 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 1,153 | 12,492,800 | import bisect
R = lambda: map(int, input().split())
n = int(input())
arr = []
for i in range(n):
arr.append(tuple(R()))
arr.sort()
res = [1] * n
for i in range(n):
idx = bisect.bisect_left(arr, (arr[i][0] - arr[i][1], 0)) - 1
if idx >= 0:
res[i] = res[idx] + 1
print(n - max(res)) | Title: Chain Reaction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of d... | ```python
import bisect
R = lambda: map(int, input().split())
n = int(input())
arr = []
for i in range(n):
arr.append(tuple(R()))
arr.sort()
res = [1] * n
for i in range(n):
idx = bisect.bisect_left(arr, (arr[i][0] - arr[i][1], 0)) - 1
if idx >= 0:
res[i] = res[idx] + 1
print(n - max(r... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,590,848,262 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 204,800 | n,m = map(int,input().split())
a = list(map(int,input().split()))
x = a.count('1')
y = a.count('-1')
for i in range(m):
l,r = map(int,input().split())
if (l-r+1)%2!=0:
print('0')
else:
if (l-r+1)/2 <=x and (l-r+1)/2 <=y :
print('1')
else:
print('0'... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n,m = map(int,input().split())
a = list(map(int,input().split()))
x = a.count('1')
y = a.count('-1')
for i in range(m):
l,r = map(int,input().split())
if (l-r+1)%2!=0:
print('0')
else:
if (l-r+1)/2 <=x and (l-r+1)/2 <=y :
print('1')
else:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,686,453,434 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n,m,a,b = getints()
if b/m < a:
print((n//m)*b+(n%m)*a)
else:
print(n*a) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
n,m,a,b = getints()
if b/m < a:
print((n//m)*b+(n%m)*a)
else:
print(n*a)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,585,997,502 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 108 | 0 | no_of_days = int(input(""))
places = input("")
S_to_F = 0
F_to_S = 0
for day in range(0,no_of_days-1):
if places[day] != places[day+1]:
if places[day] == "S":
S_to_F += 1
else:
F_to_S += 1
if S_to_F > F_to_S:
print("YES")
else:
print("NO")
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
no_of_days = int(input(""))
places = input("")
S_to_F = 0
F_to_S = 0
for day in range(0,no_of_days-1):
if places[day] != places[day+1]:
if places[day] == "S":
S_to_F += 1
else:
F_to_S += 1
if S_to_F > F_to_S:
print("YES")
else:
print("NO")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
817 | D | Imbalanced Array | PROGRAMMING | 1,900 | [
"data structures",
"divide and conquer",
"dsu",
"sortings"
] | null | null | You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.
For example, the imbalance value of ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=106) — elements of the array. | Print one integer — the imbalance value of *a*. | [
"3\n1 4 1\n"
] | [
"9\n"
] | none | 0 | [
{
"input": "3\n1 4 1",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "10\n1 4 4 3 5 2 4 2 4 5",
"output": "123"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "245"
},
{
"input": "30\n4 5 2 2 5 2 3 4 3 3 2 1 3 4 4 5 3 3 1 5... | 1,622,787,046 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 1,216 | 114,585,600 | import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
stk = [(float('-inf'), int(-1))]
stk1 = [(float('inf'), int(-1))]
leftSmaller = []
leftGreater = []
for i, a in enumerate(A):
while stk[-1][0] > a:
stk.pop()
leftSmaller.append(stk[-1][1])
stk.append((a, i))... | Title: Imbalanced Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array ... | ```python
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
stk = [(float('-inf'), int(-1))]
stk1 = [(float('inf'), int(-1))]
leftSmaller = []
leftGreater = []
for i, a in enumerate(A):
while stk[-1][0] > a:
stk.pop()
leftSmaller.append(stk[-1][1])
stk.appe... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
474 | D | Flowers | PROGRAMMING | 1,700 | [
"dp"
] | null | null | We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty... | Input contains several test cases.
The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=105), where *t* represents the number of test cases.
The next *t* lines contain two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=105), describing the *i*-th test. | Print *t* lines to the standard output. The *i*-th line should contain the number of ways in which Marmot can eat between *a**i* and *b**i* flowers at dinner modulo 1000000007 (109<=+<=7). | [
"3 2\n1 3\n2 3\n4 4\n"
] | [
"6\n5\n5\n"
] | - For *K* = 2 and length 1 Marmot can eat (*R*). - For *K* = 2 and length 2 Marmot can eat (*RR*) and (*WW*). - For *K* = 2 and length 3 Marmot can eat (*RRR*), (*RWW*) and (*WWR*). - For *K* = 2 and length 4 Marmot can eat, for example, (*WWWW*) or (*RWWR*), but for example he can't eat (*WWWR*). | 2,000 | [
{
"input": "3 2\n1 3\n2 3\n4 4",
"output": "6\n5\n5"
},
{
"input": "1 1\n1 3",
"output": "14"
},
{
"input": "1 2\n64329 79425",
"output": "0"
}
] | 1,686,856,180 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 156 | 10,444,800 | from sys import stdin
input = lambda: stdin.readline().rstrip('\r\n')
M = int(1e9) + 7
N = int(1e5) + 5
t, k = map(int, input().split())
dp = [0]*N
dp[0] = 1
for i in range(1, N):
dp[i] = dp[i-1] + (i >= k) * dp[i-k]
dp[i] %= M
for i in range(1, N):
dp[i] += dp[i-1]
dp[i] %= M
for... | Title: Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequenc... | ```python
from sys import stdin
input = lambda: stdin.readline().rstrip('\r\n')
M = int(1e9) + 7
N = int(1e5) + 5
t, k = map(int, input().split())
dp = [0]*N
dp[0] = 1
for i in range(1, N):
dp[i] = dp[i-1] + (i >= k) * dp[i-k]
dp[i] %= M
for i in range(1, N):
dp[i] += dp[i-1]
dp[i] %... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,684,780,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 |
def solve(rail, orientation):
with open('output.txt', 'w') as writer:
if (orientation.lower() == 'front' and rail == 1) or (orientation.lower() == 'back' and rail == 2):
writer.write('L')
else:
writer.write('R')
writer.close()
if __name__ == 'main':
with o... | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
def solve(rail, orientation):
with open('output.txt', 'w') as writer:
if (orientation.lower() == 'front' and rail == 1) or (orientation.lower() == 'back' and rail == 2):
writer.write('L')
else:
writer.write('R')
writer.close()
if __name__ == 'main':
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
620 | C | Pearls in a Row | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl. | On the first line print integer *k* — the maximal number of segments in a partition of the row.
Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment.
Note you should print the correct partit... | [
"5\n1 2 3 4 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 3 1 2 1\n"
] | [
"1\n1 5\n",
"-1\n",
"2\n1 3\n4 7\n"
] | none | 0 | [
{
"input": "5\n1 2 3 4 1",
"output": "1\n1 5"
},
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "2\n1 3\n4 7"
},
{
"input": "9\n1 2 1 2 1 2 1 2 1",
"output": "3\n1 3\n4 6\n7 9"
},
{
"input": "11\n1 1 2 1 2 1 2 1 2 1 1",
"... | 1,585,215,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 888 | 40,960,000 | size = int(input())
myDic,capture,limit = {},[],-1
for x,y in enumerate(map(int,input().split())):
if y in myDic:
check = x - myDic[y][-1]
if myDic[y][-1] > limit:
capture.append((myDic[y][-1]+1,x+1))
limit = x; del myDic[y]
else: myDic[y][-1] = x
else:
... | Title: Pearls in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a ... | ```python
size = int(input())
myDic,capture,limit = {},[],-1
for x,y in enumerate(map(int,input().split())):
if y in myDic:
check = x - myDic[y][-1]
if myDic[y][-1] > limit:
capture.append((myDic[y][-1]+1,x+1))
limit = x; del myDic[y]
else: myDic[y][-1] = x
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,807,357 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | string =input()
for i in range(1,len(string))
if string[i].isalpha and string[i+1].isalpha and string[i-1].isalpha
print("Yes")
else
print("No")
| Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
string =input()
for i in range(1,len(string))
if string[i].isalpha and string[i+1].isalpha and string[i-1].isalpha
print("Yes")
else
print("No")
``` | -1 | 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,655,225,182 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a=input()
s=a.upper()
d=list(s)
w=0
r=0
for i in range(len(a)):
if d[i]==a[i]:
w=w+1
else:
r=r+1
if w>r:
print(a.upper())
else:
print(a.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
a=input()
s=a.upper()
d=list(s)
w=0
r=0
for i in range(len(a)):
if d[i]==a[i]:
w=w+1
else:
r=r+1
if w>r:
print(a.upper())
else:
print(a.lower())
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,585,216,804 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 528 | 3,276,800 | def reverse_with_start_end(A, start, end):
while (start < end):
A[start] ^= A[end]
A[end] ^= A[start]
A[start] ^= A[end]
start +=1
end -= 1
return A
n, k = map(int, input().split())
A = [i for i in range(1, n + 1)]
A = reverse_with_start_end(A, 0, n - 1)
A = reverse_with_start_end(A, k, n - 1)
print(*A)
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
def reverse_with_start_end(A, start, end):
while (start < end):
A[start] ^= A[end]
A[end] ^= A[start]
A[start] ^= A[end]
start +=1
end -= 1
return A
n, k = map(int, input().split())
A = [i for i in range(1, n + 1)]
A = reverse_with_start_end(A, 0, n - 1)
A = reverse_with_start_end(A, k, n - 1)
pri... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
549 | D | Haar Features | PROGRAMMING | 1,900 | [
"greedy",
"implementation"
] | null | null | The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represent... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the feature.
Next *n* lines contain the description of the feature. Each line consists of *m* characters, the *j*-th character of the *i*-th line equals to "W", if this element of the feature ... | Print a single number — the minimum number of operations that you need to make to calculate the value of the feature. | [
"6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n",
"3 3\nWBW\nBWW\nWWW\n",
"3 6\nWWBBWW\nWWBBWW\nWWBBWW\n",
"4 4\nBBBB\nBBBB\nBBBB\nBBBW\n"
] | [
"2\n",
"4\n",
"3\n",
"4\n"
] | The first sample corresponds to feature *B*, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations:
1. add the sum of pixels... | 1,000 | [
{
"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "2"
},
{
"input": "3 3\nWBW\nBWW\nWWW",
"output": "4"
},
{
"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW",
"output": "3"
},
{
"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW",
"output": "4"
},
{
... | 1,507,716,183 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 77 | 0 | n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
la=[0 for i in range(m)]
s=0
for i in range(n-1,-1,-1):
cv=0
for j in range(m-1,-1,-1):
la[j]+=cv
if l[i][j]=='W':
if la[j]!=1:
cv+=1-la[j]
la[j]=1
... | Title: Haar Features
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we... | ```python
n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
la=[0 for i in range(m)]
s=0
for i in range(n-1,-1,-1):
cv=0
for j in range(m-1,-1,-1):
la[j]+=cv
if l[i][j]=='W':
if la[j]!=1:
cv+=1-la[j]
la[j]... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
814 | C | An impassioned circulation of affection | PROGRAMMING | 1,600 | [
"brute force",
"dp",
"strings",
"two pointers"
] | null | null | Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* fro... | The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland.
The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland.
The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000... | Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it. | [
"6\nkoyomi\n3\n1 o\n4 o\n4 m\n",
"15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n",
"10\naaaaaaaaaa\n2\n10 b\n10 z\n"
] | [
"3\n6\n5\n",
"3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n",
"10\n10\n"
] | In the first sample, there are three plans:
- In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third... | 1,750 | [
{
"input": "6\nkoyomi\n3\n1 o\n4 o\n4 m",
"output": "3\n6\n5"
},
{
"input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b",
"output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5"
},
{
"input": "10\naaaaaaaaaa\n2\n10 b\n10 z",
"output": "10\n10"
},
{
"input": "1... | 1,588,483,556 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 951 | 11,059,200 | import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
d... | Title: An impassioned circulation of affection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
... | ```python
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in ra... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,604,786,117 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | input()
n = [int(x) for x in input().split()]
for i in n:
print(i * 4 + 1) | Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
input()
n = [int(x) for x in input().split()]
for i in n:
print(i * 4 + 1)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,038,398 | 498 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 5,632,000 | def main():
a,b,c,d = input().split(" ")
if (2*eval(c) < eval(d)):
print(-1)
else:
print(a)
print(b)
print(c)
main() | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
def main():
a,b,c,d = input().split(" ")
if (2*eval(c) < eval(d)):
print(-1)
else:
print(a)
print(b)
print(c)
main()
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,602,745,380 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 155 | 0 | from sys import stdin, stdout
class SOLVE:
def solve(self):
R = stdin.readline
#f = open('input.txt');R = f.readline
W = stdout.write
s = R()[:-1]
brackets, cnt = [], 0
for i in range(len(s)):
if s[i] in ['(', '<', ... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
from sys import stdin, stdout
class SOLVE:
def solve(self):
R = stdin.readline
#f = open('input.txt');R = f.readline
W = stdout.write
s = R()[:-1]
brackets, cnt = [], 0
for i in range(len(s)):
if s[i] in [... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,647,358,657 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | s=input()
if s[0]>'a' and s[0]<'h' and s[1]>'1' and s[1]<'8':
print(8)
else:
print(5) | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
s=input()
if s[0]>'a' and s[0]<'h' and s[1]>'1' and s[1]<'8':
print(8)
else:
print(5)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,650,947,678 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | cardnum = int(input())
cards = [int(x) for x in input().split()]
amount = int(sum(cards) / (cardnum / 2))
cardcopy = list(cards)
for i in cards:
if i not in cardcopy or amount - i not in cardcopy:
continue
cardcopy.pop(cardcopy.index(i))
cardcopy.pop(cardcopy.index(amount - i))
print((f... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
cardnum = int(input())
cards = [int(x) for x in input().split()]
amount = int(sum(cards) / (cardnum / 2))
cardcopy = list(cards)
for i in cards:
if i not in cardcopy or amount - i not in cardcopy:
continue
cardcopy.pop(cardcopy.index(i))
cardcopy.pop(cardcopy.index(amount - i))
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
638 | A | Home Numbers | PROGRAMMING | 1,100 | [
"*special",
"constructive algorithms",
"math"
] | null | null | The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the pictur... | The first line of the input contains two integers, *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100<=000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. | Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house *a*. | [
"4 2\n",
"8 5\n"
] | [
"2\n",
"3\n"
] | In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with *n* = 8. House 5 is the one before last at Vasya's left. | 500 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "100000 100000",... | 1,458,478,597 | 3,397 | Python 3 | SKIPPED | TESTS | 69 | 62 | 5,120,000 | n,a = map(int, input().split(" "))
if(a%2 == 1): print(int((a+1)/2))
else:
if(n%2 == 0): print(int(n/2-a/2+1))
else: print(int((n-1)/2-a/2+1)) | Title: Home Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are nu... | ```python
n,a = map(int, input().split(" "))
if(a%2 == 1): print(int((a+1)/2))
else:
if(n%2 == 0): print(int(n/2-a/2+1))
else: print(int((n-1)/2-a/2+1))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,571,304,181 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n= int(input())
l= list(map(int,input().split()))
for i in range(n):
print(l[i]*4 + 1)
| Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
n= int(input())
l= list(map(int,input().split()))
for i in range(n):
print(l[i]*4 + 1)
``` | 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.