source
stringclasses 4
values | task_type
stringclasses 1
value | in_source_id
stringlengths 0
138
| problem
stringlengths 219
13.2k
| gold_standard_solution
stringlengths 0
413k
| problem_id
stringlengths 5
10
| metadata
dict | verification_info
dict |
---|---|---|---|---|---|---|---|
apps | verifiable_code | 647 | Solve the following coding problem using the programming language python:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the $\frac{n}{2}$ desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has all students numbered from 1 to n.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.
-----Input-----
The first input line contains a single even integer n (4 ≤ n ≤ 100) — the number of students in the class. The second line contains exactly n capital English letters "L" and "R". If the i-th letter at the second line equals "L", then the student number i is a lefthander, otherwise he is a righthander.
-----Output-----
Print $\frac{n}{2}$ integer pairs, one pair per line. In the i-th line print the numbers of students that will sit at the i-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.
-----Examples-----
Input
6
LLRLLL
Output
1 4
2 5
6 3
Input
4
RRLL
Output
3 1
4 2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# python 3
"""
"""
def lefthanders_and_righthanders(n_int, student_list) -> list:
sitting_order = []
for i in range(n_int//2):
if student_list[i] == 'R' and student_list[i + n_int//2] == 'L':
sitting_order.append((i + n_int//2 + 1, i + 1))
print(i + n_int//2 + 1, i + 1)
else:
sitting_order.append((i + 1, i + n_int//2 + 1))
print(i + 1, i + n_int//2 + 1)
return sitting_order
def __starting_point():
"""
Inside of this is the test.
Outside is the API
"""
with open("input.txt", 'r') as f_input:
n = int(f_input.readline())
students = f_input.readline()
# print(n, students)
sitting = lefthanders_and_righthanders(n, students)
with open("output.txt", 'w') as f_output:
for each in sitting:
f_output.write(str(each[0]) + ' ' + str(each[1]) + '\n')
__starting_point()
``` | vfc_12342 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/234/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nLLRLLL\n",
"output": "1 4\n2 5\n6 3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 648 | Solve the following coding problem using the programming language python:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation $y = - \frac{x}{m} + b$. Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.
Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.
Okabe is sure that the answer does not exceed 10^18. You can trust him.
-----Input-----
The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).
-----Output-----
Print the maximum number of bananas Okabe can get from the trees he cuts.
-----Examples-----
Input
1 5
Output
30
Input
2 3
Output
25
-----Note----- [Image]
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: map(int, input().split())
m, b = read()
ans = -1
def f(x, y):
return (x * (x + 1) * (y + 1) + y * (y + 1) * (x + 1)) // 2
for k in range(b + 3):
x = k * m
y = b - k
ans = max(ans, f(x, y))
print(ans)
``` | vfc_12346 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/821/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 5\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n",
"output": "459\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 649 | Solve the following coding problem using the programming language python:
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.
Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t_1, t_2, ..., t_{n}. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t_1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t_2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2^{n} - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.
Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 30) — the total depth of the recursion.
The second line contains n integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 5). On the i-th level each of 2^{i} - 1 parts will cover t_{i} cells before exploding.
-----Output-----
Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.
-----Examples-----
Input
4
4 2 2 3
Output
39
Input
6
1 1 1 1 1 3
Output
85
Input
1
3
Output
3
-----Note-----
For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t_1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39.
[Image]
For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import *
T = int(stdin.readline())
t = [int(s) for s in stdin.readline().split(' ')]
a = []
for i in range(T - 1, -1, -1):
if i % 2 == 0:
a += [(e[0], -e[1]) for e in a]
a = [(e[0] - t[i], e[1]) for e in a]
a += [(- x - 1, 0) for x in range(t[i])]
a = list(set(a))
if i % 2 == 1:
a += [(e[1], -e[0]) for e in a]
a = [(e[0] - t[i], e[1] + t[i]) for e in a]
a += [(- x - 1, x + 1) for x in range(t[i])]
a = list(set(a))
print(len(a))
``` | vfc_12350 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/750/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 2 2 3\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 1 1 1 1 3\n",
"output": "85\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 650 | Solve the following coding problem using the programming language python:
-----Input-----
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
-----Output-----
Output "YES" or "NO".
-----Examples-----
Input
NEAT
Output
YES
Input
WORD
Output
NO
Input
CODER
Output
NO
Input
APRILFOOL
Output
NO
Input
AI
Output
YES
Input
JUROR
Output
YES
Input
YES
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
p = "AEFHIKLMNTVWXYZ"
q = "BCDGJOPQRSU"
word = input()
x, y = 0, 0
for w in word:
if w in p:
x += 1
else:
y += 1
if x == 0 or y == 0:
print("YES")
else:
print("NO")
``` | vfc_12354 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1145/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "NEAT\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "WORD\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 651 | Solve the following coding problem using the programming language python:
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.
The robot can only move up, left, right, or down.
When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.
The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.
Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.
-----Input-----
The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.
-----Output-----
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
-----Examples-----
Input
5 6
.....#
S....#
.#....
.#....
...E..
333300012
Output
1
Input
6 6
......
......
..SE..
......
......
......
01232123212302123021
Output
14
Input
5 3
...
.S.
###
.E.
...
3
Output
0
-----Note-----
For the first sample, the only valid mapping is $0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$, where D is down, L is left, U is up, R is right.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import itertools
def valid(grid, path, perm, start, goal):
x, y = start
n = len(grid)
m = len(grid[0])
for move in path:
dx, dy = perm[int(move)]
x += dx
y += dy
if (x, y) == goal:
return True
if not (0 <= x < n and 0 <= y < m) or grid[x][y] == '#':
return False
return False
def main():
n, m = list(map(int, input().split()))
grid = [list(input()) for _ in range(n)]
for i in range(n):
for j in range(m):
if grid[i][j] == 'S':
sx, sy = i, j
grid[i][j] = '.'
elif grid[i][j] == 'E':
gx, gy = i, j
grid[i][j] = '.'
path = input()
moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for perm in itertools.permutations(moves):
if valid(grid, path, perm, (sx, sy), (gx, gy)):
ans += 1
print(ans)
main()
``` | vfc_12358 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/908/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n...\n.S.\n###\n.E.\n...\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n.#......#.\n#.........\n#.........\n....#.#..E\n.......#..\n....##....\n....S.....\n....#.....\n.........#\n...##...#.\n23323332313123221123020122221313323310313122323233\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 652 | Solve the following coding problem using the programming language python:
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
-----Input-----
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (x_{i}, y_{i}) (0 ≤ x_{i}, y_{i} ≤ 10^9) — the coordinates of the i-th point.
-----Output-----
Print the only integer c — the number of parallelograms with the vertices at the given points.
-----Example-----
Input
4
0 1
1 0
1 1
2 0
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
points = [0] * n
D = {}
for i in range(n):
points[i] = tuple(int(x) for x in input().split())
for i in range(n):
for j in range(i+1, n):
x1, y1 = points[i]
x2, y2 = points[j]
u, v = x2 - x1, y2 - y1
if u < 0 or u == 0 and v < 0:
u, v = -u, -v
if (u, v) in D:
D[(u, v)] += 1
else:
D[(u, v)] = 1
S = sum(D[i] * (D[i] - 1) // 2 for i in D)
print(S // 2)
``` | vfc_12362 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/660/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1\n1 0\n1 1\n2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 5\n4 2\n4 4\n8 1\n8 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 7\n2 14\n3 7\n3 13\n5 13\n13 10\n15 12\n17 1\n18 8\n19 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n0 17\n1 8\n1 9\n2 5\n2 11\n3 0\n5 10\n5 13\n6 7\n7 3\n12 13\n13 7\n14 16\n15 10\n15 18\n17 2\n17 12\n18 14\n19 18\n20 17\n",
"output": "18\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 653 | Solve the following coding problem using the programming language python:
Amugae has a hotel consisting of $10$ rooms. The rooms are numbered from $0$ to $9$ from left to right.
The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.
One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.
-----Input-----
The first line consists of an integer $n$ ($1 \le n \le 10^5$), the number of events in Amugae's memory.
The second line consists of a string of length $n$ describing the events in chronological order. Each character represents: 'L': A customer arrives from the left entrance. 'R': A customer arrives from the right entrance. '0', '1', ..., '9': The customer in room $x$ ($0$, $1$, ..., $9$ respectively) leaves.
It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room $x$ when $x$ ($0$, $1$, ..., $9$) is given. Also, all the rooms are initially empty.
-----Output-----
In the only line, output the hotel room's assignment status, from room $0$ to room $9$. Represent an empty room as '0', and an occupied room as '1', without spaces.
-----Examples-----
Input
8
LLRL1RL1
Output
1010000011
Input
9
L0L0LLRR9
Output
1100000010
-----Note-----
In the first example, hotel room's assignment status after each action is as follows. First of all, all rooms are empty. Assignment status is 0000000000. L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. L: one more customer from the left entrance. Assignment status is 1100000000. R: one more customer from the right entrance. Assignment status is 1100000001. L: one more customer from the left entrance. Assignment status is 1110000001. 1: the customer in room $1$ leaves. Assignment status is 1010000001. R: one more customer from the right entrance. Assignment status is 1010000011. L: one more customer from the left entrance. Assignment status is 1110000011. 1: the customer in room $1$ leaves. Assignment status is 1010000011.
So after all, hotel room's final assignment status is 1010000011.
In the second example, hotel room's assignment status after each action is as follows. L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. 0: the customer in room $0$ leaves. Assignment status is 0000000000. L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. 0: the customer in room $0$ leaves. Assignment status is 0000000000. L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. L: one more customer from the left entrance. Assignment status is 1100000000. R: one more customer from the right entrance. Assignment status is 1100000001. R: one more customer from the right entrance. Assignment status is 1100000011. 9: the customer in room $9$ leaves. Assignment status is 1100000010.
So after all, hotel room's final assignment status is 1100000010.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = input()
num = '0123456789'
state = [0]*(10)
for i in s:
if i in num:
state[int(i)] = 0
else:
if i=='L':
for j in range(10):
if state[j]==0:
state[j] = 1
break
else:
for j in range(9, -1, -1):
if state[j] == 0:
state[j] = 1
break
for i in state:
print(i, end='')
``` | vfc_12366 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1200/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\nLLRL1RL1\n",
"output": "1010000011",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\nL0L0LLRR9\n",
"output": "1100000010",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nL\n",
"output": "1000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\nR9L0L0R9R9L0R9R9L0R9R9R9L0R9R9R9L0L0R9L0R9L0L0L0R9R9L0R9L0R9R9L0R9R9L0R9L0L0R9R9R9L0L0L0L0R9L0L0L0L0\n",
"output": "0000000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\nRRLRRLRRLR2L0R6R2L1L3R4L0L6L2L2R5R6R1R3L6R6R8L6L4L3L6R9L6L9L8L7R7L8R1R1R7R7L2L8L2L1R8R2R8L76RR9R4R3R\n",
"output": "1111111111",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 654 | Solve the following coding problem using the programming language python:
Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys...
It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of weird things, including a trie of all correct bracket sequences of length $2n$.
The definition of correct bracket sequence is as follows: The empty sequence is a correct bracket sequence, If $s$ is a correct bracket sequence, then $(\,s\,)$ is a correct bracket sequence, If $s$ and $t$ are a correct bracket sequence, then $st$ is also a correct bracket sequence.
For example, the strings "(())", "()()" form a correct bracket sequence, while ")(" and "((" not.
Aki then came up with an interesting problem: What is the size of the maximum matching (the largest set of edges such that there are no two edges with a common vertex) in this trie? Since the answer can be quite large, print it modulo $10^9 + 7$.
-----Input-----
The only line contains a single integer $n$ ($1 \le n \le 1000$).
-----Output-----
Print exactly one integer — the size of the maximum matching in the trie. Since the answer can be quite large, print it modulo $10^9 + 7$.
-----Examples-----
Input
1
Output
1
Input
2
Output
3
Input
3
Output
9
-----Note-----
The pictures below illustrate tries in the first two examples (for clarity, the round brackets are replaced with angle brackets). The maximum matching is highlighted with blue. [Image] [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n=int(input())
mod=10**9+7
ANS=[[0]*(n+1) for i in range(n+1)]
def bra(x,y):
if ANS[x][y]!=0:
return ANS[x][y]
if x==y==0:
ANS[x][y]=0
return 0
if (x+y)%2==1:
A=1
else:
A=0
if x==y:
ANS[x][y]=A+bra(x-1,y)
return ANS[x][y]
elif x==0:
ANS[x][y]=A+bra(x,y-1)
return ANS[x][y]
elif y==0:
ANS[x][y]=A+bra(x-1,y)
return ANS[x][y]
elif x<y and x!=0 and y!=0:
ANS[x][y]=A+bra(x-1,y)+bra(x,y-1)
return ANS[x][y]
print(bra(n,n)%mod)
``` | vfc_12370 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1152/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 655 | Solve the following coding problem using the programming language python:
On a chessboard with a width of $n$ and a height of $n$, rows are numbered from bottom to top from $1$ to $n$, columns are numbered from left to right from $1$ to $n$. Therefore, for each cell of the chessboard, you can assign the coordinates $(r,c)$, where $r$ is the number of the row, and $c$ is the number of the column.
The white king has been sitting in a cell with $(1,1)$ coordinates for a thousand years, while the black king has been sitting in a cell with $(n,n)$ coordinates. They would have sat like that further, but suddenly a beautiful coin fell on the cell with coordinates $(x,y)$...
Each of the monarchs wanted to get it, so they decided to arrange a race according to slightly changed chess rules:
As in chess, the white king makes the first move, the black king makes the second one, the white king makes the third one, and so on. However, in this problem, kings can stand in adjacent cells or even in the same cell at the same time.
The player who reaches the coin first will win, that is to say, the player who reaches the cell with the coordinates $(x,y)$ first will win.
Let's recall that the king is such a chess piece that can move one cell in all directions, that is, if the king is in the $(a,b)$ cell, then in one move he can move from $(a,b)$ to the cells $(a + 1,b)$, $(a - 1,b)$, $(a,b + 1)$, $(a,b - 1)$, $(a + 1,b - 1)$, $(a + 1,b + 1)$, $(a - 1,b - 1)$, or $(a - 1,b + 1)$. Going outside of the field is prohibited.
Determine the color of the king, who will reach the cell with the coordinates $(x,y)$ first, if the white king moves first.
-----Input-----
The first line contains a single integer $n$ ($2 \le n \le 10^{18}$) — the length of the side of the chess field.
The second line contains two integers $x$ and $y$ ($1 \le x,y \le n$) — coordinates of the cell, where the coin fell.
-----Output-----
In a single line print the answer "White" (without quotes), if the white king will win, or "Black" (without quotes), if the black king will win.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
4
2 3
Output
White
Input
5
3 5
Output
Black
Input
2
2 2
Output
Black
-----Note-----
An example of the race from the first sample where both the white king and the black king move optimally: The white king moves from the cell $(1,1)$ into the cell $(2,2)$. The black king moves form the cell $(4,4)$ into the cell $(3,3)$. The white king moves from the cell $(2,2)$ into the cell $(2,3)$. This is cell containing the coin, so the white king wins. [Image]
An example of the race from the second sample where both the white king and the black king move optimally: The white king moves from the cell $(1,1)$ into the cell $(2,2)$. The black king moves form the cell $(5,5)$ into the cell $(4,4)$. The white king moves from the cell $(2,2)$ into the cell $(3,3)$. The black king moves from the cell $(4,4)$ into the cell $(3,5)$. This is the cell, where the coin fell, so the black king wins. [Image]
In the third example, the coin fell in the starting cell of the black king, so the black king immediately wins. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
x, y = map(int, input().split())
white = max(x - 1, y - 1)
black = max(n - x, n - y)
print("White" if white <= black else "Black")
``` | vfc_12374 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1075/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3\n",
"output": "White",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 5\n",
"output": "Black",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 2\n",
"output": "Black",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000\n1000000000000000000 1000000000000000000\n",
"output": "Black",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000\n1 1\n",
"output": "White",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 656 | Solve the following coding problem using the programming language python:
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of winter tires wears down and cannot be used more. It is not necessary that these k days form a continuous segment of days.
Before the first winter day Vasya still uses summer tires. It is possible to drive safely on summer tires any number of days when the average air temperature is non-negative. It is impossible to drive on summer tires at days when the average air temperature is negative.
Vasya can change summer tires to winter tires and vice versa at the beginning of any day.
Find the minimum number of times Vasya needs to change summer tires to winter tires and vice versa to drive safely during the winter. At the end of the winter the car can be with any set of tires.
-----Input-----
The first line contains two positive integers n and k (1 ≤ n ≤ 2·10^5, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total.
The second line contains a sequence of n integers t_1, t_2, ..., t_{n} ( - 20 ≤ t_{i} ≤ 20) — the average air temperature in the i-th winter day.
-----Output-----
Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1.
-----Examples-----
Input
4 3
-5 20 -3 0
Output
2
Input
4 2
-5 20 -3 0
Output
4
Input
10 6
2 -5 1 3 0 0 -4 -3 1 0
Output
3
-----Note-----
In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two.
In the second example before the first winter day Vasya should change summer tires to winter tires, and then after the first winter day change winter tires to summer tires. After the second day it is necessary to change summer tires to winter tires again, and after the third day it is necessary to change winter tires to summer tires. Thus, the total number of tires' changes equals four.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python3
def solve():
n, k = list(map(int, input().split()))
temps = list(map(int, input().split()))
summer_seqs = []
winter_seqs = []
cur_season = 1
cur_len = 0
for t in temps:
# print("Handling", t)
if cur_season * t > 0 or (t == 0 and cur_season == 1):
cur_len += 1
# print("Adding...")
else:
# print("Thats new!")
if cur_season == 1:
summer_seqs.append(cur_len)
else:
winter_seqs.append(cur_len)
cur_len = 1
cur_season = -cur_season
if cur_season == 1:
summer_seqs.append(cur_len)
else:
winter_seqs.append(cur_len)
summer_seqs = summer_seqs[1:]
cur_len = sum(winter_seqs)
if cur_len > k:
return -1
if len(summer_seqs) == 0:
return 1 if len(winter_seqs) != 0 else 0
changes = len(summer_seqs) + len(winter_seqs)
last_sum_seq = None
if temps[-1] >= 0:
last_sum_seq = summer_seqs[-1]
summer_seqs = summer_seqs[:-1]
summer_seqs = list(sorted(summer_seqs))
# print("Changes needed so far:", changes)
# print("Summer seqs: ", len(summer_seqs))
# print("Last summer seq:", last_sum_seq)
# print("Can drive for another", k - cur_len)
for s in summer_seqs:
if k - cur_len >= s:
changes -= 2
cur_len += s
else:
break
# print("Before last summer we can drive for",
# k - cur_len, "having ", changes, "changes")
if last_sum_seq is not None:
if k - cur_len >= last_sum_seq:
# print("and dont change at last")
changes -= 1
return changes
def __starting_point():
print(solve())
__starting_point()
``` | vfc_12378 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/747/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n-5 20 -3 0\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 657 | Solve the following coding problem using the programming language python:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
-----Input-----
The first line features two integers A and B (0 ≤ A, B ≤ 10^9), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 10^9) — the respective amounts of yellow, green and blue balls to be obtained.
-----Output-----
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
-----Examples-----
Input
4 3
2 1 1
Output
2
Input
3 9
1 1 3
Output
1
Input
12345678 87654321
43043751 1000000000 53798715
Output
2147483648
-----Note-----
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python3
def main():
a, b = list(map(int, input().split()))
x, y, z = list(map(int, input().split()))
print(max(x * 2 + y - a, 0) + max(y + z * 3 - b, 0))
try:
while True:
main()
except EOFError:
pass
``` | vfc_12382 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/912/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9\n1 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 658 | Solve the following coding problem using the programming language python:
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
-----Input-----
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 10^9, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers x_{i} and y_{i} ( - 10^9 ≤ x_{i} ≤ 10^9, 0 ≤ y_{i} ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
-----Output-----
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10^{ - 6}.
-----Example-----
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
-----Note-----
Following image describes initial position in the first sample case:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, w, v, u = list(map(int, input().split()))
versh = []
for i in range(n):
a, b = list(map(int, input().split()))
versh.append((a, b))
versh.sort(key=lambda x : x[1])
for i in versh:
if i[0] / v < i[1] / u:
break
else:
print(w / u)
return
y = 0
time = 0
for i in versh:
x = i[0] - time * v
if x < 0:
continue
if x / v >= (i[1] - y) / u:
time += x / v
y = i[1]
time += (w - y) / u
print(time)
``` | vfc_12386 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/703/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n",
"output": "5.0000000000",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 659 | Solve the following coding problem using the programming language python:
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions: a_1 ≤ a_2 ≤ ... ≤ a_{n}; a_1 ≥ a_2 ≥ ... ≥ a_{n}.
Help Petya find the two required positions to swap or else say that they do not exist.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^5). The second line contains n non-negative space-separated integers a_1, a_2, ..., a_{n} — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.
-----Output-----
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
-----Examples-----
Input
1
1
Output
-1
Input
2
1 2
Output
-1
Input
4
1 2 3 4
Output
1 2
Input
3
1 1 1
Output
-1
-----Note-----
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def solve():
n, = rv()
a, = rl(1)
for i in range(min(10, n - 1)):
for j in range(max(i + 1, n - 10), n):
if a[i] != a[j]:
a[i], a[j] = a[j], a[i]
if notsorted(a):
print(i + 1, j + 1)
return
a[i], a[j] = a[j], a[i]
count = 0
for i in range(n - 1):
if a[i] != a[i + 1]:
a[i], a[i + 1] = a[i + 1], a[i]
if notsorted(a):
print(i + 1, i + 2)
return
a[i], a[i + 1] = a[i + 1], a[i]
count += 1
if count == 100: break
print(-1)
def notsorted(a):
first, second = True, True
for i in range(len(a) - 1):
if a[i] > a[i + 1]:
first = False
break
for i in range(len(a) - 1):
if a[i] < a[i + 1]:
second = False
break
return True if not first and not second else False
def prt(l): return print(''.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()
``` | vfc_12390 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/252/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 3 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 660 | Solve the following coding problem using the programming language python:
A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round): let k be the maximal power of the number 2 such that k ≤ m, k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly, when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
-----Input-----
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
-----Output-----
Print two integers x and y — the number of bottles and towels need for the tournament.
-----Examples-----
Input
5 2 3
Output
20 15
Input
8 2 4
Output
35 32
-----Note-----
In the first example will be three rounds: in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), in the second round will be only one match, so we need another 5 bottles of water, in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, b, p = map(int, input().split())
answer1 = 0
answer2 = n
while n > 1:
k = 1
while k < n:
k *= 2
answer1 += k * b + (k // 2)
n = k // 2 + n - k
print(answer1, answer2 * p)
``` | vfc_12394 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/628/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 3\n",
"output": "20 15\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 662 | Solve the following coding problem using the programming language python:
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules: Alex and Bob play the first game, and Carl is spectating; When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.
Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played.
Then n lines follow, describing the game log. i-th line contains one integer a_{i} (1 ≤ a_{i} ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.
-----Output-----
Print YES if the situation described in the log was possible. Otherwise print NO.
-----Examples-----
Input
3
1
1
2
Output
YES
Input
2
1
2
Output
NO
-----Note-----
In the first example the possible situation is: Alex wins, Carl starts playing instead of Bob; Alex wins, Bob replaces Carl; Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import Counter, defaultdict
import itertools
import sys
def main():
n = int(input())
spec = 3
poss = True
for _ in range(n):
winner = int(input())
if winner != spec:
spec = 6 - winner - spec
else:
poss = False
print('YES' if poss else 'NO')
main()
``` | vfc_12402 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/893/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n1\n2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 663 | Solve the following coding problem using the programming language python:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
-----Input-----
Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 10^5, - 10^5 ≤ x, y, x', y' ≤ 10^5), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
-----Output-----
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
-----Examples-----
Input
2 0 0 0 4
Output
1
Input
1 1 1 4 4
Output
3
Input
4 5 6 5 6
Output
0
-----Note-----
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import ceil
def dist(x, y):
return (x ** 2 + y ** 2) ** 0.5
r, x, y, x2, y2 = map(int, input().split())
print(ceil(dist(x - x2, y - y2) / (2 * r)))
``` | vfc_12406 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/507/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 0 0 0 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 664 | Solve the following coding problem using the programming language python:
One day, Twilight Sparkle is interested in how to sort a sequence of integers a_1, a_2, ..., a_{n} in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:a_1, a_2, ..., a_{n} → a_{n}, a_1, a_2, ..., a_{n} - 1.
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
-----Input-----
The first line contains an integer n (2 ≤ n ≤ 10^5). The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5).
-----Output-----
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
-----Examples-----
Input
2
2 1
Output
1
Input
3
1 3 2
Output
-1
Input
2
1 2
Output
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(1, n):
d.append(a[i] - a[i - 1])
d.append(a[0] - a[n - 1])
cnt = 0
for i in range(0, n):
if d[i] < 0:
cnt += 1
pos = i
if cnt == 0:
print(0)
elif cnt > 1:
print(-1)
else:
print(n - pos - 1)
``` | vfc_12410 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/454/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 2\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 665 | Solve the following coding problem using the programming language python:
New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.
Vasya's verse contains $n$ parts. It takes $a_i$ seconds to recite the $i$-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes $a_1$ seconds, secondly — the part which takes $a_2$ seconds, and so on. After reciting the verse, Vasya will get the number of presents equal to the number of parts he fully recited.
Vasya can skip at most one part of the verse while reciting it (if he skips more than one part, then Santa will definitely notice it).
Santa will listen to Vasya's verse for no more than $s$ seconds. For example, if $s = 10$, $a = [100, 9, 1, 1]$, and Vasya skips the first part of verse, then he gets two presents.
Note that it is possible to recite the whole verse (if there is enough time).
Determine which part Vasya needs to skip to obtain the maximum possible number of gifts. If Vasya shouldn't skip anything, print 0. If there are multiple answers, print any of them.
You have to process $t$ test cases.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains two integers $n$ and $s$ ($1 \le n \le 10^5, 1 \le s \le 10^9$) — the number of parts in the verse and the maximum number of seconds Santa will listen to Vasya, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the time it takes to recite each part of the verse.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case print one integer — the number of the part that Vasya needs to skip to obtain the maximum number of gifts. If Vasya shouldn't skip any parts, print 0.
-----Example-----
Input
3
7 11
2 9 1 3 18 1 4
4 35
11 9 10 7
1 8
5
Output
2
1
0
-----Note-----
In the first test case if Vasya skips the second part then he gets three gifts.
In the second test case no matter what part of the verse Vasya skips.
In the third test case Vasya can recite the whole verse.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for i in range(t):
n, s = [int(x) for x in input().split()]
a= [int(x) for x in input().split()]
need = -1
if (sum(a)) <= s:
print(0)
else:
for i in range(n):
if a[i] > need:
need= a[i]
index = i
if s - a[i] < 0:
print(index + 1)
break
s -= a[i]
``` | vfc_12414 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1279/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7 11\n2 9 1 3 18 1 4\n4 35\n11 9 10 7\n1 8\n5\n",
"output": "2\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10 1000000000\n5 6 7 4 1000000000 10 74 1000000000 1000000000 1000000000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n24 1\n2 1 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n7 1000000000\n500000000 999999999 500000000 1000000000 1000000000 1000000000 294967297\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9 1000000000\n999999999 9 999999990 999999999 999999999 999999999 999999999 9 999999999\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 666 | Solve the following coding problem using the programming language python:
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
-----Input-----
The only line contains integer n (1 ≤ n ≤ 10^14) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Output-----
Print the element in the n-th position of the sequence (the elements are numerated from one).
-----Examples-----
Input
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def f(m):
return m * (m + 1) // 2
n = int(input())
l, r = 0, n
while r - l > 1:
m = (r + l) // 2
if f(m) >= n:
r = m
else:
l = m
n -= f(l)
print(n)
``` | vfc_12418 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/622/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "55\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 667 | Solve the following coding problem using the programming language python:
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them.
-----Input-----
The first line of the input contains a single integer N (3 ≤ N ≤ 10).
The following N lines each contain N space-separated integers. jth integer in ith line a_{ij} is the length of the edge that connects vertices i and j. a_{ij} = a_{ji}, a_{ii} = 0, 1 ≤ a_{ij} ≤ 100 for i ≠ j.
-----Output-----
Output the maximum length of the shortest path between any pair of vertices in the graph.
-----Examples-----
Input
3
0 1 1
1 0 4
1 4 0
Output
2
Input
4
0 1 2 3
1 0 4 5
2 4 0 6
3 5 6 0
Output
5
-----Note-----
You're running short of keywords, so you can't use some of them:define
do
for
foreach
while
repeat
until
if
then
else
elif
elsif
elseif
case
switch
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#!/usr/bin/env python
import base64
exec(base64.b64decode(b'Cm4gPSBpbnQoaW5wdXQoKSkKZ3JhcGggPSBbW2ludCh4KSBmb3IgeCBpbiBpbnB1dCgpLnNwbGl0KCldIGZvciBfIGluIHJhbmdlKG4pXQpkaXN0ID0gW3Jvd1s6XSBmb3Igcm93IGluIGdyYXBoXQoKZm9yIGsgaW4gcmFuZ2Uobik6CiAgICBmb3IgaSBpbiByYW5nZShuKToKICAgICAgICBmb3IgaiBpbiByYW5nZShuKToKICAgICAgICAgICAgaWYgZGlzdFtpXVtqXSA+IGRpc3RbaV1ba10gKyBkaXN0W2tdW2pdOgogICAgICAgICAgICAgICAgZGlzdFtpXVtqXSA9IGRpc3RbaV1ba10gKyBkaXN0W2tdW2pdCgpwcmludChtYXgobWF4KHggZm9yIHggaW4gcm93KSBmb3Igcm93IGluIGRpc3QpKQo='))
``` | vfc_12422 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/656/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 1 1\n1 0 4\n1 4 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 58\n25 55 20 7 42 24 100 10 0 29\n42 99 91 32 99 45 22 58 29 0\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 1 1 1 1 1 1 1 1 100\n1 0 1 1 1 1 1 1 1 1\n1 1 0 1 1 1 1 1 1 1\n1 1 1 0 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1\n1 1 1 1 1 0 1 1 1 1\n1 1 1 1 1 1 0 1 1 1\n1 1 1 1 1 1 1 0 1 1\n1 1 1 1 1 1 1 1 0 1\n100 1 1 1 1 1 1 1 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 1 100 100 100 100 100 100 100 100\n1 0 1 100 100 100 100 100 100 100\n100 1 0 1 100 100 100 100 100 100\n100 100 1 0 1 100 100 100 100 100\n100 100 100 1 0 1 100 100 100 100\n100 100 100 100 1 0 1 100 100 100\n100 100 100 100 100 1 0 1 100 100\n100 100 100 100 100 100 1 0 1 100\n100 100 100 100 100 100 100 1 0 1\n100 100 100 100 100 100 100 100 1 0\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 1 1\n1 0 1\n1 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 668 | Solve the following coding problem using the programming language python:
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value a_{i} — the maximum number of messages which the i-th student is agree to send per day. The student can't send messages to himself.
In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages.
Your task is to make a plan of using private messages, so that:
the student i sends no more than a_{i} messages (for all i from 1 to n); all students knew the news about the credit (initially only Polycarp knew it); the student can inform the other student only if he knows it himself.
Let's consider that all students are numerated by distinct numbers from 1 to n, and Polycarp always has the number 1.
In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above.
-----Input-----
The first line contains the positive integer n (2 ≤ n ≤ 100) — the number of students.
The second line contains the sequence a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 100), where a_{i} equals to the maximum number of messages which can the i-th student agree to send. Consider that Polycarp always has the number 1.
-----Output-----
Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer k — the number of messages which will be sent. In each of the next k lines print two distinct integers f and t, meaning that the student number f sent the message with news to the student number t. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit.
If there are several answers, it is acceptable to print any of them.
-----Examples-----
Input
4
1 2 1 0
Output
3
1 2
2 4
2 3
Input
6
2 0 1 3 2 0
Output
6
1 3
3 4
1 2
4 5
5 6
4 6
Input
3
0 2 2
Output
-1
-----Note-----
In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def solve():
n = int(input())
A = list(map(int, input().split()))
x, A = A[0], A[1:]
A = [(A[i], i + 2) for i in range(len(A))]
A.sort(reverse=True)
cnt = 1
msg = x
total = 1
for a in A:
if not msg:
print(-1)
return
msg += a[0] - 1
total += a[0]
cnt += 1
if total >= n:
break
print(n - 1)
total = x
for j in range(min(x, len(A))):
print(1, A[j][1])
if total >= n - 1:
return
for i in range(len(A)):
for j in range(total, min(total + A[i][0], len(A))):
print(A[i][1], A[j][1])
total += 1
if total >= n - 1:
return
solve()
``` | vfc_12426 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/769/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1 0\n",
"output": "3\n1 2\n2 3\n2 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 0 1 3 2 0\n",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n",
"output": "1\n1 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 669 | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b_1, b_2, ..., b_{k} (1 ≤ b_1 < b_2 < ... < b_{k} ≤ n) in such a way that the value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$ is maximized. Chosen sequence can be empty.
Print the maximum possible value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$.
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
Print the maximum possible value of $\sum_{i = 1}^{k} a_{b_{i}} \operatorname{mod} m$.
-----Examples-----
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
-----Note-----
In the first example you can choose a sequence b = {1, 2}, so the sum $\sum_{i = 1}^{k} a_{b_{i}}$ is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import bisect
n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
# n : number of integers
# m : mod
half_n = n // 2
a1, a2 = a[:half_n], a[half_n:]
n1, n2 = len(a1), len(a2)
r1, r2 = [], []
def dfs1(i, sum):
if i == n1:
r1.append(sum)
else:
dfs1(i+1, sum)
dfs1(i+1, (sum+a1[i])%m)
def dfs2(i, sum):
if i == n2:
r2.append(sum)
else:
dfs2(i+1, sum)
dfs2(i+1, (sum+a2[i])%m)
dfs1(0,0)
dfs2(0,0)
r1, r2 = [sorted(set(x)) for x in [r1, r2]]
ans = 0
for i, x in enumerate(r1):
p = bisect.bisect_left(r2, m-x)
tmp_ans = r2[p-1] + x
if tmp_ans > ans:
ans = tmp_ans
print(ans)
``` | vfc_12430 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/888/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n5 2 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 20\n199 41 299\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10\n47 100 49 2 56\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 671 | Solve the following coding problem using the programming language python:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.
-----Input-----
The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.
-----Output-----
Print the n-th digit of the line.
-----Examples-----
Input
3
Output
3
Input
11
Output
0
-----Note-----
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s=""
for i in range(10000):
s+=str(i)
print(s[int(input())])
``` | vfc_12438 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/672/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 672 | Solve the following coding problem using the programming language python:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as the remainder of division of i by j and denote it by $i \operatorname{mod} j$. A Modular Equation, as Hamed's teacher described, is an equation of the form $a \operatorname{mod} x = b$ in which a and b are two non-negative integers and x is a variable. We call a positive integer x for which $a \operatorname{mod} x = b$ a solution of our equation.
Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers a and b determines how many answers the Modular Equation $a \operatorname{mod} x = b$ has.
-----Input-----
In the only line of the input two space-separated integers a and b (0 ≤ a, b ≤ 10^9) are given.
-----Output-----
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation $a \operatorname{mod} x = b$.
-----Examples-----
Input
21 5
Output
2
Input
9435152 272
Output
282
Input
10 10
Output
infinity
-----Note-----
In the first sample the answers of the Modular Equation are 8 and 16 since $21 \operatorname{mod} 8 = 21 \operatorname{mod} 16 = 5$
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# fin = open("input.txt")
# a, b = map(int, fin.readline().split())
a, b = list(map(int, input().split()))
a2 = a - b
if a2 == 0:
print("infinity")
else:
Count = 0
i = 1
while i ** 2 <= a2:
Count += (a2 % i == 0 and i > b) + (a2 % i == 0 and a2 // i > b and i != a2 // i)
i += 1
print(Count)
``` | vfc_12442 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/495/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "21 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9435152 272\n",
"output": "282\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n",
"output": "infinity\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 673 | Solve the following coding problem using the programming language python:
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.
-----Input-----
The only line contains two integers n and k (1 ≤ n, k ≤ 10^9).
-----Output-----
Print the smallest integer x > n, so it is divisible by the number k.
-----Examples-----
Input
5 3
Output
6
Input
25 13
Output
26
Input
26 13
Output
39
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int, input().split()))
print(k * (n // k + 1))
``` | vfc_12446 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/678/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "25 13\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "26 13\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 8\n",
"output": "16\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 674 | Solve the following coding problem using the programming language python:
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Restore the non-empty good string with minimum length. If several such strings exist, restore lexicographically minimum string. If there are no good strings, print "NO" (without quotes).
A substring of a string is a contiguous subsequence of letters in the string. For example, "ab", "c", "abc" are substrings of string "abc", while "ac" is not a substring of that string.
The number of occurrences of a substring in a string is the number of starting positions in the string where the substring occurs. These occurrences could overlap.
String a is lexicographically smaller than string b, if a is a prefix of b, or a has a smaller letter at the first position where a and b differ.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 10^5) — the number of strings in the set.
Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 10^5.
-----Output-----
Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.
-----Examples-----
Input
4
mail
ai
lru
cf
Output
cfmailru
Input
3
kek
preceq
cheburek
Output
NO
-----Note-----
One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
wrong_str = False
strings = []
sets = []
for _ in range(n):
new_string = input()
new_string_set = set(new_string)
if len(new_string) != len(new_string_set):
wrong_str = True
break
strings.append(new_string)
sets.append(new_string_set)
if wrong_str:
print("NO")
return
connections = []
for _ in range(n):
connections.append((-1,-1))
changed = True
while changed:
changed = False
for i in range(len(strings)):
if strings[i] == None:
continue
for j in range(i + 1, len(strings)):
if strings[j] == None:
continue
if len(set(strings[i]).intersection(set(strings[j]))) == 0:
continue
a = strings[i]
b = strings[j]
#print(a, b)
if b in a:
strings[j] = None
changed = True
elif a in b:
strings[i] = b
strings[j] = None
changed = True
else:
is_ok = False
start_index = a.find(b[0])
if start_index != -1 and a[start_index:] in b:
strings[i] += strings[j][len(a) - start_index:]
strings[j] = None
is_ok = True
changed = True
if not is_ok:
start_index = b.find(a[0])
if start_index != -1 and b[start_index:] in a:
strings[i] = strings[j] + strings[i][len(b) - start_index:]
strings[j] = None
is_ok = True
changed = True
if not is_ok:
print("NO")
return
if wrong_str:
print("NO")
return
strings = [x for x in strings if x is not None]
whole_str = "".join(strings)
if len(whole_str) != len(set(whole_str)):
print("NO")
return
print("".join(sorted(strings)))
``` | vfc_12450 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/886/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nmail\nai\nlru\ncf\n",
"output": "cfmailru\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nkek\npreceq\ncheburek\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 675 | Solve the following coding problem using the programming language python:
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.
For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen w_{i} seconds after midnight, all w_{i}'s are distinct. Each visit lasts exactly one second.
What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
-----Input-----
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers w_{i} (1 ≤ i ≤ m, 1 ≤ w_{i} ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All w_{i}'s are distinct, they follow in the strictly increasing order.
-----Output-----
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1.
-----Examples-----
Input
1 8 3
10
Output
3
Input
2 10 1
5 8
Output
1
Input
1 1 3
10
Output
-1
-----Note-----
Anya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.
It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.
In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.
In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.
In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Contest 288 Div 2 Problem C
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
m,t,r = read()
w = read()
if t < r: return -1
covers = [0]*1000
ct = 0
for i in w:
x = covers[i]
for j in range(r-x):
for k in range(t):
covers[i-j+k] += 1
ct += 1
return ct
#################################################### HELPERS
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0: return inputs
if mode == 1: return inputs.split()
if mode == 2: return list(map(int, inputs.split()))
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
write(main())
``` | vfc_12454 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/508/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 8 3\n10\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 676 | Solve the following coding problem using the programming language python:
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x_1, x_2, x_3, x_4} (x_1 ≤ x_2 ≤ x_3 ≤ x_4) arithmetic mean is $\frac{x_{1} + x_{2} + x_{3} + x_{4}}{4}$, median is $\frac{x_{2} + x_{3}}{2}$ and range is x_4 - x_1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.
For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.
Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains a_{i} candies.
Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?
-----Input-----
The first line of input contains an only integer n (0 ≤ n ≤ 4).
The next n lines contain integers a_{i}, denoting the number of candies in the i-th box (1 ≤ a_{i} ≤ 500).
-----Output-----
In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution.
If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box.
All your numbers b must satisfy inequality 1 ≤ b ≤ 10^6. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them.
Given numbers a_{i} may follow in any order in the input, not necessary in non-decreasing.
a_{i} may have stood at any positions in the original set, not necessary on lowest n first positions.
-----Examples-----
Input
2
1
1
Output
YES
3
3
Input
3
1
1
1
Output
NO
Input
4
1
2
2
3
Output
YES
-----Note-----
For the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all 2.
For the second sample, it's impossible to find the missing number of candies.
In the third example no box has been lost and numbers satisfy the condition.
You may output b in any order.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
a = sorted(a)
#print(a)
if n == 0:
print('YES')
print(1)
print(1)
print(3)
print(3)
elif n == 1:
print('YES')
print(a[0])
print(3 * a[0])
print(3 * a[0])
elif n == 2:
if a[0] * 3 >= a[1]:
print('YES')
print(a[0] * 3)
print(a[0] * 4 - a[1])
elif a[1] % 3 == 0 and a[1] // 3 <= a[0]:
print('YES')
print(a[1] // 3)
print(a[1] + a[1] // 3 - a[0])
elif (a[0] + a[1]) % 4 == 0 and (a[0] + a[1]) // 4 <= a[0]:
print('YES')
print((a[0] + a[1]) // 4)
print(3 * ((a[0] + a[1]) // 4))
else:
print('NO')
elif n == 3:
if a[0] * 3 >= a[2] and 4 * a[0] == a[1] + a[2]:
print('YES')
print(a[0] * 3)
elif a[2] % 3 == 0 and a[2] // 3 <= a[0] and a[2] + a[2] // 3 == a[0] + a[1]:
print('YES')
print(a[2] // 3)
elif a[2] == a[0] * 3:
print('YES')
print(4 * a[0] - a[1])
else:
print('NO')
elif n == 4:
if a[3] == 3 * a[0] and a[0] + a[3] == a[1] + a[2]:
print('YES')
else:
print('NO')
``` | vfc_12458 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/488/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n1\n",
"output": "YES\n3\n3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 677 | Solve the following coding problem using the programming language python:
You are given $q$ queries in the following form:
Given three integers $l_i$, $r_i$ and $d_i$, find minimum positive integer $x_i$ such that it is divisible by $d_i$ and it does not belong to the segment $[l_i, r_i]$.
Can you answer all the queries?
Recall that a number $x$ belongs to segment $[l, r]$ if $l \le x \le r$.
-----Input-----
The first line contains one integer $q$ ($1 \le q \le 500$) — the number of queries.
Then $q$ lines follow, each containing a query given in the format $l_i$ $r_i$ $d_i$ ($1 \le l_i \le r_i \le 10^9$, $1 \le d_i \le 10^9$). $l_i$, $r_i$ and $d_i$ are integers.
-----Output-----
For each query print one integer: the answer to this query.
-----Example-----
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
q = int(input())
for _ in range(q):
l, r, d = list(map(int, input().split()))
if d < l:
print(d)
else:
v = d * (r // d)
while v <= r:
v += d
print(v)
``` | vfc_12462 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1101/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"output": "6\n4\n1\n3\n10\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 678 | Solve the following coding problem using the programming language python:
HAI
I HAS A TUX
GIMMEH TUX
I HAS A FOO ITS 0
I HAS A BAR ITS 0
I HAS A BAZ ITS 0
I HAS A QUZ ITS 1
TUX IS NOW A NUMBR
IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0
I HAS A PUR
GIMMEH PUR
PUR IS NOW A NUMBR
FOO R SUM OF FOO AN PUR
BAR R SUM OF BAR AN 1
BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ
O RLY?
YA RLY
BAZ R FOO
QUZ R BAR
OIC
IM OUTTA YR LOOP
BAZ IS NOW A NUMBAR
VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ
KTHXBYE
-----Input-----
The input contains between 1 and 10 lines, i-th line contains an integer number x_{i} (0 ≤ x_{i} ≤ 9).
-----Output-----
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10^{ - 4}.
-----Examples-----
Input
3
0
1
1
Output
0.666667
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
foo = baz = 0
quz = 1
for bar in range(1, int(input()) + 1):
foo += int(input())
if foo * quz < baz * bar: break
baz, quz = foo, bar
print(baz / quz)
``` | vfc_12466 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/290/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0\n1\n1\n",
"output": "0.666667\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 679 | Solve the following coding problem using the programming language python:
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.
"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 of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
-----Input-----
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-----
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).
-----Examples-----
Input
.BAC.
Output
Yes
Input
AA..CB
Output
No
-----Note-----
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.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
s = input()
n = len(s)
poss = False
for i in range(n - 2):
t = s[i:i + 3]
if 'A' in t and 'B' in t and 'C' in t:
poss = True
break
print('Yes' if poss else 'No')
main()
``` | vfc_12470 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/989/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": ".BAC.\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "AA..CB\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ".\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ACB.AAAAAA\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "B.BC.BBBCA\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "BA..CAB..B\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 680 | Solve the following coding problem using the programming language python:
The Squareland national forest is divided into equal $1 \times 1$ square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates $(x, y)$ of its south-west corner.
Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land $A, B, C$ in the forest. Initially, all plots in the forest (including the plots $A, B, C$) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots $A, B, C$ from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. [Image] For example, $A=(0,0)$, $B=(1,1)$, $C=(2,2)$. The minimal number of plots to be cleared is $5$. One of the ways to do it is shown with the gray color.
Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.
-----Input-----
The first line contains two integers $x_A$ and $y_A$ — coordinates of the plot $A$ ($0 \leq x_A, y_A \leq 1000$). The following two lines describe coordinates $(x_B, y_B)$ and $(x_C, y_C)$ of plots $B$ and $C$ respectively in the same format ($0 \leq x_B, y_B, x_C, y_C \leq 1000$). It is guaranteed that all three plots are distinct.
-----Output-----
On the first line print a single integer $k$ — the smallest number of plots needed to be cleaned from trees. The following $k$ lines should contain coordinates of all plots needed to be cleaned. All $k$ plots should be distinct. You can output the plots in any order.
If there are multiple solutions, print any of them.
-----Examples-----
Input
0 0
1 1
2 2
Output
5
0 0
1 0
1 1
1 2
2 2
Input
0 0
2 0
1 1
Output
4
0 0
1 0
1 1
2 0
-----Note-----
The first example is shown on the picture in the legend.
The second example is illustrated with the following image: [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ax, ay = list(map(int, input().split()))
bx, by = list(map(int, input().split()))
cx, cy = list(map(int, input().split()))
def f(cx, ax, bx, cy, ay, by):
mxy = max(ay, by, cy)
mny = min(ay, by, cy)
print(abs(cx - bx) + mxy - mny + 1)
for i in range(mny, mxy + 1):
print(ax, i)
if cx <= bx:
for i in range(cx, ax):
print(i, cy)
for i in range(ax + 1, bx + 1):
print(i, by)
else:
for i in range(bx, ax):
print(i, by)
for i in range(ax + 1, cx + 1):
print(i, cy)
if cx <= ax <= bx or bx <= ax <= cx:
f(cx, ax, bx, cy, ay, by)
elif cx <= bx <= ax or ax <= bx <= cx:
f(cx, bx, ax, cy, by, ay)
elif bx <= cx <= ax or ax <= cx <= bx:
f(bx, cx, ax, by, cy, ay)
``` | vfc_12474 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1085/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0\n1 1\n2 2\n",
"output": "5\n0 0\n1 0\n1 1\n1 2\n2 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n2 0\n1 1\n",
"output": "4\n0 0\n1 0\n1 1\n2 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n0 1\n0 2\n",
"output": "3\n0 0\n0 1\n0 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n5 0\n10 0\n",
"output": "11\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n1 2\n2 1\n",
"output": "5\n0 0\n1 0\n1 1\n1 2\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n5 0\n0 6\n",
"output": "12\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n1 0\n2 0\n3 0\n4 0\n5 0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 681 | Solve the following coding problem using the programming language python:
Reziba has many magic gems. Each magic gem can be split into $M$ normal gems. The amount of space each magic (and normal) gem takes is $1$ unit. A normal gem cannot be split.
Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is $N$ units. If a magic gem is chosen and split, it takes $M$ units of space (since it is split into $M$ gems); if a magic gem is not split, it takes $1$ unit.
How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is $N$ units? Print the answer modulo $1000000007$ ($10^9+7$). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.
-----Input-----
The input contains a single line consisting of $2$ integers $N$ and $M$ ($1 \le N \le 10^{18}$, $2 \le M \le 100$).
-----Output-----
Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is $N$ units. Print the answer modulo $1000000007$ ($10^9+7$).
-----Examples-----
Input
4 2
Output
5
Input
3 2
Output
3
-----Note-----
In the first example each magic gem can split into $2$ normal gems, and we know that the total amount of gems are $4$.
Let $1$ denote a magic gem, and $0$ denote a normal gem.
The total configurations you can have is: $1 1 1 1$ (None of the gems split); $0 0 1 1$ (First magic gem splits into $2$ normal gems); $1 0 0 1$ (Second magic gem splits into $2$ normal gems); $1 1 0 0$ (Third magic gem splits into $2$ normal gems); $0 0 0 0$ (First and second magic gems split into total $4$ normal gems).
Hence, answer is $5$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
MOD = 10**9+7
# Polymod
def polymod(P,Q):
assert(Q[-1]==1)
n = len(Q)
while len(P)>=n:
p = P[-1]
for i in range(n):
P[-i-1] -= p*Q[-i-1]
assert(P[-1]==0)
P.pop()
return P
def polyprod(P,Q):
n = len(P)
m = len(Q)
W = [0]*(n+m-1)
for i in range(n):
for j in range(m):
W[i+j]+=P[i]*Q[j]
return [w%MOD for w in W]
# Calc A^m * B
def power(A,B,m,mult):
if m == 0:
return B
while m>1:
if m%2==1:
B = mult(A,B)
A = mult(A,A)
m//=2
return mult(A,B)
def calc_nth_term(init,linear_coeff,n):
def mult(A,B):
return polymod(polyprod(A,B),linear_coeff)
ans = power([0,1],[1],n,mult)
return sum(ans[i]*init[i] for i in range(len(ans)))
n,m = [int(x) for x in input().split()]
linear_rec = [0]*(m+1)
linear_rec[0] = -1
linear_rec[m-1] = -1
linear_rec[m] = 1
print(calc_nth_term([1]*m,linear_rec,n)%MOD)
``` | vfc_12478 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1117/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000000000000 2\n",
"output": "680057396\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 682 | Solve the following coding problem using the programming language python:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: A rook moves any number of fields horizontally or vertically. A bishop moves any number of fields diagonally. A king moves one field in any direction — horizontally, vertically or diagonally. [Image] The pieces move like that
Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r_1, c_1) to field (r_2, c_2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.
-----Input-----
The input contains four integers r_1, c_1, r_2, c_2 (1 ≤ r_1, c_1, r_2, c_2 ≤ 8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.
-----Output-----
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r_1, c_1) to field (r_2, c_2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
-----Examples-----
Input
4 3 1 6
Output
2 1 3
Input
5 5 5 6
Output
1 0 1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
x1, y1, x2, y2 = map(int, input().split())
if (x1 == x2) and (y1 == y2):
print(0, 0, 0)
else:
# ladya
if (x1 == x2) or (y1 == y2):
l = 1
else:
l = 2
#slon
if (abs(x1 - x2) == abs(y1 - y2)):
s = 1
elif ((x1 + y1) % 2 == (x2 + y2) % 2):
s = 2
else:
s = 0
#korol
k = max(abs(x1 - x2), abs(y1 - y2))
print(l, s, k)
``` | vfc_12482 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/370/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 1 6\n",
"output": "2 1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 5 6\n",
"output": "1 0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 8 8\n",
"output": "2 1 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 8 1\n",
"output": "1 0 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 8\n",
"output": "1 0 7\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 683 | Solve the following coding problem using the programming language python:
-----Input-----
The input contains a single integer a (0 ≤ a ≤ 35).
-----Output-----
Output a single integer.
-----Examples-----
Input
3
Output
8
Input
10
Output
1024
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
a = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208, 16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968]
print(a[int(sys.stdin.readline())])
``` | vfc_12486 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/656/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "1024\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "35\n",
"output": "33940307968\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 684 | Solve the following coding problem using the programming language python:
Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.
These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she is solving the following problem.[Image]
You are given four positive integers $a$, $b$, $c$, $d$, such that $a \leq b \leq c \leq d$.
Your task is to find three integers $x$, $y$, $z$, satisfying the following conditions: $a \leq x \leq b$. $b \leq y \leq c$. $c \leq z \leq d$. There exists a triangle with a positive non-zero area and the lengths of its three sides are $x$, $y$, and $z$.
Ichihime desires to get the cookie, but the problem seems too hard for her. Can you help her?
-----Input-----
The first line contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
The next $t$ lines describe test cases. Each test case is given as four space-separated integers $a$, $b$, $c$, $d$ ($1 \leq a \leq b \leq c \leq d \leq 10^9$).
-----Output-----
For each test case, print three integers $x$, $y$, $z$ — the integers you found satisfying the conditions given in the statement.
It is guaranteed that the answer always exists. If there are multiple answers, print any.
-----Example-----
Input
4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810
Output
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810
-----Note-----
One of the possible solutions to the first test case:
[Image]
One of the possible solutions to the second test case:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t=int(input())
for j in range(t):
a,b,c,d=map(int, input().split())
print(b,c,c)
``` | vfc_12490 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1337/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 5 7\n1 5 5 7\n100000 200000 300000 400000\n1 1 977539810 977539810\n",
"output": "3 5 5\n5 5 5\n200000 300000 300000\n1 977539810 977539810\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 1 1 1\n",
"output": "1 1 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 685 | Solve the following coding problem using the programming language python:
A plane is flying at a constant height of $h$ meters above the ground surface. Let's consider that it is flying from the point $(-10^9, h)$ to the point $(10^9, h)$ parallel with $Ox$ axis.
A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only when the plane's coordinates are integers). After jumping from the plane, he will fly in the same direction as the plane, parallel to $Ox$ axis, covering a unit of distance every second. Naturally, he will also descend; thus his second coordinate will decrease by one unit every second.
There are ascending air flows on certain segments, each such segment is characterized by two numbers $x_1$ and $x_2$ ($x_1 < x_2$) representing its endpoints. No two segments share any common points. When the glider is inside one of such segments, he doesn't descend, so his second coordinate stays the same each second. The glider still flies along $Ox$ axis, covering one unit of distance every second. [Image] If the glider jumps out at $1$, he will stop at $10$. Otherwise, if he jumps out at $2$, he will stop at $12$.
Determine the maximum distance along $Ox$ axis from the point where the glider's flight starts to the point where his flight ends if the glider can choose any integer coordinate to jump from the plane and start his flight. After touching the ground the glider stops altogether, so he cannot glide through an ascending airflow segment if his second coordinate is $0$.
-----Input-----
The first line contains two integers $n$ and $h$ $(1 \le n \le 2\cdot10^{5}, 1 \le h \le 10^{9})$ — the number of ascending air flow segments and the altitude at which the plane is flying, respectively.
Each of the next $n$ lines contains two integers $x_{i1}$ and $x_{i2}$ $(1 \le x_{i1} < x_{i2} \le 10^{9})$ — the endpoints of the $i$-th ascending air flow segment. No two segments intersect, and they are given in ascending order.
-----Output-----
Print one integer — the maximum distance along $Ox$ axis that the glider can fly from the point where he jumps off the plane to the point where he lands if he can start his flight at any integer coordinate.
-----Examples-----
Input
3 4
2 5
7 9
10 11
Output
10
Input
5 10
5 7
11 12
16 20
25 26
30 33
Output
18
Input
1 1000000000
1 1000000000
Output
1999999999
-----Note-----
In the first example if the glider can jump out at $(2, 4)$, then the landing point is $(12, 0)$, so the distance is $12-2 = 10$.
In the second example the glider can fly from $(16,10)$ to $(34,0)$, and the distance is $34-16=18$.
In the third example the glider can fly from $(-100,1000000000)$ to $(1999999899,0)$, so the distance is $1999999899-(-100)=1999999999$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from bisect import bisect_left
n, h = map(int, input().split())
x1, x2 = map(int, input().split())
if n == 1:
print(h + x2 - x1)
else:
gap_sum = [0]
airflow_sum = [x2 - x1]
for _ in range(n - 1):
oldx1, oldx2 = x1, x2
x1, x2 = map(int, input().split())
gap_sum.append(gap_sum[-1] + x1 - oldx2)
airflow_sum.append(airflow_sum[-1] + x2 - oldx2)
#print(gap_sum)
#print(airflow_sum)
ans = h
for i in range(n):
cnt = bisect_left(gap_sum, h + gap_sum[i])
if i == 0:
res = airflow_sum[cnt-1] + h - gap_sum[cnt-1]
else:
res = airflow_sum[cnt-1] - (airflow_sum[i-1] + gap_sum[i] - gap_sum[i - 1]) + h - (gap_sum[cnt-1] - gap_sum[i])
if res > ans:
ans = res
print(ans)
``` | vfc_12494 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1041/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n2 5\n7 9\n10 11\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 10\n5 7\n11 12\n16 20\n25 26\n30 33\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000000000\n1 1000000000\n",
"output": "1999999999\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1000000000\n999999999 1000000000\n",
"output": "1000000001\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 687 | Solve the following coding problem using the programming language python:
Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation $a + 1 = b$ with positive integers $a$ and $b$, but Kolya forgot the numbers $a$ and $b$. He does, however, remember that the first (leftmost) digit of $a$ was $d_a$, and the first (leftmost) digit of $b$ was $d_b$.
Can you reconstruct any equation $a + 1 = b$ that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.
-----Input-----
The only line contains two space-separated digits $d_a$ and $d_b$ ($1 \leq d_a, d_b \leq 9$).
-----Output-----
If there is no equation $a + 1 = b$ with positive integers $a$ and $b$ such that the first digit of $a$ is $d_a$, and the first digit of $b$ is $d_b$, print a single number $-1$.
Otherwise, print any suitable $a$ and $b$ that both are positive and do not exceed $10^9$. It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding $10^9$.
-----Examples-----
Input
1 2
Output
199 200
Input
4 4
Output
412 413
Input
5 7
Output
-1
Input
6 2
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = map(int, input().split())
if a == 9 and b == 1:
print(9, 10)
elif a == b - 1:
print(a, b)
elif a == b:
print(a * 10, a * 10 + 1)
else:
print(-1)
``` | vfc_12502 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1225/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n",
"output": "1 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 688 | Solve the following coding problem using the programming language python:
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".
Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
-----Input-----
The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
-----Output-----
Print the required number of instances.
-----Examples-----
Input
42
23454
Output
2
Input
169
12118999
Output
1
-----Note-----
This problem contains very weak pretests.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t1 = map(int,input().strip())
t2 = map(int,input().strip())
ar1 = [0] * 10
ar2 = [0]*10
for j in t1:
ar1[j]+=1
for j in t2:
ar2[j]+=1
ar1[2]+=ar1[5]
ar1[6]+=ar1[9]
ar1[5]=ar1[9]=0
ar2[2]+=ar2[5]
ar2[6]+=ar2[9]
ar2[5]=ar2[9]=0
print(int(min(map(lambda x:ar2[x]/ar1[x] if ar1[x]!=0 else 100500 ,range(10)))))
``` | vfc_12506 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/328/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "42\n23454\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 689 | Solve the following coding problem using the programming language python:
You are given $n$ strings $s_1, s_2, \ldots, s_n$ consisting of lowercase Latin letters.
In one operation you can remove a character from a string $s_i$ and insert it to an arbitrary position in a string $s_j$ ($j$ may be equal to $i$). You may perform this operation any number of times. Is it possible to make all $n$ strings equal?
-----Input-----
The first line contains $t$ ($1 \le t \le 10$): the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 1000$): the number of strings.
$n$ lines follow, the $i$-th line contains $s_i$ ($1 \le \lvert s_i \rvert \le 1000$).
The sum of lengths of all strings in all test cases does not exceed $1000$.
-----Output-----
If it is possible to make the strings equal, print "YES" (without quotes).
Otherwise, print "NO" (without quotes).
You can output each character in either lowercase or uppercase.
-----Example-----
Input
4
2
caa
cbb
3
cba
cba
cbb
4
ccab
cbac
bca
acbcc
4
acb
caf
c
cbafc
Output
YES
NO
YES
NO
-----Note-----
In the first test case, you can do the following: Remove the third character of the first string and insert it after the second character of the second string, making the two strings "ca" and "cbab" respectively. Remove the second character of the second string and insert it after the second character of the first string, making both strings equal to "cab".
In the second test case, it is impossible to make all $n$ strings equal.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
n = val()
cnt = Counter()
for j in range(n):
cnt += Counter(st())
ans = 1
for i in cnt:
if cnt[i] % n:
ans = 0
print('YES' if ans else 'NO')
``` | vfc_12510 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1397/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2\ncaa\ncbb\n3\ncba\ncba\ncbb\n4\nccab\ncbac\nbca\nacbcc\n4\nacb\ncaf\nc\ncbafc\n",
"output": "YES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 690 | Solve the following coding problem using the programming language python:
You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. [Image]
Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: Set the value of a digit equal to 0. If the go-dama is shifted to the right, add 5. Add the number of ichi-damas shifted to the left.
Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720.
Write the program that prints the way Soroban shows the given number n.
-----Input-----
The first line contains a single integer n (0 ≤ n < 10^9).
-----Output-----
Print the description of the decimal digits of number n from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number n without leading zeroes. We can assume that number 0 has no leading zeroes.
-----Examples-----
Input
2
Output
O-|OO-OO
Input
13
Output
O-|OOO-O
O-|O-OOO
Input
720
Output
O-|-OOOO
O-|OO-OO
-O|OO-OO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
N = input()
for digit in N[::-1]:
Os = int(digit)%5
if int(digit) >= 5:
print("-O|"+Os*"O"+"-"+(4-Os)*"O")
else:
print("O-|"+Os*"O"+"-"+(4-Os)*"O")
``` | vfc_12514 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/363/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n",
"output": "O-|OO-OO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n",
"output": "O-|OOO-O\nO-|O-OOO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "720\n",
"output": "O-|-OOOO\nO-|OO-OO\n-O|OO-OO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0\n",
"output": "O-|-OOOO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "O-|O-OOO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "O-|OOO-O\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 691 | Solve the following coding problem using the programming language python:
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 10^6.
-----Input-----
The only line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the set and the desired bitwise-xor, respectively.
-----Output-----
If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
-----Examples-----
Input
5 5
Output
YES
1 2 4 5 7
Input
3 6
Output
YES
1 2 5
-----Note-----
You can read more about the bitwise-xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR
For the first sample $1 \oplus 2 \oplus 4 \oplus 5 \oplus 7 = 5$.
For the second sample $1 \oplus 2 \oplus 5 = 6$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, x = input().split()
n, x = int(n), int(x)
m1 = 2 ** 17
m2 = 2 ** 18
if n == 2 and x == 0:
print("NO")
elif n == 1:
a = [x]
elif n == 2 and x > 0:
a = [0, x]
else:
a = []
ans = 0
for i in range(1, n-2):
ans ^= i
a.append(i)
if ans == x:
a.append(m1)
a.append(m2)
a.append(m1+m2)
else:
a.append(m1)
a.append(m1 ^ x ^ ans)
a.append(0)
if not (n == 2 and x == 0):
print("YES")
print(" ".join([str(e) for e in a]))
``` | vfc_12518 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/862/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n",
"output": "YES\n1 2 131072 131078 0 \n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 692 | Solve the following coding problem using the programming language python:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
-----Input-----
The first line of input contains a single integer N (1 ≤ N ≤ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
-----Output-----
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10^{ - 4}.
-----Examples-----
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ct = 0
x = int(input())
y = list(map(int, input().split(' ')))
z = list(map(int, input().split(' ')))
for i in range(1, 720721):
for j in range(x):
if i%y[j] == z[j]:
ct+=1
break
print(ct/720720)
``` | vfc_12522 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/656/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n0\n",
"output": "0.500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n1 0\n",
"output": "0.666667\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 4 4\n0 1 3\n",
"output": "1.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n16\n15\n",
"output": "0.062500\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
"output": "1.000000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 693 | Solve the following coding problem using the programming language python:
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k_1 knights with lightsabers of the first color, k_2 knights with lightsabers of the second color, ..., k_{m} knights with lightsabers of the m-th color.
However, since the last time, she has learned that it is not always possible to select such an interval. Therefore, she decided to ask some Jedi Knights to go on an indefinite unpaid vacation leave near certain pits on Tatooine, if you know what I mean. Help Heidi decide what is the minimum number of Jedi Knights that need to be let go before she is able to select the desired interval from the subsequence of remaining knights.
-----Input-----
The first line of the input contains n (1 ≤ n ≤ 2·10^5) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k_1, k_2, ..., k_{m} (with $1 \leq \sum_{i = 1}^{m} k_{i} \leq n$) – the desired counts of Jedi Knights with lightsabers of each color from 1 to m.
-----Output-----
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1.
-----Example-----
Input
8 3
3 3 1 2 2 1 1 3
3 1 1
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict
n, m = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))
summs = sum(ms)
target = {
i: m
for i, m in enumerate(ms, 1)
}
remain = set(i for i, m in list(target.items()) if m != 0)
count = defaultdict(int)
a = 0
b = 0
while remain and b < n:
count[ns[b]] += 1
if ns[b] in remain and target[ns[b]] <= count[ns[b]]:
remain.remove(ns[b])
b += 1
if remain:
print(-1)
else:
ans = b - summs
while b <= n:
if remain:
if b >= n:
break
count[ns[b]] += 1
if ns[b] in remain and target[ns[b]] <= count[ns[b]]:
remain.remove(ns[b])
b += 1
else:
count[ns[a]] -= 1
if target[ns[a]] > count[ns[a]]:
remain.add(ns[a])
else:
ans = min(ans, b - a - 1 - summs)
a += 1
print(ans)
``` | vfc_12526 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/958/F2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n1 2 4 2 4 3\n0 0 1 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 1\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 694 | Solve the following coding problem using the programming language python:
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
-----Input-----
The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 10^6 digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 10^8).
-----Output-----
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
-----Examples-----
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
s, x, pfx = input(), 0, []
a, b = list(map(int, input().split()))
try:
for i, c in enumerate(s, 1):
x = (x * 10 + ord(c) - 48) % a
if not x and s[i] != '0':
pfx.append(i)
except IndexError:
pass
x, p, i = 0, 1, len(s)
for stop in reversed(pfx):
for i in range(i - 1, stop - 1, -1):
x = (x + (ord(s[i]) - 48) * p) % b
p = p * 10 % b
if not x:
print("YES")
print(s[:i])
print(s[i:])
return
print("NO")
def __starting_point():
main()
__starting_point()
``` | vfc_12530 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/490/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "116401024\n97 1024\n",
"output": "YES\n11640\n1024\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "284254589153928171911281811000\n1009 1000\n",
"output": "YES\n2842545891539\n28171911281811000\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 695 | Solve the following coding problem using the programming language python:
[Image]
-----Input-----
The input contains two integers a_1, a_2 (0 ≤ a_{i} ≤ 32), separated by a single space.
-----Output-----
Output a single integer.
-----Examples-----
Input
1 1
Output
0
Input
3 7
Output
0
Input
13 10
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
import re
from fractions import Fraction
class Task:
table = ['111111101010101111100101001111111\n', '100000100000000001010110001000001\n', '101110100110110000011010001011101\n', '101110101011001001111101001011101\n', '101110101100011000111100101011101\n', '100000101010101011010000101000001\n', '111111101010101010101010101111111\n', '000000001111101111100111100000000\n', '100010111100100001011110111111001\n', '110111001111111100100001000101100\n', '011100111010000101000111010001010\n', '011110000110001111110101100000011\n', '111111111111111000111001001011000\n', '111000010111010011010011010100100\n', '101010100010110010110101010000010\n', '101100000101010001111101000000000\n', '000010100011001101000111101011010\n', '101001001111101111000101010001110\n', '101101111111000100100001110001000\n', '000010011000100110000011010000010\n', '001101101001101110010010011011000\n', '011101011010001000111101010100110\n', '111010100110011101001101000001110\n', '110001010010101111000101111111000\n', '001000111011100001010110111110000\n', '000000001110010110100010100010110\n', '111111101000101111000110101011010\n', '100000100111010101111100100011011\n', '101110101001010000101000111111000\n', '101110100011010010010111111011010\n', '101110100100011011110110101110000\n', '100000100110011001111100111100000\n', '111111101101000101001101110010001\n']
x, y = 0, 0
answer = 0
def __init__(self):
self.x, self.y = [int(_) for _ in input().split()]
#inFile = open('input.txt', 'r')
#self.table = inFile.readlines()
def solve(self):
table, x, y = self.table, self.x, self.y
self.answer = table[x][y]
def printAnswer(self):
print(self.answer)
task = Task()
task.solve()
task.printAnswer()
``` | vfc_12534 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/290/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "14 14\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 696 | Solve the following coding problem using the programming language python:
The cows have just learned what a primitive root is! Given a prime p, a primitive root $\operatorname{mod} p$ is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p} - 2 - 1 are divisible by p, but x^{p} - 1 - 1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots $\operatorname{mod} p$.
-----Input-----
The input contains a single line containing an integer p (2 ≤ p < 2000). It is guaranteed that p is a prime.
-----Output-----
Output on a single line the number of primitive roots $\operatorname{mod} p$.
-----Examples-----
Input
3
Output
1
Input
5
Output
2
-----Note-----
The only primitive root $\operatorname{mod} 3$ is 2.
The primitive roots $\operatorname{mod} 5$ are 2 and 3.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x=int(input())
if(x==2):
print(1)
else:
x-=1
cnt=0
for i in range(1,x):
ok=0
for j in range(2,i+1):
if(x%j==0 and i%j==0): ok=1
if(ok==0) :cnt+=1
print(cnt)
``` | vfc_12538 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/284/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 697 | Solve the following coding problem using the programming language python:
Natasha's favourite numbers are $n$ and $1$, and Sasha's favourite numbers are $m$ and $-1$. One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements are equal to $-1$. For each such array they counted its maximal prefix sum, probably an empty one which is equal to $0$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $f(a)$ the maximal prefix sum of an array $a_{1, \ldots ,l}$ of length $l \geq 0$. Then:
$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )$$
Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo $998\: 244\: 853$.
-----Input-----
The only line contains two integers $n$ and $m$ ($0 \le n,m \le 2\,000$).
-----Output-----
Output the answer to the problem modulo $998\: 244\: 853$.
-----Examples-----
Input
0 2
Output
0
Input
2 0
Output
2
Input
2 2
Output
5
Input
2000 2000
Output
674532367
-----Note-----
In the first example the only possible array is [-1,-1], its maximal prefix sum is equal to $0$.
In the second example the only possible array is [1,1], its maximal prefix sum is equal to $2$.
There are $6$ possible arrays in the third example:
[1,1,-1,-1], f([1,1,-1,-1]) = 2
[1,-1,1,-1], f([1,-1,1,-1]) = 1
[1,-1,-1,1], f([1,-1,-1,1]) = 1
[-1,1,1,-1], f([-1,1,1,-1]) = 1
[-1,1,-1,1], f([-1,1,-1,1]) = 0
[-1,-1,1,1], f([-1,-1,1,1]) = 0
So the answer for the third example is $2+1+1+1+0+0 = 5$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = list(map(int, input().split()))
mod = 998244853
fact = [1]
invfact = [1]
def pw(x, y):
ans = 1
while (y):
if (y & 1):
ans = (ans * x) % mod
x = x * x % mod
y >>= 1
return ans
def inv(x):
return pw(x, mod - 2)
for i in range(1, n + m + 1):
fact.append(fact[i - 1] * i % mod)
invfact.append(invfact[i - 1] * inv(i) % mod)
mn = max(0, n - m)
def ways_to(sub):
inc = (n + m + sub) // 2
return fact[n + m] * invfact[inc] * invfact[n + m - inc] % mod
ans = 0
ways = [0 for x in range(0, n + 2)]
for i in range (mn, n + 1):
ways[i] = ways_to(n - m) - ways_to(2 * i - n + m)
ways[n + 1] = ways_to(n - m)
for i in range(1, n + 1):
ans += i * (ways[i + 1] - ways[i])
ans %= mod
if (ans < 0) :
ans += mod
print(ans)
``` | vfc_12542 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1204/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2000 2000\n",
"output": "674532367\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 698 | Solve the following coding problem using the programming language python:
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.
Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.
-----Input-----
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num_2 num_1" (where num_2 is the identifier of this Div2 round, num_1 is the identifier of the Div1 round). It is guaranteed that num_1 - num_2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.
-----Output-----
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
-----Examples-----
Input
3 2
2 1
2 2
Output
0 0
Input
9 3
1 2 3
2 8
1 4 5
Output
2 3
Input
10 0
Output
5 9
-----Note-----
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
X,n=list(map(int,input().split()))
Taken=[True]*(X+1)
for i in range(n):
x=list(map(int,input().split()))
if(x[0]==1):
Taken[x[1]]=False
Taken[x[2]]=False
else:
Taken[x[1]]=False
cnt=0
minn=0
maxx=0
ans=0
for i in range(1,X):
if(Taken[i]):
cnt+=1
maxx+=1
else:
ans+=cnt//2
if(cnt%2!=0):
ans+=1
cnt=0
ans+=cnt//2
if(cnt%2!=0):
ans+=1
print(ans,maxx)
``` | vfc_12546 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/401/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 1\n2 2\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 3\n1 2 3\n2 8\n1 4 5\n",
"output": "2 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 0\n",
"output": "5 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n1 1 2\n1 8 9\n",
"output": "3 5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 3\n1 4 5\n1 1 2\n1 6 7\n",
"output": "2 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n2 3\n1 5 6\n",
"output": "2 3",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 699 | Solve the following coding problem using the programming language python:
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater than n, and, secondly, was divisible by k.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
-----Input-----
The first line of input contains three integers y, k, n (1 ≤ y, k, n ≤ 10^9; $\frac{n}{k}$ ≤ 10^5).
-----Output-----
Print the list of whitespace-separated integers — all possible values of x in ascending order. You should print each possible value of x exactly once.
If there are no such values of x print a single integer -1.
-----Examples-----
Input
10 1 10
Output
-1
Input
10 6 40
Output
2 8 14 20 26
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
f = sys.stdin
# f = open("input.txt", "r")
y, k, n = map(int, f.readline().strip().split())
if y >= n:
first = -1
else:
t = k
while t <= y:
t += k
first = t-y
if first == -1:
print(-1)
else:
if first+y > n:
print(-1)
else:
res = []
for i in range(first, n+1-y, k):
res.append(i)
print(*res)
``` | vfc_12550 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/239/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 1 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 6 40\n",
"output": "2 8 14 20 26 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1 20\n",
"output": "1 2 3 4 5 6 7 8 9 10 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "84817 1 33457\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 700 | Solve the following coding problem using the programming language python:
The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.
Two rebel spies have provided her with the maps of the solar system. Each map is an N × N grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.
Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.
-----Input-----
The first line of the input contains one number N (1 ≤ N ≤ 10) – the dimension of each map. Next N lines each contain N characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next N lines each contain N characters, depicting the second map in the same format.
-----Output-----
The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.
-----Examples-----
Input
4
XOOO
XXOO
OOOO
XXXX
XOOO
XOOO
XOXO
XOXX
Output
Yes
Input
2
XX
OO
XO
OX
Output
No
-----Note-----
In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
import copy
def rotate90(n, f):
return [[f[n - j - 1][i] for j in range(n)] for i in range(n)]
def fliphor(n, f):
return [[f[i][n - j - 1] for j in range(n)] for i in range(n)]
def flipver(n, f):
return [[f[n - i - 1][j] for j in range(n)] for i in range(n)]
def eq(n, f, g):
for i in range(n):
for j in range(n):
if f[i][j] != g[i][j]:
return False
return True
n = int(input())
f = [list(input()) for i in range(n)]
g = [list(input()) for i in range(n)]
for doflipv in range(2):
for dofliph in range(2):
for nrot in range(4):
h = copy.deepcopy(f)
if dofliph == 1:
h = fliphor(n, h)
if doflipv == 1:
h = flipver(n, h)
for i in range(nrot):
h = rotate90(n, h)
if eq(n, h, g):
print("Yes")
return
print("No")
``` | vfc_12554 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/958/A1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 701 | Solve the following coding problem using the programming language python:
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
-----Input-----
The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
-----Output-----
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
-----Examples-----
Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
Output
need tree
-----Note-----
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s, t = input(), input()
sx, tx = str(sorted(s)), str(sorted(t))
def subset(s, t):
i = 0
for c in s:
if c == t[i]: i += 1
if i == len(t): break
return i == len(t)
if sx == tx:
print("array")
elif subset(s, t):
print("automaton")
elif subset(sx, tx):
print("both")
else:
print("need tree")
``` | vfc_12558 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/448/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "automaton\ntomat\n",
"output": "automaton\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "array\narary\n",
"output": "array\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "both\nhot\n",
"output": "both\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 702 | Solve the following coding problem using the programming language python:
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile: [Image] By the pieces lay a large square wooden board. The board is divided into $n^2$ cells arranged into $n$ rows and $n$ columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free.
Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it's possible to fully tile the board?
-----Input-----
The first line of the input contains a single integer $n$ ($3 \leq n \leq 50$) — the size of the board.
The following $n$ lines describe the board. The $i$-th line ($1 \leq i \leq n$) contains a single string of length $n$. Its $j$-th character ($1 \leq j \leq n$) is equal to "." if the cell in the $i$-th row and the $j$-th column is free; it is equal to "#" if it's occupied.
You can assume that the board contains at least one free cell.
-----Output-----
Output YES if the board can be tiled by Alice's pieces, or NO otherwise. You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
#.#
...
#.#
Output
YES
Input
4
##.#
#...
####
##.#
Output
NO
Input
5
#.###
....#
#....
###.#
#####
Output
YES
Input
5
#.###
....#
#....
....#
#..##
Output
NO
-----Note-----
The following sketches show the example boards and their tilings if such tilings exist: [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
board =[]
for i in range(n):
board.append(list(input()))
f = 1
for i in range(n):
for j in range(n):
if board[i][j] == '.':
if i < n - 2 and j < n - 1 and j > 0 and board[i+1][j] == '.' and board[i+2][j] == '.' and board[i+1][j-1] == '.' and board[i+1][j+1] == '.':
board[i+1][j] = '#'
board[i+2][j] = '#'
board[i+1][j-1] = '#'
board[i+1][j+1] = '#'
else:
f = 0
break
if f == 1:
print("YES")
else:
print("NO")
``` | vfc_12562 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1150/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n#.#\n...\n#.#\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n##.#\n#...\n####\n##.#\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n#.###\n....#\n#....\n###.#\n#####\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n#.###\n....#\n#....\n....#\n#..##\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n#.##.#\n......\n#.##.#\n......\n##.###\n#...##\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 703 | Solve the following coding problem using the programming language python:
You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
-----Input-----
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
3 10 3 3
Output
2
Input
3 10 1 3
Output
3
Input
100 100 1 1000
Output
1
-----Note-----
In the first sample you can act like this: Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts. Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k, a, b, v = map(int, input().split())
for i in range(1, 1010):
if a <= v * (i + min(b, (k - 1) * i)):
print(i)
break
``` | vfc_12566 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/402/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 10 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 100 1 1000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 704 | Solve the following coding problem using the programming language python:
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, but none — in writing a composition.
As Vasya was fishing for a sentence in the dark pond of his imagination, he suddenly wondered: what is the least number of times he should push a key to shift the cursor from one position to another one?
Let's describe his question more formally: to type a text, Vasya is using the text editor. He has already written n lines, the i-th line contains a_{i} characters (including spaces). If some line contains k characters, then this line overall contains (k + 1) positions where the cursor can stand: before some character or after all characters (at the end of the line). Thus, the cursor's position is determined by a pair of integers (r, c), where r is the number of the line and c is the cursor's position in the line (the positions are indexed starting from one from the beginning of the line).
Vasya doesn't use the mouse to move the cursor. He uses keys "Up", "Down", "Right" and "Left". When he pushes each of these keys, the cursor shifts in the needed direction. Let's assume that before the corresponding key is pressed, the cursor was located in the position (r, c), then Vasya pushed key: "Up": if the cursor was located in the first line (r = 1), then it does not move. Otherwise, it moves to the previous line (with number r - 1), to the same position. At that, if the previous line was short, that is, the cursor couldn't occupy position c there, the cursor moves to the last position of the line with number r - 1; "Down": if the cursor was located in the last line (r = n), then it does not move. Otherwise, it moves to the next line (with number r + 1), to the same position. At that, if the next line was short, that is, the cursor couldn't occupy position c there, the cursor moves to the last position of the line with number r + 1; "Right": if the cursor can move to the right in this line (c < a_{r} + 1), then it moves to the right (to position c + 1). Otherwise, it is located at the end of the line and doesn't move anywhere when Vasya presses the "Right" key; "Left": if the cursor can move to the left in this line (c > 1), then it moves to the left (to position c - 1). Otherwise, it is located at the beginning of the line and doesn't move anywhere when Vasya presses the "Left" key.
You've got the number of lines in the text file and the number of characters, written in each line of this file. Find the least number of times Vasya should push the keys, described above, to shift the cursor from position (r_1, c_1) to position (r_2, c_2).
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 100) — the number of lines in the file. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^5), separated by single spaces. The third line contains four integers r_1, c_1, r_2, c_2 (1 ≤ r_1, r_2 ≤ n, 1 ≤ c_1 ≤ a_{r}_1 + 1, 1 ≤ c_2 ≤ a_{r}_2 + 1).
-----Output-----
Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (r_1, c_1) to position (r_2, c_2).
-----Examples-----
Input
4
2 1 6 4
3 4 4 2
Output
3
Input
4
10 5 6 4
1 11 4 2
Output
6
Input
3
10 1 10
1 10 1 1
Output
3
-----Note-----
In the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter s represents the cursor's initial position, letter t represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.
123
12
123s567
1t345
One of the possible answers in the given sample is: "Left", "Down", "Left".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
sys.stdin = open('input.txt')
sys.stdout = open('output.txt','w')
n = int(input())
a = list(map(int, input().split()))
r1, c1, r2, c2 = (i - 1 for i in map(int, input().split()))
x, y = (r1, r2) if r1 < r2 else (r2, r1)
if r1 < r2: c1 = min(c1, min(a[i] for i in range(r1 + 1, r2 + 1)))
elif r2 < r1: c1 = min(c1, min(a[i] for i in range(r2, r1)))
d = abs(c1 - c2)
c = c1
for i in range(x - 1, -1, -1):
if c > a[i]:
c = a[i]
q = abs(c2 - c) + 2 * abs(x - i)
if q < d: d = q
c = c1
for i in range(y + 1, n):
if c > a[i]:
c = a[i]
q = abs(c2 - c) + 2 * abs(i - y)
if q < d: d = q
print(d + abs(r2 - r1))
``` | vfc_12570 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/253/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 1 6 4\n3 4 4 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 5 6 4\n1 11 4 2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 705 | Solve the following coding problem using the programming language python:
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x_1, x_2, ..., x_{n} and y_1, y_2, ..., y_{n} respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.
Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value x_{i} xor y_{j} equals to one of the 2n integers. Here xor means the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.
Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
-----Input-----
The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.
The second line contains n space-separated integers x_1, x_2, ..., x_{n} (1 ≤ x_{i} ≤ 2·10^6) — the integers finally chosen by Koyomi.
The third line contains n space-separated integers y_1, y_2, ..., y_{n} (1 ≤ y_{i} ≤ 2·10^6) — the integers finally chosen by Karen.
Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: x_{i} = y_{j}; i ≠ j and x_{i} = x_{j}; i ≠ j and y_{i} = y_{j}.
-----Output-----
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
-----Examples-----
Input
3
1 2 3
4 5 6
Output
Karen
Input
5
2 4 6 8 10
9 7 5 3 1
Output
Karen
-----Note-----
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
print('Karen')
``` | vfc_12574 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/869/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n4 5 6\n",
"output": "Karen\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4 6 8 10\n9 7 5 3 1\n",
"output": "Karen\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n2000000\n",
"output": "Karen\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 706 | Solve the following coding problem using the programming language python:
Consider a linear function f(x) = Ax + B. Let's define g^{(0)}(x) = x and g^{(}n)(x) = f(g^{(}n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g^{(}n)(x) modulo 10^9 + 7.
-----Input-----
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 10^9, 1 ≤ n ≤ 10^18) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Output-----
Print the only integer s — the value g^{(}n)(x) modulo 10^9 + 7.
-----Examples-----
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b, n, x = list(map(int, input().split(' ')))
fir = pow(a, n, 10**9+7)*x%(10**9+7)
sec = b*(pow(a, n, 10**9+7)-1)*(pow(a-1, 10**9+5, 10**9+7))%(10**9+7)
if (a == 1):
sec = n * b
print((fir+sec)%(10**9+7))
``` | vfc_12578 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/678/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 1 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 2 1\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 3 1\n",
"output": "79\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 707 | Solve the following coding problem using the programming language python:
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the $i$-th of them will start during the $x_i$-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes $x_1, x_2, \dots, x_n$, so he will be awake during each of these minutes (note that it does not matter if his alarm clock will ring during any other minute).
Ivan can choose two properties for the alarm clock — the first minute it will ring (let's denote it as $y$) and the interval between two consecutive signals (let's denote it by $p$). After the clock is set, it will ring during minutes $y, y + p, y + 2p, y + 3p$ and so on.
Ivan can choose any minute as the first one, but he cannot choose any arbitrary value of $p$. He has to pick it among the given values $p_1, p_2, \dots, p_m$ (his phone does not support any other options for this setting).
So Ivan has to choose the first minute $y$ when the alarm clock should start ringing and the interval between two consecutive signals $p_j$ in such a way that it will ring during all given minutes $x_1, x_2, \dots, x_n$ (and it does not matter if his alarm clock will ring in any other minutes).
Your task is to tell the first minute $y$ and the index $j$ such that if Ivan sets his alarm clock with properties $y$ and $p_j$ it will ring during all given minutes $x_1, x_2, \dots, x_n$ or say that it is impossible to choose such values of the given properties. If there are multiple answers, you can print any.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 3 \cdot 10^5, 1 \le m \le 3 \cdot 10^5$) — the number of events and the number of possible settings for the interval between signals.
The second line of the input contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^{18}$), where $x_i$ is the minute when $i$-th event starts. It is guaranteed that all $x_i$ are given in increasing order (i. e. the condition $x_1 < x_2 < \dots < x_n$ holds).
The third line of the input contains $m$ integers $p_1, p_2, \dots, p_m$ ($1 \le p_j \le 10^{18}$), where $p_j$ is the $j$-th option for the interval between two consecutive signals.
-----Output-----
If it's impossible to choose such values $y$ and $j$ so all constraints are satisfied, print "NO" in the first line.
Otherwise print "YES" in the first line. Then print two integers $y$ ($1 \le y \le 10^{18}$) and $j$ ($1 \le j \le m$) in the second line, where $y$ is the first minute Ivan's alarm clock should start ringing and $j$ is the index of the option for the interval between two consecutive signals (options are numbered from $1$ to $m$ in the order they are given input). These values should be chosen in such a way that the alarm clock will ring during all given minutes $x_1, x_2, \dots, x_n$. If there are multiple answers, you can print any.
-----Examples-----
Input
3 5
3 12 18
2 6 5 3 3
Output
YES
3 4
Input
4 2
1 5 17 19
4 5
Output
NO
Input
4 2
1 5 17 19
2 1
Output
YES
1 1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input=sys.stdin.readline
def gcd(x,y):
if y==0:
return x
if x<y:
x,y=y,x
return gcd(y,x%y)
n,m=map(int,input().split())
X=list(map(int,input().split()))
P=list(map(int,input().split()))
d=X[1]-X[0]
for i in range(2,n):
d=gcd(d,X[i]-X[i-1])
for i,p in enumerate(P):
if d%p==0:
print('YES')
print(X[0],i+1)
break
else:
print('NO')
``` | vfc_12582 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1155/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n3 12 18\n2 6 5 3 3\n",
"output": "YES\n3 4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 708 | Solve the following coding problem using the programming language python:
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally: There is no road between a and b. There exists a sequence (path) of n distinct cities v_1, v_2, ..., v_{n} that v_1 = a, v_{n} = b and there is a road between v_{i} and v_{i} + 1 for $i \in \{1,2, \ldots, n - 1 \}$.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u_1, u_2, ..., u_{n} that u_1 = c, u_{n} = d and there is a road between u_{i} and u_{i} + 1 for $i \in \{1,2, \ldots, n - 1 \}$.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v_1, ..., v_{n}) and (u_1, ..., u_{n}) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
-----Input-----
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
-----Output-----
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v_1, v_2, ..., v_{n} where v_1 = a and v_{n} = b. The second line should contain n distinct integers u_1, u_2, ..., u_{n} where u_1 = c and u_{n} = d.
Two paths generate at most 2n - 2 roads: (v_1, v_2), (v_2, v_3), ..., (v_{n} - 1, v_{n}), (u_1, u_2), (u_2, u_3), ..., (u_{n} - 1, u_{n}). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
-----Examples-----
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
-----Note-----
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
(n, k) = (int(x) for x in input().split())
(a, b, c, d) = (int(x) for x in input().split())
(path1, path2) = solver(n, k, a, b, c, d)
if path1 == None:
print(-1)
else:
for x in path1:
print(x, end = ' ')
print()
for x in path2:
print(x, end = ' ')
def solver(n, k, a, b, c, d):
if k <= n or n == 4:
return (None, None)
else:
path1 = [a, c] + \
[i for i in range(1, n + 1) if i not in (a, b, c, d)] + \
[d, b]
path2 = [c, a] + \
[i for i in range(1, n + 1) if i not in (a, b, c, d)] + \
[b, d]
return (path1, path2)
main()
#print(solver(7, 11, 2, 4, 7, 3))
# def reorder(path, n, a, b, c, d):
# for i in range(len(path)):
# if path[i] == a:
# path[i] = 1
# elif path[i] == b:
# path[i] = n
# elif path[i] == c:
# path[i] = 2
# elif path[i] == d:
# path[i] = 3
# elif path[i] == 1:
# path[i] = a
# elif path[i] == n:
# path[i] = b
# elif path[i] == 2:
# path[i] = c
# elif path[i] == 3:
# path[i] = d
``` | vfc_12586 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/643/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 11\n2 4 7 3\n",
"output": "2 7 1 3 6 5 4\n7 1 5 4 6 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 999\n10 20 30 40\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 2 3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6\n5 2 4 1\n",
"output": "5 4 3 1 2\n4 5 3 2 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 709 | Solve the following coding problem using the programming language python:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
-----Input-----
The only line containing one integer x (1 ≤ x ≤ 10^9).
-----Output-----
The only line containing one integer: the answer.
-----Examples-----
Input
5
Output
2
Input
8
Output
1
-----Note-----
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
ans = 1
while n != 1:
if n % 2 == 1:
ans += 1
n -= 1
else:
n //= 2
print(ans)
``` | vfc_12590 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/579/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "536870911\n",
"output": "29\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 710 | Solve the following coding problem using the programming language python:
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".
Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string $s$ consisting of uppercase letters and length of at least $4$, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string $s$ with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the next — "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".
Help Maxim solve the problem that the teacher gave him.
A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
-----Input-----
The first line contains a single integer $n$ ($4 \leq n \leq 50$) — the length of the string $s$.
The second line contains the string $s$, consisting of exactly $n$ uppercase letters of the Latin alphabet.
-----Output-----
Output the minimum number of operations that need to be applied to the string $s$ so that the genome appears as a substring in it.
-----Examples-----
Input
4
ZCTH
Output
2
Input
5
ZDATG
Output
5
Input
6
AFBAKC
Output
16
-----Note-----
In the first example, you should replace the letter "Z" with "A" for one operation, the letter "H" — with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.
In the second example, we replace the letter "A" with "C" for two operations, the letter "D" — with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
g = "ACTG"
def dist(a, b):
p = abs(ord(a) - ord(b))
return min(p, 26 - p)
def price(s):
return sum(dist(x, y) for x, y in zip(g, s))
n = int(input())
s = input()
ans = 100000
for i in range(len(s) - 3):
ans = min(ans, price(s[i:i+4]))
print(ans)
``` | vfc_12594 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1151/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nZCTH\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nZDATG\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nAFBAKC\n",
"output": "16",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 712 | Solve the following coding problem using the programming language python:
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.
Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.
Your task is to help him solve this complicated task.
-----Input-----
The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.
-----Output-----
Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10^{ - 6}.
-----Examples-----
Input
1 0.50 1
Output
0.5
Input
1 0.50 4
Output
0.9375
Input
4 0.20 2
Output
0.4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = input().split()
n = int(a[0])
p = float(a[1])
t = int(a[2])
den = 100 ** t
p = round(p * 100 + 1e-9)
q = 100 - p
ncr = [1 for i in range(2001)]
for i in range(1, t + 1):
ncr[i] = ncr[i - 1] * (t - i + 1) // i
ans = 0
for i in range(2001):
ans += min(i, n) * ncr[i] * (p ** i) * (q ** (t - i)) if t >= i else 0
ans /= den
print(ans)
``` | vfc_12602 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/518/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 0.50 1\n",
"output": "0.500000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0.50 4\n",
"output": "0.937500000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0.20 2\n",
"output": "0.400000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2000 0.61 2000\n",
"output": "1219.999999999999545\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 1.00 200\n",
"output": "100.000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "417 0.57 742\n",
"output": "414.074442142061741\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 713 | Solve the following coding problem using the programming language python:
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: The coordinates of each point in the set are integers. For any two points from the set, the distance between them is a non-integer.
Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points.
-----Input-----
The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).
-----Output-----
In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them.
-----Examples-----
Input
2 2
Output
3
0 1
1 2
2 0
Input
4 3
Output
4
0 3
2 1
3 0
4 2
-----Note-----
Consider the first sample. The distance between points (0, 1) and (1, 2) equals $\sqrt{2}$, between (0, 1) and (2, 0) — $\sqrt{5}$, between (1, 2) and (2, 0) — $\sqrt{5}$. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s=min(list(map(int,input().split())))
print(s+1)
for i in range(s+1):print(i,s-i)
``` | vfc_12606 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/268/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n",
"output": "3\n0 1\n1 2\n2 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n",
"output": "4\n0 3\n2 1\n3 0\n4 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "21 21\n",
"output": "22\n21 0\n20 1\n19 2\n18 3\n17 4\n16 5\n15 6\n14 7\n13 8\n12 9\n11 10\n10 11\n9 12\n8 13\n7 14\n6 15\n5 16\n4 17\n3 18\n2 19\n1 20\n0 21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n",
"output": "2\n1 0\n0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "2\n1 0\n0 1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 714 | Solve the following coding problem using the programming language python:
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 will be equal for each player. It is guaranteed that it is always possible.
-----Input-----
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.
-----Output-----
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 any of them.
-----Examples-----
Input
6
1 5 7 4 4 3
Output
1 3
6 2
4 5
Input
4
10 10 10 10
Output
1 2
3 4
-----Note-----
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_{i} are equal. Thus, any distribution is acceptable.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
A[i] = [A[i], i+1]
A.sort()
for i in range(n//2):
print(A[i][1], A[n-i-1][1])
``` | vfc_12610 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/701/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 5 7 4 4 3\n",
"output": "1 3\n6 2\n4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 10 10 10\n",
"output": "1 4\n2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n82 46 8 44\n",
"output": "3 1\n4 2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 715 | Solve the following coding problem using the programming language python:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
-----Input-----
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
-----Output-----
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
-----Examples-----
Input
A.VFleaKing_is_the_author_of_this_problem
B.Picks_is_the_author_of_this_problem
C.Picking_is_the_author_of_this_problem
D.Ftiasch_is_cute
Output
D
Input
A.ab
B.abcde
C.ab
D.abc
Output
C
Input
A.c
B.cc
C.c
D.c
Output
B
-----Note-----
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Round 250 Div 2 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
class IOHandlerObject(object):
def getInput(self, mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2:
return [int(x) for x in inputs.split()]
def writeOutput(self, s="\n"):
if isinstance(s, list): s = " ".join(s)
print(s)
IOHandler = IOHandlerObject()
g = IOHandler.getInput
w = IOHandler.writeOutput
############################## SOLUTION ##############################
a,b,c,d = g(0),g(0),g(0),g(0)
r = [(len(a)-2,0), (len(b)-2,1), (len(c)-2,2), (len(d)-2,3)]
r.sort()
t = -1
if r[0][0]*2 <= r[1][0]: t = r[0][1]
if r[3][0] >= r[2][0] * 2:
if not t+1:
t = r[3][1]
else:
t = 5
if t == -1 or t == 5:
print("C")
else:
print(chr(65+t))
``` | vfc_12614 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/437/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"output": "D\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A.ab\nB.abcde\nC.ab\nD.abc\n",
"output": "C\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A.c\nB.cc\nC.c\nD.c\n",
"output": "B\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a\n",
"output": "C\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "A.a___FXIcs_gB____dxFFzst_p_P_Xp_vS__cS_C_ei_\nB.fmnmkS_SeZYx_tSys_d__Exbojv_a_YPEL_BPj__I_aYH\nC._nrPx_j\nD.o_A_UwmNbC_sZ_AXk_Y___i_SN_U_UxrBN_qo_____\n",
"output": "C\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 716 | Solve the following coding problem using the programming language python:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.
Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
-----Input-----
The first line contains three integers n, a, and b (1 ≤ n ≤ 10^5, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.
-----Output-----
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
-----Examples-----
Input
4 1 4
1010
Output
1
Input
5 5 2
10110
Output
0
-----Note-----
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.
In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, a, b = list(map(int, input().split()))
m = input()
if m[a - 1] == m[b - 1]:
print(0)
else:
print(1)
``` | vfc_12618 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/743/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 4\n1010\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 2\n10110\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 9 5\n1011111001\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3 7\n1110111\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 717 | Solve the following coding problem using the programming language python:
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor i goes to work on the s_{i}-th day and works every d_{i} day. So, he works on days s_{i}, s_{i} + d_{i}, s_{i} + 2d_{i}, ....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
-----Input-----
First line contains an integer n — number of doctors (1 ≤ n ≤ 1000).
Next n lines contain two numbers s_{i} and d_{i} (1 ≤ s_{i}, d_{i} ≤ 1000).
-----Output-----
Output a single integer — the minimum day at which Borya can visit the last doctor.
-----Examples-----
Input
3
2 2
1 2
2 2
Output
4
Input
2
10 1
6 5
Output
11
-----Note-----
In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
ans = 0
for i in range(n):
s, d = list(map(int, input().split()))
visit = s
while visit <= ans:
visit += d
ans = visit
print(ans)
``` | vfc_12622 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/879/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 2\n1 2\n2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10 1\n6 5\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n6 10\n3 3\n8 2\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 8\n10 10\n4 2\n8 2\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8\n",
"output": "14\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 718 | Solve the following coding problem using the programming language python:
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
-----Input-----
The only line of input contains an integer a ( - 10^9 ≤ a ≤ 10^9).
-----Output-----
Print the minimum b in a line.
-----Examples-----
Input
179
Output
1
Input
-1
Output
9
Input
18
Output
10
-----Note-----
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = int(input())
for i in range(a+1, a+47):
if ('8' in str(i)):
print(i-a)
break
``` | vfc_12626 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/488/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "179\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "18\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-410058385\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 720 | Solve the following coding problem using the programming language python:
You still have partial information about the score during the historic football match. You are given a set of pairs $(a_i, b_i)$, indicating that at some point during the match the score was "$a_i$: $b_i$". It is known that if the current score is «$x$:$y$», then after the goal it will change to "$x+1$:$y$" or "$x$:$y+1$". What is the largest number of times a draw could appear on the scoreboard?
The pairs "$a_i$:$b_i$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10000$) — the number of known moments in the match.
Each of the next $n$ lines contains integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).
All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match.
-----Output-----
Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.
-----Examples-----
Input
3
2 0
3 1
3 4
Output
2
Input
3
0 0
0 0
0 0
Output
1
Input
1
5 4
Output
5
-----Note-----
In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n = int(input())
res = 0
la, lb = 0, 0
max_draw = -1
for _ in range(n):
a, b = [int(x) for x in input().split()]
mx = max(la, lb)
mn = min(a, b)
if mx <= max_draw:
mx = max_draw + 1
if mx <= mn:
res += mn - mx + 1
max_draw = mn
la, lb = a, b
print(res)
def __starting_point():
main()
__starting_point()
``` | vfc_12634 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1131/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n3 1\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0\n0 0\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 721 | Solve the following coding problem using the programming language python:
Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs a_{i} rubles. Only one person can hang clothes on one hook.
Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest.
Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.
-----Input-----
The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 100). The third line contains integer m (1 ≤ m ≤ 100).
-----Output-----
In a single line print a single integer — the answer to the problem.
-----Examples-----
Input
2 1
2 1
2
Output
3
Input
2 1
2 1
10
Output
-5
-----Note-----
In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.
In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,d=list(map(int,input().split()))
A=list(map(int,input().split()))
m=int(input())
A.sort()
if(m<=n):
print(sum(A[:m]))
else:
print(sum(A)-(d*(m-n)))
``` | vfc_12638 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/368/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n2 1\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 1\n10\n",
"output": "-5\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 722 | Solve the following coding problem using the programming language python:
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.
For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.
You are given a list of abbreviations. For each of them determine the year it stands for.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.
Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
-----Output-----
For each abbreviation given in the input, find the year of the corresponding Olympiad.
-----Examples-----
Input
5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0
Output
2015
12015
1991
1989
1990
Input
4
IAO'9
IAO'99
IAO'999
IAO'9999
Output
1989
1999
2999
9999
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
l = []
for i in range(int(input())):
y, n, m = 1989, 0, 1
for d in input()[-1:3:-1]:
n += (ord(d) - 48) * m
m *= 10
t = n - y % m
y += (m + t if t < 0 else t) + m
l.append(y - m)
print('\n'.join(map(str, l)))
def __starting_point():
main()
__starting_point()
``` | vfc_12642 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/662/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n",
"output": "2015\n12015\n1991\n1989\n1990\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 723 | Solve the following coding problem using the programming language python:
Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно описать следующим образом. На фотографии каждый из друзей занимает прямоугольник из пикселей: в стоячем положении i-й из них занимает прямоугольник ширины w_{i} пикселей и высоты h_{i} пикселей. Но также, при фотографировании каждый человек может лечь, и тогда он будет занимать прямоугольник ширины h_{i} пикселей и высоты w_{i} пикселей.
Общая фотография будет иметь размеры W × H, где W — суммарная ширина всех прямоугольников-людей, а H — максимальная из высот. Друзья хотят определить, какую минимальную площадь может иметь общая фотография. Помогите им в этом.
-----Входные данные-----
В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа w_{i}, h_{i} (1 ≤ w_{i}, h_{i} ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей.
-----Выходные данные-----
Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей.
-----Примеры-----
Входные данные
3
10 1
20 2
30 3
Выходные данные
180
Входные данные
3
3 1
2 2
4 3
Выходные данные
21
Входные данные
1
5 10
Выходные данные
50
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
import sys
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n = tokens.pop()
people = [(tokens.pop(), tokens.pop()) for i in range(n)]
result = float("inf")
for i in range(n):
for j in range(2):
maxh = people[i][j]
S = people[i][j ^ 1]
for k in range(n):
if k != i:
w, h = people[k]
w, h = min(w, h), max(w, h)
if w > maxh:
S = float("inf")
break
if h > maxh:
S += h
else:
S += w
result = min(result, S * maxh)
print(result)
main()
``` | vfc_12646 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/524/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 1\n20 2\n30 3\n",
"output": "180\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 1\n2 2\n4 3\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5 10\n",
"output": "50\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 724 | Solve the following coding problem using the programming language python:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.
Diameter of multiset consisting of one point is 0.
You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?
-----Input-----
The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.
The second line contains n space separated integers (1 ≤ x_{i} ≤ 100) — the coordinates of the points.
-----Output-----
Output a single integer — the minimum number of points you have to remove.
-----Examples-----
Input
3 1
2 1 4
Output
1
Input
3 0
7 7 7
Output
0
Input
6 3
1 3 4 6 9 10
Output
3
-----Note-----
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def read_int():
return int(input())
def read_ints():
return [int(x) for x in input().split()]
n, d = read_ints()
a = read_ints()
a = sorted(a)
best = 0
for i in range(n):
for j in range(i, n):
if a[j] - a[i] <= d:
best = max(best, j - i + 1)
print(len(a) - best)
``` | vfc_12650 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/940/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n2 1 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n7 7 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3\n1 3 4 6 9 10\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 725 | Solve the following coding problem using the programming language python:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: 'C' (cyan) 'M' (magenta) 'Y' (yellow) 'W' (white) 'G' (grey) 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
-----Input-----
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
-----Output-----
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
-----Examples-----
Input
2 2
C M
Y Y
Output
#Color
Input
3 2
W W
W W
B B
Output
#Black&White
Input
1 1
W
Output
#Black&White
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = list(map(int, input().split()))
for i in range(n):
for j in input().split():
if j in "CMY":
print("#Color")
return
print("#Black&White")
``` | vfc_12654 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/707/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nC M\nY Y\n",
"output": "#Color",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nW W\nW W\nB B\n",
"output": "#Black&White",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\nW\n",
"output": "#Black&White",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\nW W W\nB G Y\n",
"output": "#Color",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\nW\n",
"output": "#Black&White",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 726 | Solve the following coding problem using the programming language python:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city.
Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.
Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
-----Input-----
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
-----Output-----
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
-----Examples-----
Input
4 3
-3 2 9 16
Output
6
Input
5 2
4 8 11 18 19
Output
5
-----Note-----
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: map(int, input().split())
n, d = read()
x = sorted(read())
ans = 2
for i in range(1, n):
dx = x[i] - x[i - 1]
if dx == 2 * d:
ans += 1
elif dx > 2 * d:
ans += 2
print(ans)
``` | vfc_12658 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1004/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n-3 2 9 16\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n4 8 11 18 19\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10\n0 20 48 58 81 95 111 137 147 159\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 727 | Solve the following coding problem using the programming language python:
Vasya has an array of integers of length n.
Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is [13, 13, 7, 7, 7, 2, 2, 2], then after one operation it becomes [13, 13, 2, 2, 2].
Compute the number of operations Vasya should make until the array becomes empty, i.e. Vasya removes all elements from it.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.
The second line contains a sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — Vasya's array.
-----Output-----
Print the number of operations Vasya should make to remove all elements from the array.
-----Examples-----
Input
4
2 5 5 2
Output
2
Input
5
6 3 4 1 5
Output
5
Input
8
4 4 4 2 2 100 100 100
Output
3
Input
6
10 10 50 10 50 50
Output
4
-----Note-----
In the first example, at first Vasya removes two fives at the second and third positions. The array becomes [2, 2]. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.
In the second example Vasya has to perform five operations to make the array empty. In each of them he removes the first element from the array.
In the third example Vasya needs three operations. In the first operation he removes all integers 4, in the second — all integers 100, in the third — all integers 2.
In the fourth example in the first operation Vasya removes the first two integers 10. After that the array becomes [50, 10, 50, 50]. Then in the second operation Vasya removes the two rightmost integers 50, so that the array becomes [50, 10]. In the third operation he removes the remaining 50, and the array becomes [10] after that. In the last, fourth operation he removes the only remaining 10. The array is empty after that.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin
from heapq import heappop, heappush, heapify
def main():
n = int(stdin.readline())
a = stdin.readline().split()
q = []
p = 0
c = 0
l = [0] * (n + 1)
r = [0] * (n + 1)
k = [0] * (n + 1)
pa = [0] * (n + 1)
for i, x in enumerate(a):
if x == a[p]:
c += 1
else:
l[p] = p - 1
k[p] = k[i-1] = c
pa[p] = i - 1
pa[i-1] = p
r[i-1] = i
q.append((-c, p))
p = i
c = 1
q.append((-c, p))
l[p] = p - 1
k[p] = k[n-1] = c
pa[p] = n - 1
pa[n-1] = p
r[n-1] = n
heapify(q)
ans = 0
while len(q):
c, p = heappop(q)
c = -c
if k[p] > c:
continue
ans += 1
ls = l[p]
rs = r[pa[p]]
if ls >= 0 and rs < n and a[ls] == a[rs]:
nc = k[ls] + k[rs]
nl, nr = pa[ls], pa[rs]
k[nl] = k[nr] = k[ls] = k[rs] = nc
pa[nr] = nl
pa[nl] = nr
heappush(q, (-nc, nl))
else:
if ls >= 0:
r[ls] = rs
if rs < n:
l[rs] = ls
print (ans)
main()
``` | vfc_12662 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/899/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 5 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 728 | Solve the following coding problem using the programming language python:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get a_{i} votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.
Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
-----Input-----
The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
-----Output-----
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
-----Examples-----
Input
5
5 1 11 2 8
Output
4
Input
4
1 8 8 8
Output
6
Input
2
7 6
Output
0
-----Note-----
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8.
In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6.
In the third sample Limak is a winner without bribing any citizen.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
a=list(map(int,input().split()))
b=0
a[1:]=sorted(a[1:])
while a[0]<=a[-1]:
a[-1]-=1
a[0]+=1
b+=1
a[1:]=sorted(a[1:])
print(b)
``` | vfc_12666 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/574/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 1 11 2 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 8 8 8\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 729 | Solve the following coding problem using the programming language python:
You are given a string $s$, consisting of $n$ lowercase Latin letters.
A substring of string $s$ is a continuous segment of letters from $s$. For example, "defor" is a substring of "codeforces" and "fors" is not.
The length of the substring is the number of letters in it.
Let's call some string of length $n$ diverse if and only if there is no letter to appear strictly more than $\frac n 2$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.
Your task is to find any diverse substring of string $s$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 1000$) — the length of string $s$.
The second line is the string $s$, consisting of exactly $n$ lowercase Latin letters.
-----Output-----
Print "NO" if there is no diverse substring in the string $s$.
Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $s$.
-----Examples-----
Input
10
codeforces
Output
YES
code
Input
5
aaaaa
Output
NO
-----Note-----
The first example has lots of correct answers.
Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = input()
for i in range(n - 1):
if (s[i] != s[i+1]):
print("YES")
print(s[i:i+2])
return
print("NO")
``` | vfc_12670 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1073/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\ncodeforces\n",
"output": "YES\nco\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\naaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 730 | Solve the following coding problem using the programming language python:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. [Image]
The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.
In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.
-----Input-----
The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.
-----Output-----
Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.
-----Examples-----
Input
9
Output
+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+
Input
20
Output
+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = [
"+------------------------+",
"|#.#.#.#.#.#.#.#.#.#.#.|D|)",
"|#.#.#.#.#.#.#.#.#.#.#.|.|",
"|#.......................|",
"|#.#.#.#.#.#.#.#.#.#.#.|.|)",
"+------------------------+"
]
n = int(input())
row = 1
pos = 1
for i in range(n):
a[pos] = a[pos][:row] + 'O' + a[pos][row + 1:]
pos += 1
if row != 1 and pos == 3:
pos += 1
if pos > 4:
pos = 1
row += 2
for x in a:
print(x)
``` | vfc_12674 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/475/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9\n",
"output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n",
"output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30\n",
"output": "+------------------------+\n|O.O.O.O.O.O.O.O.O.O.#.|D|)\n|O.O.O.O.O.O.O.O.O.O.#.|.|\n|O.......................|\n|O.O.O.O.O.O.O.O.O.#.#.|.|)\n+------------------------+\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "+------------------------+\n|O.O.#.#.#.#.#.#.#.#.#.|D|)\n|O.#.#.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.#.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 731 | Solve the following coding problem using the programming language python:
We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6.
You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)·k to add the number n to the sequence.
You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
-----Input-----
The first line contains three integers w (1 ≤ w ≤ 10^16), m (1 ≤ m ≤ 10^16), k (1 ≤ k ≤ 10^9).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
-----Output-----
The first line should contain a single integer — the answer to the problem.
-----Examples-----
Input
9 1 1
Output
9
Input
77 7 7
Output
7
Input
114 5 14
Output
6
Input
1 1 2
Output
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
w,m,k=list(map(int,input().split()))
x=int("1"+("0"*len(str(m))))
h=x-m
n=len(str(m))
ans=w//(n*k)
if(ans>h):
ans=h
w-=h*n*k
while(w>0):
n+=1
x=w//(n*k)
if(x>=10**(n-1)*9):
ans+=(10**(n-1))*(9)
w-=(n*k*(10**(n-1))*(9))
else:
ans+=x
break
print(ans)
``` | vfc_12678 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/373/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 1 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "77 7 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "114 5 14\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "462 183 8\n",
"output": "19\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 732 | Solve the following coding problem using the programming language python:
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^9) — Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#CF Round 150. Div II Prob. A - Dividing Orange
import sys
dp = [[[-1 for j in range(3)] for i in range (1 << 10)] for k in range(11)]
In = sys.stdin
n = In.readline().strip()
def go (idx, mask, equal):
if dp[idx][mask][equal] != -1:
return dp[idx][mask][equal]
if bin(mask).count("1") > 2:
return 0
if idx == len(n):
return 1
res = 0
if idx == 0 or equal == 2:
res += go(idx + 1, mask, 2)
elif equal == 1 and int(n[idx]) == 0:
res += go(idx + 1, mask | 1, 1)
else:
res += go(idx + 1, mask | 1, 0)
for i in range(1, 10):
if equal == 1 and i > int(n[idx]):
break
elif equal == 1 and i == int(n[idx]):
res += go(idx + 1, mask | (1 << i), 1)
else:
res += go(idx + 1, mask | (1 << i), 0)
dp[idx][mask][equal] = res
return res
print(go(0, 0, 1) - 1)
``` | vfc_12682 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/244/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "123\n",
"output": "113\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000\n",
"output": "352\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 733 | Solve the following coding problem using the programming language python:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips x - 1 consecutive bricks, then he paints the x-th one. That is, he'll paint bricks x, 2·x, 3·x and so on red. Similarly, Floyd skips y - 1 consecutive bricks, then he paints the y-th one. Hence he'll paint bricks y, 2·y, 3·y and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question.
-----Input-----
The input will have a single line containing four integers in this order: x, y, a, b. (1 ≤ x, y ≤ 1000, 1 ≤ a, b ≤ 2·10^9, a ≤ b).
-----Output-----
Output a single integer — the number of bricks numbered no less than a and no greater than b that are painted both red and pink.
-----Examples-----
Input
2 3 6 18
Output
3
-----Note-----
Let's look at the bricks from a to b (a = 6, b = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import fractions
x, y, a, b = list(map(int, input().split()))
d = fractions.gcd(x, y)
d = x * y // d
print(b // d - (a - 1) // d)
``` | vfc_12686 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/340/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 6 18\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6 20 201\n",
"output": "15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 27 100 10000\n",
"output": "74",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "105 60 3456 78910\n",
"output": "179",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 734 | Solve the following coding problem using the programming language python:
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface.
The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$.
There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$
Find the maximum number of blocks you can remove such that the views for both the cameras would not change.
Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either.
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right.
-----Output-----
Print exactly one integer — the maximum number of blocks that can be removed.
-----Examples-----
Input
5 6
3 3 3 3 3
Output
10
Input
3 5
1 2 4
Output
3
Input
5 5
2 3 1 4 4
Output
9
Input
1 1000
548
Output
0
Input
3 3
3 1 1
Output
1
-----Note-----
The following pictures illustrate the first example and its possible solution.
Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mx = a[-1]
t = 0
ans = 0;
for i in a:
if i > 0:
if i > t:
t += 1
ans += i - 1
ans -= mx - t
print(ans)
``` | vfc_12690 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1061/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6\n3 3 3 3 3\n",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n1 2 4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n2 3 1 4 4\n",
"output": "9",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 735 | Solve the following coding problem using the programming language python:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 10^5) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 10^9).
-----Output-----
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
-----Examples-----
Input
3
3 2 1
Output
yes
1 3
Input
4
2 1 3 4
Output
yes
1 2
Input
4
3 1 2 4
Output
no
Input
2
1 2
Output
yes
1 1
-----Note-----
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array will become:
a[1], a[2], ..., a[l - 2], a[l - 1], a[r], a[r - 1], ..., a[l + 1], a[l], a[r + 1], a[r + 2], ..., a[n - 1], a[n].
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
if sorted(a) == a:
print('yes')
print('1 1')
return
start = 0
end = n - 1
seen = 0
for i in range(n-1):
if not seen:
if a[i] > a[i+1]:
seen += 1
start = i
else:
if a[i] <= a[i+1]:
end = i
break
#print(a)
#print(a[:start], a[start:end+1][::-1], a[end+1:], sep='\n')
a = a[:start] + a[start:end+1][::-1] + a[end+1:]
#print(a)
#print(start, end)
if sorted(a) == a:
print('yes')
print(start+1, end+1)
else:
print('no')
``` | vfc_12694 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/451/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n3 2 1\n",
"output": "yes\n1 3\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 736 | Solve the following coding problem using the programming language python:
Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
-----Input-----
The single line contains two space separated integers n, m (0 < n ≤ 10000, 1 < m ≤ 10).
-----Output-----
Print a single integer — the minimal number of moves being a multiple of m. If there is no way he can climb satisfying condition print - 1 instead.
-----Examples-----
Input
10 2
Output
6
Input
3 5
Output
-1
-----Note-----
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# 272 D2 A
def func(p,m,n):
w = p
while w % m != 0 and w<=n:
w += 1
if w<= n:
return w
else:
return -1
l = input().split()
n = int(l[0])
m = int(l[1])
if n % 2 == 0:
p = int(n/2)
else:
p = int(n/2)+1
print(func(p,m,n))
``` | vfc_12698 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/476/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29 7\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 737 | Solve the following coding problem using the programming language python:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.
-----Input-----
Input will consist of a single integer N (1 ≤ N ≤ 10^6), the number of city blocks that must be enclosed by the route.
-----Output-----
Print the minimum perimeter that can be achieved.
-----Examples-----
Input
4
Output
8
Input
11
Output
14
Input
22
Output
20
-----Note-----
Here are some possible shapes for the examples:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = 1
while a * a < n:
a += 1
if a * (a - 1) >= n:
print(2 * a + 2 * (a - 1))
else:
print(4 * a)
``` | vfc_12702 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/859/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "22\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1024\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n",
"output": "42\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 738 | Solve the following coding problem using the programming language python:
Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds?
Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.
The triangle is called non-degenerate if and only if its vertices are not collinear.
-----Input-----
The first line contains four integers: $A$, $B$, $C$ and $D$ ($1 \leq A \leq B \leq C \leq D \leq 5 \cdot 10^5$) — Yuri's favourite numbers.
-----Output-----
Print the number of non-degenerate triangles with integer sides $x$, $y$, and $z$ such that the inequality $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds.
-----Examples-----
Input
1 2 3 4
Output
4
Input
1 2 2 5
Output
3
Input
500000 500000 500000 500000
Output
1
-----Note-----
In the first example Yuri can make up triangles with sides $(1, 3, 3)$, $(2, 2, 3)$, $(2, 3, 3)$ and $(2, 3, 4)$.
In the second example Yuri can make up triangles with sides $(1, 2, 2)$, $(2, 2, 2)$ and $(2, 2, 3)$.
In the third example Yuri can make up only one equilateral triangle with sides equal to $5 \cdot 10^5$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
a, b, c, d = nm()
m = 10**6 + 10
l = [0]*m
for i in range(a, b+1):
l[i+b] += 1
l[i+c+1] += -1
for i in range(m-1):
l[i] += l[i-1]
for i in range(m-2, -1, -1):
l[i] += l[i+1]
print(sum(l[i+1] for i in range(c, d+1)))
return
solve()
# T = ni()
# for _ in range(T):
# solve()
``` | vfc_12706 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1355/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "500000 500000 500000 500000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "276 391 634 932\n",
"output": "5866404\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 740 | Solve the following coding problem using the programming language python:
You have k pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n_1 washing machines, n_2 drying machines and n_3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it before it is dried. Moreover, after a piece of laundry is washed, it needs to be immediately moved into a drying machine, and after it is dried, it needs to be immediately moved into a folding machine.
It takes t_1 minutes to wash one piece of laundry in a washing machine, t_2 minutes to dry it in a drying machine, and t_3 minutes to fold it in a folding machine. Find the smallest number of minutes that is enough to wash, dry and fold all the laundry you have.
-----Input-----
The only line of the input contains seven integers: k, n_1, n_2, n_3, t_1, t_2, t_3 (1 ≤ k ≤ 10^4; 1 ≤ n_1, n_2, n_3, t_1, t_2, t_3 ≤ 1000).
-----Output-----
Print one integer — smallest number of minutes to do all your laundry.
-----Examples-----
Input
1 1 1 1 5 5 5
Output
15
Input
8 4 3 2 10 5 2
Output
32
-----Note-----
In the first example there's one instance of each machine, each taking 5 minutes to complete. You have only one piece of laundry, so it takes 15 minutes to process it.
In the second example you start washing first two pieces at moment 0. If you start the third piece of laundry immediately, then by the time it is dried, there will be no folding machine available, so you have to wait, and start washing third piece at moment 2. Similarly, you can't start washing next piece until moment 5, since otherwise there will be no dryer available, when it is washed. Start time for each of the eight pieces of laundry is 0, 0, 2, 5, 10, 10, 12 and 15 minutes respectively. The last piece of laundry will be ready after 15 + 10 + 5 + 2 = 32 minutes.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k, na, nb, nc, ta, tb, tc = list(map(int, input().split()))
from collections import deque
a = deque()
b = deque()
c = deque()
for i in range(na):
a.append(0)
for i in range(nb):
b.append(0)
for i in range(nc):
c.append(0)
t = 0
for i in range(k):
vr = max(a[0], b[0] - ta, c[0] - (ta + tb))
a.popleft()
a.append(vr + ta)
b.popleft()
b.append(vr + tb + ta)
c.popleft()
c.append(vr + ta + tb + tc)
t = vr + ta + tb + tc
print(t)
``` | vfc_12714 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/452/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 1 5 5 5\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4 3 2 10 5 2\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000 1000 1000 1000 1000 1000 1000\n",
"output": "12000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 3 4 3 10 9 4\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 4 5 9 9 6\n",
"output": "42\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 741 | Solve the following coding problem using the programming language python:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
-----Input-----
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
-----Output-----
Print the only integer — maximum possible total time when the lamp is lit.
-----Examples-----
Input
3 10
4 6 7
Output
8
Input
2 12
1 10
Output
9
Input
2 7
3 4
Output
6
-----Note-----
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n, M = mi()
a = [0] + li() + [M]
n = len(a)
ans = 0
p = [0] * n
q = [0] * n
for i in range(1, n):
p[i] = p[i - 1]
q[i] = q[i - 1]
if i % 2 == 0:
p[i] += a[i] - a[i - 1]
else:
q[i] += a[i] - a[i - 1]
ans = q[-1]
for i in range(1, n):
if a[i] == a[i - 1] + 1:
continue
if i % 2 == 0:
ans = max(ans, q[i] + 1 + p[-1] - p[i], q[i] + a[i] - a[i - 1] - 1 + p[-1] - p[i])
else:
ans = max(ans, q[i] - 1 + p[-1] - p[i], q[i] - (a[i] - a[i - 1] - 1) + p[-1] - p[i])
print(ans)
``` | vfc_12718 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1000/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n4 6 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 12\n1 10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 7\n3 4\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 743 | Solve the following coding problem using the programming language python:
Fox Ciel is playing a game with numbers now.
Ciel has n positive integers: x_1, x_2, ..., x_{n}. She can do the following operation as many times as needed: select two different indexes i and j such that x_{i} > x_{j} hold, and then apply assignment x_{i} = x_{i} - x_{j}. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
-----Input-----
The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x_1, x_2, ..., x_{n} (1 ≤ x_{i} ≤ 100).
-----Output-----
Output a single integer — the required minimal sum.
-----Examples-----
Input
2
1 2
Output
2
Input
3
2 4 6
Output
6
Input
2
12 18
Output
12
Input
5
45 12 27 30 18
Output
15
-----Note-----
In the first example the optimal way is to do the assignment: x_2 = x_2 - x_1.
In the second example the optimal sequence of operations is: x_3 = x_3 - x_2, x_2 = x_2 - x_1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
no=a[0]
for i in range(1,n):
no=gcd(no,a[i])
print(no*n)
``` | vfc_12726 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/389/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 4 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n12 18\n",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 744 | Solve the following coding problem using the programming language python:
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 remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.
-----Input-----
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 in chronological order, i.e. today is the last day in this sequence.
-----Output-----
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).
-----Examples-----
Input
4
FSSF
Output
NO
Input
2
SF
Output
YES
Input
10
FFFFFFFFFF
Output
NO
Input
10
SSFFSFFSFF
Output
YES
-----Note-----
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 stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = input()
si, sf = 0, 0
for i in range(1, n):
if s[i] == 'S' and s[i - 1] != 'S':
si += 1
elif s[i] == 'F' and s[i - 1] != 'F':
sf += 1
if sf > si:
print('YES')
else:
print('NO')
``` | vfc_12730 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/867/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nFSSF\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nSF\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nFFFFFFFFFF\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nSSFFSFFSFF\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\nSFSFFFFSSFFFFSSSSFSS\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 745 | Solve the following coding problem using the programming language python:
Calculate the number of ways to place $n$ rooks on $n \times n$ chessboard so that both following conditions are met:
each empty cell is under attack; exactly $k$ pairs of rooks attack each other.
An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture:
[Image] One of the ways to place the rooks for $n = 3$ and $k = 2$
Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.
The answer might be large, so print it modulo $998244353$.
-----Input-----
The only line of the input contains two integers $n$ and $k$ ($1 \le n \le 200000$; $0 \le k \le \frac{n(n - 1)}{2}$).
-----Output-----
Print one integer — the number of ways to place the rooks, taken modulo $998244353$.
-----Examples-----
Input
3 2
Output
6
Input
3 3
Output
0
Input
4 0
Output
24
Input
1337 42
Output
807905441
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
MOD = 998244353
def inv(x):
return pow(x,MOD - 2, MOD)
n, k = list(map(int, input().split()))
if k >= n:
print(0)
else:
out = 0
col = n - k
binom = 1
mult = 1
for i in range(n, col, -1):
mult *= i
mult *= inv(n + 1 - i)
mult %= MOD
for i in range(col, 0, -1):
out += binom * pow(i, n, MOD)
out %= MOD
binom *= i
binom *= inv(col + 1 - i)
binom *= -1
binom %= MOD
out *= mult
if k > 0:
out *= 2
print(out % MOD)
``` | vfc_12734 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1342/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 747 | Solve the following coding problem using the programming language python:
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. [Image]
One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of h_{i} centimeters above the floor of the house, its mass is m_{i}. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.
What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?
-----Input-----
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following n lines contains three integers t_{i}, h_{i}, m_{i} (0 ≤ t_{i} ≤ 1; 1 ≤ h_{i}, m_{i} ≤ 2000) — the type, height and the mass of the i-th candy. If number t_{i} equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.
-----Output-----
Print a single integer — the maximum number of candies Om Nom can eat.
-----Examples-----
Input
5 3
0 2 4
1 3 1
0 8 3
0 20 10
1 5 5
Output
4
-----Note-----
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import itertools
import operator
n, x = list(map(int, str.split(input())))
a = []
b = []
for _ in range(n):
t, h, m = list(map(int, str.split(input())))
(a if t else b).append((h, m))
best = 0
for ca, cb in ((a, b), (b, a)):
cx = x
count = 0
ca, cb = ca[:], cb[:]
while True:
available = tuple([candy for candy in enumerate(ca) if candy[1][0] <= cx])
if available:
i, candy = max(available, key=lambda candy: candy[1][1])
ca.pop(i)
count += 1
cx += candy[1]
else:
break
ca, cb = cb, ca
best = max(best, count)
print(best)
``` | vfc_12742 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/436/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4 2\n0 3 1\n0 9 2\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 748 | Solve the following coding problem using the programming language python:
Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held: a < b < c; a divides b, b divides c.
Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has $\frac{n}{3}$ groups of three.
Help Xenia, find the required partition or else say that it doesn't exist.
-----Input-----
The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.
It is guaranteed that n is divisible by 3.
-----Output-----
If the required partition exists, print $\frac{n}{3}$ groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1.
-----Examples-----
Input
6
1 1 1 2 2 2
Output
-1
Input
6
2 2 1 1 4 6
Output
1 2 4
1 2 6
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def __starting_point():
N = int(input())
L = [0,0,0,0,0,0,0,0]
inp = input()
for i in inp.split(' '):
L[int(i)]+=1
it = N//3
fnd = True
ans = []
for ic in range(it):
Tl = []
for el in range(len(L)):
if L[el]!=0:
if len(Tl)==0:
Tl.append(el)
L[el]-=1
elif el%Tl[-1]==0:
Tl.append(el)
L[el]-=1
if len(Tl)==3:
break
if len(Tl)==3:
ans.append(str(Tl[0])+" "+str(Tl[1])+" "+str(Tl[2]))
else:
fnd=False
break
if fnd:
for a in ans:
print(a)
else:
print("-1")
__starting_point()
``` | vfc_12746 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/342/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 1 1 2 2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 2 1 1 4 6\n",
"output": "1 2 4\n1 2 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n7 5 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 750 | Solve the following coding problem using the programming language python:
Petya is having a party soon, and he has decided to invite his $n$ friends.
He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $k$ sheets. That is, each notebook contains $k$ sheets of either red, green, or blue.
Find the minimum number of notebooks that Petya needs to buy to invite all $n$ of his friends.
-----Input-----
The first line contains two integers $n$ and $k$ ($1\leq n, k\leq 10^8$) — the number of Petya's friends and the number of sheets in each notebook respectively.
-----Output-----
Print one number — the minimum number of notebooks that Petya needs to buy.
-----Examples-----
Input
3 5
Output
10
Input
15 6
Output
38
-----Note-----
In the first example, we need $2$ red notebooks, $3$ green notebooks, and $5$ blue notebooks.
In the second example, we need $5$ red notebooks, $13$ green notebooks, and $20$ blue notebooks.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import ceil
n, k = list(map(int, input().split()))
print(ceil((8 * n) / k) + ceil((5 * n) / k) + ceil((2 * n) / k))
``` | vfc_12754 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1080/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 6\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "15\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 751 | Solve the following coding problem using the programming language python:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has n groups of people. The i-th group from the beginning has a_{i} people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ m).
-----Output-----
Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.
-----Examples-----
Input
4 3
2 3 2 1
Output
3
Input
3 4
1 2 1
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,m=list(map(int,input().split()))
L=list(map(int,input().split()))
ans=0
ind=0
bus=0
while(ind<n):
ans+=1
while(ind<n and bus+L[ind]<=m):
bus+=L[ind]
ind+=1
bus=0
print(ans)
``` | vfc_12758 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/435/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 3 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 752 | Solve the following coding problem using the programming language python:
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
There are $n$ winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.
Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.
What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?
The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts.
The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year.
The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year.
It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list $b$ from the list $a$.
-----Output-----
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
-----Examples-----
Input
3
XS
XS
M
XL
S
XS
Output
2
Input
2
XXXL
XXL
XXL
XXXS
Output
1
Input
2
M
XS
XS
M
Output
0
-----Note-----
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".
In the second example Ksenia should replace "L" in "XXXL" with "S".
In the third example lists are equal.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict
n = int(input())
d = defaultdict(int)
r = 0
for i in range(n):
d[input()] += 1
for i in range(n):
s = input()
if d[s]:
d[s] -= 1
else:
r += 1
print(r)
``` | vfc_12762 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1000/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nXS\nXS\nM\nXL\nS\nXS\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 753 | Solve the following coding problem using the programming language python:
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.
Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fraction p / q.
-----Input-----
A single line contains four space-separated integers a, b, c, d (1 ≤ a, b, c, d ≤ 1000).
-----Output-----
Print the answer to the problem as "p/q", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.
-----Examples-----
Input
1 1 3 2
Output
1/3
Input
4 3 2 2
Output
1/4
-----Note-----
Sample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension: [Image]
Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension: [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from fractions import Fraction,gcd
a,b,c,d = [int(x) for x in input().split()]
if a*d > b*c:
num = a*d-b*c
denom = a*d
else:
num = b*c-a*d
denom = b*c
div = gcd(num,denom)
print('%d/%d'%(num//div,denom//div))
``` | vfc_12766 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/337/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 3 2\n",
"output": "1/3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 2 2\n",
"output": "1/4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4 2 3\n",
"output": "1/9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 5 5\n",
"output": "0/1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1\n",
"output": "0/1\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 754 | Solve the following coding problem using the programming language python:
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.
The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.
-----Output-----
Print a single integer — the answer to the problem.
-----Examples-----
Input
3
RRG
Output
1
Input
5
RRRRR
Output
4
Input
4
BRBG
Output
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
s = input()
r = 0
for i in range(1, n):
if s[i] == s[i - 1]:
r += 1
print(r)
``` | vfc_12770 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/266/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nRRG\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nRRRRR\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
apps | verifiable_code | 755 | Solve the following coding problem using the programming language python:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
-----Input-----
The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.
-----Output-----
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
-----Examples-----
Input
5
Output
1
Input
12
Output
3
-----Note-----
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import ceil
n = int(input())
print(ceil(n/5))
``` | vfc_12774 | {
"difficulty": "interview",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/617/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits