contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
625
B
War of the Corporations
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "strings" ]
null
null
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence. Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring. Substring is a continuous subsequence of a string.
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
[ "intellect\ntell\n", "google\napple\n", "sirisiri\nsir\n" ]
[ "1", "0", "2" ]
In the first sample AI's name may be replaced with "int#llect". In the second sample Gogol can just keep things as they are. In the third sample one of the new possible names of AI may be "s#ris#ri".
750
[ { "input": "intellect\ntell", "output": "1" }, { "input": "google\napple", "output": "0" }, { "input": "sirisiri\nsir", "output": "2" }, { "input": "sirisiri\nsiri", "output": "2" }, { "input": "aaaaaaa\naaaa", "output": "1" }, { "input": "bbbbbb\nbb", "output": "3" }, { "input": "abc\nabcabc", "output": "0" }, { "input": "kek\nkekekek", "output": "0" }, { "input": "aaaaa\naaa", "output": "1" }, { "input": "abcdabcv\nabcd", "output": "1" }, { "input": "abcabcabczabcabcabcz\ncab", "output": "4" }, { "input": "aatopotopotopotaa\ntopot", "output": "2" }, { "input": "abcabcabcabcabcabcabcabcabcabc\nabcabcabcabcabcabcabcabcabcabc", "output": "1" }, { "input": "sosossosos\nsos", "output": "2" }, { "input": "sosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosos\nsos", "output": "20" }, { "input": "tatatx\ntatx", "output": "1" }, { "input": "sxxsxxsxxd\nsxxsxxd", "output": "1" } ]
1,662,233,995
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
156
4,710,400
from collections import deque,Counter from math import * import sys import random from bisect import * from functools import reduce from sys import stdin import copy def find(s,t): p = 31 m = 10**9 + 9 p_pow = [0] * max(len(s),len(t)) p_pow[0] = 1 for i in range(1,len(p_pow)): p_pow[i] = (p_pow[i-1] * p) % m h = [0]*(len(t)+1) for i in range(len(t)): h[i+1] = (h[i] + (ord(t[i]) - 97)*p_pow[i])%m h_s = 0 for i in range(len(s)): h_s = (h_s + (ord(s[i]) - 97)*p_pow[i])%m ans = 0 for i in range(len(t)-len(s)+1): curr_h = (h[i+len(s)] - h[i])%m if curr_h == (h_s * p_pow[i])%m: ans+=1 return ans t = input() s = input() print(find(s,t))
Title: War of the Corporations Time Limit: None seconds Memory Limit: None megabytes Problem Description: A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence. Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring. Substring is a continuous subsequence of a string. Input Specification: The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. Output Specification: Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. Demo Input: ['intellect\ntell\n', 'google\napple\n', 'sirisiri\nsir\n'] Demo Output: ['1', '0', '2'] Note: In the first sample AI's name may be replaced with "int#llect". In the second sample Gogol can just keep things as they are. In the third sample one of the new possible names of AI may be "s#ris#ri".
```python from collections import deque,Counter from math import * import sys import random from bisect import * from functools import reduce from sys import stdin import copy def find(s,t): p = 31 m = 10**9 + 9 p_pow = [0] * max(len(s),len(t)) p_pow[0] = 1 for i in range(1,len(p_pow)): p_pow[i] = (p_pow[i-1] * p) % m h = [0]*(len(t)+1) for i in range(len(t)): h[i+1] = (h[i] + (ord(t[i]) - 97)*p_pow[i])%m h_s = 0 for i in range(len(s)): h_s = (h_s + (ord(s[i]) - 97)*p_pow[i])%m ans = 0 for i in range(len(t)-len(s)+1): curr_h = (h[i+len(s)] - h[i])%m if curr_h == (h_s * p_pow[i])%m: ans+=1 return ans t = input() s = input() print(find(s,t)) ```
0
377
A
Maze
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
500
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#" }, { "input": "1 1 0\n.", "output": "." }, { "input": "2 3 1\n..#\n#..", "output": "X.#\n#.." }, { "input": "2 3 1\n#..\n..#", "output": "#.X\n..#" }, { "input": "3 3 1\n...\n.#.\n..#", "output": "...\n.#X\n..#" }, { "input": "3 3 1\n...\n.#.\n#..", "output": "...\nX#.\n#.." }, { "input": "5 4 4\n#..#\n....\n.##.\n....\n#..#", "output": "#XX#\nXX..\n.##.\n....\n#..#" }, { "input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "output": "X#..#\nX.#.#\n#....\n##.#.\n###.." }, { "input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "output": "#.....\n#X#.#X\nX#...#\n...#.#" }, { "input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#" }, { "input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###" }, { "input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################" }, { "input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#" }, { "input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###" }, { "input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######" }, { "input": "3 5 1\n#...#\n..#..\n..#..", "output": "#...#\n..#..\nX.#.." }, { "input": "4 5 10\n.....\n.....\n..#..\n..#..", "output": "XXX..\nXXX..\nXX#..\nXX#.." }, { "input": "3 5 3\n.....\n..#..\n..#..", "output": ".....\nX.#..\nXX#.." }, { "input": "3 5 1\n#....\n..#..\n..###", "output": "#....\n..#.X\n..###" }, { "input": "4 5 1\n.....\n.##..\n..#..\n..###", "output": ".....\n.##..\n..#.X\n..###" }, { "input": "3 5 2\n..#..\n..#..\n....#", "output": "X.#..\nX.#..\n....#" }, { "input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########" }, { "input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###" }, { "input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.." }, { "input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.." }, { "input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########" }, { "input": "4 5 1\n.....\n.###.\n..#..\n..#..", "output": ".....\n.###.\n..#..\n.X#.." }, { "input": "2 5 2\n###..\n###..", "output": "###X.\n###X." }, { "input": "2 5 3\n.....\n..#..", "output": "X....\nXX#.." }, { "input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n#####", "output": ".....\n.##.X\n..###\n..###\n#####" }, { "input": "4 4 1\n....\n.#..\n..##\n..##", "output": "....\n.#.X\n..##\n..##" }, { "input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "output": "....#\n.##..\n.##.X\n...##\n...##" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n..###", "output": ".....\n.##.X\n..###\n..###\n..###" }, { "input": "4 5 1\n#....\n#.#..\n..###\n..###", "output": "#....\n#.#.X\n..###\n..###" }, { "input": "4 4 3\n....\n.#..\n..##\n..##", "output": "...X\n.#XX\n..##\n..##" }, { "input": "4 7 6\n.......\n....#..\n.##.#..\n....#..", "output": "X......\nX...#..\nX##.#..\nXXX.#.." }, { "input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######", "output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######" } ]
1,667,461,550
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
233
21,504,000
from collections import defaultdict grid = [] n,m,k = list(map(int, input().split())) count = 0 def solve(): global n,m,k, count for _ in range(n): grid.append(list(input())) total = 0 x,y = -1,-1 for i in range(n): for j in range(m): if grid[i][j] == '.': grid[i][j] = 'X' total += 1 x = i y = j stack = [(x,y)] while stack: if count == (total - k): return i,j = stack.pop() count += 1 grid[i][j] = '.' for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]: n_i,n_j = i + dx , j + dy if 0 <= n_i < n and 0 <= n_j < m and grid[n_i][n_j] == 'X': stack.append((n_i, n_j)) solve() for i in range(n): print("".join(grid[i]))
Title: Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. Output Specification: Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. Demo Input: ['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n'] Demo Output: ['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n'] Note: none
```python from collections import defaultdict grid = [] n,m,k = list(map(int, input().split())) count = 0 def solve(): global n,m,k, count for _ in range(n): grid.append(list(input())) total = 0 x,y = -1,-1 for i in range(n): for j in range(m): if grid[i][j] == '.': grid[i][j] = 'X' total += 1 x = i y = j stack = [(x,y)] while stack: if count == (total - k): return i,j = stack.pop() count += 1 grid[i][j] = '.' for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]: n_i,n_j = i + dx , j + dy if 0 <= n_i < n and 0 <= n_j < m and grid[n_i][n_j] == 'X': stack.append((n_i, n_j)) solve() for i in range(n): print("".join(grid[i])) ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,615,248,249
2,147,483,647
Python 3
OK
TESTS
102
109
2,764,800
from operator import xor from typing import Callable, List, TypeVar, cast F = TypeVar("F", bound=Callable[[], None]) def my_decorator(func: F) -> F: def wrapper(): for _ in range(int(input("Times: "))): func() return cast(F, wrapper) def main() -> None: VALUES: List[str] = [input() for _ in range(2)] print(f"{xor(*(int(value,2)for value in VALUES)):b}".zfill(len(VALUES[0]))) if __name__ == "__main__": main()
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python from operator import xor from typing import Callable, List, TypeVar, cast F = TypeVar("F", bound=Callable[[], None]) def my_decorator(func: F) -> F: def wrapper(): for _ in range(int(input("Times: "))): func() return cast(F, wrapper) def main() -> None: VALUES: List[str] = [input() for _ in range(2)] print(f"{xor(*(int(value,2)for value in VALUES)):b}".zfill(len(VALUES[0]))) if __name__ == "__main__": main() ```
3.9676
548
A
Mike and Fax
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length. He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length.
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
[ "saba\n2\n", "saddastavvat\n2\n" ]
[ "NO\n", "YES\n" ]
Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
500
[ { "input": "saba\n2", "output": "NO" }, { "input": "saddastavvat\n2", "output": "YES" }, { "input": "aaaaaaaaaa\n3", "output": "NO" }, { "input": "aaaaaa\n3", "output": "YES" }, { "input": "abaacca\n2", "output": "NO" }, { "input": "a\n1", "output": "YES" }, { "input": "princeofpersia\n1", "output": "NO" }, { "input": "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqththlrdwnyklbrxallihyvasunlvrxdemnfyjzfkivqsqrdizpcbjecmxmcyvapirlgxaifyrodbwhx\n1", "output": "YES" }, { "input": "yfhqnbzaqeqmcvtsbcdn\n456", "output": "NO" }, { "input": "lgsdfiforlqrohhjyzrigewkigiiffvbyrapzmjvtkklndeyuqpuukajgtguhlarjdqlxksyekbjgrmhuyiqdlzjqqzlxufffpelyptodwhvkfbalxbufrlcsjgxmfxeqsszqghcustqrqjljattgvzynyvfbjgbuynbcguqtyfowgtcbbaywvcrgzrulqpghwoflutswu\n584", "output": "NO" }, { "input": "awlrhmxxivqbntvtapwkdkunamcqoerfncfmookhdnuxtttlxmejojpwbdyxirdsjippzjhdrpjepremruczbedxrjpodlyyldopjrxdebzcurmerpejprdhjzppijsdrixydbwpjojemxltttxundhkoomfcnfreoqcmanukdkwpatvtnbqvixxmhrlwa\n1", "output": "YES" }, { "input": "kafzpsglcpzludxojtdhzynpbekzssvhzizfrboxbhqvojiqtjitrackqccxgenwwnegxccqkcartijtqijovqhbxobrfzizhvsszkebpnyzhdtjoxdulzpclgspzfakvcbbjejeubvrrzlvjjgrcprntbyuakoxowoybbxgdugjffgbtfwrfiobifrshyaqqayhsrfiboifrwftbgffjgudgxbbyowoxokauybtnrpcrgjjvlzrrvbuejejbbcv\n2", "output": "YES" }, { "input": "zieqwmmbrtoxysvavwdemmdeatfrolsqvvlgphhhmojjfxfurtuiqdiilhlcwwqedlhblrzmvuoaczcwrqzyymiggpvbpkycibsvkhytrzhguksxyykkkvfljbbnjblylftmqxkojithwsegzsaexlpuicexbdzpwesrkzbqltxhifwqcehzsjgsqbwkujvjbjpqxdpmlimsusumizizpyigmkxwuberthdghnepyrxzvvidxeafwylegschhtywvqsxuqmsddhkzgkdiekodqpnftdyhnpicsnbhfxemxllvaurkmjvtrmqkulerxtaolmokiqqvqgechkqxmendpmgxwiaffcajmqjmvrwryzxujmiasuqtosuisiclnv\n8", "output": "NO" }, { "input": "syghzncbi\n829", "output": "NO" }, { "input": "ljpdpstntznciejqqtpysskztdfawuncqzwwfefrfsihyrdopwawowshquqnjhesxszuywezpebpzhtopgngrnqgwnoqhyrykojguybvdbjpfpmvkxscocywzsxcivysfrrzsonayztzzuybrkiombhqcfkszyscykzistiobrpavezedgobowjszfadcccmxyqehmkgywiwxffibzetb\n137", "output": "NO" }, { "input": "eytuqriplfczwsqlsnjetfpzehzvzayickkbnfqddaisfpasvigwtnvbybwultsgrtjbaebktvubwofysgidpufzteuhuaaqkhmhguockoczlrmlrrzouvqtwbcchxxiydbohnvrmtqjzhkfmvdulojhdvgwudvidpausvfujkjprxsobliuauxleqvsmz\n253", "output": "NO" }, { "input": "xkaqgwabuilhuqwhnrdtyattmqcjfbiqodjlwzgcyvghqncklbhnlmagvjvwysrfryrlmclninogumjfmyenkmydlmifxpkvlaapgnfarejaowftxxztshsesjtsgommaeslrhronruqdurvjesydrzmxirmxumrcqezznqltngsgdcthivdnjnshjfujtiqsltpttgbljfcbqsfwbzokciqlavrthgaqbzikpwwsebzwddlvdwrmztwmhcxdinwlbklwmteeybbdbzevfbsrtldapulwgusuvnreiflkytonzmervyrlbqhzapgxepwauaiwygpxarfeyqhimzlxntjuaaigeisgrvwgbhqemqetzyallzaoqprhzpjibkutgwrodruqu\n857", "output": "NO" }, { "input": "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwvdwatvjxaubtiwhgvrqwjhgfnauqegqmcwnaruinplmtmxhvohhqgvcatsdqiwkvslhqzqevdgdhpijjevuyuitnixdjhwlmjsstmugownjdhvxueg\n677", "output": "NO" }, { "input": "a\n3", "output": "NO" }, { "input": "aa\n2", "output": "YES" }, { "input": "abcaabca\n2", "output": "NO" }, { "input": "aaaaaaaaab\n5", "output": "NO" }, { "input": "aabbb\n3", "output": "NO" }, { "input": "abcde\n5", "output": "YES" }, { "input": "aabc\n2", "output": "NO" }, { "input": "aabcaa\n3", "output": "NO" } ]
1,657,257,121
2,147,483,647
Python 3
OK
TESTS
56
46
0
string = input() partskitnekarnehai = int(input()) if len(string)%partskitnekarnehai!=0: print('NO') exit() nayalength = len(string) // partskitnekarnehai # o is length of part for j in range(partskitnekarnehai): seedha_part = string[ j*nayalength : (j + 1)*nayalength] # print(seedha_part) ulta_part=reversed(seedha_part) # print("".join(ulta_part)) if seedha_part != "".join(ulta_part): print("NO") exit() print("YES") ''' https://codeforces.com/problemset/problem/548/A 1. Aaj exit() seekha, kaafi useful, i always thought agar aise kuch karna hai to i'll have to define a function, fir use return to get out of the code. 4. Abe yaar mai bhi kya gadha hu, like agar NO hai answer, to exit karna chahiye, i exited on YES wala case 3. Are bhai yaaar wo sabse upar wala block mai bhool hi gaya tha, gahdam ek aur wrong submission 2. Also line 7 me agar -1 kia to it only check first part of string '''
Title: Mike and Fax Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length. He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. Input Specification: The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). Output Specification: Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. Demo Input: ['saba\n2\n', 'saddastavvat\n2\n'] Demo Output: ['NO\n', 'YES\n'] Note: Palindrome is a string reading the same forward and backward. In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
```python string = input() partskitnekarnehai = int(input()) if len(string)%partskitnekarnehai!=0: print('NO') exit() nayalength = len(string) // partskitnekarnehai # o is length of part for j in range(partskitnekarnehai): seedha_part = string[ j*nayalength : (j + 1)*nayalength] # print(seedha_part) ulta_part=reversed(seedha_part) # print("".join(ulta_part)) if seedha_part != "".join(ulta_part): print("NO") exit() print("YES") ''' https://codeforces.com/problemset/problem/548/A 1. Aaj exit() seekha, kaafi useful, i always thought agar aise kuch karna hai to i'll have to define a function, fir use return to get out of the code. 4. Abe yaar mai bhi kya gadha hu, like agar NO hai answer, to exit karna chahiye, i exited on YES wala case 3. Are bhai yaaar wo sabse upar wala block mai bhool hi gaya tha, gahdam ek aur wrong submission 2. Also line 7 me agar -1 kia to it only check first part of string ''' ```
3
411
A
Password Check
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check. Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: - the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q.
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n" ]
none
0
[ { "input": "abacaba", "output": "Too weak" }, { "input": "X12345", "output": "Too weak" }, { "input": "CONTEST_is_STARTED!!11", "output": "Correct" }, { "input": "1zA__", "output": "Correct" }, { "input": "1zA_", "output": "Too weak" }, { "input": "zA___", "output": "Too weak" }, { "input": "1A___", "output": "Too weak" }, { "input": "z1___", "output": "Too weak" }, { "input": "0", "output": "Too weak" }, { "input": "_", "output": "Too weak" }, { "input": "a", "output": "Too weak" }, { "input": "D", "output": "Too weak" }, { "input": "_", "output": "Too weak" }, { "input": "?", "output": "Too weak" }, { "input": "?", "output": "Too weak" }, { "input": "._,.!.,...?_,!.", "output": "Too weak" }, { "input": "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.", "output": "Too weak" }, { "input": "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!", "output": "Too weak" }, { "input": "XZX", "output": "Too weak" }, { "input": "R", "output": "Too weak" }, { "input": "H.FZ", "output": "Too weak" }, { "input": "KSHMICWPK,LSBM_JVZ!IPDYDG_GOPCHXFJTKJBIFY,FPHMY,CB?PZEAG..,X,.GFHPIDBB,IQ?MZ", "output": "Too weak" }, { "input": "EFHI,,Y?HMMUI,,FJGAY?FYPBJQMYM!DZHLFCTFWT?JOPDW,S_!OR?ATT?RWFBMAAKUHIDMHSD?LCZQY!UD_CGYGBAIRDPICYS", "output": "Too weak" }, { "input": "T,NDMUYCCXH_L_FJHMCCAGX_XSCPGOUZSY?D?CNDSYRITYS,VAT!PJVKNTBMXGGRYKACLYU.RJQ_?UWKXYIDE_AE", "output": "Too weak" }, { "input": "y", "output": "Too weak" }, { "input": "qgw", "output": "Too weak" }, { "input": "g", "output": "Too weak" }, { "input": "loaray", "output": "Too weak" }, { "input": "d_iymyvxolmjayhwpedocopqwmy.oalrdg!_n?.lrxpamhygps?kkzxydsbcaihfs.j?eu!oszjsy.vzu?!vs.bprz_j", "output": "Too weak" }, { "input": "txguglvclyillwnono", "output": "Too weak" }, { "input": "FwX", "output": "Too weak" }, { "input": "Zi", "output": "Too weak" }, { "input": "PodE", "output": "Too weak" }, { "input": "SdoOuJ?nj_wJyf", "output": "Too weak" }, { "input": "MhnfZjsUyXYw?f?ubKA", "output": "Too weak" }, { "input": "CpWxDVzwHfYFfoXNtXMFuAZr", "output": "Too weak" }, { "input": "9.,0", "output": "Too weak" }, { "input": "5,8", "output": "Too weak" }, { "input": "7", "output": "Too weak" }, { "input": "34__39_02!,!,82!129!2!566", "output": "Too weak" }, { "input": "96156027.65935663!_87!,44,..7914_!0_1,.4!!62!.8350!17_282!!9.2584,!!7__51.526.7", "output": "Too weak" }, { "input": "90328_", "output": "Too weak" }, { "input": "B9", "output": "Too weak" }, { "input": "P1H", "output": "Too weak" }, { "input": "J2", "output": "Too weak" }, { "input": "M6BCAKW!85OSYX1D?.53KDXP42F", "output": "Too weak" }, { "input": "C672F429Y8X6XU7S,.K9111UD3232YXT81S4!729ER7DZ.J7U1R_7VG6.FQO,LDH", "output": "Too weak" }, { "input": "W2PI__!.O91H8OFY6AB__R30L9XOU8800?ZUD84L5KT99818NFNE35V.8LJJ5P2MM.B6B", "output": "Too weak" }, { "input": "z1", "output": "Too weak" }, { "input": "p1j", "output": "Too weak" }, { "input": "j9", "output": "Too weak" }, { "input": "v8eycoylzv0qkix5mfs_nhkn6k!?ovrk9!b69zy!4frc?k", "output": "Too weak" }, { "input": "l4!m_44kpw8.jg!?oh,?y5oraw1tg7_x1.osl0!ny?_aihzhtt0e2!mr92tnk0es!1f,9he40_usa6c50l", "output": "Too weak" }, { "input": "d4r!ak.igzhnu!boghwd6jl", "output": "Too weak" }, { "input": "It0", "output": "Too weak" }, { "input": "Yb1x", "output": "Too weak" }, { "input": "Qf7", "output": "Too weak" }, { "input": "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te", "output": "Correct" }, { "input": "Ka4hGE,vkvNQbNolnfwp", "output": "Correct" }, { "input": "Ee9oluD?amNItsjeQVtOjwj4w_ALCRh7F3eaZah", "output": "Correct" }, { "input": "Um3Fj?QLhNuRE_Gx0cjMLOkGCm", "output": "Correct" }, { "input": "Oq2LYmV9HmlaW", "output": "Correct" }, { "input": "Cq7r3Wrb.lDb_0wsf7!ruUUGSf08RkxD?VsBEDdyE?SHK73TFFy0f8gmcATqGafgTv8OOg8or2HyMPIPiQ2Hsx8q5rn3_WZe", "output": "Correct" }, { "input": "Wx4p1fOrEMDlQpTlIx0p.1cnFD7BnX2K8?_dNLh4cQBx_Zqsv83BnL5hGKNcBE9g3QB,!fmSvgBeQ_qiH7", "output": "Correct" }, { "input": "k673,", "output": "Too weak" }, { "input": "LzuYQ", "output": "Too weak" }, { "input": "Pasq!", "output": "Too weak" }, { "input": "x5hve", "output": "Too weak" }, { "input": "b27fk", "output": "Too weak" }, { "input": "h6y1l", "output": "Too weak" }, { "input": "i9nij", "output": "Too weak" }, { "input": "Gf5Q6", "output": "Correct" }, { "input": "Uf24o", "output": "Correct" }, { "input": "Oj9vu", "output": "Correct" }, { "input": "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr", "output": "Too weak" }, { "input": "i6a.,8jb,n0kv4.1!7h?p.96pnhhgy6cl7dg7e4o6o384ys3z.t71kkq,,w,oqi4?u,,m5!rzu6wym_4hm,ohjy!.vvksl?pt,,1", "output": "Too weak" }, { "input": "M10V_MN_1K8YX2LA!89EYV7!5V9?,.IDHDP6JEC.OGLY.180LMZ6KW3Z5E17IT94ZNHS!79GN09Q6LH0,F3AYNKP?KM,QP_?XRD6", "output": "Too weak" }, { "input": "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f", "output": "Correct" }, { "input": "Bk2Q38vDSW5JqYu.077iYC.9YoiPc!Dh6FJWOVze6?YXiFjPNa4F1RG?154m9mY2jQobBnbxM,cDV8l1UX1?v?p.tTYIyJO!NYmE", "output": "Correct" }, { "input": "Ro1HcZ.piN,JRR88DLh,WtW!pbFM076?wCSbqfK7N2s5zUySFBtzk7HV,BxHXR0zALAr016z5jvvB.WUdEcKgYFav5TygwHQC..C", "output": "Correct" }, { "input": "!?.,_", "output": "Too weak" } ]
1,618,994,030
2,147,483,647
Python 3
OK
TESTS
81
93
819,200
import string def selection_sort(l): for i in range(len(l)): min_val = l[i] min_val_index = i for j in range(i, len(l)): if l[j] < min_val: min_val = l[j] min_val_index = j l[i], l[min_val_index] = l[min_val_index], l[i] return l def merge_sort(l): def merge(l1, l2): output_list = [] i, j = 0, 0 while i < len(l1) and j < len(l2): if l1[i] < l2[j]: output_list.append(l1[i]) i += 1 else: output_list.append(l2[j]) j += 1 if i == len(l1): output_list += l2[j:] else: output_list += l1[i:] return output_list def sort(li): if len(li) < 2: return li mid = len(li) // 2 left = sort(li[:mid]) right = sort(li[mid:]) return merge(left, right) return sort(l) def main_function(): is_len_greater_than_5 = False does_contain_digit = False does_contain_upper = False does_contain_lower = False password = input() if len(password) >= 5: is_len_greater_than_5 = True for i in password: if i.isdigit(): does_contain_digit = True elif i.isupper(): does_contain_upper = True elif i.islower(): does_contain_lower = True if is_len_greater_than_5 and does_contain_lower and does_contain_upper and does_contain_digit: return "Correct" return "Too weak" print(main_function())
Title: Password Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check. Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: - the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q. Input Specification: The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". Output Specification: If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). Demo Input: ['abacaba\n', 'X12345\n', 'CONTEST_is_STARTED!!11\n'] Demo Output: ['Too weak\n', 'Too weak\n', 'Correct\n'] Note: none
```python import string def selection_sort(l): for i in range(len(l)): min_val = l[i] min_val_index = i for j in range(i, len(l)): if l[j] < min_val: min_val = l[j] min_val_index = j l[i], l[min_val_index] = l[min_val_index], l[i] return l def merge_sort(l): def merge(l1, l2): output_list = [] i, j = 0, 0 while i < len(l1) and j < len(l2): if l1[i] < l2[j]: output_list.append(l1[i]) i += 1 else: output_list.append(l2[j]) j += 1 if i == len(l1): output_list += l2[j:] else: output_list += l1[i:] return output_list def sort(li): if len(li) < 2: return li mid = len(li) // 2 left = sort(li[:mid]) right = sort(li[mid:]) return merge(left, right) return sort(l) def main_function(): is_len_greater_than_5 = False does_contain_digit = False does_contain_upper = False does_contain_lower = False password = input() if len(password) >= 5: is_len_greater_than_5 = True for i in password: if i.isdigit(): does_contain_digit = True elif i.isupper(): does_contain_upper = True elif i.islower(): does_contain_lower = True if is_len_greater_than_5 and does_contain_lower and does_contain_upper and does_contain_digit: return "Correct" return "Too weak" print(main_function()) ```
3
755
C
PolandBall and Forest
PROGRAMMING
1,300
[ "dfs and similar", "dsu", "graphs", "interactive", "trees" ]
null
null
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree. There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to *n*. For each Ball *i* we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those. How many trees are there in the forest?
The first line contains single integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls living in the forest. The second line contains a sequence *p*1,<=*p*2,<=...,<=*p**n* of length *n*, where (1<=≤<=*p**i*<=≤<=*n*) holds and *p**i* denotes the most distant from Ball *i* relative living on the same tree. If there are several most distant relatives living on the same tree, *p**i* is the id of one with the smallest id. It's guaranteed that the sequence *p* corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence *p* will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls and the integer *m* (0<=≤<=*m*<=&lt;<=*n*) — the total number of edges in the forest. Then *m* lines should follow. The *i*-th of them should contain two integers *a**i* and *b**i* and represent an edge between vertices in which relatives *a**i* and *b**i* live. For example, the first sample is written as follows:
You should output the number of trees in the forest where PolandBall lives.
[ "5\n2 1 5 3 3", "1\n1\n" ]
[ "2", "1" ]
In the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall. In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
1,500
[ { "input": "5 3\n1 2\n3 4\n4 5", "output": "2" }, { "input": "1 0", "output": "1" }, { "input": "5 1\n4 5", "output": "4" }, { "input": "10 3\n2 8\n5 9\n6 10", "output": "7" }, { "input": "18 2\n9 17\n1 18", "output": "16" }, { "input": "1 0", "output": "1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "3 1\n2 3", "output": "2" }, { "input": "3 2\n1 2\n2 3", "output": "1" }, { "input": "3 0", "output": "3" }, { "input": "10000 1\n1725 10000", "output": "9999" }, { "input": "5 4\n1 3\n1 4\n4 2\n5 2", "output": "1" }, { "input": "4 3\n3 1\n1 2\n2 4", "output": "1" }, { "input": "5 4\n3 2\n2 5\n5 1\n1 4", "output": "1" }, { "input": "5 4\n1 2\n1 3\n1 4\n3 5", "output": "1" }, { "input": "6 5\n1 4\n2 3\n3 4\n4 5\n5 6", "output": "1" } ]
1,629,203,300
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
77
8,089,600
# Problem: C. PolandBall and Forest # Contest: Codeforces - 8VC Venture Cup 2017 - Elimination Round # URL: https://codeforces.com/contest/755/problem/C # Memory Limit: 256 MB # Time Limit: 1000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) from sys import stdin def get_ints(): return list(map(int, stdin.readline().strip().split())) class DSU: def __init__(self, n): # Constructor to create and # initialize sets of n items self.rank = [1] * n self.parent = [i for i in range(n)] # Finds set of given item x def find(self, x): # Finds the representative of the set # that x is an element of if (self.parent[x] != x): # if x is not the parent of itself # Then x is not the representative of # its set, self.parent[x] = self.find(self.parent[x]) # so we recursively call Find on its parent # and move i's node directly under the # representative of this set return self.parent[x] # Do union of two sets represented # by x and y. def Union(self, x, y): # Find current sets of x and y xset = self.find(x) yset = self.find(y) # If they are already in same set if xset == yset: return # Put smaller ranked item under # bigger ranked item if ranks are # different if self.rank[xset] < self.rank[yset]: self.parent[xset] = yset elif self.rank[xset] > self.rank[yset]: self.parent[yset] = xset # If ranks are same, then move y under # x (doesn't matter which one goes where) # and increment rank of x's tree else: self.parent[yset] = xset self.rank[xset] = self.rank[xset] + 1 n = int(input()) dsu = DSU(n) ar = get_ints() for i in range(n): dsu.Union(i,ar[i]-1) print(len(set(dsu.parent)))
Title: PolandBall and Forest Time Limit: None seconds Memory Limit: None megabytes Problem Description: PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with *k* vertices and *k*<=-<=1 edges, where *k* is some integer. Note that one vertex is a valid tree. There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to *n*. For each Ball *i* we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those. How many trees are there in the forest? Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls living in the forest. The second line contains a sequence *p*1,<=*p*2,<=...,<=*p**n* of length *n*, where (1<=≤<=*p**i*<=≤<=*n*) holds and *p**i* denotes the most distant from Ball *i* relative living on the same tree. If there are several most distant relatives living on the same tree, *p**i* is the id of one with the smallest id. It's guaranteed that the sequence *p* corresponds to some valid forest. Hacking: To hack someone, you should provide a correct forest as a test. The sequence *p* will be calculated according to the forest and given to the solution you try to hack as input. Use the following format: In the first line, output the integer *n* (1<=≤<=*n*<=≤<=104) — the number of Balls and the integer *m* (0<=≤<=*m*<=&lt;<=*n*) — the total number of edges in the forest. Then *m* lines should follow. The *i*-th of them should contain two integers *a**i* and *b**i* and represent an edge between vertices in which relatives *a**i* and *b**i* live. For example, the first sample is written as follows: Output Specification: You should output the number of trees in the forest where PolandBall lives. Demo Input: ['5\n2 1 5 3 3', '1\n1\n'] Demo Output: ['2', '1'] Note: In the first sample testcase, possible forest is: 1-2 3-4-5. There are 2 trees overall. In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.
```python # Problem: C. PolandBall and Forest # Contest: Codeforces - 8VC Venture Cup 2017 - Elimination Round # URL: https://codeforces.com/contest/755/problem/C # Memory Limit: 256 MB # Time Limit: 1000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) from sys import stdin def get_ints(): return list(map(int, stdin.readline().strip().split())) class DSU: def __init__(self, n): # Constructor to create and # initialize sets of n items self.rank = [1] * n self.parent = [i for i in range(n)] # Finds set of given item x def find(self, x): # Finds the representative of the set # that x is an element of if (self.parent[x] != x): # if x is not the parent of itself # Then x is not the representative of # its set, self.parent[x] = self.find(self.parent[x]) # so we recursively call Find on its parent # and move i's node directly under the # representative of this set return self.parent[x] # Do union of two sets represented # by x and y. def Union(self, x, y): # Find current sets of x and y xset = self.find(x) yset = self.find(y) # If they are already in same set if xset == yset: return # Put smaller ranked item under # bigger ranked item if ranks are # different if self.rank[xset] < self.rank[yset]: self.parent[xset] = yset elif self.rank[xset] > self.rank[yset]: self.parent[yset] = xset # If ranks are same, then move y under # x (doesn't matter which one goes where) # and increment rank of x's tree else: self.parent[yset] = xset self.rank[xset] = self.rank[xset] + 1 n = int(input()) dsu = DSU(n) ar = get_ints() for i in range(n): dsu.Union(i,ar[i]-1) print(len(set(dsu.parent))) ```
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,603,101,859
2,147,483,647
Python 3
OK
TESTS
36
218
0
m = max(list(map(int,input().split()))) if m==1: print('1/1') elif m==2: print('5/6') elif m==3: print('2/3') elif m==4: print('1/2') elif m==5: print('1/3') else: print('1/6')
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python m = max(list(map(int,input().split()))) if m==1: print('1/1') elif m==2: print('5/6') elif m==3: print('2/3') elif m==4: print('1/2') elif m==5: print('1/3') else: print('1/6') ```
3.891
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,696,536,861
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
17,408,000
from sys import stdin, stdout def input(): return stdin.readline().strip() def print(string): return stdout.write(str(string) + "\n") def main(): n, v, p = int(input()), 0, 0 a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] for i in range(m): bi = a.index(b[i]) v += bi + 1 p += n - bi print(f"{v} {p}") if __name__ == "__main__": main()
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python from sys import stdin, stdout def input(): return stdin.readline().strip() def print(string): return stdout.write(str(string) + "\n") def main(): n, v, p = int(input()), 0, 0 a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] for i in range(m): bi = a.index(b[i]) v += bi + 1 p += n - bi print(f"{v} {p}") if __name__ == "__main__": main() ```
0
225
B
Well-known Numbers
PROGRAMMING
1,600
[ "binary search", "greedy", "number theory" ]
null
null
Numbers *k*-bonacci (*k* is integer, *k*<=&gt;<=1) are a generalization of Fibonacci numbers and are determined as follows: - *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=&lt;<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), for integer *n*, *n*<=&gt;<=*k*. Note that we determine the *k*-bonacci numbers, *F*(*k*,<=*n*), only for integer values of *n* and *k*. You've got a number *s*, represent it as a sum of several (at least two) distinct *k*-bonacci numbers.
The first line contains two integers *s* and *k* (1<=≤<=*s*,<=*k*<=≤<=109; *k*<=&gt;<=1).
In the first line print an integer *m* (*m*<=≥<=2) that shows how many numbers are in the found representation. In the second line print *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m*. Each printed integer should be a *k*-bonacci number. The sum of printed integers must equal *s*. It is guaranteed that the answer exists. If there are several possible answers, print any of them.
[ "5 2\n", "21 5\n" ]
[ "3\n0 2 3\n", "3\n4 1 16\n" ]
none
1,000
[ { "input": "5 2", "output": "3\n0 2 3" }, { "input": "21 5", "output": "3\n4 1 16" }, { "input": "1 1000", "output": "2\n1 0 " }, { "input": "1000000000 1000000000", "output": "14\n536870912 268435456 134217728 33554432 16777216 8388608 1048576 524288 131072 32768 16384 2048 512 0 " }, { "input": "122 7", "output": "6\n64 32 16 8 2 0 " }, { "input": "4 3", "output": "2\n4 0 " }, { "input": "321123 3211232", "output": "11\n262144 32768 16384 8192 1024 512 64 32 2 1 0 " }, { "input": "1 2", "output": "2\n1 0 " }, { "input": "2 2", "output": "2\n2 0 " }, { "input": "3 2", "output": "2\n3 0 " }, { "input": "8 2", "output": "2\n8 0 " }, { "input": "17 2", "output": "4\n13 3 1 0 " }, { "input": "137 2", "output": "5\n89 34 13 1 0 " }, { "input": "7298 2", "output": "7\n6765 377 144 8 3 1 0 " }, { "input": "76754 2", "output": "7\n75025 1597 89 34 8 1 0 " }, { "input": "12345678 2", "output": "8\n9227465 2178309 832040 75025 28657 4181 1 0 " }, { "input": "987654321 2", "output": "16\n701408733 267914296 14930352 2178309 832040 317811 46368 17711 6765 1597 233 89 13 3 1 0 " }, { "input": "1000000000 2", "output": "15\n701408733 267914296 24157817 5702887 514229 196418 75025 28657 1597 233 89 13 5 1 0 " }, { "input": "701408733 2", "output": "2\n701408733 0 " }, { "input": "1 3", "output": "2\n1 0 " }, { "input": "2 3", "output": "2\n2 0 " }, { "input": "3 3", "output": "3\n2 1 0 " }, { "input": "100 3", "output": "5\n81 13 4 2 0 " }, { "input": "87783 3", "output": "8\n66012 19513 1705 504 44 4 1 0 " }, { "input": "615693473 3", "output": "23\n334745777 181997601 53798080 29249425 8646064 4700770 1389537 755476 223317 121415 35890 19513 5768 3136 927 504 149 81 24 13 4 2 0 " }, { "input": "615693474 3", "output": "2\n615693474 0 " }, { "input": "1000000000 3", "output": "15\n615693474 334745777 29249425 15902591 2555757 1389537 410744 35890 10609 5768 274 149 4 1 0 " }, { "input": "1 4", "output": "2\n1 0 " }, { "input": "2 4", "output": "2\n2 0 " }, { "input": "17 4", "output": "3\n15 2 0 " }, { "input": "234 4", "output": "6\n208 15 8 2 1 0 " }, { "input": "23435345 4", "output": "13\n14564533 7555935 1055026 147312 76424 20569 10671 2872 1490 401 108 4 0 " }, { "input": "989464701 4", "output": "18\n747044834 201061985 28074040 7555935 3919944 1055026 547337 147312 39648 10671 5536 1490 773 108 56 4 2 0 " }, { "input": "464 5", "output": "2\n464 0 " }, { "input": "7647474 5", "output": "8\n5976577 1546352 103519 13624 6930 464 8 0 " }, { "input": "457787655 5", "output": "14\n345052351 89277256 23099186 203513 103519 26784 13624 6930 3525 912 31 16 8 0 " }, { "input": "764747 6", "output": "13\n463968 233904 59448 3840 1936 976 492 125 32 16 8 2 0 " }, { "input": "980765665 7", "output": "16\n971364608 7805695 987568 495776 62725 31489 15808 1004 504 253 127 64 32 8 4 0 " }, { "input": "877655444 8", "output": "17\n512966536 256993248 64504063 32316160 8111200 2035872 510994 128257 64256 16128 8080 509 128 8 4 1 0 " }, { "input": "567886500 9", "output": "11\n525375999 32965728 8257696 1035269 129792 64960 32512 16272 8144 128 0 " }, { "input": "656777660 10", "output": "13\n531372800 66519472 33276064 16646200 8327186 521472 65280 32656 16336 128 64 2 0 " }, { "input": "197445609 11", "output": "18\n133628064 33423378 16715781 8359937 4180992 1045760 65424 16364 8184 1024 512 128 32 16 8 4 1 0 " }, { "input": "647474474 12", "output": "18\n535625888 66977797 33492993 8375296 2094336 523712 261888 65488 32748 16376 4095 2048 1024 512 256 16 1 0 " }, { "input": "856644446 14", "output": "16\n536592385 268304384 33541120 16771072 1048320 262096 65528 32765 16383 8192 2048 128 16 8 1 0 " }, { "input": "980345678 19", "output": "18\n536864768 268432640 134216448 33554176 4194284 2097144 524287 262144 131072 65536 2048 1024 64 32 8 2 1 0 " }, { "input": "561854567 23", "output": "17\n536870656 16777213 4194304 2097152 1048576 524288 262144 65536 8192 4096 2048 256 64 32 8 2 0 " }, { "input": "987654321 27", "output": "20\n536870904 268435453 134217727 33554432 8388608 4194304 1048576 524288 262144 131072 16384 8192 2048 128 32 16 8 4 1 0 " }, { "input": "780787655 29", "output": "18\n536870911 134217728 67108864 33554432 8388608 524288 65536 32768 16384 4096 2048 1024 512 256 128 64 8 0 " }, { "input": "999999999 30", "output": "22\n536870912 268435456 134217728 33554432 16777216 8388608 1048576 524288 131072 32768 16384 2048 256 128 64 32 16 8 4 2 1 0 " }, { "input": "1 50", "output": "2\n1 0 " }, { "input": "5 54", "output": "3\n4 1 0 " }, { "input": "378 83", "output": "7\n256 64 32 16 8 2 0 " }, { "input": "283847 111", "output": "10\n262144 16384 4096 1024 128 64 4 2 1 0 " }, { "input": "38746466 2847", "output": "14\n33554432 4194304 524288 262144 131072 65536 8192 4096 2048 256 64 32 2 0 " }, { "input": "83768466 12345", "output": "15\n67108864 8388608 4194304 2097152 1048576 524288 262144 131072 8192 4096 1024 128 16 2 0 " }, { "input": "987654321 7475657", "output": "18\n536870912 268435456 134217728 33554432 8388608 4194304 1048576 524288 262144 131072 16384 8192 2048 128 32 16 1 0 " }, { "input": "10 174764570", "output": "3\n8 2 0 " }, { "input": "967755664 974301345", "output": "17\n536870912 268435456 134217728 16777216 8388608 2097152 524288 262144 131072 32768 16384 1024 512 256 128 16 0 " }, { "input": "76 758866446", "output": "4\n64 8 4 0 " }, { "input": "1 1000000000", "output": "2\n1 0 " }, { "input": "469766205 719342208", "output": "10\n268435456 134217728 67108864 4096 32 16 8 4 1 0 " }, { "input": "918938066 77", "output": "17\n536870912 268435456 67108864 33554432 8388608 4194304 262144 65536 32768 16384 8192 256 128 64 16 2 0 " }, { "input": "856089381 19", "output": "15\n536864768 268432640 33554176 16777104 262144 131072 65536 1024 512 256 128 16 4 1 0 " }, { "input": "152235195 16", "output": "16\n134204416 16775936 1048528 131069 65535 8192 1024 256 128 64 32 8 4 2 1 0 " }, { "input": "429960894 3101", "output": "17\n268435456 134217728 16777216 8388608 2097152 32768 8192 2048 1024 512 128 32 16 8 4 2 0 " }, { "input": "450695564 7", "output": "18\n244804400 122895984 61695880 15548665 3918592 987568 495776 248888 62725 31489 3984 1004 504 64 32 8 1 0 " }, { "input": "154517270 24", "output": "18\n134217708 16777215 2097152 1048576 262144 65536 32768 8192 4096 2048 1024 512 256 32 8 2 1 0 " }, { "input": "300919980 24", "output": "20\n268435408 16777215 8388608 4194304 2097152 524288 262144 131072 65536 32768 8192 2048 1024 128 64 16 8 4 1 0 " }, { "input": "900077555 2", "output": "16\n701408733 165580141 24157817 5702887 2178309 832040 196418 17711 2584 610 233 55 13 3 1 0 " }, { "input": "172285923 26", "output": "17\n134217725 33554432 4194304 262144 32768 16384 4096 2048 1024 512 256 128 64 32 4 2 0 " } ]
1,642,937,340
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
s = input().split() (m,k) = (int(i) for i in s) a = [0 for i in range(k-1)] a.append(1) i = 0 #print(a[-1],m) while(a[-1] <= m): a.append(sum(a[i:i+k])) i += 1 res = [] res.append(a[-2]) m -= a[-2] while(m>0): if(m in a): res.append(m) m = 0 else: res.append(1) m -= 1 print(len(res)) res = res[::-1] for i in range(len(res)): print(res[i], end = ' ')
Title: Well-known Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Numbers *k*-bonacci (*k* is integer, *k*<=&gt;<=1) are a generalization of Fibonacci numbers and are determined as follows: - *F*(*k*,<=*n*)<==<=0, for integer *n*, 1<=≤<=*n*<=&lt;<=*k*; - *F*(*k*,<=*k*)<==<=1; - *F*(*k*,<=*n*)<==<=*F*(*k*,<=*n*<=-<=1)<=+<=*F*(*k*,<=*n*<=-<=2)<=+<=...<=+<=*F*(*k*,<=*n*<=-<=*k*), for integer *n*, *n*<=&gt;<=*k*. Note that we determine the *k*-bonacci numbers, *F*(*k*,<=*n*), only for integer values of *n* and *k*. You've got a number *s*, represent it as a sum of several (at least two) distinct *k*-bonacci numbers. Input Specification: The first line contains two integers *s* and *k* (1<=≤<=*s*,<=*k*<=≤<=109; *k*<=&gt;<=1). Output Specification: In the first line print an integer *m* (*m*<=≥<=2) that shows how many numbers are in the found representation. In the second line print *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m*. Each printed integer should be a *k*-bonacci number. The sum of printed integers must equal *s*. It is guaranteed that the answer exists. If there are several possible answers, print any of them. Demo Input: ['5 2\n', '21 5\n'] Demo Output: ['3\n0 2 3\n', '3\n4 1 16\n'] Note: none
```python s = input().split() (m,k) = (int(i) for i in s) a = [0 for i in range(k-1)] a.append(1) i = 0 #print(a[-1],m) while(a[-1] <= m): a.append(sum(a[i:i+k])) i += 1 res = [] res.append(a[-2]) m -= a[-2] while(m>0): if(m in a): res.append(m) m = 0 else: res.append(1) m -= 1 print(len(res)) res = res[::-1] for i in range(len(res)): print(res[i], end = ' ') ```
0
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "2", "output": "22" }, { "input": "3", "output": "33" }, { "input": "4", "output": "44" }, { "input": "5", "output": "55" }, { "input": "6", "output": "66" }, { "input": "7", "output": "77" }, { "input": "8", "output": "88" }, { "input": "9", "output": "99" }, { "input": "13", "output": "1331" }, { "input": "14", "output": "1441" }, { "input": "15", "output": "1551" }, { "input": "16", "output": "1661" }, { "input": "17", "output": "1771" }, { "input": "18", "output": "1881" }, { "input": "19", "output": "1991" }, { "input": "20", "output": "2002" }, { "input": "26550", "output": "2655005562" }, { "input": "16137", "output": "1613773161" }, { "input": "91471", "output": "9147117419" }, { "input": "41242", "output": "4124224214" }, { "input": "30866", "output": "3086666803" }, { "input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444" }, { "input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252", "output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087" }, { "input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913", "output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422" }, { "input": "123451", "output": "123451154321" } ]
1,672,745,218
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n=input() print(n+n[-1:])
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). Output Specification: Print the *n*-th even-length palindrome number. Demo Input: ['1\n', '10\n'] Demo Output: ['11\n', '1001\n'] Note: The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
```python n=input() print(n+n[-1:]) ```
0
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "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" }, { "input": "4\n82 46 8 44", "output": "3 1\n4 2" }, { "input": "2\n35 50", "output": "1 2" }, { "input": "8\n24 39 49 38 44 64 44 50", "output": "1 6\n4 8\n2 3\n5 7" }, { "input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14", "output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15" }, { "input": "12\n22 83 2 67 55 12 40 93 83 73 12 28", "output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5" }, { "input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43", "output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7" }, { "input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58", "output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16" }, { "input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62", "output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12" }, { "input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76", "output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3" }, { "input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8", "output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5" }, { "input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41", "output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36" }, { "input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55", "output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12" }, { "input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25", "output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27" }, { "input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30", "output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10" }, { "input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39", "output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32" }, { "input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26", "output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54" }, { "input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30", "output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10" }, { "input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18", "output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34" }, { "input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65", "output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53" }, { "input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50", "output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14" }, { "input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57", "output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7" }, { "input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49", "output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24" }, { "input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69", "output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9" }, { "input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57", "output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20" }, { "input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34", "output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11" }, { "input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43", "output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3" }, { "input": "4\n100 100 1 1", "output": "3 2\n4 1" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "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" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "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" }, { "input": "4\n3 4 4 5", "output": "1 4\n2 3" }, { "input": "4\n1 1 2 2", "output": "1 4\n2 3" }, { "input": "4\n1 2 3 4", "output": "1 4\n2 3" } ]
1,570,361,214
2,147,483,647
Python 3
OK
TESTS
35
109
0
n=int(input()) l=list(map(int,input().split())) a=[] for q in range(n): a.append([l[q],q]) a.sort() for q in range(n//2): print(a[q][1]+1,a[n-q-1][1]+1)
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one 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 Specification: 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 Specification: 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. Demo Input: ['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n'] Demo Output: ['1 3\n6 2\n4 5\n', '1 2\n3 4\n'] 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*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
```python n=int(input()) l=list(map(int,input().split())) a=[] for q in range(n): a.append([l[q],q]) a.sort() for q in range(n//2): print(a[q][1]+1,a[n-q-1][1]+1) ```
3
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integer — the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { "input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600", "output": "94" }, { "input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600", "output": "1" }, { "input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12", "output": "13" }, { "input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391", "output": "33" }, { "input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3", "output": "3" }, { "input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55", "output": "93" }, { "input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13", "output": "13" }, { "input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1", "output": "1" }, { "input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37", "output": "61" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 600", "output": "1" }, { "input": "4\n1 1 1 2", "output": "2" }, { "input": "4\n0 0 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "2\n0 5", "output": "1" }, { "input": "5\n1 0 0 1 2", "output": "2" } ]
1,671,085,105
2,147,483,647
Python 3
OK
TESTS
21
46
0
n=int(input()) a=list(map(int,input().split())) sa=set(a) arr=list(sa) count=0 for i in sa: if i!=0: count+=1 print(count)
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. Output Specification: Print a single integer — the desired number of ways. Demo Input: ['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n'] Demo Output: ['3\n', '1\n', '1\n'] Note: There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
```python n=int(input()) a=list(map(int,input().split())) sa=set(a) arr=list(sa) count=0 for i in sa: if i!=0: count+=1 print(count) ```
3
990
B
Micro-World
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Print the only integer — minimal possible number of bacteria can remain.
[ "7 1\n101 53 42 102 101 55 54\n", "6 5\n20 15 10 15 20 25\n", "7 1000000\n1 1 1 1 1 1 1\n" ]
[ "3\n", "1\n", "7\n" ]
The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
0
[ { "input": "7 1\n101 53 42 102 101 55 54", "output": "3" }, { "input": "6 5\n20 15 10 15 20 25", "output": "1" }, { "input": "7 1000000\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 4\n8", "output": "1" }, { "input": "10 1\n1 2 3 5 6 8 10 11 9 4", "output": "2" }, { "input": "9 2\n1 6 1 5 5 8 6 8 7", "output": "4" }, { "input": "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "2 1000000\n1 1000000", "output": "1" }, { "input": "7 2\n1 5 5 8 9 8 8", "output": "4" }, { "input": "10 1\n2 6 3 4 2 4 4 3 2 1", "output": "4" }, { "input": "4 1\n2 2 1 1", "output": "2" }, { "input": "10 1\n6 3 1 3 6 4 1 3 6 4", "output": "7" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "8 2\n3 13 9 8 3 13 9 14", "output": "5" }, { "input": "8 1000000\n1 1 5 1000000 1000000 2 2 2", "output": "2" }, { "input": "2 1\n999152 999153", "output": "1" } ]
1,553,015,310
2,147,483,647
Python 3
OK
TESTS
36
358
14,643,200
n, K = map(int, input().split()) a = sorted(list(map(int, input().split()))) num = 0 for i in a: while a[num] < i: if i <= K+a[num]: n-=1 num += 1 print(n)
Title: Micro-World Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. Input Specification: The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. Output Specification: Print the only integer — minimal possible number of bacteria can remain. Demo Input: ['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n'] Demo Output: ['3\n', '1\n', '7\n'] Note: The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
```python n, K = map(int, input().split()) a = sorted(list(map(int, input().split()))) num = 0 for i in a: while a[num] < i: if i <= K+a[num]: n-=1 num += 1 print(n) ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,688,908,307
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
t=int(input()) for i in range(t): w=input("") l=len(w) s=w[1:l-1] print("word")if l<=10 else print(w[0]+str(len(s))+w[l-1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python t=int(input()) for i in range(t): w=input("") l=len(w) s=w[1:l-1] print("word")if l<=10 else print(w[0]+str(len(s))+w[l-1]) ```
0
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "output": "67" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU", "output": "99" }, { "input": "3\nRUR", "output": "2" }, { "input": "1\nR", "output": "1" }, { "input": "5\nRURUU", "output": "3" }, { "input": "1\nU", "output": "1" }, { "input": "2\nUR", "output": "1" }, { "input": "23\nUUUUUUUUUUUUUUUUUUUUUUU", "output": "23" } ]
1,637,228,111
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = input() s= len(n) j =n.count('RU' and 'UR') print((s-(j*2))+j-1)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python n = input() s= len(n) j =n.count('RU' and 'UR') print((s-(j*2))+j-1) ```
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "output": "1" }, { "input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77", "output": "6" }, { "input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35", "output": "4" }, { "input": "2\n46 6\n6 46", "output": "2" }, { "input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11", "output": "10" }, { "input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33", "output": "6" }, { "input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73", "output": "0" }, { "input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2", "output": "1" }, { "input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100", "output": "8" }, { "input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "450" }, { "input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3", "output": "0" }, { "input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5", "output": "20" }, { "input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2", "output": "108" }, { "input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2", "output": "312" }, { "input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6", "output": "96" }, { "input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97", "output": "210" }, { "input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78", "output": "73" }, { "input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80", "output": "277" }, { "input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21", "output": "154" }, { "input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17", "output": "418" }, { "input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80", "output": "74" }, { "input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9", "output": "59" }, { "input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67", "output": "100" }, { "input": "4\n8 7\n8 7\n7 8\n7 8", "output": "8" }, { "input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1", "output": "10" }, { "input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "72" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "8" } ]
1,697,790,922
2,147,483,647
Python 3
OK
TESTS
31
92
0
teams=int(input()) matches=[] for i in range(teams): z=list(map(int,input().split(' '))) matches.append(z) out=0 for i in matches: for m in matches: if i[0]==m[1]: out+=1 print(out)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. Output Specification: In a single line print the number of games where the host team is going to play in the guest uniform. Demo Input: ['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n'] Demo Output: ['1\n', '5\n', '0\n'] Note: In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
```python teams=int(input()) matches=[] for i in range(teams): z=list(map(int,input().split(' '))) matches.append(z) out=0 for i in matches: for m in matches: if i[0]==m[1]: out+=1 print(out) ```
3
415
A
Mashmokh and Lights
PROGRAMMING
900
[ "implementation" ]
null
null
Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turned on turns off. Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed *m* distinct buttons *b*1,<=*b*2,<=...,<=*b**m* (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button *b**i* is actually *b**i*, not *i*. Please, help Mashmokh, print these indices.
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*). It is guaranteed that all lights will be turned off after pushing all buttons.
Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off.
[ "5 4\n4 3 1 2\n", "5 5\n5 4 3 2 1\n" ]
[ "1 1 3 4 4 \n", "1 2 3 4 5 \n" ]
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
500
[ { "input": "5 4\n4 3 1 2", "output": "1 1 3 4 4 " }, { "input": "5 5\n5 4 3 2 1", "output": "1 2 3 4 5 " }, { "input": "16 11\n8 5 12 10 14 2 6 3 15 9 1", "output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 " }, { "input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 61 12 60 57", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 28 28 28 28 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 76 76 76 76 " }, { "input": "25 19\n3 12 21 11 19 6 5 15 4 16 20 8 9 1 22 23 25 18 13", "output": "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "48 8\n42 27 40 1 18 3 19 2", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 42 42 42 42 42 42 42 " }, { "input": "44 19\n13 20 7 10 9 14 43 17 18 39 21 42 37 1 33 8 35 4 6", "output": "1 1 1 1 1 1 7 7 7 7 7 7 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 " }, { "input": "80 29\n79 51 28 73 65 39 10 1 59 29 7 70 64 3 35 17 24 71 74 2 6 49 66 80 13 18 60 15 12", "output": "1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 79 79 " }, { "input": "31 4\n8 18 30 1", "output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 " }, { "input": "62 29\n61 55 35 13 51 56 23 6 8 26 27 40 48 11 18 12 19 50 54 14 24 21 32 17 43 33 1 2 3", "output": "1 1 1 1 1 6 6 6 6 6 6 6 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 55 55 55 55 55 55 61 61 " }, { "input": "5 4\n2 3 4 1", "output": "1 2 2 2 2 " }, { "input": "39 37\n2 5 17 24 19 33 35 16 20 3 1 34 10 36 15 37 14 8 28 21 13 31 30 29 7 25 32 12 6 27 22 4 11 39 18 9 26", "output": "1 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 " }, { "input": "100 100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "1 1\n1", "output": "1 " }, { "input": "18 3\n18 1 11", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 18 " }, { "input": "67 20\n66 23 40 49 3 39 60 43 52 47 16 36 22 5 41 10 55 34 64 1", "output": "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 66 66 " }, { "input": "92 52\n9 85 44 13 27 61 8 1 28 41 6 14 70 67 39 71 56 80 34 21 5 10 40 73 63 38 90 57 37 36 82 86 65 46 7 54 81 12 45 49 83 59 64 26 62 25 60 24 91 47 53 55", "output": "1 1 1 1 1 1 1 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "66 36\n44 62 32 29 3 15 47 30 50 42 35 2 33 65 10 13 56 12 1 16 7 36 39 11 25 28 20 52 46 38 37 8 61 49 48 14", "output": "1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 29 29 29 32 32 32 32 32 32 32 32 32 32 32 32 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 " }, { "input": "32 8\n27 23 1 13 18 24 17 26", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 23 23 23 27 27 27 27 27 27 " }, { "input": "26 13\n1 14 13 2 4 24 21 22 16 3 10 12 6", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "31 20\n10 11 20 2 4 26 31 7 13 12 28 1 30 18 21 8 3 16 15 19", "output": "1 2 2 2 2 2 2 2 2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 " }, { "input": "86 25\n22 62 8 23 53 77 9 31 43 1 58 16 72 11 15 35 60 39 79 4 82 64 76 63 59", "output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 " }, { "input": "62 54\n2 5 4 47 40 61 37 31 41 16 44 42 48 32 10 6 62 38 52 49 11 20 55 22 3 36 25 21 50 8 28 14 18 39 34 54 53 19 46 27 15 23 12 24 60 17 33 57 58 1 35 29 51 7", "output": "1 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 " }, { "input": "57 19\n43 45 37 40 42 55 16 33 47 32 34 35 9 41 1 6 8 15 5", "output": "1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 37 37 37 37 37 37 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 " }, { "input": "32 14\n4 7 13 1 25 22 9 27 6 28 30 2 14 21", "output": "1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 " }, { "input": "57 12\n8 53 51 38 1 6 16 33 13 46 28 35", "output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 " }, { "input": "87 9\n57 34 78 1 52 67 56 6 54", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 " }, { "input": "88 42\n85 45 52 14 63 53 70 71 16 86 66 47 12 22 10 72 4 31 3 69 11 77 17 25 46 75 23 1 21 84 44 20 18 33 48 88 41 83 67 61 73 34", "output": "1 1 3 4 4 4 4 4 4 10 10 12 12 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 85 85 85 85 " }, { "input": "27 25\n9 21 17 5 16 3 23 7 12 4 14 11 13 1 15 19 27 8 20 10 22 25 6 18 26", "output": "1 1 3 3 5 5 5 5 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 " }, { "input": "89 28\n5 22 79 42 16 35 66 48 57 55 1 37 29 31 40 38 45 62 41 87 64 89 81 13 60 44 71 82", "output": "1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 " }, { "input": "17 4\n4 3 1 2", "output": "1 1 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 " } ]
1,556,639,925
2,147,483,647
Python 3
OK
TESTS
31
109
0
def main(): [n, m] = [int(_) for _ in input().split()] buttons = [int(_) for _ in input().split()] # index = 0 # while index < len(buttons) - 1: # button = buttons[index] # buttons = buttons[:(index + 1)] + [buttons[i] for i in range(index + 1, len(buttons)) if buttons[i] < button] # index += 1 lights = [0] * (n + 1) for button in buttons: i = button while i <= n and lights[i] == 0: lights[i] = button i += 1 result = ' '.join([str(lights[i]) for i in range(1, n + 1)]) print(result) if __name__ == '__main__': main()
Title: Mashmokh and Lights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turned on turns off. Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed *m* distinct buttons *b*1,<=*b*2,<=...,<=*b**m* (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button *b**i* is actually *b**i*, not *i*. Please, help Mashmokh, print these indices. Input Specification: The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*). It is guaranteed that all lights will be turned off after pushing all buttons. Output Specification: Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. Demo Input: ['5 4\n4 3 1 2\n', '5 5\n5 4 3 2 1\n'] Demo Output: ['1 1 3 4 4 \n', '1 2 3 4 5 \n'] Note: In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
```python def main(): [n, m] = [int(_) for _ in input().split()] buttons = [int(_) for _ in input().split()] # index = 0 # while index < len(buttons) - 1: # button = buttons[index] # buttons = buttons[:(index + 1)] + [buttons[i] for i in range(index + 1, len(buttons)) if buttons[i] < button] # index += 1 lights = [0] * (n + 1) for button in buttons: i = button while i <= n and lights[i] == 0: lights[i] = button i += 1 result = ' '.join([str(lights[i]) for i in range(1, n + 1)]) print(result) if __name__ == '__main__': main() ```
3
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3 d g\n5 5 h h\n2 8 g d\n8 9 a f\n5 9 c e\n1 7 f d\n1 6 e e\n5 7 c a\n8 9 b b\n2 6 e b\n6 6 g h\n1 2 b b\n1 5 a f\n5 8 f h\n1 5 e g\n3 9 f h\n6 8 g a\n4 6 h g\n1 5 f a\n5 6 a c\n4 8 e d\n1 4 d g\n7 8 b f\n5 6 h b\n3 9 c e\n1 9 b a", "output": "aahaddddh" }, { "input": "28 45\ndcbbaddjhbeefjadjchgkhgggfha\n10 25 c a\n13 19 a f\n12 28 e d\n12 27 e a\n9 20 b e\n7 17 g d\n22 26 j j\n8 16 c g\n14 16 a d\n3 10 f c\n10 26 d b\n8 17 i e\n10 19 d i\n6 21 c j\n7 22 b k\n17 19 a i\n4 18 j k\n8 25 a g\n10 27 j e\n9 18 g d\n16 23 h a\n17 26 k e\n8 16 h f\n1 15 d f\n22 28 k k\n11 20 c k\n6 11 b h\n17 17 e i\n15 22 g h\n8 18 c f\n4 16 e a\n8 25 b c\n6 24 d g\n5 9 f j\n12 19 i h\n4 25 e f\n15 25 c j\n15 27 e e\n11 20 b f\n19 27 e k\n2 21 d a\n9 27 k e\n14 24 b a\n3 6 i g\n2 26 k f", "output": "fcbbajjfjaaefefehfahfagggfha" }, { "input": "87 5\nnfinedeojadjmgafnaogekfjkjfncnliagfchjfcmellgigjjcaaoeakdolchjcecljdeblmheimkibkgdkcdml\n47 56 a k\n51 81 o d\n5 11 j h\n48 62 j d\n16 30 k m", "output": "nfinedeohadjmgafnaogemfjmjfncnliagfchjfcmellgigddckkdekkddlchdcecljdeblmheimkibkgdkcdml" }, { "input": "5 16\nacfbb\n1 2 e f\n2 5 a f\n2 3 b e\n4 4 f a\n2 3 f a\n1 2 b e\n4 5 c d\n2 4 e c\n1 4 e a\n1 3 d c\n3 5 e b\n3 5 e b\n2 2 e d\n1 3 e c\n3 3 a e\n1 5 a a", "output": "acebb" }, { "input": "94 13\nbcaaaaaaccacddcdaacbdaabbcbaddbccbccbbbddbadddcccbddadddaadbdababadaacdcdbcdadabdcdcbcbcbcbbcd\n52 77 d d\n21 92 d b\n45 48 c b\n20 25 d a\n57 88 d b\n3 91 b d\n64 73 a a\n5 83 b d\n2 69 c c\n28 89 a b\n49 67 c b\n41 62 a c\n49 87 b c", "output": "bcaaaaaaccacddcdaacddaaddcdbdddccdccddddddbdddddcdddcdddccdddcdcdcdcccdcddcdcdcddcdcdcdcdcdbcd" }, { "input": "67 39\nacbcbccccbabaabcabcaaaaaaccbcbbcbaaaacbbcccbcbabbcacccbbabbabbabaac\n4 36 a b\n25 38 a a\n3 44 b c\n35 57 b a\n4 8 a c\n20 67 c a\n30 66 b b\n27 40 a a\n2 56 a b\n10 47 c a\n22 65 c b\n29 42 a b\n1 46 c b\n57 64 b c\n20 29 b a\n14 51 c a\n12 55 b b\n20 20 a c\n2 57 c a\n22 60 c b\n16 51 c c\n31 64 a c\n17 30 c a\n23 36 c c\n28 67 a c\n37 40 a c\n37 50 b c\n29 48 c b\n2 34 b c\n21 53 b a\n26 63 a c\n23 28 c a\n51 56 c b\n32 61 b b\n64 67 b b\n21 67 b c\n8 53 c c\n40 62 b b\n32 38 c c", "output": "accccccccaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccc" }, { "input": "53 33\nhhcbhfafeececbhadfbdbehdfacfchbhdbfebdfeghebfcgdhehfh\n27 41 h g\n18 35 c b\n15 46 h f\n48 53 e g\n30 41 b c\n12 30 b f\n10 37 e f\n18 43 a h\n10 52 d a\n22 48 c e\n40 53 f d\n7 12 b h\n12 51 f a\n3 53 g a\n19 41 d h\n22 29 b h\n2 30 a b\n26 28 e h\n25 35 f a\n19 31 h h\n44 44 d e\n19 22 e c\n29 44 d h\n25 33 d h\n3 53 g c\n18 44 h b\n19 28 f e\n3 22 g h\n8 17 c a\n37 51 d d\n3 28 e h\n27 50 h h\n27 46 f b", "output": "hhcbhfbfhfababbbbbbbbbbbbbbbbbeaaeaaeaaeabebdeaahahdh" }, { "input": "83 10\nfhbecdgadecabbbecedcgfdcefcbgechbedagecgdgfgdaahchdgchbeaedgafdefecdchceececfcdhcdh\n9 77 e e\n26 34 b g\n34 70 b a\n40 64 e g\n33 78 h f\n14 26 a a\n17 70 d g\n56 65 a c\n8 41 d c\n11 82 c b", "output": "fhbecdgacebabbbebegbgfgbefbggebhgegagebgggfggaafbfggbfagbgggbfggfebgbfbeebebfbdhbdh" }, { "input": "1 4\ne\n1 1 c e\n1 1 e a\n1 1 e c\n1 1 d a", "output": "a" }, { "input": "71 21\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n61 61 a a\n32 56 a a\n10 67 a a\n7 32 a a\n26 66 a a\n41 55 a a\n49 55 a a\n4 61 a a\n53 59 a a\n37 58 a a\n7 63 a a\n39 40 a a\n51 64 a a\n27 37 a a\n22 71 a a\n4 45 a a\n7 8 a a\n43 46 a a\n19 28 a a\n51 54 a a\n14 67 a a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "30 4\neaaddabedcbbcccddbabdecadcecce\n2 17 c a\n16 29 e e\n16 21 c b\n7 11 b c", "output": "eaaddacedacbaaaddbabdecadcecce" }, { "input": "48 30\naaaabaabbaababbbaabaabaababbabbbaabbbaabaaaaaaba\n3 45 a b\n1 14 a a\n15 32 a b\n37 47 a b\n9 35 a b\n36 39 b b\n6 26 a b\n36 44 a a\n28 44 b a\n29 31 b a\n20 39 a a\n45 45 a b\n21 32 b b\n7 43 a b\n14 48 a b\n14 33 a b\n39 44 a a\n9 36 b b\n4 23 b b\n9 42 b b\n41 41 b a\n30 47 a b\n8 42 b a\n14 38 b b\n3 15 a a\n35 47 b b\n14 34 a b\n38 43 a b\n1 35 b a\n16 28 b a", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbb" }, { "input": "89 29\nbabaabaaabaaaababbbbbbbabbbaaaaababbaababababbababaaabbababaaabbbbaaabaaaaaabaaabaabbabab\n39 70 b b\n3 56 b b\n5 22 b a\n4 39 a b\n41 87 b b\n34 41 a a\n10 86 a b\n29 75 a b\n2 68 a a\n27 28 b b\n42 51 b a\n18 61 a a\n6 67 b a\n47 63 a a\n8 68 a b\n4 74 b a\n19 65 a b\n8 55 a b\n5 30 a a\n3 65 a b\n16 57 a b\n34 56 b a\n1 70 a b\n59 68 b b\n29 57 b a\n47 49 b b\n49 73 a a\n32 61 b b\n29 42 a a", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaabbbbbbbbbbbbbab" }, { "input": "59 14\nfbebcfabdefbaaedcefdeecababcabebadfbccaaedaebfdaefdbbcbebbe\n5 32 e f\n8 46 e e\n31 43 e f\n3 10 e a\n53 54 f d\n55 59 d a\n39 58 e b\n54 56 f a\n9 40 b e\n28 37 d a\n7 35 e b\n7 56 c f\n23 26 e a\n15 44 e d", "output": "fbabcfabdffbaafdfffdfffababfabfbaafdffaafdabbfdabfdbbfbbbbe" }, { "input": "7 17\nbbaabab\n3 5 a b\n5 7 a a\n5 5 a a\n4 4 b a\n7 7 a a\n5 6 b b\n1 3 b a\n6 7 a b\n4 6 a b\n6 6 a a\n2 4 b a\n1 7 b a\n4 6 b b\n2 5 b b\n2 5 a b\n1 4 a a\n4 4 b a", "output": "abbabaa" }, { "input": "100 1\ndebaaagbfdgehagadabfgheegggfghghgeeeabgceffeffggcbcegfgebbdhebhfagcgadcbdbabddbcadgbgdebdfehceehcaef\n13 99 f c", "output": "debaaagbfdgehagadabcgheegggcghghgeeeabgcecceccggcbcegcgebbdhebhcagcgadcbdbabddbcadgbgdebdcehceehcaef" }, { "input": "1 1\na\n1 1 a b", "output": "b" }, { "input": "100 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1 100 a b", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, { "input": "2 2\naa\n1 2 a b\n1 2 b c", "output": "cc" }, { "input": "3 3\naaa\n1 3 a b\n1 3 b c\n1 3 c d", "output": "ddd" }, { "input": "2 2\naa\n2 2 a b\n1 1 a b", "output": "bb" } ]
1,619,169,874
2,147,483,647
PyPy 3
OK
TESTS
47
108
2,560,000
n, m = map(int, input().rstrip().split()) s=list(input()) for i in range(m): l, r, c1,c2 = map(str,input().rstrip().split()) for j in range(int(l)-1,int(r)): if s[j]==c1: s[j]=c2 print("".join(s))
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length *n*. Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed. Grick wants to know the final string after all the *m* operations. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space. Output Specification: Output string *s* after performing *m* operations described above. Demo Input: ['3 1\nioi\n1 1 i n\n', '5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n'] Demo Output: ['noi', 'gaaak'] Note: For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
```python n, m = map(int, input().rstrip().split()) s=list(input()) for i in range(m): l, r, c1,c2 = map(str,input().rstrip().split()) for j in range(int(l)-1,int(r)): if s[j]==c1: s[j]=c2 print("".join(s)) ```
3
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed?
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": "2" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n2\n-1", "output": "2" }, { "input": "2\n-1\n-1", "output": "1" }, { "input": "3\n2\n-1\n1", "output": "3" }, { "input": "3\n-1\n-1\n-1", "output": "1" }, { "input": "5\n4\n5\n1\n-1\n4", "output": "3" }, { "input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "output": "4" }, { "input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "output": "5" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1", "output": "2" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "output": "1" }, { "input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11", "output": "12" }, { "input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2", "output": "11" }, { "input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6", "output": "6" }, { "input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1", "output": "3" }, { "input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1", "output": "2" }, { "input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1", "output": "3" }, { "input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8", "output": "5" }, { "input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10", "output": "6" }, { "input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1", "output": "4" }, { "input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9", "output": "4" }, { "input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8", "output": "3" }, { "input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11", "output": "7" }, { "input": "7\n7\n6\n-1\n-1\n4\n4\n-1", "output": "3" }, { "input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34", "output": "6" }, { "input": "5\n2\n3\n4\n5\n-1", "output": "5" } ]
1,681,107,614
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
92
716,800
#!/bin/python3 import math import os import random import re import sys n = int(input()) visited = [0]*2001 checks = [] for i in range(1, n+1): t = int(input()) checks.append([t, i]) checks.sort() for x in range(0, len(checks)): i = checks[x][1] t = checks[x][0] if t == -1: visited[i] = 1 else: visited[i] = visited[t]+1 print(max(visited))
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. Output Specification: Print a single integer denoting the minimum number of groups that will be formed in the party. Demo Input: ['5\n-1\n1\n2\n1\n-1\n'] Demo Output: ['3\n'] Note: For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
```python #!/bin/python3 import math import os import random import re import sys n = int(input()) visited = [0]*2001 checks = [] for i in range(1, n+1): t = int(input()) checks.append([t, i]) checks.sort() for x in range(0, len(checks)): i = checks[x][1] t = checks[x][0] if t == -1: visited[i] = 1 else: visited[i] = visited[t]+1 print(max(visited)) ```
0
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,529,575,877
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
77
0
n1,n2=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) l1.sort() l2.sort(reverse=True) print(l1[-2]*l2[0])
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python n1,n2=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) l1.sort() l2.sort(reverse=True) print(l1[-2]*l2[0]) ```
0
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "output": "16" }, { "input": "10\n2 3 0 1 3 1 2 2 1 0", "output": "3" }, { "input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n1 3", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n3 3", "output": "0" }, { "input": "3\n3 3 3", "output": "0" }, { "input": "2\n3 2", "output": "0" }, { "input": "2\n0 2", "output": "1" }, { "input": "10\n2 2 3 3 3 3 2 1 3 2", "output": "2" }, { "input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0", "output": "11" }, { "input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1", "output": "4" }, { "input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2", "output": "3" }, { "input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0", "output": "12" }, { "input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3", "output": "5" }, { "input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2", "output": "4" }, { "input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1", "output": "16" }, { "input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3", "output": "5" }, { "input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3", "output": "3" }, { "input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0", "output": "22" }, { "input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2", "output": "9" }, { "input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3", "output": "2" }, { "input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0", "output": "21" }, { "input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2", "output": "11" }, { "input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2", "output": "7" }, { "input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0", "output": "28" }, { "input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1", "output": "10" }, { "input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3", "output": "8" }, { "input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2", "output": "29" }, { "input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3", "output": "8" }, { "input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0", "output": "32" }, { "input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2", "output": "16" }, { "input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3", "output": "7" }, { "input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0", "output": "40" }, { "input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2", "output": "13" }, { "input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3", "output": "7" }, { "input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0", "output": "44" }, { "input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2", "output": "15" }, { "input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3", "output": "8" }, { "input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1", "output": "35" }, { "input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3", "output": "13" }, { "input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3", "output": "6" }, { "input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1", "output": "43" }, { "input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1", "output": "16" }, { "input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1", "output": "10" }, { "input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0", "output": "51" }, { "input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1", "output": "16" }, { "input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1", "output": "11" }, { "input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1", "output": "56" }, { "input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0", "output": "17" }, { "input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3", "output": "9" }, { "input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0", "output": "54" }, { "input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3", "output": "19" }, { "input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3", "output": "9" }, { "input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1", "output": "57" }, { "input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1", "output": "17" }, { "input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2", "output": "9" }, { "input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1", "output": "61" }, { "input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2", "output": "15" }, { "input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2", "output": "14" }, { "input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2", "output": "63" }, { "input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3", "output": "15" }, { "input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2", "output": "0" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "0" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "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", "output": "50" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "49" }, { "input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "2\n0 3", "output": "1" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 0", "output": "1" }, { "input": "2\n2 1", "output": "0" }, { "input": "2\n2 3", "output": "0" }, { "input": "2\n3 0", "output": "1" }, { "input": "2\n3 1", "output": "0" }, { "input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0", "output": "50" } ]
1,666,420,095
2,147,483,647
Python 3
OK
TESTS
88
62
716,800
from calendar import calendar def List(): return list(map(int,input().split())) def Lst(): return list(input()) def Int(): return int(input()) def two(): return map(int,input().split()) numOfVactions = Int() calendar = List() outPut = 0 prevState = 0 for currState in calendar: if currState == 3: prevState = currState - prevState elif currState == 0 or currState == prevState: outPut +=1 prevState = 0 else: prevState = currState print(outPut)
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python from calendar import calendar def List(): return list(map(int,input().split())) def Lst(): return list(input()) def Int(): return int(input()) def two(): return map(int,input().split()) numOfVactions = Int() calendar = List() outPut = 0 prevState = 0 for currState in calendar: if currState == 3: prevState = currState - prevState elif currState == 0 or currState == prevState: outPut +=1 prevState = 0 else: prevState = currState print(outPut) ```
3
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, { "input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "output": "1" }, { "input": "RRGGBRGRBG\nBRRGGBBGGR", "output": "7" }, { "input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG", "output": "15" }, { "input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR", "output": "8" }, { "input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR", "output": "16" }, { "input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR", "output": "18" }, { "input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG", "output": "23" }, { "input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR", "output": "14" }, { "input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG", "output": "12" }, { "input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB", "output": "12" }, { "input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR", "output": "2" }, { "input": "R\nB", "output": "1" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "50" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" }, { "input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" } ]
1,647,890,424
2,147,483,647
Python 3
OK
TESTS
19
186
6,041,600
#A. Colorful Stones from tkinter import S s = input() t = input() i = 0 j = 0 counter = 1 while j < len(t): if s[i] != t[j]: j += 1 elif s[i] == t[j]: i += 1 j += 1 counter += 1 print(counter)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. Input Specification: The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. Output Specification: Print the final 1-based position of Liss in a single line. Demo Input: ['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n'] Demo Output: ['2\n', '3\n', '15\n'] Note: none
```python #A. Colorful Stones from tkinter import S s = input() t = input() i = 0 j = 0 counter = 1 while j < len(t): if s[i] != t[j]: j += 1 elif s[i] == t[j]: i += 1 j += 1 counter += 1 print(counter) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,604,048,357
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
import math y,w=map(int,input().split()) g=math.gcd(y,w) print(str(w//g)+"/"+str(y//g))
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python import math y,w=map(int,input().split()) g=math.gcd(y,w) print(str(w//g)+"/"+str(y//g)) ```
0
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
1,510,509,514
6,814
Python 3
RUNTIME_ERROR
PRETESTS
0
46
0
from itertools import groupby k=0 l=0 l1=0 a=[] s=0 n=int(input()) for i in range(n): k=int(input()) a.append(k) new = [el for el, _ in groupby(a)] a.reverse() for i in range(len(new)): l=a.index(new[i-1]) if l>l1: l1=l; s=new[i-1] print(s)
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python from itertools import groupby k=0 l=0 l1=0 a=[] s=0 n=int(input()) for i in range(n): k=int(input()) a.append(k) new = [el for el, _ in groupby(a)] a.reverse() for i in range(len(new)): l=a.index(new[i-1]) if l>l1: l1=l; s=new[i-1] print(s) ```
-1
616
C
The Labyrinth
PROGRAMMING
1,600
[ "dfs and similar" ]
null
null
You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component. For each impassable cell (*x*,<=*y*) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (*x*,<=*y*). You should do it for each impassable cell independently. The answer should be printed as a matrix with *n* rows and *m* columns. The *j*-th symbol of the *i*-th row should be "." if the cell is empty at the start. Otherwise the *j*-th symbol of the *i*-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces. To make your output faster it is recommended to build the output as an array of *n* strings having length *m* and print it as a sequence of lines. It will be much faster than writing character-by-character. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field. Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells.
Print the answer as a matrix as described above. See the examples to precise the format of the output.
[ "3 3\n*.*\n.*.\n*.*\n", "4 5\n**..*\n..***\n.*.*.\n*.*.*\n" ]
[ "3.3\n.5.\n3.3\n", "46..3\n..732\n.6.4.\n5.4.3\n" ]
In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner).
0
[ { "input": "3 3\n*.*\n.*.\n*.*", "output": "3.3\n.5.\n3.3" }, { "input": "4 5\n**..*\n..***\n.*.*.\n*.*.*", "output": "46..3\n..732\n.6.4.\n5.4.3" }, { "input": "1 1\n*", "output": "1" }, { "input": "1 1\n.", "output": "." }, { "input": "1 10\n**********", "output": "1111111111" }, { "input": "1 10\n*.***.**.*", "output": "2.212.22.2" }, { "input": "10 1\n*\n*\n*\n*\n*\n.\n*\n.\n*\n*", "output": "1\n1\n1\n1\n2\n.\n3\n.\n2\n1" }, { "input": "10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "output": ".\n.\n.\n.\n.\n.\n.\n.\n.\n." } ]
1,594,530,330
2,147,483,647
PyPy 3
OK
TESTS
19
810
70,348,800
# n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): from collections import Counter #from fractions import Fraction #n=int(input()) #arr=list(map(int,input().split())) #ls = [list(map(int, input().split())) for i in range(n)] from math import log2 #for _ in range(int(input())): #n, m = map(int, input().split()) # for _ in range(int(input())): from math import gcd #n=int(input()) # for i in range(m): # for i in range(int(input())): # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=sys.stdin.readline() # n=int(n) # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=int(inaput()) #for _ in range(int(input())): #arr=list(map(int,input().split())) from collections import deque dx=[-1,0,0,1] dy=[0,-1,1,0] def bfs(x,y): global total total+=1 q=deque([(x,y)]) v[x][y]=True h[x][y]=comp #q.append() while q: x,y=q.pop() for i in range(4): nx=x+dx[i] ny=y+dy[i] #print("nx,y",nx, ny) if (nx>=0 and nx<n) and (ny>=0 and ny<m) and (v[nx][ny]==False) and (g[nx][ny]=="."): q.appendleft((nx,ny)) total+=1 v[nx][ny]=True h[nx][ny]=comp #global g,h,r,comp,total n, m = map(int, input().split()) h=[[-1 for i in range(m)] for j in range(n)] g=[] v=[[False for i in range(m)]for j in range(n)] for i in range(n): g.append(list(input())) component=[] for i in range(n): for j in range(m): if v[i][j]==False and g[i][j]==".":############ comp=len(component) #global total total=0 bfs(i,j) component.append(total) #print(component) for x in range(n): for y in range(m): if g[x][y] == "*": ans = 0 s = set() for k in range(4): nx = x + dx[k] ny = y + dy[k] if nx >= 0 and nx < n and ny >= 0 and ny < m and g[nx][ny] == ".": s.add(h[nx][ny]) for itm in s: ans += component[itm] ans += 1 ans %= 10 g[x][y] = str(ans) for i in range(n): print("".join(g[i]))
Title: The Labyrinth Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component. For each impassable cell (*x*,<=*y*) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (*x*,<=*y*). You should do it for each impassable cell independently. The answer should be printed as a matrix with *n* rows and *m* columns. The *j*-th symbol of the *i*-th row should be "." if the cell is empty at the start. Otherwise the *j*-th symbol of the *i*-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces. To make your output faster it is recommended to build the output as an array of *n* strings having length *m* and print it as a sequence of lines. It will be much faster than writing character-by-character. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field. Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells. Output Specification: Print the answer as a matrix as described above. See the examples to precise the format of the output. Demo Input: ['3 3\n*.*\n.*.\n*.*\n', '4 5\n**..*\n..***\n.*.*.\n*.*.*\n'] Demo Output: ['3.3\n.5.\n3.3\n', '46..3\n..732\n.6.4.\n5.4.3\n'] Note: In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner).
```python # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): from collections import Counter #from fractions import Fraction #n=int(input()) #arr=list(map(int,input().split())) #ls = [list(map(int, input().split())) for i in range(n)] from math import log2 #for _ in range(int(input())): #n, m = map(int, input().split()) # for _ in range(int(input())): from math import gcd #n=int(input()) # for i in range(m): # for i in range(int(input())): # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=sys.stdin.readline() # n=int(n) # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=int(inaput()) #for _ in range(int(input())): #arr=list(map(int,input().split())) from collections import deque dx=[-1,0,0,1] dy=[0,-1,1,0] def bfs(x,y): global total total+=1 q=deque([(x,y)]) v[x][y]=True h[x][y]=comp #q.append() while q: x,y=q.pop() for i in range(4): nx=x+dx[i] ny=y+dy[i] #print("nx,y",nx, ny) if (nx>=0 and nx<n) and (ny>=0 and ny<m) and (v[nx][ny]==False) and (g[nx][ny]=="."): q.appendleft((nx,ny)) total+=1 v[nx][ny]=True h[nx][ny]=comp #global g,h,r,comp,total n, m = map(int, input().split()) h=[[-1 for i in range(m)] for j in range(n)] g=[] v=[[False for i in range(m)]for j in range(n)] for i in range(n): g.append(list(input())) component=[] for i in range(n): for j in range(m): if v[i][j]==False and g[i][j]==".":############ comp=len(component) #global total total=0 bfs(i,j) component.append(total) #print(component) for x in range(n): for y in range(m): if g[x][y] == "*": ans = 0 s = set() for k in range(4): nx = x + dx[k] ny = y + dy[k] if nx >= 0 and nx < n and ny >= 0 and ny < m and g[nx][ny] == ".": s.add(h[nx][ny]) for itm in s: ans += component[itm] ans += 1 ans %= 10 g[x][y] = str(ans) for i in range(n): print("".join(g[i])) ```
3
553
B
Kyoya and Permutation
PROGRAMMING
1,900
[ "binary search", "combinatorics", "constructive algorithms", "greedy", "implementation", "math" ]
null
null
Let's define the permutation of length *n* as an array *p*<==<=[*p*1,<=*p*2,<=...,<=*p**n*] consisting of *n* distinct integers from range from 1 to *n*. We say that this permutation maps value 1 into the value *p*1, value 2 into the value *p*2 and so on. Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of *p* as a collection of cycles forming *p*. For example, permutation *p*<==<=[4,<=1,<=6,<=2,<=5,<=3] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place. Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4,<=1,<=6,<=2,<=5,<=3] is (421)(5)(63). Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4,<=1,<=6,<=2,<=5,<=3] will become [4,<=2,<=1,<=5,<=6,<=3]. Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length *n* that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers *n* and *k*, print the permutation that was *k*-th on Kyoya's list.
The first line will contain two integers *n*, *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=*min*{1018,<=*l*} where *l* is the length of the Kyoya's list).
Print *n* space-separated integers, representing the permutation that is the answer for the question.
[ "4 3\n", "10 1\n" ]
[ "1 3 2 4\n", "1 2 3 4 5 6 7 8 9 10\n" ]
The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].
500
[ { "input": "4 3", "output": "1 3 2 4" }, { "input": "10 1", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "1 1", "output": "1" }, { "input": "50 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50" }, { "input": "10 57", "output": "2 1 3 4 5 6 7 8 10 9" }, { "input": "50 20365011074", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49" }, { "input": "20 9999", "output": "2 1 4 3 5 7 6 8 9 10 11 13 12 14 15 17 16 18 19 20" }, { "input": "49 12586269025", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 49" }, { "input": "49 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49" }, { "input": "10 89", "output": "2 1 4 3 6 5 8 7 10 9" }, { "input": "10 1", "output": "1 2 3 4 5 6 7 8 9 10" }, { "input": "5 8", "output": "2 1 4 3 5" }, { "input": "5 1", "output": "1 2 3 4 5" }, { "input": "25 121393", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 25" }, { "input": "25 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2 1" }, { "input": "3 3", "output": "2 1 3" }, { "input": "4 2", "output": "1 2 4 3" }, { "input": "5 8", "output": "2 1 4 3 5" }, { "input": "6 10", "output": "2 1 3 4 6 5" }, { "input": "7 20", "output": "2 1 4 3 5 7 6" }, { "input": "8 24", "output": "2 1 3 4 5 7 6 8" }, { "input": "9 1", "output": "1 2 3 4 5 6 7 8 9" }, { "input": "10 24", "output": "1 2 4 3 5 6 7 9 8 10" }, { "input": "11 77", "output": "1 3 2 5 4 6 7 8 9 10 11" }, { "input": "12 101", "output": "1 3 2 4 5 6 8 7 10 9 11 12" }, { "input": "13 240", "output": "2 1 3 4 5 6 7 8 10 9 11 13 12" }, { "input": "14 356", "output": "1 3 2 5 4 6 8 7 10 9 12 11 14 13" }, { "input": "15 463", "output": "1 3 2 4 5 7 6 9 8 11 10 12 13 15 14" }, { "input": "16 747", "output": "1 3 2 4 5 7 6 9 8 11 10 12 13 14 15 16" }, { "input": "17 734", "output": "1 2 4 3 5 6 8 7 10 9 11 12 13 14 15 16 17" }, { "input": "18 1809", "output": "1 3 2 4 5 6 8 7 10 9 11 12 14 13 16 15 18 17" }, { "input": "19 859", "output": "1 2 3 4 6 5 8 7 9 10 11 12 14 13 15 16 18 17 19" }, { "input": "20 491", "output": "1 2 3 4 5 6 8 7 9 11 10 12 14 13 15 16 18 17 19 20" }, { "input": "21 14921", "output": "2 1 3 5 4 7 6 9 8 10 11 12 13 15 14 16 18 17 19 20 21" }, { "input": "22 731", "output": "1 2 3 4 5 6 7 9 8 10 11 13 12 14 16 15 18 17 19 21 20 22" }, { "input": "23 45599", "output": "2 1 4 3 6 5 8 7 9 10 11 13 12 15 14 16 18 17 20 19 21 22 23" }, { "input": "24 47430", "output": "2 1 3 4 5 6 7 8 10 9 11 12 13 14 16 15 17 19 18 21 20 22 24 23" }, { "input": "25 58467", "output": "1 3 2 4 6 5 7 8 9 11 10 12 13 15 14 16 17 19 18 20 21 22 23 24 25" }, { "input": "26 168988", "output": "2 1 4 3 5 6 7 8 9 10 12 11 13 15 14 16 17 18 19 20 21 23 22 24 26 25" }, { "input": "27 298209", "output": "2 1 4 3 5 7 6 9 8 10 12 11 14 13 15 16 17 19 18 21 20 22 24 23 25 27 26" }, { "input": "28 77078", "output": "1 2 3 5 4 6 7 8 9 10 11 13 12 14 16 15 17 18 20 19 22 21 23 24 25 27 26 28" }, { "input": "29 668648", "output": "2 1 3 5 4 6 8 7 9 10 12 11 13 14 15 16 17 19 18 20 22 21 23 25 24 26 27 29 28" }, { "input": "30 582773", "output": "1 3 2 4 5 6 8 7 10 9 11 13 12 14 15 16 17 19 18 20 21 23 22 25 24 26 28 27 29 30" }, { "input": "31 1899100", "output": "2 1 4 3 5 6 7 8 10 9 11 13 12 15 14 16 17 19 18 21 20 23 22 24 26 25 28 27 29 31 30" }, { "input": "32 1314567", "output": "1 2 4 3 6 5 8 7 9 11 10 13 12 14 16 15 18 17 19 20 22 21 23 24 25 26 27 28 30 29 32 31" }, { "input": "33 1811927", "output": "1 2 4 3 5 7 6 9 8 10 11 13 12 15 14 16 18 17 19 21 20 22 23 24 25 26 27 28 29 31 30 32 33" }, { "input": "34 2412850", "output": "1 2 4 3 5 6 7 9 8 10 11 13 12 14 16 15 18 17 19 20 21 22 23 25 24 26 28 27 29 31 30 32 34 33" }, { "input": "35 706065", "output": "1 2 3 4 5 6 8 7 9 11 10 13 12 15 14 16 18 17 20 19 21 23 22 25 24 27 26 28 29 31 30 32 33 35 34" }, { "input": "36 7074882", "output": "1 2 4 3 5 7 6 8 9 10 11 12 13 14 16 15 18 17 19 20 22 21 23 25 24 26 27 28 30 29 32 31 33 34 35 36" }, { "input": "37 27668397", "output": "2 1 3 4 5 7 6 9 8 11 10 13 12 15 14 16 18 17 19 21 20 23 22 24 25 26 28 27 30 29 32 31 34 33 35 36 37" }, { "input": "38 23790805", "output": "1 2 4 3 6 5 8 7 10 9 11 12 14 13 15 16 18 17 20 19 21 22 24 23 25 27 26 29 28 31 30 32 33 34 36 35 38 37" }, { "input": "39 68773650", "output": "2 1 3 4 5 6 8 7 10 9 12 11 13 15 14 16 17 19 18 20 21 23 22 24 26 25 28 27 29 31 30 32 33 34 35 36 37 39 38" }, { "input": "40 43782404", "output": "1 2 4 3 5 6 7 9 8 10 12 11 14 13 15 16 17 18 20 19 21 22 23 25 24 26 28 27 29 31 30 32 34 33 36 35 37 39 38 40" }, { "input": "41 130268954", "output": "1 3 2 4 6 5 7 8 10 9 11 12 13 14 16 15 17 19 18 20 21 23 22 25 24 26 27 28 30 29 31 32 34 33 35 36 37 38 39 41 40" }, { "input": "42 40985206", "output": "1 2 3 4 6 5 7 8 9 10 11 13 12 15 14 16 17 18 19 21 20 22 24 23 25 26 28 27 29 30 31 33 32 35 34 36 37 39 38 40 42 41" }, { "input": "43 193787781", "output": "1 2 4 3 5 6 8 7 9 10 12 11 13 14 16 15 17 18 19 20 21 22 24 23 25 26 27 28 29 30 31 32 33 35 34 36 38 37 39 40 41 43 42" }, { "input": "44 863791309", "output": "2 1 3 4 6 5 8 7 10 9 12 11 13 14 15 16 18 17 19 20 21 22 23 24 26 25 27 29 28 31 30 32 34 33 36 35 38 37 40 39 41 42 44 43" }, { "input": "45 1817653076", "output": "2 1 4 3 6 5 8 7 9 11 10 12 14 13 16 15 18 17 19 20 22 21 24 23 25 27 26 29 28 30 32 31 34 33 35 36 38 37 39 40 42 41 43 44 45" }, { "input": "46 1176411936", "output": "1 3 2 4 5 6 7 8 10 9 11 12 13 14 16 15 17 18 19 21 20 22 23 25 24 27 26 29 28 31 30 32 34 33 35 37 36 38 40 39 41 42 43 44 46 45" }, { "input": "47 4199125763", "output": "2 1 4 3 5 6 7 8 10 9 12 11 13 14 16 15 18 17 20 19 22 21 23 24 25 27 26 28 30 29 31 32 33 34 36 35 38 37 39 40 41 43 42 44 45 46 47" }, { "input": "48 4534695914", "output": "1 3 2 5 4 6 8 7 10 9 12 11 14 13 15 17 16 18 19 21 20 23 22 25 24 26 27 28 29 30 31 32 33 34 36 35 37 38 40 39 41 43 42 44 46 45 47 48" }, { "input": "49 3790978105", "output": "1 2 4 3 5 7 6 8 9 11 10 12 13 15 14 16 17 18 19 21 20 22 24 23 25 27 26 28 30 29 31 33 32 35 34 37 36 38 39 41 40 42 44 43 45 47 46 48 49" }, { "input": "50 5608642004", "output": "1 2 4 3 5 6 8 7 9 10 11 13 12 15 14 17 16 18 20 19 22 21 23 24 25 26 28 27 30 29 31 32 33 34 35 36 38 37 40 39 42 41 44 43 45 46 47 48 50 49" } ]
1,435,166,677
3,277
Python 3
OK
TESTS
65
62
0
#!/usr/bin/python3 arr = [1] * 51 for i in range(2, 51): arr[i] = arr[i - 1] + arr[i - 2] ans = [] def generate(i, n, to): if i == n: assert to == 1 print(" ".join(map(str, ans))) return if i + 1 == n: ans.append(n) generate(i + 1, n, to) return if arr[n - i - 1] < to: ans.append(i + 2) ans.append(i + 1) generate(i + 2, n, to - arr[n - i - 1]) else: ans.append(i + 1) generate(i + 1, n, to) n, k = map(int, input().split()) generate(0, n, k)
Title: Kyoya and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define the permutation of length *n* as an array *p*<==<=[*p*1,<=*p*2,<=...,<=*p**n*] consisting of *n* distinct integers from range from 1 to *n*. We say that this permutation maps value 1 into the value *p*1, value 2 into the value *p*2 and so on. Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of *p* as a collection of cycles forming *p*. For example, permutation *p*<==<=[4,<=1,<=6,<=2,<=5,<=3] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place. Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4,<=1,<=6,<=2,<=5,<=3] is (421)(5)(63). Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4,<=1,<=6,<=2,<=5,<=3] will become [4,<=2,<=1,<=5,<=6,<=3]. Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length *n* that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers *n* and *k*, print the permutation that was *k*-th on Kyoya's list. Input Specification: The first line will contain two integers *n*, *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=*min*{1018,<=*l*} where *l* is the length of the Kyoya's list). Output Specification: Print *n* space-separated integers, representing the permutation that is the answer for the question. Demo Input: ['4 3\n', '10 1\n'] Demo Output: ['1 3 2 4\n', '1 2 3 4 5 6 7 8 9 10\n'] Note: The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].
```python #!/usr/bin/python3 arr = [1] * 51 for i in range(2, 51): arr[i] = arr[i - 1] + arr[i - 2] ans = [] def generate(i, n, to): if i == n: assert to == 1 print(" ".join(map(str, ans))) return if i + 1 == n: ans.append(n) generate(i + 1, n, to) return if arr[n - i - 1] < to: ans.append(i + 2) ans.append(i + 1) generate(i + 2, n, to - arr[n - i - 1]) else: ans.append(i + 1) generate(i + 1, n, to) n, k = map(int, input().split()) generate(0, n, k) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,588,614,256
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
156
307,200
ipnum=int(input()) mylist=[] ans=[] count=0 for i in range(ipnum): listip=[int(n) for n in input().split()] mylist.append(listip) #print(mylist) for i in range(len(mylist)): summ=0 for j in range(len(mylist[0])): summ=summ + mylist[j][i] ans.append(summ) #print(ans) for item in ans: if item==0: count=count+1 if count==len(ans): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python ipnum=int(input()) mylist=[] ans=[] count=0 for i in range(ipnum): listip=[int(n) for n in input().split()] mylist.append(listip) #print(mylist) for i in range(len(mylist)): summ=0 for j in range(len(mylist[0])): summ=summ + mylist[j][i] ans.append(summ) #print(ans) for item in ans: if item==0: count=count+1 if count==len(ans): print("YES") else: print("NO") ```
-1
954
D
Fight Against Traffic
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Little town Nsk consists of *n* junctions connected by *m* bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible number of roads on a path between them. In order to improve the transportation system, the city council asks mayor to build one new road. The problem is that the mayor has just bought a wonderful new car and he really enjoys a ride from his home, located near junction *s* to work located near junction *t*. Thus, he wants to build a new road in such a way that the distance between these two junctions won't decrease. You are assigned a task to compute the number of pairs of junctions that are not connected by the road, such that if the new road between these two junctions is built the distance between *s* and *t* won't decrease.
The firt line of the input contains integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*m*<=≤<=1000, 1<=≤<=*s*,<=*t*<=≤<=*n*, *s*<=≠<=*t*) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The *i*-th of the following *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*), meaning that this road connects junctions *u**i* and *v**i* directly. It is guaranteed that there is a path between any two junctions and no two roads connect the same pair of junctions.
Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions *s* and *t*.
[ "5 4 1 5\n1 2\n2 3\n3 4\n4 5\n", "5 4 3 5\n1 2\n2 3\n3 4\n4 5\n", "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5\n" ]
[ "0\n", "5\n", "3\n" ]
none
0
[ { "input": "5 4 1 5\n1 2\n2 3\n3 4\n4 5", "output": "0" }, { "input": "5 4 3 5\n1 2\n2 3\n3 4\n4 5", "output": "5" }, { "input": "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5", "output": "3" }, { "input": "2 1 2 1\n1 2", "output": "0" }, { "input": "3 2 2 3\n1 2\n2 3", "output": "1" }, { "input": "3 2 1 3\n1 2\n2 3", "output": "0" }, { "input": "3 3 2 3\n1 2\n2 3\n1 3", "output": "0" } ]
1,671,700,141
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
109
4,608,000
from collections import defaultdict from heapq import heappop, heappush n, m, s, t = list(map(int, input().split())) graph = defaultdict(set) for _ in range(m): u, v = list(map(int, input().split())) graph[u - 1].add((v - 1, 1)) graph[v - 1].add((u - 1, 1)) total_edges = [((n*(n-1))//2) - m] queue = [(s - 1, 0)] distance = [float('inf')]*n distance[s - 1] = 0 while queue: size = len(queue) for _ in range(size): node, distance_so_far = heappop(queue) for nei, weight in graph[node]: if distance_so_far + weight < distance[nei]: distance[nei] = distance_so_far + weight heappush(queue, (nei, distance[nei])) min_distance = distance[t - 1] # print(distance) total_min_paths = [0] def dfs(cur_node = s - 1, parent = -1, depth = 0): # print(cur_node) if cur_node == t - 1: # print(depth) if depth == min_distance: total_min_paths[0] += 1 return for nei, weight in graph[cur_node]: if nei != parent: dfs(nei, cur_node, depth + 1) dfs() nodes = min_distance + 1 max_possible = ((nodes*(nodes-1))//2) - min_distance deductable = (total_min_paths[0]*max_possible) - ((total_min_paths[0]) - 1) total_edges[0] -= deductable print(total_edges[0])
Title: Fight Against Traffic Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little town Nsk consists of *n* junctions connected by *m* bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible number of roads on a path between them. In order to improve the transportation system, the city council asks mayor to build one new road. The problem is that the mayor has just bought a wonderful new car and he really enjoys a ride from his home, located near junction *s* to work located near junction *t*. Thus, he wants to build a new road in such a way that the distance between these two junctions won't decrease. You are assigned a task to compute the number of pairs of junctions that are not connected by the road, such that if the new road between these two junctions is built the distance between *s* and *t* won't decrease. Input Specification: The firt line of the input contains integers *n*, *m*, *s* and *t* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*m*<=≤<=1000, 1<=≤<=*s*,<=*t*<=≤<=*n*, *s*<=≠<=*t*) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The *i*-th of the following *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*), meaning that this road connects junctions *u**i* and *v**i* directly. It is guaranteed that there is a path between any two junctions and no two roads connect the same pair of junctions. Output Specification: Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions *s* and *t*. Demo Input: ['5 4 1 5\n1 2\n2 3\n3 4\n4 5\n', '5 4 3 5\n1 2\n2 3\n3 4\n4 5\n', '5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5\n'] Demo Output: ['0\n', '5\n', '3\n'] Note: none
```python from collections import defaultdict from heapq import heappop, heappush n, m, s, t = list(map(int, input().split())) graph = defaultdict(set) for _ in range(m): u, v = list(map(int, input().split())) graph[u - 1].add((v - 1, 1)) graph[v - 1].add((u - 1, 1)) total_edges = [((n*(n-1))//2) - m] queue = [(s - 1, 0)] distance = [float('inf')]*n distance[s - 1] = 0 while queue: size = len(queue) for _ in range(size): node, distance_so_far = heappop(queue) for nei, weight in graph[node]: if distance_so_far + weight < distance[nei]: distance[nei] = distance_so_far + weight heappush(queue, (nei, distance[nei])) min_distance = distance[t - 1] # print(distance) total_min_paths = [0] def dfs(cur_node = s - 1, parent = -1, depth = 0): # print(cur_node) if cur_node == t - 1: # print(depth) if depth == min_distance: total_min_paths[0] += 1 return for nei, weight in graph[cur_node]: if nei != parent: dfs(nei, cur_node, depth + 1) dfs() nodes = min_distance + 1 max_possible = ((nodes*(nodes-1))//2) - min_distance deductable = (total_min_paths[0]*max_possible) - ((total_min_paths[0]) - 1) total_edges[0] -= deductable print(total_edges[0]) ```
0
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated. Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired. The answer is one, as one crime (on step 5) will go untreated.
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5", "output": "5" }, { "input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 1", "output": "13" }, { "input": "3\n-1 5 4", "output": "1" }, { "input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1", "output": "5" }, { "input": "1\n2", "output": "0" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n1 -1", "output": "0" }, { "input": "2\n-1 1", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n-1 -1", "output": "2" }, { "input": "4\n10 -1 -1 -1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "4\n-1 -1 1 1", "output": "2" } ]
1,676,643,475
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n = int(input()) s = [int(i) for i in input().split()] kol = 0 n=len(s)-1 p=0 while True: if(s[n]==-1): break n-=1 while True: if(s[p]>0): break p+=1 out = s[p] i=p l=len(s) while i<n: try: s[p]+=s[p+1] s.pop(p+1) i+=1 except: out = abs(sum([i for i in s if i<0])) break out = abs(sum([i for i in s if i<0])) print(out)
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated. Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. Input Specification: The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. Output Specification: Print a single integer, the number of crimes which will go untreated. Demo Input: ['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n'] Demo Output: ['2\n', '1\n', '8\n'] Note: Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired. The answer is one, as one crime (on step 5) will go untreated.
```python n = int(input()) s = [int(i) for i in input().split()] kol = 0 n=len(s)-1 p=0 while True: if(s[n]==-1): break n-=1 while True: if(s[p]>0): break p+=1 out = s[p] i=p l=len(s) while i<n: try: s[p]+=s[p+1] s.pop(p+1) i+=1 except: out = abs(sum([i for i in s if i<0])) break out = abs(sum([i for i in s if i<0])) print(out) ```
0
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 " }, { "input": "31 581", "output": "581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1000", "output": "1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..." }, { "input": "100 999", "output": "999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 998", "output": "998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 997", "output": "997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "81 111", "output": "111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 111 0 0..." }, { "input": "1 407", "output": "407 " }, { "input": "54 341", "output": "341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "92 460", "output": "460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "34 47", "output": "47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 ..." }, { "input": "11 547", "output": "547 0 0 0 0 0 0 0 0 0 0 \n0 547 0 0 0 0 0 0 0 0 0 \n0 0 547 0 0 0 0 0 0 0 0 \n0 0 0 547 0 0 0 0 0 0 0 \n0 0 0 0 547 0 0 0 0 0 0 \n0 0 0 0 0 547 0 0 0 0 0 \n0 0 0 0 0 0 547 0 0 0 0 \n0 0 0 0 0 0 0 547 0 0 0 \n0 0 0 0 0 0 0 0 547 0 0 \n0 0 0 0 0 0 0 0 0 547 0 \n0 0 0 0 0 0 0 0 0 0 547 " }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "99 2", "output": "2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "2 7", "output": "7 0 \n0 7 " }, { "input": "100 100", "output": "100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "4 3", "output": "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 " }, { "input": "3 2", "output": "2 0 0 \n0 2 0 \n0 0 2 " } ]
1,614,523,427
2,147,483,647
Python 3
OK
TESTS
22
77
307,200
n, k = map(int, input().split()); a = list(range(n)); for i in range (0, n): a[i] = list(range(n)); for j in range (0, n): if j == i: a[i][j] = k; else: a[i][j] = 0; print(*a[i], sep=" ")
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. Input Specification: The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Output Specification: Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. Demo Input: ['2 4\n', '4 7\n'] Demo Output: ['1 3\n3 1\n', '2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n'] Note: In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
```python n, k = map(int, input().split()); a = list(range(n)); for i in range (0, n): a[i] = list(range(n)); for j in range (0, n): if j == i: a[i][j] = k; else: a[i][j] = 0; print(*a[i], sep=" ") ```
3
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894", "output": "894" }, { "input": "6058 8581", "output": "8581" }, { "input": "97259 41764", "output": "125292" }, { "input": "453145 333625", "output": "667250" }, { "input": "2233224 4394826", "output": "4394826" }, { "input": "76770926 13350712", "output": "80104272" }, { "input": "687355301 142098087", "output": "710490435" }, { "input": "1000000000 999999999", "output": "1999999998" }, { "input": "1000000000 1000000000", "output": "2000000000" }, { "input": "999999999 1000000000", "output": "1000000000" }, { "input": "1000000000 1", "output": "1000000001" }, { "input": "1000000000 2", "output": "1000000002" }, { "input": "999999999 1", "output": "1000000000" }, { "input": "100000000 1", "output": "100000001" }, { "input": "999999999 500000000", "output": "1000000000" }, { "input": "999999990 10", "output": "1000000000" }, { "input": "1000000000 999999997", "output": "1999999994" }, { "input": "999999999 2", "output": "1000000000" }, { "input": "999999984 1", "output": "999999985" }, { "input": "999999983 1", "output": "999999984" }, { "input": "666666666 1", "output": "666666667" }, { "input": "1000000000 990000000", "output": "1980000000" }, { "input": "41 48", "output": "48" }, { "input": "123456 2", "output": "123458" }, { "input": "111 111", "output": "222" }, { "input": "878787 1", "output": "878788" }, { "input": "121 1", "output": "122" }, { "input": "114514 114514", "output": "229028" }, { "input": "500000001 1000000000", "output": "1000000000" }, { "input": "999999997 1", "output": "999999998" }, { "input": "100000000 10", "output": "100000010" } ]
1,594,989,439
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
6,656,000
n,k=map(int,input().split()) for i in range(1,k): if(k*i>n): print(k*i) break
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Output Specification: Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Demo Input: ['5 3\n', '25 13\n', '26 13\n'] Demo Output: ['6\n', '26\n', '39\n'] Note: none
```python n,k=map(int,input().split()) for i in range(1,k): if(k*i>n): print(k*i) break ```
0
582
A
GCD Table
PROGRAMMING
1,700
[ "constructive algorithms", "greedy", "number theory" ]
null
null
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*.
The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*.
In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them.
[ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ]
[ "4 3 6 2", "42 ", "1 1 " ]
none
750
[ { "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 " }, { "input": "1\n42", "output": "42 " }, { "input": "2\n1 1 1 1", "output": "1 1 " }, { "input": "2\n54748096 1 641009859 1", "output": "54748096 641009859 " }, { "input": "3\n1 7 923264237 374288891 7 524125987 1 1 1", "output": "374288891 524125987 923264237 " }, { "input": "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "output": "496813081 561219907 673102149 702209411 " }, { "input": "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "output": "291882089 365329221 412106895 564718673 585325539 " }, { "input": "5\n1 161 1 534447872 161 233427865 1 7 7 73701396 1 401939237 4 1 1 1 1 1 7 115704211 1 4 1 7 1", "output": "73701396 115704211 233427865 401939237 534447872 " }, { "input": "5\n2 11 1 1 2 4 2 1 181951 4 345484316 2 4 4 4 2 1 140772746 1 634524 4 521302304 1 2 11", "output": "181951 634524 140772746 345484316 521302304 " }, { "input": "5\n27 675 1 1 347621274 5 2 13 189 738040275 5 1 189 13 1 959752125 770516962 769220855 5 5 2 675 1 1 27", "output": "347621274 738040275 769220855 770516962 959752125 " }, { "input": "5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2029 165353355 4058 2029 731472761 739767313 2029 2029 2029 585281282", "output": "165353355 527243766 585281282 731472761 739767313 " }, { "input": "5\n537163 537163 537163 537163 537163 537163 1074326 537163 537163 537163 515139317 1074326 537163 537163 537163 539311652 321760637 170817834 537163 537163 537163 537163 537163 537163 392666153", "output": "170817834 321760637 392666153 515139317 539311652 " }, { "input": "4\n1 188110 607844 2 1 1 695147 1 1 1 143380513 1 1 1 1 2", "output": "188110 607844 695147 143380513 " }, { "input": "4\n3 1 96256522 120 360284388 3 3 2 2 2 3 12 12 2 1 198192381", "output": "120 96256522 198192381 360284388 " }, { "input": "4\n67025 13405 1915 1915 1915 1915 5745 676469920 53620 5745 660330300 67025 53620 380098775 533084295 13405", "output": "380098775 533084295 660330300 676469920 " }, { "input": "4\n700521 233507 759364764 467014 468181535 233507 233507 890362191 233507 700521 467014 233507 946637378 233507 233507 233507", "output": "468181535 759364764 890362191 946637378 " }, { "input": "3\n484799 1 1 744137 1 1 909312183 1 1", "output": "484799 744137 909312183 " }, { "input": "3\n1 716963379 1 1 205 1 1 964 1", "output": "205 964 716963379 " }, { "input": "3\n5993 781145599 54740062 5993 5993 267030101 5993 5993 5993", "output": "54740062 267030101 781145599 " }, { "input": "3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339", "output": "55451923 435485671 531222142 " }, { "input": "5\n4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1", "output": "1 2 4 4 4 " }, { "input": "4\n1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3", "output": "1 1 3 3 " }, { "input": "6\n1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6", "output": "1 3 3 6 6 6 " } ]
1,592,034,328
2,147,483,647
PyPy 3
OK
TESTS
54
451
21,811,200
import math as ma import sys input=sys.stdin.readline def fu(b): for i in b: if b[i]!=0: return i return -1 def gcd(a,b): if a%b==0: return b else: return gcd(b,a%b) n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) b={} for i in range(n*n): if a[i] in b.keys(): b[a[i]]+=1 else: b[a[i]]=1 c=[] for i in b: c.append(i) b[i]-=1 break while 1>0: if len(c)<n: a=fu(b) if a==-1: break else: b[a]-=1 for i in range(len(c)): b[gcd(a,c[i])]-=2 c.append(a) else: break print(*c)
Title: GCD Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*. Output Specification: In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. Demo Input: ['4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n', '1\n42\n', '2\n1 1 1 1\n'] Demo Output: ['4 3 6 2', '42 ', '1 1 '] Note: none
```python import math as ma import sys input=sys.stdin.readline def fu(b): for i in b: if b[i]!=0: return i return -1 def gcd(a,b): if a%b==0: return b else: return gcd(b,a%b) n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) b={} for i in range(n*n): if a[i] in b.keys(): b[a[i]]+=1 else: b[a[i]]=1 c=[] for i in b: c.append(i) b[i]-=1 break while 1>0: if len(c)<n: a=fu(b) if a==-1: break else: b[a]-=1 for i in range(len(c)): b[gcd(a,c[i])]-=2 c.append(a) else: break print(*c) ```
3
960
B
Minimize the error
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
[ "2 0 0\n1 2\n2 3\n", "2 1 0\n1 2\n2 2\n", "2 5 7\n3 4\n14 4\n" ]
[ "2", "0", "1" ]
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
1,000
[ { "input": "2 0 0\n1 2\n2 3", "output": "2" }, { "input": "2 1 0\n1 2\n2 2", "output": "0" }, { "input": "2 5 7\n3 4\n14 4", "output": "1" }, { "input": "2 0 1\n1 2\n2 2", "output": "0" }, { "input": "2 1 1\n0 0\n1 1", "output": "0" }, { "input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "3 4 5\n1 2 3\n3 2 1", "output": "1" }, { "input": "3 1000 0\n1 2 3\n-1000 -1000 -1000", "output": "1341346" }, { "input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3", "output": "1" }, { "input": "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 21 25 2 -3 45 -7 -98 -56", "output": "0" }, { "input": "10 10 580\n302 -553 -281 -299 -270 -890 -989 -749 -418 486\n735 330 6 725 -984 209 -855 -786 -502 967", "output": "2983082" }, { "input": "10 403 187\n9691 -3200 3016 3540 -9475 8840 -4705 7940 6293 -2631\n-2288 9129 4067 696 -6754 9869 -5747 701 3344 -3426", "output": "361744892" }, { "input": "10 561 439\n76639 67839 10670 -23 -18393 65114 46538 67596 86615 90480\n50690 620 -33631 -75857 75634 91321 -81662 -93668 -98557 -43621", "output": "116776723778" }, { "input": "10 765 62\n-929885 -995154 254071 -370672 -435272 584846 -301610 -234118 -82557 743536\n-36327 439149 -977780 -821019 -585558 953598 -151943 140715 -311253 -383103", "output": "6216649853365" }, { "input": "22 334 246\n-462653 -618002 4973 -348485 366658 192390 274752 200590 138367 779540 -661269 642587 113645 -110388 -604418 -491231 -933401 -219332 -603140 836439 167007 210226\n357638 -646669 -558432 -434313 -285851 -119233 323088 -512237 -729293 215256 39316 -984201 -209814 715016 -271932 796550 988227 -89577 67202 462973 -942079 -823339", "output": "15389604923763" }, { "input": "1 1000 0\n1000000\n-1000000", "output": "3996001000000" }, { "input": "1 1000 0\n1000000\n1000000", "output": "0" }, { "input": "1 0 1000\n-1000000\n1000000", "output": "3996001000000" }, { "input": "1 0 1000\n1000000\n1000000", "output": "0" }, { "input": "1 5 7\n1\n2", "output": "1" }, { "input": "2 1 3\n2 2\n2 2", "output": "0" }, { "input": "3 3 0\n1 1 1\n1 1 1", "output": "1" }, { "input": "1 0 6\n0\n0", "output": "0" }, { "input": "2 1 1\n2 2\n0 0", "output": "2" }, { "input": "3 1 4\n0 0 0\n1 5 6", "output": "19" }, { "input": "1 1 2\n0\n8", "output": "25" }, { "input": "2 2 0\n3 3\n3 3", "output": "0" } ]
1,523,118,753
1,653
Python 3
RUNTIME_ERROR
PRETESTS
7
93
7,168,000
from collections import Counter n, k1, k2 = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = k1 + k2 d = [abs(a[i] - b[i]) for i in range(n)] C = Counter(d) if sum(d) > k: while k > 0: m = max(C.keys()) t = min(k, C[m]) k -= t C[m] -= t if C[m] == 0: del C[m] m = max(C.keys()) C[m] += t else: break ans = sum([k ** 2 * v for k, v in C.items()]) print(ans) else: print((k - sum(d)) % 2)
Title: Minimize the error Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. Input Specification: The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*. Output Specification: Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. Demo Input: ['2 0 0\n1 2\n2 3\n', '2 1 0\n1 2\n2 2\n', '2 5 7\n3 4\n14 4\n'] Demo Output: ['2', '0', '1'] Note: In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
```python from collections import Counter n, k1, k2 = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = k1 + k2 d = [abs(a[i] - b[i]) for i in range(n)] C = Counter(d) if sum(d) > k: while k > 0: m = max(C.keys()) t = min(k, C[m]) k -= t C[m] -= t if C[m] == 0: del C[m] m = max(C.keys()) C[m] += t else: break ans = sum([k ** 2 * v for k, v in C.items()]) print(ans) else: print((k - sum(d)) % 2) ```
-1
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,647,802,245
2,147,483,647
Python 3
OK
TESTS
51
124
0
s=input() c=0 while(len(s)>1): sum=0 for i in s: sum+=int(i) s=str(sum) c+=1 print(c)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python s=input() c=0 while(len(s)>1): sum=0 for i in s: sum+=int(i) s=str(sum) c+=1 print(c) ```
3.969
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,687,879,406
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
s = str(input()) x = 0 if len(s) > 5 : if "h" in s : x += 1 if "e" in s : x+= 1 if "l" in s : x += 1 if "o" in s : x += 1 if x >= 5 or "hello" in s: print("YES") else : print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = str(input()) x = 0 if len(s) > 5 : if "h" in s : x += 1 if "e" in s : x+= 1 if "l" in s : x += 1 if "o" in s : x += 1 if x >= 5 or "hello" in s: print("YES") else : print("NO") ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,553,772,872
2,147,483,647
Python 3
OK
TESTS
102
124
0
m = input() oo = [] mm = list(m) n = input() nn = list(n) for i in range(0,len(m)): oo.append(int(mm[i]) + int(nn[i])) for i in range(0,len(oo)): oo[i] = str(oo[i]) str1 = ''.join(oo) finfin = str1.replace('2','0') print(finfin)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python m = input() oo = [] mm = list(m) n = input() nn = list(n) for i in range(0,len(m)): oo.append(int(mm[i]) + int(nn[i])) for i in range(0,len(oo)): oo[i] = str(oo[i]) str1 = ''.join(oo) finfin = str1.replace('2','0') print(finfin) ```
3.969
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*.
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces.
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "output": "6" }, { "input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "5\n1 0\n1 0\n1 0\n0 1\n0 1", "output": "4" } ]
1,634,793,345
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
4,505,600
n = int(input()) l = [] for i in range(n): a = list(map(int, input().split())) l.append(a) #1 == open, 0 == closed clo = clc = cro = crc = 0 for i in l: if i[0] == 1: clo+=1 else: clc+=1 if i[1] == 1: cro+=1 else: crc +=1 ld = rd = 0 if clo > cro or clc < crc: ld = 1 rd = 0 else: ld = 0 rd = 1 if ld == 1: #if left doors have to be open print(clc+cro) else: print(clo+crc)
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. Input Specification: The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. Output Specification: In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Demo Input: ['5\n0 1\n1 0\n0 1\n1 1\n0 1\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) l = [] for i in range(n): a = list(map(int, input().split())) l.append(a) #1 == open, 0 == closed clo = clc = cro = crc = 0 for i in l: if i[0] == 1: clo+=1 else: clc+=1 if i[1] == 1: cro+=1 else: crc +=1 ld = rd = 0 if clo > cro or clc < crc: ld = 1 rd = 0 else: ld = 0 rd = 1 if ld == 1: #if left doors have to be open print(clc+cro) else: print(clo+crc) ```
0
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "input": "24 22 9235", "output": "34" }, { "input": "74 8 417", "output": "1" }, { "input": "972 1 203", "output": "0" }, { "input": "550 1 754", "output": "1" }, { "input": "860 1 884", "output": "1" }, { "input": "358 2 809", "output": "2" }, { "input": "33 27 216", "output": "0" }, { "input": "2940 1 9311", "output": "3" }, { "input": "4624 1 1953", "output": "0" }, { "input": "2696 2 7345", "output": "2" }, { "input": "3443 2 6701", "output": "0" }, { "input": "3 613 2275", "output": "1" }, { "input": "1 10000 10000", "output": "1" }, { "input": "10000 1 10000", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1 10000", "output": "10000" }, { "input": "34 27 10000", "output": "10" }, { "input": "2 2 9999", "output": "4999" }, { "input": "2 2 1", "output": "0" }, { "input": "6 4 36", "output": "3" }, { "input": "33 6 3005", "output": "45" }, { "input": "5 1 20", "output": "4" }, { "input": "1 2 10", "output": "5" }, { "input": "2 1 100", "output": "50" }, { "input": "10 20 10000", "output": "500" }, { "input": "8 12 12", "output": "0" } ]
1,486,136,023
2,147,483,647
Python 3
OK
TESTS
32
61
5,939,200
n, m, z = (int(i) for i in input().split()) calls = set(i for i in range(0, z + 1, n)) art = set(i for i in range(0, z + 1, m)) print(len(calls & art) - 1)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. Input Specification: The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). Output Specification: Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Demo Input: ['1 1 10\n', '1 2 5\n', '2 3 9\n'] Demo Output: ['10\n', '2\n', '1\n'] Note: Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
```python n, m, z = (int(i) for i in input().split()) calls = set(i for i in range(0, z + 1, n)) art = set(i for i in range(0, z + 1, m)) print(len(calls & art) - 1) ```
3
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not.
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", "output": "YES" }, { "input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", "output": "NO" }, { "input": " furuike ya\nkawazu tobikomu\nmizu no oto ", "output": "YES" }, { "input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ", "output": "NO" }, { "input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det", "output": "YES" }, { "input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel", "output": "NO" }, { "input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti", "output": "NO" }, { "input": "kutaburete\nyado karu koro ya\nfuji no hana", "output": "YES" }, { "input": " beginnings of poetry\n the rice planting songs \n of the interior", "output": "NO" }, { "input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden", "output": "NO" }, { "input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut", "output": "YES" }, { "input": "writing in the dark\nunaware that my pen\nhas run out of ink", "output": "NO" }, { "input": "kusaaiu\nuieueua\nuo efaa", "output": "YES" }, { "input": "v\nh\np", "output": "NO" }, { "input": "i\ni\nu", "output": "NO" }, { "input": "awmio eoj\nabdoolceegood\nwaadeuoy", "output": "YES" }, { "input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo", "output": "YES" }, { "input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr", "output": "YES" }, { "input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd", "output": "YES" }, { "input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ", "output": "YES" }, { "input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs", "output": "YES" }, { "input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn", "output": "NO" }, { "input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl", "output": "NO" }, { "input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr", "output": "NO" }, { "input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf", "output": "NO" }, { "input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi", "output": "NO" }, { "input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu", "output": "NO" }, { "input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt", "output": "NO" }, { "input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo", "output": "NO" }, { "input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau", "output": "NO" }, { "input": "ab\na\na", "output": "NO" }, { "input": "on codeforcs\nbeta round is runnineg\na rustling of keys", "output": "NO" }, { "input": "coooooooooooooooood\nd\nd", "output": "NO" }, { "input": "on codeforces \nbeta round is runninog\n a rustling of keys", "output": "NO" }, { "input": "aaaaaaaaaaaaaaa\na\na", "output": "NO" }, { "input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "YES" }, { "input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "output": "NO" }, { "input": "aaaaaa\naaaaaa\naaaaa", "output": "NO" } ]
1,572,794,228
2,147,483,647
Python 3
OK
TESTS
40
218
0
a=input() b=input() c=input() p=['a','e','i','o','u'] d=0 e=0 f=0 for i in a: if i in p: d=d+1 for j in b: if j in p: e=e+1 for k in c: if k in p: f=f+1 if d==5 and e==7 and f==5: print('YES') else: print('NO')
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input Specification: The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Specification: Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Demo Input: ['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n'] Demo Output: ['YES', 'NO'] Note: none
```python a=input() b=input() c=input() p=['a','e','i','o','u'] d=0 e=0 f=0 for i in a: if i in p: d=d+1 for j in b: if j in p: e=e+1 for k in c: if k in p: f=f+1 if d==5 and e==7 and f==5: print('YES') else: print('NO') ```
3.9455
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
1,552,765,663
2,147,483,647
Python 3
OK
TESTS
18
109
0
import math k,n,s,p=map(int,input().split()) print(math.ceil(k*math.ceil(n/s)/p))
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python import math k,n,s,p=map(int,input().split()) print(math.ceil(k*math.ceil(n/s)/p)) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,586,000,560
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
307,200
n=input("please enter number1") m=input("please enter number2") list_a=[] list_b=[] list_c=[] for ch1 in n: list_a.append(ch1) for ch2 in m: list_b.append(ch2) for i in range(len(n)): for j in range(len(m)): if i==j : if list_a.pop()==list_b.pop(): list_c.append(0) else: list_c.append(1) list_c.reverse() for k in list_c: print(k,end='')
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python n=input("please enter number1") m=input("please enter number2") list_a=[] list_b=[] list_c=[] for ch1 in n: list_a.append(ch1) for ch2 in m: list_b.append(ch2) for i in range(len(n)): for j in range(len(m)): if i==j : if list_a.pop()==list_b.pop(): list_c.append(0) else: list_c.append(1) list_c.reverse() for k in list_c: print(k,end='') ```
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,696,332,928
2,147,483,647
Python 3
OK
TESTS
44
92
0
line = input() ans = "NO" for i in range(len(line) - 6): if line[i: i + 7].count('0') == 7 or line[i: i + 7].count('1') == 7: ans = "YES" break print(ans)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python line = input() ans = "NO" for i in range(len(line) - 6): if line[i: i + 7].count('0') == 7 or line[i: i + 7].count('1') == 7: ans = "YES" break print(ans) ```
3.977
609
B
The Best Gift
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*.
The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre.
Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109.
[ "4 3\n2 1 3 1\n", "7 4\n4 2 3 1 2 4 3\n" ]
[ "5\n", "18\n" ]
The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
0
[ { "input": "4 3\n2 1 3 1", "output": "5" }, { "input": "7 4\n4 2 3 1 2 4 3", "output": "18" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "3 2\n1 2 2", "output": "2" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "45" }, { "input": "9 2\n1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "12 3\n1 2 3 1 2 3 1 2 3 1 2 3", "output": "48" }, { "input": "100 3\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3", "output": "3296" }, { "input": "100 5\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5", "output": "3953" }, { "input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6", "output": "4428" } ]
1,647,091,117
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
18
2,000
11,264,000
asd = input() num = input().split() count = 0 for j in range(len(num)): for i in num[j+1:]: if num[j] != i: count += 1 print(count)
Title: The Best Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*. Input Specification: The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre. Output Specification: Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109. Demo Input: ['4 3\n2 1 3 1\n', '7 4\n4 2 3 1 2 4 3\n'] Demo Output: ['5\n', '18\n'] Note: The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
```python asd = input() num = input().split() count = 0 for j in range(len(num)): for i in num[j+1:]: if num[j] != i: count += 1 print(count) ```
0
560
A
Currency System in Geraldion
PROGRAMMING
1,000
[ "implementation", "sortings" ]
null
null
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?
The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion. The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes.
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1.
[ "5\n1 2 3 4 5\n" ]
[ "-1\n" ]
none
500
[ { "input": "5\n1 2 3 4 5", "output": "-1" }, { "input": "1\n2", "output": "1" }, { "input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "output": "-1" }, { "input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "output": "1" }, { "input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156", "output": "-1" }, { "input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173", "output": "1" }, { "input": "1\n1", "output": "-1" }, { "input": "1\n1000000", "output": "1" }, { "input": "2\n3 2", "output": "1" }, { "input": "2\n2 3", "output": "1" } ]
1,450,812,026
2,147,483,647
Python 3
OK
TESTS
16
46
0
n = int(input()) num = map(int, input().rstrip().split()) if 1 in num: print(-1) else: print(1)
Title: Currency System in Geraldion Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion. The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. Output Specification: Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. Demo Input: ['5\n1 2 3 4 5\n'] Demo Output: ['-1\n'] Note: none
```python n = int(input()) num = map(int, input().rstrip().split()) if 1 in num: print(-1) else: print(1) ```
3
703
C
Chris and Road
PROGRAMMING
2,100
[ "geometry", "implementation" ]
null
null
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.
The first line of the input contains four integers *n*, *w*, *v*, *u* (3<=≤<=*n*<=≤<=10<=000, 1<=≤<=*w*<=≤<=109, 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* (<=-<=109<=≤<=*x**i*<=≤<=109, 0<=≤<=*y**i*<=≤<=*w*) — coordinates of *i*-th polygon point. It is guaranteed that the polygon is non-degenerate.
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.
[ "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n" ]
[ "5.0000000000" ]
Following image describes initial position in the first sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/6d0966ee3194a0c11a228fa83f19a00157de89f7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,750
[ { "input": "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4", "output": "5.0000000000" }, { "input": "3 3 5 2\n3 1\n4 0\n5 1", "output": "1.5000000000" }, { "input": "3 3 2 4\n0 1\n2 1\n1 2", "output": "1.5000000000" }, { "input": "3 3 1 1\n0 0\n1 1\n0 2", "output": "3.0000000000" }, { "input": "9 10 5 2\n22 5\n25 0\n29 0\n31 2\n32 5\n31 8\n29 10\n25 10\n23 8", "output": "5.0000000000" }, { "input": "10 10 2 4\n-4 5\n-3 2\n-1 0\n3 0\n5 2\n6 5\n5 8\n3 10\n-1 10\n-2 9", "output": "4.5000000000" }, { "input": "10 10 1 4\n-1 5\n0 2\n2 0\n5 0\n7 1\n9 5\n8 8\n6 10\n2 10\n0 8", "output": "10.2500000000" }, { "input": "10 10 1 1\n5 5\n7 1\n8 0\n12 0\n14 2\n15 5\n14 8\n12 10\n8 10\n6 8", "output": "22.0000000000" }, { "input": "10 1000 4 5\n-175 23\n-52 1\n129 24\n412 255\n399 767\n218 938\n110 982\n62 993\n-168 979\n-501 650", "output": "252.0000000000" }, { "input": "10 1000 8 4\n1015 375\n1399 10\n1605 11\n1863 157\n1934 747\n1798 901\n1790 907\n1609 988\n1404 991\n1177 883", "output": "447.8750000000" }, { "input": "10 1000 2 8\n-75 224\n-56 197\n0 135\n84 72\n264 6\n643 899\n572 944\n282 996\n110 943\n1 866", "output": "334.1250000000" }, { "input": "10 1000 6 2\n1901 411\n1933 304\n2203 38\n2230 27\n2250 21\n2396 0\n2814 230\n2705 891\n2445 997\n2081 891", "output": "899.3333333333" }, { "input": "10 1000 4 7\n-253 81\n67 2\n341 117\n488 324\n489 673\n380 847\n62 998\n20 1000\n-85 989\n-378 803", "output": "218.5714285714" }, { "input": "10 1000 4 1\n2659 245\n2715 168\n2972 14\n3229 20\n3232 21\n3479 187\n3496 210\n3370 914\n3035 997\n2938 977", "output": "1787.2500000000" }, { "input": "10 1000 2 2\n60 123\n404 0\n619 56\n715 121\n740 144\n614 947\n566 968\n448 997\n300 992\n270 986", "output": "798.0000000000" }, { "input": "10 1000 10 4\n554 284\n720 89\n788 50\n820 35\n924 7\n1324 115\n1309 897\n1063 997\n592 782\n584 770", "output": "353.6500000000" }, { "input": "10 1000 4 8\n-261 776\n-94 67\n-45 42\n23 18\n175 0\n415 72\n258 989\n183 999\n114 998\n-217 833", "output": "219.7500000000" }, { "input": "10 1000 10 2\n2731 286\n3154 1\n3590 210\n3674 406\n3667 625\n3546 844\n3275 991\n3154 999\n2771 783\n2754 757", "output": "814.9000000000" }, { "input": "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796", "output": "2.6246719160" }, { "input": "10 1000 519 882\n-407 135\n-222 25\n-211 22\n-168 11\n-90 1\n43 12\n312 828\n175 939\n-174 988\n-329 925", "output": "1.2030330437" }, { "input": "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734", "output": "2.0760668149" }, { "input": "10 1000 35 722\n320 31\n528 1\n676 34\n979 378\n990 563\n916 768\n613 986\n197 902\n164 876\n34 696", "output": "1.3850415512" }, { "input": "10 1000 791 415\n613 191\n618 185\n999 0\n1023 0\n1084 6\n1162 25\n1306 100\n1351 138\n713 905\n559 724", "output": "3.8197492879" }, { "input": "10 1000 763 109\n-449 324\n-398 224\n-357 170\n45 1\n328 107\n406 183\n428 212\n65 998\n-160 967\n-262 914", "output": "9.2241153342" }, { "input": "10 1000 12 255\n120 71\n847 668\n814 741\n705 877\n698 883\n622 935\n473 991\n176 958\n131 936\n41 871", "output": "3.9215686275" }, { "input": "10 1000 471 348\n-161 383\n339 0\n398 5\n462 19\n606 86\n770 728\n765 737\n747 768\n546 949\n529 956", "output": "3.9130609854" }, { "input": "10 1000 35 450\n259 41\n383 6\n506 2\n552 9\n852 193\n943 383\n908 716\n770 890\n536 994\n28 757", "output": "28.3139682540" }, { "input": "10 1000 750 426\n1037 589\n1215 111\n1545 0\n1616 8\n1729 42\n2026 445\n1964 747\n1904 831\n1763 942\n1757 945", "output": "2.3474178404" }, { "input": "10 1000 505 223\n1564 401\n1689 158\n2078 1\n2428 168\n2477 767\n2424 836\n1929 984\n1906 978\n1764 907\n1723 875", "output": "8.5946721130" }, { "input": "10 1000 774 517\n-252 138\n150 3\n501 211\n543 282\n575 367\n534 736\n382 908\n84 1000\n-78 970\n-344 743", "output": "2.1733990074" }, { "input": "10 1000 22 255\n70 266\n272 61\n328 35\n740 55\n850 868\n550 999\n448 996\n371 980\n302 954\n62 718", "output": "3.9215686275" }, { "input": "10 1000 482 756\n114 363\n190 207\n1016 230\n1039 270\n912 887\n629 999\n514 993\n439 975\n292 898\n266 877", "output": "3.1264023359" }, { "input": "10 1000 750 154\n-154 43\n-134 35\n-41 8\n127 6\n387 868\n179 983\n77 999\n26 999\n-51 990\n-239 909", "output": "6.6238787879" }, { "input": "10 1000 998 596\n1681 18\n2048 59\n2110 98\n2201 185\n2282 327\n2250 743\n2122 893\n1844 999\n1618 960\n1564 934", "output": "1.6778523490" }, { "input": "10 1000 458 393\n826 363\n1241 4\n1402 9\n1441 18\n1800 417\n1804 555\n1248 997\n1207 990\n1116 962\n1029 916", "output": "5.6450159450" }, { "input": "10 1000 430 983\n-206 338\n-86 146\n221 2\n766 532\n531 925\n507 939\n430 973\n369 989\n29 940\n-170 743", "output": "2.2574889399" }, { "input": "5 5 100 2\n1 2\n3 1\n4 3\n3 4\n1 4", "output": "2.5000000000" }, { "input": "3 10 3 2\n1 5\n2 2\n2 8", "output": "5.0000000000" } ]
1,689,168,344
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689168344.601377")# 1689168344.601391
Title: Chris and Road Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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 Specification: The first line of the input contains four integers *n*, *w*, *v*, *u* (3<=≤<=*n*<=≤<=10<=000, 1<=≤<=*w*<=≤<=109, 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* (<=-<=109<=≤<=*x**i*<=≤<=109, 0<=≤<=*y**i*<=≤<=*w*) — coordinates of *i*-th polygon point. It is guaranteed that the polygon is non-degenerate. Output Specification: 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. Demo Input: ['5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n'] Demo Output: ['5.0000000000'] Note: Following image describes initial position in the first sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/6d0966ee3194a0c11a228fa83f19a00157de89f7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python print("_RANDOM_GUESS_1689168344.601377")# 1689168344.601391 ```
0
462
A
Appleman and Easy Task
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
[ "3\nxxo\nxox\noxx\n", "4\nxxxo\nxoxo\noxox\nxxxx\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "3\nxxo\nxox\noxx", "output": "YES" }, { "input": "4\nxxxo\nxoxo\noxox\nxxxx", "output": "NO" }, { "input": "1\no", "output": "YES" }, { "input": "2\nox\nxo", "output": "YES" }, { "input": "2\nxx\nxo", "output": "NO" }, { "input": "3\nooo\noxo\nxoo", "output": "NO" }, { "input": "3\nxxx\nxxo\nxxo", "output": "NO" }, { "input": "4\nxooo\nooxo\noxoo\nooox", "output": "YES" }, { "input": "4\noooo\noxxo\nxoxo\noooo", "output": "NO" }, { "input": "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "output": "YES" }, { "input": "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "output": "NO" }, { "input": "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxoxoxo\noxxxooooxo\noxooooxxxo\noxoxoxxooo\noxoooxooxx\noxxxxxoxxo\noooooooxox", "output": "YES" }, { "input": "10\nxxxxxxxoox\nxooxxooooo\noxoooxxooo\nxoxxxxxxxx\nxxoxooxxox\nooxoxxooox\nooxxxxxooo\nxxxxoxooox\nxoxxooxxxx\noooooxxoxo", "output": "NO" }, { "input": "19\noxoxoxoxooxoooxxoox\nxxxxxxxxoxxoxoooooo\noxoxoxooxxxooxxxooo\nxxoxxxooxooxxxoxxox\noxoxooxxxooooxxoxox\nxxxoooxoxxoxxoxxxoo\noxooxxxoooooxxoooxo\nxxooxooxoxxoxxoxxoo\noxxxxooooxxxooooxxx\nooxooxoxxoxxoxooxoo\nxxxooooxxxooooxoxox\noooxoxooxxoxooxooxx\nxxoooxxxooooxxoooxo\nooxxxooxoxooxooxxxx\nxoxoxxooxoxxxooxoxo\nxoxxoxoxooxooxxxxxx\noooxxxooxxxooxoxoxo\nxoooooxoxooxxxxxxxo\nxooxxoooxxoxoxoxoxx", "output": "NO" }, { "input": "12\nxxooxxoxxxoo\nxxoooxoxoxoo\nooxoxoxxooxx\nooxxooooxoxo\nxxxxxxxxoxxx\noxooooxxxooo\noxxoxoxoooxx\nxxxxxxxooxox\noxoooooxoxxx\nxxooxxoxxoxx\noxxxxxxxooxx\nooxoxooxxooo", "output": "NO" }, { "input": "2\noo\nxx", "output": "NO" } ]
1,648,535,153
2,147,483,647
Python 3
OK
TESTS
32
46
0
num = int(input()) li = [] for x in range(num): l = input() for i in l: if i == "x": li.append(0) else: li.append(1) li = [0 for x in range(num)] + li + [0 for x in range(num)] lis = [] for x in range(num,len(li)-num): if x%num==0: lis.append(li[x+1]+ li[x-num]+ li[x+num]) elif (x+1)%num==0: lis.append(li[x-1]+ li[x-num]+ li[x+num]) else: lis.append(li[x-1]+ li[x+1]+ li[x-num]+ li[x+num]) yes = True for i in lis: if i%2 == 0: yes = True else: yes = False break if yes: print("YES") else: print("NO")
Title: Appleman and Easy Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. Output Specification: Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Demo Input: ['3\nxxo\nxox\noxx\n', '4\nxxxo\nxoxo\noxox\nxxxx\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python num = int(input()) li = [] for x in range(num): l = input() for i in l: if i == "x": li.append(0) else: li.append(1) li = [0 for x in range(num)] + li + [0 for x in range(num)] lis = [] for x in range(num,len(li)-num): if x%num==0: lis.append(li[x+1]+ li[x-num]+ li[x+num]) elif (x+1)%num==0: lis.append(li[x-1]+ li[x-num]+ li[x+num]) else: lis.append(li[x-1]+ li[x+1]+ li[x-num]+ li[x+num]) yes = True for i in lis: if i%2 == 0: yes = True else: yes = False break if yes: print("YES") else: print("NO") ```
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,694,806,020
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
s = input() start = 1 end = len(s) - 1 counts = 0 res = s if len(s) <= 1: break for i in range(start, end): if len(s) >= 10: counts+=1 re = str(counts) res = (f"{s[0]}{counts}{s[end]}") print(res)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python s = input() start = 1 end = len(s) - 1 counts = 0 res = s if len(s) <= 1: break for i in range(start, end): if len(s) >= 10: counts+=1 re = str(counts) res = (f"{s[0]}{counts}{s[end]}") print(res) ```
-1
622
C
Not Equal on a Segment
PROGRAMMING
1,700
[ "data structures", "implementation" ]
null
null
You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query.
Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number.
[ "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n" ]
[ "2\n6\n-1\n4\n" ]
none
0
[ { "input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2", "output": "2\n6\n-1\n4" }, { "input": "1 1\n1\n1 1 1", "output": "-1" }, { "input": "1 1\n2\n1 1 2", "output": "-1" }, { "input": "1 1\n569888\n1 1 967368", "output": "1" }, { "input": "10 10\n1 1 1 1 1 1 1 1 1 1\n3 10 1\n3 6 1\n1 8 1\n1 7 1\n1 5 1\n3 7 1\n4 7 1\n9 9 1\n6 7 1\n3 4 1", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1" }, { "input": "10 10\n1 2 2 2 2 1 1 2 1 1\n3 3 1\n4 9 1\n4 8 1\n2 7 2\n2 8 2\n3 10 1\n7 7 2\n10 10 2\n1 5 1\n1 2 1", "output": "3\n8\n8\n7\n7\n8\n7\n10\n5\n2" }, { "input": "10 10\n318890 307761 832732 700511 820583 522866 130891 914566 128429 739710\n4 9 178864\n6 9 741003\n4 9 172997\n4 6 314469\n1 4 694802\n8 8 401658\n7 10 376243\n7 8 508771\n3 5 30038\n2 10 591490", "output": "9\n9\n9\n6\n4\n8\n10\n8\n5\n10" }, { "input": "1 1\n2\n1 1 1", "output": "1" }, { "input": "10 10\n1 1 1 1 1 2 1 1 1 1\n1 9 1\n6 7 1\n2 4 1\n7 8 1\n1 3 1\n10 10 1\n3 5 1\n6 7 1\n1 10 1\n6 6 1", "output": "6\n6\n-1\n-1\n-1\n-1\n-1\n6\n6\n6" }, { "input": "7 1\n2 1 3 2 2 2 2\n1 7 2", "output": "3" }, { "input": "4 1\n3 1 2 2\n1 4 2", "output": "2" }, { "input": "6 1\n3 2 4 3 3 3\n1 6 3", "output": "3" }, { "input": "4 1\n1 3 2 2\n1 4 2", "output": "2" }, { "input": "5 1\n2 3 1 2 2\n1 5 2", "output": "3" }, { "input": "3 1\n1 9 5\n1 3 5", "output": "2" }, { "input": "4 1\n4 2 6 4\n1 4 4", "output": "3" }, { "input": "2 1\n1 3\n1 2 2", "output": "2" }, { "input": "10 1\n2 2 1 3 2 2 2 2 2 2\n2 5 2", "output": "4" }, { "input": "7 1\n6 5 7 6 6 6 6\n1 7 6", "output": "3" }, { "input": "3 1\n2 4 3\n1 3 3", "output": "2" }, { "input": "4 1\n4 2 3 3\n1 4 3", "output": "2" }, { "input": "5 1\n3 2 4 5 5\n1 3 3", "output": "3" }, { "input": "2 6\n1 1\n1 1 1\n1 1 2\n1 2 1\n1 2 2\n2 2 1\n2 2 2", "output": "-1\n1\n-1\n2\n-1\n2" } ]
1,463,127,229
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
5,120,000
class number: def __init__(self,n,num): self.n = n self.num = num def upquicksort(sta,l,r): if l >= r: return i = l j = r temp = sta[i] while i != j: while j > i and sta[j].n > temp.n: j -= 1 if j > i: sta[i] = sta[j] i += 1 while j > i and sta[i].n < temp.n: i += 1 if j > i: sta[j] = sta[i] j -= 1 sta[i] = temp upquicksort(sta,l,i-1) upquicksort(sta,i+1,r) return n,m = map(int,input().split()) a1 = list(map(int,input().split())) a = [] for i in range(len(a1)): a.append(number(a1[i],i+1)) for i in range(m): b = list(map(int,input().split())) c = a[b[0]-1:b[1]] upquicksort(c,0,len(c)-1) if c[0].n != b[2]: print (c[0].num) elif c[-1].n != b[2]: print (c[-1].num) else: print (-1)
Title: Not Equal on a Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array *a* with *n* integers and *m* queries. The *i*-th query is given with three integers *l**i*,<=*r**i*,<=*x**i*. For the *i*-th query find any position *p**i* (*l**i*<=≤<=*p**i*<=≤<=*r**i*) so that *a**p**i*<=≠<=*x**i*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the number of elements in *a* and the number of queries. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Each of the next *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106) — the parameters of the *i*-th query. Output Specification: Print *m* lines. On the *i*-th line print integer *p**i* — the position of any number not equal to *x**i* in segment [*l**i*,<=*r**i*] or the value <=-<=1 if there is no such number. Demo Input: ['6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n'] Demo Output: ['2\n6\n-1\n4\n'] Note: none
```python class number: def __init__(self,n,num): self.n = n self.num = num def upquicksort(sta,l,r): if l >= r: return i = l j = r temp = sta[i] while i != j: while j > i and sta[j].n > temp.n: j -= 1 if j > i: sta[i] = sta[j] i += 1 while j > i and sta[i].n < temp.n: i += 1 if j > i: sta[j] = sta[i] j -= 1 sta[i] = temp upquicksort(sta,l,i-1) upquicksort(sta,i+1,r) return n,m = map(int,input().split()) a1 = list(map(int,input().split())) a = [] for i in range(len(a1)): a.append(number(a1[i],i+1)) for i in range(m): b = list(map(int,input().split())) c = a[b[0]-1:b[1]] upquicksort(c,0,len(c)-1) if c[0].n != b[2]: print (c[0].num) elif c[-1].n != b[2]: print (c[-1].num) else: print (-1) ```
0
855
B
Marvolo Gaunt's Ring
PROGRAMMING
1,500
[ "brute force", "data structures", "dp" ]
null
null
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
[ "5 1 2 3\n1 2 3 4 5\n", "5 1 2 -3\n-1 -2 -3 -4 -5\n" ]
[ "30\n", "12\n" ]
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
1,000
[ { "input": "5 1 2 3\n1 2 3 4 5", "output": "30" }, { "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12" }, { "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046" }, { "input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "output": "547306902373544674" }, { "input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "output": "1876641179289775029" }, { "input": "1 0 0 0\n0", "output": "0" }, { "input": "1 1000000000 1000000000 1000000000\n1000000000", "output": "3000000000000000000" }, { "input": "1 -1000000000 -1000000000 1000000000\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 -1000000000\n1000000000", "output": "-3000000000000000000" }, { "input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000", "output": "-3000000000000000000" }, { "input": "1 1 1 1\n-1", "output": "-3" }, { "input": "1 -1 -1 -1\n1", "output": "-3" }, { "input": "1 1000000000 1000000000 1000000000\n-1000000000", "output": "-3000000000000000000" }, { "input": "1 1 2 3\n-1", "output": "-6" }, { "input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "3 1 1 1\n-1 -1 -1", "output": "-3" }, { "input": "1 -1000000000 0 0\n1000000000", "output": "-1000000000000000000" }, { "input": "1 -100 -100 -100\n100", "output": "-30000" }, { "input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-3000000000000000000" }, { "input": "1 999999999 999999999 999999999\n-999999999", "output": "-2999999994000000003" }, { "input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000", "output": "-1999999999000000000" }, { "input": "3 -2 3 -2\n1 2 1", "output": "2" }, { "input": "2 1 -1 1\n1 -1", "output": "1" }, { "input": "1 -1000000000 1 -1000000000\n1000000000", "output": "-1999999999000000000" }, { "input": "1 1000000000 1000000000 -1000000000\n-1000000000", "output": "-1000000000000000000" }, { "input": "1 -1000000000 -1000000000 0\n1000000000", "output": "-2000000000000000000" } ]
1,691,231,512
2,147,483,647
PyPy 3-64
OK
TESTS
82
108
17,920,000
n,p,q,r=map(int,input().split()) arr=list(map(int,input().strip().split())) pi,qj,rk= [],[],[] for i in range(n): x=arr[i] pi.append(x*p) qj.append(x*q) rk.append(x*r) for i in range(1,n): pi[i]=max(pi[i-1],pi[i]) rk[n-i-1]=max(rk[n-i],rk[n-i-1]) s=pi[0]+qj[0]+rk[0] for i in range(1,n):s=max(s,pi[i]+qj[i]+rk[i]) print(s)
Title: Marvolo Gaunt's Ring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. Input Specification: First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Output Specification: Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Demo Input: ['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n'] Demo Output: ['30\n', '12\n'] Note: In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30. In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12.
```python n,p,q,r=map(int,input().split()) arr=list(map(int,input().strip().split())) pi,qj,rk= [],[],[] for i in range(n): x=arr[i] pi.append(x*p) qj.append(x*q) rk.append(x*r) for i in range(1,n): pi[i]=max(pi[i-1],pi[i]) rk[n-i-1]=max(rk[n-i],rk[n-i-1]) s=pi[0]+qj[0]+rk[0] for i in range(1,n):s=max(s,pi[i]+qj[i]+rk[i]) print(s) ```
3
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,615,054,742
2,147,483,647
Python 3
OK
TESTS
53
154
716,800
a = input() b = input() d = 0 f = [] if not len(a) == len(b): print('NO') else: for i in range(len(a)): if not a[i] == b[i]: d += 1 if d == 3: break f.append([a[i], b[i]]) if d == 2: print('YES' if f[0][0] == f[1][1] and f[0][1] == f[1][0] else 'NO') else: print('NO')
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python a = input() b = input() d = 0 f = [] if not len(a) == len(b): print('NO') else: for i in range(len(a)): if not a[i] == b[i]: d += 1 if d == 3: break f.append([a[i], b[i]]) if d == 2: print('YES' if f[0][0] == f[1][1] and f[0][1] == f[1][0] else 'NO') else: print('NO') ```
3
982
B
Bus of Characters
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation" ]
null
null
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it; - an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row.
Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.
[ "2\n3 1\n0011\n", "6\n10 8 9 11 13 5\n010010011101\n" ]
[ "2 1 1 2 \n", "6 6 2 3 3 1 4 4 1 2 5 5 \n" ]
In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.
1,000
[ { "input": "2\n3 1\n0011", "output": "2 1 1 2 " }, { "input": "6\n10 8 9 11 13 5\n010010011101", "output": "6 6 2 3 3 1 4 4 1 2 5 5 " }, { "input": "1\n1\n01", "output": "1 1 " }, { "input": "1\n1000000\n01", "output": "1 1 " }, { "input": "2\n1 1000000\n0011", "output": "1 2 2 1 " }, { "input": "2\n1000000000 1\n0101", "output": "2 2 1 1 " }, { "input": "2\n1000000000 999999999\n0011", "output": "2 1 1 2 " }, { "input": "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111", "output": "6 3 3 7 1 9 10 2 8 5 4 4 5 8 2 10 9 1 7 6 " } ]
1,598,898,097
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
140
0
try: n = int(input()) ans = [] ansst = "" seats = list(map(int,input().split())) que = input() quelen = len(que) mis = min(seats) ind = seats.index(mis) ans.append(ind+1) ansst+=str(ind+1) ansst+=" " seats[ind]=23563652 for k in range(1,quelen): if(que[k]=='0'): mis = min(seats) ind = seats.index(mis) ans.append(ind+1) ansst+=str(ind+1) ansst+=" " seats[ind]=23563652 else: for u in range(len(ans)-1,-1,-1): if(ans.count(ans[u])!=2): ans.append(ans[u]) ansst+=str(ans[u]) ansst+=" " break print(ansst) except: pass
Title: Bus of Characters Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it; - an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row. Output Specification: Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input. Demo Input: ['2\n3 1\n0011\n', '6\n10 8 9 11 13 5\n010010011101\n'] Demo Output: ['2 1 1 2 \n', '6 6 2 3 3 1 4 4 1 2 5 5 \n'] Note: In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.
```python try: n = int(input()) ans = [] ansst = "" seats = list(map(int,input().split())) que = input() quelen = len(que) mis = min(seats) ind = seats.index(mis) ans.append(ind+1) ansst+=str(ind+1) ansst+=" " seats[ind]=23563652 for k in range(1,quelen): if(que[k]=='0'): mis = min(seats) ind = seats.index(mis) ans.append(ind+1) ansst+=str(ind+1) ansst+=" " seats[ind]=23563652 else: for u in range(len(ans)-1,-1,-1): if(ans.count(ans[u])!=2): ans.append(ans[u]) ansst+=str(ans[u]) ansst+=" " break print(ansst) except: pass ```
0
358
B
Dima and Text Messages
PROGRAMMING
1,500
[ "brute force", "strings" ]
null
null
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
[ "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n" ]
[ "yes\n", "no\n" ]
Please note that Dima got a good old kick in the pants for the second sample from the statement.
1,000
[ { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes" }, { "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "output": "yes" }, { "input": "4\na\nb\nc\nd\n<3a<3b<3c<3d", "output": "no" }, { "input": "4\na\nb\nc\nd\na<3b<3c<3d<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<3you<3", "output": "yes" }, { "input": "1\na\na", "output": "no" }, { "input": "1\na\n<3a<3b", "output": "yes" }, { "input": "1\naa\n<3a<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww", "output": "yes" }, { "input": "3\ni\nlove\nyou\n<3ilove<23you<3", "output": "no" }, { "input": "2\na\ni\n<3ai<3", "output": "no" } ]
1,653,941,980
2,147,483,647
PyPy 3
OK
TESTS
30
702
10,035,200
s = [] for i in range(int(input())): s.append(input()) s = "<3" + '<3'.join(s) + "<3" cur = 0 t = input() for i in t: if i == s[cur]: cur += 1 if cur == len(s): break print('yes' if cur == len(s) else 'no')
Title: Dima and Text Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. Output Specification: In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. Demo Input: ['3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n', '7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n'] Demo Output: ['yes\n', 'no\n'] Note: Please note that Dima got a good old kick in the pants for the second sample from the statement.
```python s = [] for i in range(int(input())): s.append(input()) s = "<3" + '<3'.join(s) + "<3" cur = 0 t = input() for i in t: if i == s[cur]: cur += 1 if cur == len(s): break print('yes' if cur == len(s) else 'no') ```
3
250
A
Paper Work
PROGRAMMING
1,000
[ "greedy" ]
null
null
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=&lt;<=0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence *a**i*, will print the minimum number of folders.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*.
Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder. If there are multiple ways to sort the reports into *k* days, print any of them.
[ "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n", "5\n0 -1 100 -1 0\n" ]
[ "3\n5 3 3 ", "1\n5 " ]
Here goes a way to sort the reports from the first sample into three folders: In the second sample you can put all five reports in one folder.
500
[ { "input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3 " }, { "input": "5\n0 -1 100 -1 0", "output": "1\n5 " }, { "input": "1\n0", "output": "1\n1 " }, { "input": "1\n-1", "output": "1\n1 " }, { "input": "2\n0 0", "output": "1\n2 " }, { "input": "2\n-2 2", "output": "1\n2 " }, { "input": "2\n-2 -1", "output": "1\n2 " }, { "input": "12\n1 -12 -5 -8 0 -8 -1 -1 -6 12 -9 12", "output": "4\n3 3 2 4 " }, { "input": "4\n1 2 0 3", "output": "1\n4 " }, { "input": "4\n4 -3 3 3", "output": "1\n4 " }, { "input": "4\n0 -3 4 -3", "output": "1\n4 " }, { "input": "4\n-3 -2 4 -3", "output": "2\n1 3 " }, { "input": "4\n-3 -2 -1 -4", "output": "2\n2 2 " }, { "input": "5\n-2 -2 4 0 -1", "output": "2\n1 4 " }, { "input": "5\n-5 -3 -1 2 -1", "output": "2\n2 3 " }, { "input": "5\n-3 -2 -3 -2 -3", "output": "3\n1 2 2 " }, { "input": "10\n0 5 2 3 10 9 4 9 9 3", "output": "1\n10 " }, { "input": "10\n10 2 1 2 9 10 7 4 -4 5", "output": "1\n10 " }, { "input": "10\n1 -3 1 10 -7 -6 7 0 -5 3", "output": "2\n5 5 " }, { "input": "10\n6 5 -10 -4 -3 -7 5 -2 -6 -10", "output": "4\n3 2 3 2 " }, { "input": "10\n-2 -4 -1 -6 -5 -5 -7 0 -7 -8", "output": "5\n1 2 2 2 3 " }, { "input": "100\n48 36 10 85 15 57 100 70 14 82 15 75 67 44 40 83 12 94 80 77 92 40 39 80 11 10 2 22 71 31 93 51 22 29 98 90 33 91 66 64 87 70 46 86 62 13 85 15 37 3 49 11 21 57 26 14 5 80 33 82 9 75 26 76 50 32 48 100 62 11 97 47 67 81 86 80 51 51 44 97 2 22 18 52 43 54 65 91 94 54 22 80 23 63 44 7 52 98 80 69", "output": "1\n100 " }, { "input": "100\n7 51 31 14 17 0 72 29 77 6 32 94 70 94 1 64 85 29 67 66 56 -90 38 85 51 5 69 36 62 99 99 43 43 40 68 88 62 39 45 75 50 95 51 96 69 60 65 27 63 89 23 43 49 39 92 90 1 49 22 78 13 90 97 87 5 100 60 82 50 49 0 11 87 34 67 7 35 65 20 92 89 29 73 48 41 8 14 76 91 34 13 18 42 75 36 14 78 80 74 9", "output": "1\n100 " }, { "input": "100\n83 71 43 50 61 54 -45 44 36 35 44 21 34 65 23 32 73 36 70 17 46 47 10 30 48 25 84 58 63 96 44 88 24 93 26 24 70 69 90 75 20 42 63 11 0 41 54 23 95 99 17 27 43 20 46 100 65 -79 15 72 78 0 13 94 76 72 69 35 61 3 65 83 28 12 27 48 8 37 30 37 40 87 30 76 81 78 71 44 79 92 10 60 5 7 9 33 79 31 86 51", "output": "1\n100 " }, { "input": "100\n78 96 4 24 -66 42 28 16 42 -48 89 0 74 19 12 86 75 21 42 100 2 43 11 -76 85 24 12 51 26 48 22 74 68 73 22 39 53 42 37 -78 100 5 9 58 10 63 19 89 76 42 10 -96 76 49 67 59 86 37 13 66 75 92 48 80 37 59 49 -4 83 1 82 25 0 31 73 40 52 3 -47 17 68 94 51 84 47 76 73 -65 83 72 56 50 62 -5 40 12 81 75 84 -6", "output": "5\n10 30 28 20 12 " }, { "input": "100\n-63 20 79 73 18 82 23 -93 55 8 -31 37 33 24 30 41 70 77 14 34 84 79 -94 88 54 81 7 90 74 35 29 3 75 71 14 28 -61 63 90 79 71 97 -90 74 -33 10 27 34 46 31 9 90 100 -73 58 2 73 51 5 46 -27 -9 30 65 73 28 15 14 1 59 96 21 100 78 12 97 72 37 -28 52 12 0 -42 84 88 8 88 8 -48 39 13 -78 20 56 38 82 32 -87 45 39", "output": "8\n1 10 26 8 16 18 10 11 " }, { "input": "100\n21 40 60 28 85 10 15 -3 -27 -7 26 26 9 93 -3 -65 70 88 68 -85 24 75 24 -69 53 56 44 -53 -15 -74 12 22 37 22 77 90 9 95 40 15 -76 7 -81 65 83 51 -57 59 19 78 34 40 11 17 99 75 56 67 -81 39 22 86 -78 61 19 25 53 13 -91 91 17 71 45 39 63 32 -57 83 70 26 100 -53 7 95 67 -47 84 84 28 56 94 72 48 58 21 -89 91 73 16 93", "output": "10\n9 6 5 8 2 13 16 10 13 18 " }, { "input": "100\n39 -70 7 7 11 27 88 16 -3 94 94 -2 23 91 41 49 69 61 53 -99 98 54 87 44 48 73 62 80 86 -33 34 -87 56 48 4 18 92 14 -37 84 7 42 9 70 0 -78 17 68 54 -82 65 -21 59 90 72 -19 -81 8 92 88 -68 65 -42 -60 98 -39 -2 2 88 24 9 -95 17 75 12 -32 -9 85 7 88 59 14 90 69 19 -88 -73 1 2 72 15 -83 65 18 26 25 -71 3 -51 95", "output": "13\n2 10 18 9 11 6 5 3 3 9 10 6 8 " }, { "input": "100\n-47 -28 -90 -35 28 32 63 77 88 3 -48 18 48 22 47 47 89 2 88 46 25 60 65 44 100 28 73 71 19 -55 44 47 30 -25 50 15 -98 5 73 -56 61 15 15 77 67 59 -64 22 17 70 67 -12 26 -81 -58 -20 1 22 34 52 -45 56 78 29 47 -11 -10 70 -57 -2 62 85 -84 -54 -67 67 85 23 6 -65 -6 -79 -13 -1 12 68 1 71 73 77 48 -48 90 70 52 100 45 38 -43 -93", "output": "15\n2 2 26 7 10 7 2 10 3 4 2 6 2 9 8 " }, { "input": "100\n-34 -61 96 14 87 33 29 64 -76 7 47 -41 54 60 79 -28 -18 88 95 29 -89 -29 52 39 8 13 68 13 15 46 -34 -49 78 -73 64 -56 83 -16 45 17 40 11 -86 55 56 -35 91 81 38 -77 -41 67 16 -37 -56 -84 -42 99 -83 45 46 -56 -14 -15 79 77 -48 -87 94 46 77 18 -32 16 -18 47 67 35 89 95 36 -32 51 46 40 78 0 58 81 -47 41 5 -48 65 89 6 -79 -56 -25 74", "output": "18\n1 8 7 5 10 3 4 8 5 4 2 5 2 4 7 15 7 3 " }, { "input": "100\n14 36 94 -66 24 -24 14 -87 86 94 44 88 -68 59 4 -27 -74 12 -75 92 -31 29 18 -69 -47 45 -85 67 95 -77 7 -56 -80 -46 -40 73 40 71 41 -86 50 87 94 16 43 -96 96 -63 66 24 3 90 16 42 50 41 15 -45 72 32 -94 -93 91 -31 -30 -73 -88 33 45 9 71 18 37 -26 43 -82 87 67 62 -9 29 -70 -34 99 -30 -25 -86 -91 -70 -48 24 51 53 25 90 69 -17 -53 87 -62", "output": "20\n6 7 4 4 4 5 3 2 11 12 4 3 2 9 6 3 2 2 8 3 " }, { "input": "100\n-40 87 -68 72 -49 48 -62 73 95 27 80 53 76 33 -95 -53 31 18 -61 -75 84 40 35 -82 49 47 -13 22 -81 -65 -17 47 -61 21 9 -12 52 67 31 -86 -63 42 18 -25 70 45 -3 -18 94 -62 -28 16 -100 36 -96 -73 83 -65 9 -51 83 36 65 -24 77 38 81 -84 32 -34 75 -50 -92 11 -73 -17 81 -66 -61 33 -47 -50 -72 -95 -58 54 68 -46 -41 8 76 28 58 87 88 100 61 -61 75 -1", "output": "23\n1 4 10 4 5 5 2 5 5 6 3 3 3 4 8 4 3 3 3 2 2 4 11 " }, { "input": "100\n-61 56 1 -37 61 -77 -6 -5 28 36 27 -32 -10 -44 -89 -26 67 100 -94 80 -18 -5 -92 94 81 -38 -76 4 -77 2 79 55 -93 54 -19 10 -35 -12 -42 -32 -23 -67 -95 -62 -16 23 -25 41 -16 -51 3 -45 -1 53 20 0 0 21 87 28 15 62 64 -21 6 45 -19 95 -23 87 15 -35 21 -88 47 -81 89 68 66 -65 95 54 18 -97 65 -7 75 -58 -54 -3 99 -95 -57 -84 98 -6 33 44 81 -56", "output": "25\n4 3 5 2 2 5 2 4 6 4 2 2 2 2 4 3 12 5 5 6 6 3 3 2 6 " }, { "input": "100\n-21 61 -52 47 -25 -42 -48 -46 58 -13 75 -65 52 88 -59 68 -12 -25 33 14 -2 78 32 -41 -79 17 0 85 -39 -80 61 30 -27 -92 -100 66 -53 -11 -59 65 -5 92 -2 -85 87 -72 19 -50 -24 32 -27 -92 -100 14 72 13 67 -22 -27 -56 -84 -90 -74 -70 44 -92 70 -49 -50 11 57 -73 23 68 65 99 82 -18 -93 -34 85 45 89 -58 -80 5 -57 -98 -11 -96 28 30 29 -71 47 50 -15 30 -96 -53", "output": "28\n1 4 2 3 5 3 6 5 4 2 3 3 3 4 3 2 6 2 2 3 3 9 2 5 3 2 7 3 " }, { "input": "100\n-61 15 -88 52 -75 -71 -36 29 93 99 -73 -97 -69 39 -78 80 -28 -20 -36 -89 88 -82 56 -37 -13 33 2 -6 -88 -9 8 -24 40 5 8 -33 -83 -90 -48 55 69 -12 -49 -41 -4 92 42 57 -17 -68 -41 -68 77 -17 -45 -64 -39 24 -78 -3 -49 77 3 -23 84 -36 -19 -16 -72 74 -19 -81 65 -79 -57 64 89 -29 49 69 88 -18 16 26 -86 -58 -91 69 -43 -28 86 6 -87 47 -71 18 81 -55 -42 -30", "output": "30\n3 3 5 2 4 2 3 3 4 3 5 2 4 2 5 2 3 2 3 4 3 2 3 3 7 4 3 4 5 2 " }, { "input": "100\n-21 -98 -66 26 3 -5 86 99 96 -22 78 -16 20 -3 93 22 -67 -37 -27 12 -97 43 -46 -48 -58 -4 -19 26 -87 -61 67 -76 -42 57 -87 -50 -24 -79 -6 43 -68 -42 13 -1 -82 81 -32 -88 -6 -99 46 42 19 -17 89 14 -98 -24 34 -37 -17 49 76 81 -61 23 -46 -79 -48 -5 87 14 -97 -67 -31 94 -77 15 -44 38 -44 -67 -69 -84 -58 -59 -17 -54 3 -15 79 -28 -10 -26 34 -73 -37 -57 -42 -44", "output": "33\n1 2 7 4 4 3 3 2 3 3 3 2 2 3 3 3 2 7 3 5 3 2 4 3 4 2 2 2 3 3 3 2 2 " }, { "input": "100\n-63 -62 -88 -14 -58 -75 -28 19 -71 60 -38 77 98 95 -49 -64 -87 -97 2 -37 -37 -41 -47 -96 -58 -42 -88 12 -90 -65 0 52 -59 87 -79 -68 -66 -90 -19 -4 86 -65 -49 -94 67 93 -61 100 68 -40 -35 -67 -4 -100 -90 -86 15 -3 -75 57 65 -91 -80 -57 51 -88 -61 -54 -13 -46 -64 53 -87 -54 -69 29 -67 -23 -96 -93 -3 -77 -10 85 55 -44 17 24 -78 -82 -33 14 85 79 84 -91 -81 54 -89 -86", "output": "35\n2 2 2 3 6 2 3 2 2 2 3 4 3 2 2 3 4 4 2 2 3 4 2 3 2 2 3 3 2 2 2 6 2 6 3 " }, { "input": "100\n30 -47 -87 -49 -4 -58 -10 -10 -37 -15 -12 -85 4 24 -3 -2 57 57 -60 94 -21 82 1 -54 -39 -98 -72 57 84 -6 -41 82 93 -81 -61 -30 18 -68 -88 17 87 -6 43 -26 72 -14 -40 -75 -69 60 -91 -70 -26 -62 -13 -19 -97 -14 -59 -17 -44 -15 -65 60 -60 74 26 -6 12 -83 -49 82 -76 -96 -31 -98 -100 49 -50 -42 -43 92 -56 -79 -38 -86 -99 -37 -75 -26 -79 -12 -9 -87 -63 -62 -25 -3 -5 -92", "output": "38\n2 2 2 2 2 2 4 5 4 2 4 4 3 4 4 2 3 2 2 2 2 2 2 5 3 3 2 3 2 3 2 2 2 2 2 2 2 2 " }, { "input": "100\n-58 -18 -94 -96 -18 -2 -35 -49 47 69 96 -46 -88 -91 -9 -95 -12 -46 -12 16 44 -53 -96 71 -11 -98 -62 -27 -89 -88 -28 -11 -14 -47 67 -69 -33 -64 15 -24 67 53 -93 -10 -75 -98 -8 -97 -62 67 -52 -59 -9 -89 -39 -23 -37 -61 -83 -89 23 -47 -67 18 -38 -63 -73 -98 -65 -70 -20 13 -33 -46 -50 -30 -33 85 -93 -42 -37 48 -8 -11 -32 0 -58 -70 -27 -79 -52 82 22 -62 -100 -12 -5 -82 88 -74", "output": "40\n2 2 2 2 5 2 2 2 4 3 2 2 2 2 3 3 4 2 2 3 2 2 2 2 3 3 2 2 2 3 2 3 2 3 3 2 2 4 2 3 " }, { "input": "100\n-60 -62 -19 -42 -50 -22 -90 -82 -56 40 87 -1 -30 -76 -8 -32 -57 38 -14 -39 84 -60 -28 -82 -62 -83 -37 -59 -61 -86 -13 48 18 -8 50 -27 -47 -100 -42 -88 -19 -45 30 -93 -46 3 -26 -80 -61 -13 -20 76 -95 -51 -26 -1 39 -92 -41 -76 -67 26 -23 30 79 -26 -51 -40 -29 -14 -2 -43 -30 -19 -62 -65 -1 -90 -66 -38 -50 89 -17 -53 -6 -13 -41 -54 -1 -23 -31 -88 -59 -44 -67 -11 -83 -16 -23 -71", "output": "43\n1 2 2 2 2 4 2 2 3 3 2 2 2 2 5 2 2 2 3 3 2 3 2 3 2 3 4 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 " }, { "input": "100\n-1 -65 76 -28 -58 -63 -86 -54 -62 -66 -39 -3 -62 -35 -2 -86 -6 -16 -85 -30 -6 -41 -88 38 -8 -78 -6 -73 -83 -12 40 -99 -78 -51 -97 -15 81 -76 -1 -78 -38 -14 -24 -2 -70 -80 -24 -28 -51 -50 61 -64 -81 -32 -59 -60 -58 -10 -24 -81 -42 -7 58 -23 -11 -14 -84 -27 -45 2 -31 -32 -20 -72 -2 -81 -31 -6 -8 -91 55 -76 -93 -65 -94 -8 -57 -20 -75 -20 -27 -37 -82 97 -37 -8 -16 49 -90 -3", "output": "45\n2 3 2 2 2 2 2 2 2 2 2 3 2 2 3 2 3 2 2 2 2 2 2 3 2 2 2 2 3 2 2 3 2 2 2 2 3 2 2 2 2 2 3 2 3 " }, { "input": "100\n-75 -29 -14 -2 99 -94 -75 82 -17 -19 -61 -18 -14 -94 -17 16 -16 -4 -41 -8 -81 -26 -65 24 -7 -87 -85 -22 -74 -21 46 -31 -39 -82 -88 -20 -2 -13 -46 -1 -78 -66 -83 -50 -13 -15 -60 -56 36 -79 -99 -52 -96 -80 -97 -74 80 -90 -52 -33 -1 -78 73 -45 -3 -77 62 -4 -85 -44 -62 -74 -33 -35 -44 -14 -80 -20 -17 -83 -32 -40 -74 -13 -90 -62 -15 -16 -59 -15 -40 -50 -98 -33 -73 -25 -86 -35 -84 -41", "output": "46\n1 2 3 3 2 2 2 3 2 2 3 2 2 3 2 2 2 2 2 2 2 2 3 2 2 3 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n-43 -90 -65 -70 -7 -49 -90 -93 -43 -80 -2 -47 -13 -5 -70 -42 -71 -68 -60 -71 -27 -84 82 -74 -75 -65 -32 -32 -50 -74 62 -96 -85 -95 -65 -51 -69 49 3 -19 -92 -61 -33 -7 -70 -51 -3 -1 -48 -48 -64 -7 -4 -46 -11 -36 -80 -69 -67 -1 -39 -40 66 -9 -40 -8 -58 -74 -27 66 -52 -26 -62 -72 -48 -25 -41 -13 -65 -82 -50 -68 -94 -52 -77 -91 -37 -18 -8 -51 -19 -22 -52 -95 35 -32 59 -41 -54 -88", "output": "46\n2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 4 2 " }, { "input": "100\n-67 -100 -7 -13 -9 -78 -55 -68 -31 -18 -92 -23 -4 -99 -54 -97 -45 -24 -33 -95 -42 -20 -63 -24 -89 -25 -55 -35 -84 -30 -1 57 -88 -94 -67 -27 -91 -14 -13 -20 -7 -8 -33 -95 -1 -75 -80 -49 -15 -64 -73 -49 -87 -19 -44 -50 -19 -10 -90 -51 -74 90 -42 -18 -93 -99 -43 51 -96 95 -97 -36 -21 -13 -73 -37 -33 -22 -83 -33 -44 -84 -20 -78 -34 -70 -83 -83 -85 -17 -36 62 83 -73 -6 51 -77 -82 -83 -68", "output": "47\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 4 3 2 " }, { "input": "100\n-30 -40 -64 -50 -13 -69 -87 -54 -7 -32 -38 30 -79 -31 57 -50 -3 -6 -13 -94 -28 -57 -95 -67 -82 -49 -83 -39 -41 -12 -73 -20 -17 -46 -92 -31 -36 -31 -80 -47 -37 -67 -41 -65 -7 -95 -85 -53 -87 -18 -52 -61 -98 -85 -6 -80 -96 -95 -72 -9 -19 -49 74 84 -60 -69 -64 -39 -82 -28 -24 -82 -13 -7 -15 -28 -26 -48 -88 -9 -36 -38 -75 -1 9 -15 -12 -47 -11 -45 -3 -10 -60 -62 -54 -60 45 -8 -43 -89", "output": "47\n2 2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 3 2 2 2 2 3 2 " }, { "input": "100\n-78 -77 -84 -29 -99 -15 -60 97 -56 -9 -19 -21 -5 -29 -20 -41 -56 -15 -77 -22 -87 -75 -56 -96 -46 -24 -35 -64 63 -5 -16 -27 34 -77 84 -30 -9 -73 -58 -93 -20 -20 -69 -16 -42 -40 -44 -66 -42 -90 -47 -35 -87 -55 -37 -48 -34 -3 -40 -3 -46 -25 -80 -55 -12 -62 -46 -99 -38 -33 -72 -60 -18 -12 -52 -3 -75 -5 -48 -30 -59 -56 99 -52 -59 -72 -41 -15 -19 -19 -26 -28 -16 -23 -46 -93 -92 -38 -12 -75", "output": "48\n1 2 2 2 3 2 2 2 2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 " }, { "input": "100\n22 -83 -95 -61 -100 -53 -50 -19 -24 -85 -45 -43 -3 -74 -6 -24 -78 -54 -58 -52 -42 -16 -18 -56 -93 -45 -97 -67 -88 -27 83 -7 -72 -85 -24 -45 -22 -82 -83 -94 -75 -79 -22 -44 -22 -44 -42 -44 -61 85 -11 -16 -91 -12 -15 -3 -15 -82 -1 -2 -28 -24 -68 -22 -25 -46 -40 -21 -67 -90 -31 -33 -54 -83 -91 -74 -56 -67 -87 -36 -8 -100 -76 -88 -90 -45 -64 -25 -55 -15 -84 -67 -57 -73 -78 86 -28 -41 -63 -57", "output": "48\n3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 " }, { "input": "100\n-13 -43 -95 -61 -62 -94 -97 -48 -16 -88 -96 -74 -26 -58 -79 -44 -72 -22 -18 -66 -8 85 -98 -3 -36 -17 -80 -82 -77 -41 -24 -86 -62 -1 -22 -29 -30 -18 -25 -90 -66 -58 -86 -81 -34 -76 -67 -72 -77 -29 -66 -67 -34 3 -16 -90 -9 -14 -28 -60 -26 -99 75 -74 -94 -55 -54 -23 -30 -34 -4 -92 -88 -46 -52 -63 -98 -6 -89 -99 -80 -100 -97 -62 -70 -97 -75 -85 -22 -2 -32 -47 -85 -44 -23 -4 -21 -30 -6 -34", "output": "49\n1 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n-5 -37 -22 -85 -63 -46 -44 -43 -23 -77 -75 -64 -84 -46 -78 -94 -67 -19 -5 -59 -32 -92 -10 -92 -58 -73 -72 -16 99 -58 -94 -49 -60 -3 -60 -74 -12 -8 -32 -94 -63 -53 -24 -29 -6 -46 -30 -32 -87 -41 -58 -70 -53 -20 -73 -42 -54 -5 -84 -45 -11 -9 -84 -7 -68 -100 -11 -2 -87 -27 -65 -45 -17 -33 -88 -55 90 -58 -89 -13 -66 -1 -46 -90 -69 -74 -84 -90 -50 -32 -62 -37 -44 -51 -25 -94 -73 -43 -1 -44", "output": "49\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n-76 -48 -63 -62 -94 -37 -54 -67 -9 -52 -83 -1 -87 -36 -94 -10 -19 -55 -93 -23 -2 -87 -15 -59 -60 -87 -63 -18 -62 -92 -10 -61 -12 -89 -85 -38 -37 -3 -71 -22 -94 -96 -100 -47 -20 -93 -28 77 -35 -74 -50 -72 -38 -29 -58 -80 -24 -9 -59 -4 -93 -65 -31 -47 -36 -13 -89 -96 -99 -83 -99 -36 -45 -58 -22 -93 -51 -26 -93 -36 -85 -72 -49 -27 -69 -29 -51 -84 -35 -26 -41 -43 -45 -87 -65 -100 -45 -69 -69 -73", "output": "50\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 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 " }, { "input": "100\n-77 -6 -71 -86 -42 -1 -40 -41 -31 -67 -75 -49 -62 -21 -2 -40 -2 -82 -90 -42 -43 -14 -72 -50 -33 -37 -58 -51 -67 -96 -63 -39 -56 -22 -17 -69 -88 -60 -18 -47 -16 -41 -32 -59 -82 -48 -22 -46 -29 -69 -21 -2 -41 -52 -83 -3 -49 -39 -31 -78 -60 -100 -12 -64 -28 -72 -43 -68 -60 -98 -21 -29 -72 -82 -5 -4 -65 -76 -60 -40 -37 -17 -77 -21 -19 -98 -39 -67 -49 -75 -7 -45 -11 -13 -45 -19 -83 -38 -14 -89", "output": "50\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 " }, { "input": "4\n1 2 3 4", "output": "1\n4 " }, { "input": "4\n1 2 3 -4", "output": "1\n4 " }, { "input": "4\n-4 2 1 2", "output": "1\n4 " }, { "input": "1\n-1", "output": "1\n1 " }, { "input": "2\n2 -1", "output": "1\n2 " }, { "input": "2\n-100 100", "output": "1\n2 " }, { "input": "3\n-100 0 -100", "output": "1\n3 " }, { "input": "5\n1 2 3 -1 -1", "output": "1\n5 " }, { "input": "5\n-1 -1 2 3 4", "output": "1\n5 " }, { "input": "3\n-3 -4 -5", "output": "2\n1 2 " }, { "input": "4\n-3 -4 1 -3", "output": "2\n1 3 " }, { "input": "1\n-1", "output": "1\n1 " }, { "input": "2\n-1 0", "output": "1\n2 " }, { "input": "4\n0 0 0 0", "output": "1\n4 " }, { "input": "3\n-1 -1 -1", "output": "2\n1 2 " }, { "input": "6\n-1 -1 0 -1 -1 -1", "output": "3\n1 3 2 " }, { "input": "2\n0 0", "output": "1\n2 " }, { "input": "6\n0 0 -1 -1 -1 0", "output": "2\n3 3 " } ]
1,667,083,853
2,147,483,647
Python 3
OK
TESTS
69
92
0
days = int(input()) sequence = input().split() folder = 1 bad_rep = 0 rep = 0 ans = "" for profit in sequence: rep += 1 if int(profit) < 0: bad_rep += 1 if bad_rep == 3: folder += 1 ans = ans + str(rep - 1) + " " bad_rep = 1 rep = 1 ans += str(rep) print(folder) print(ans)
Title: Paper Work Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=&lt;<=0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence *a**i*, will print the minimum number of folders. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. Output Specification: Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder. If there are multiple ways to sort the reports into *k* days, print any of them. Demo Input: ['11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n', '5\n0 -1 100 -1 0\n'] Demo Output: ['3\n5 3 3 ', '1\n5 '] Note: Here goes a way to sort the reports from the first sample into three folders: In the second sample you can put all five reports in one folder.
```python days = int(input()) sequence = input().split() folder = 1 bad_rep = 0 rep = 0 ans = "" for profit in sequence: rep += 1 if int(profit) < 0: bad_rep += 1 if bad_rep == 3: folder += 1 ans = ans + str(rep - 1) + " " bad_rep = 1 rep = 1 ans += str(rep) print(folder) print(ans) ```
3
938
B
Run For Your Prize
PROGRAMMING
1,100
[ "brute force", "greedy" ]
null
null
You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Print one integer — the minimum number of seconds it will take to collect all prizes.
[ "3\n2 3 9\n", "2\n2 999995\n" ]
[ "8\n", "5\n" ]
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
0
[ { "input": "3\n2 3 9", "output": "8" }, { "input": "2\n2 999995", "output": "5" }, { "input": "1\n20", "output": "19" }, { "input": "6\n2 3 500000 999997 999998 999999", "output": "499999" }, { "input": "1\n999999", "output": "1" }, { "input": "1\n510000", "output": "490000" }, { "input": "3\n2 5 27", "output": "26" }, { "input": "2\n600000 800000", "output": "400000" }, { "input": "5\n2 5 6 27 29", "output": "28" }, { "input": "1\n500001", "output": "499999" }, { "input": "10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055", "output": "98054" }, { "input": "1\n900000", "output": "100000" }, { "input": "1\n500000", "output": "499999" }, { "input": "1\n999998", "output": "2" }, { "input": "3\n999997 999998 999999", "output": "3" }, { "input": "2\n999997 999999", "output": "3" }, { "input": "2\n2 999998", "output": "2" }, { "input": "2\n500000 500001", "output": "499999" }, { "input": "1\n500002", "output": "499998" }, { "input": "1\n700000", "output": "300000" }, { "input": "2\n2 999999", "output": "1" }, { "input": "2\n999998 999999", "output": "2" }, { "input": "1\n999995", "output": "5" }, { "input": "2\n499999 500001", "output": "499999" }, { "input": "1\n499999", "output": "499998" }, { "input": "2\n100 999900", "output": "100" }, { "input": "2\n499999 500000", "output": "499999" }, { "input": "2\n500001 999999", "output": "499999" }, { "input": "3\n500000 500001 500002", "output": "499999" }, { "input": "2\n2 500001", "output": "499999" }, { "input": "2\n499999 999999", "output": "499998" }, { "input": "2\n2 500000", "output": "499999" }, { "input": "4\n2 3 4 999999", "output": "3" }, { "input": "2\n100000 500001", "output": "499999" }, { "input": "1\n2", "output": "1" }, { "input": "1\n800000", "output": "200000" }, { "input": "1\n505050", "output": "494950" }, { "input": "1\n753572", "output": "246428" }, { "input": "2\n576696 760487", "output": "423304" }, { "input": "10\n3 4 5 6 7 8 9 10 11 12", "output": "11" }, { "input": "4\n2 3 4 5", "output": "4" }, { "input": "4\n999996 999997 999998 999999", "output": "4" } ]
1,639,988,402
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
78
7,372,800
n = int(input()) if n!=0: str = list(map(int,input().split())) sum = 0 A = [] B = [] for i in str: if i <= 500000: A.append(i) if i > 500000: B.append(i) A.sort() A.reverse() B.sort() if len(A)!=0 and len(B)!=0: print(A[0]-1+999999-B[0]) if len(A)!=0 and len(B)==0: print(A[0]-1) if len(A)==0 and len(b)!=0: print(999999-B[0])
Title: Run For Your Prize Time Limit: None seconds Memory Limit: None megabytes Problem Description: You and your friend are participating in a TV show "Run For Your Prize". At the start of the show *n* prizes are located on a straight line. *i*-th prize is located at position *a**i*. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order. You know that it takes exactly 1 second to move from position *x* to position *x*<=+<=1 or *x*<=-<=1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all. Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend. What is the minimum number of seconds it will take to pick up all the prizes? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the number of prizes. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (2<=≤<=*a**i*<=≤<=106<=-<=1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order. Output Specification: Print one integer — the minimum number of seconds it will take to collect all prizes. Demo Input: ['3\n2 3 9\n', '2\n2 999995\n'] Demo Output: ['8\n', '5\n'] Note: In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8. In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.
```python n = int(input()) if n!=0: str = list(map(int,input().split())) sum = 0 A = [] B = [] for i in str: if i <= 500000: A.append(i) if i > 500000: B.append(i) A.sort() A.reverse() B.sort() if len(A)!=0 and len(B)!=0: print(A[0]-1+999999-B[0]) if len(A)!=0 and len(B)==0: print(A[0]-1) if len(A)==0 and len(b)!=0: print(999999-B[0]) ```
0
404
D
Minesweeper 1D
PROGRAMMING
1,900
[ "dp", "implementation" ]
null
null
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is *n* squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares. For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs. Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of *n* cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end.
The first line contains sequence of characters without spaces *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106), containing only characters "*", "?" and digits "0", "1" or "2". If character *s**i* equals "*", then the *i*-th cell of the field contains a bomb. If character *s**i* equals "?", then Valera hasn't yet decided what to put in the *i*-th cell. Character *s**i*, that is equal to a digit, represents the digit written in the *i*-th square.
Print a single integer — the number of ways Valera can fill the empty cells and get a correct field. As the answer can be rather large, print it modulo 1000000007 (109<=+<=7).
[ "?01???\n", "?\n", "**12\n", "1\n" ]
[ "4\n", "2\n", "0\n", "0\n" ]
In the first test sample you can get the following correct fields: 001**1, 001***, 001*2*, 001*10.
2,000
[ { "input": "?01???", "output": "4" }, { "input": "?", "output": "2" }, { "input": "**12", "output": "0" }, { "input": "1", "output": "0" }, { "input": "?01*??****", "output": "4" }, { "input": "0", "output": "1" }, { "input": "2", "output": "0" }, { "input": "*", "output": "1" }, { "input": "0*", "output": "0" }, { "input": "0?", "output": "1" }, { "input": "01", "output": "0" }, { "input": "1*", "output": "1" }, { "input": "1?", "output": "1" }, { "input": "?1?", "output": "2" }, { "input": "12", "output": "0" }, { "input": "2*", "output": "0" }, { "input": "2?", "output": "0" }, { "input": "2??", "output": "0" }, { "input": "?2?", "output": "1" }, { "input": "?2*?2*??1*2**?2*1???*2???100?????*???*?*????0????2?*?*?1??1??*?01**2**1001??**??**??1*?*???00??**??*", "output": "147483634" }, { "input": "00***???01", "output": "0" }, { "input": "21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?022*110*2*2022120*2*2100*0?0*02?012?1", "output": "0" } ]
1,675,861,476
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
889
3,072,000
# LUOGU_RID: 101728300 s=input() mod=1000000007 a,b,c=1,1,0 for ch in s: if ch=='0':a,b,c=a,0,0 elif ch=='1':a,b,c=c,a,0 elif ch=='2':a,b,c=0,c,0 elif ch=='*':a,b,c=0,0,b+c else:a,b,c=a+c,a+c,b+c a%=mod b%=mod c%=mod print(a+c)
Title: Minesweeper 1D Time Limit: None seconds Memory Limit: None megabytes Problem Description: Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is *n* squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares. For example, the correct field to play looks like that: 001*2***101*. The cells that are marked with "*" contain bombs. Note that on the correct field the numbers represent the number of bombs in adjacent cells. For example, field 2* is not correct, because cell with value 2 must have two adjacent cells with bombs. Valera wants to make a correct field to play "Minesweeper 1D". He has already painted a squared field with width of *n* cells, put several bombs on the field and wrote numbers into some cells. Now he wonders how many ways to fill the remaining cells with bombs and numbers are there if we should get a correct field in the end. Input Specification: The first line contains sequence of characters without spaces *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106), containing only characters "*", "?" and digits "0", "1" or "2". If character *s**i* equals "*", then the *i*-th cell of the field contains a bomb. If character *s**i* equals "?", then Valera hasn't yet decided what to put in the *i*-th cell. Character *s**i*, that is equal to a digit, represents the digit written in the *i*-th square. Output Specification: Print a single integer — the number of ways Valera can fill the empty cells and get a correct field. As the answer can be rather large, print it modulo 1000000007 (109<=+<=7). Demo Input: ['?01???\n', '?\n', '**12\n', '1\n'] Demo Output: ['4\n', '2\n', '0\n', '0\n'] Note: In the first test sample you can get the following correct fields: 001**1, 001***, 001*2*, 001*10.
```python # LUOGU_RID: 101728300 s=input() mod=1000000007 a,b,c=1,1,0 for ch in s: if ch=='0':a,b,c=a,0,0 elif ch=='1':a,b,c=c,a,0 elif ch=='2':a,b,c=0,c,0 elif ch=='*':a,b,c=0,0,b+c else:a,b,c=a+c,a+c,b+c a%=mod b%=mod c%=mod print(a+c) ```
0
907
A
Masha and Bears
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3.
Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes).
[ "50 30 10 10\n", "100 50 10 21\n" ]
[ "50\n30\n10\n", "-1\n" ]
In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
500
[ { "input": "50 30 10 10", "output": "50\n30\n10" }, { "input": "100 50 10 21", "output": "-1" }, { "input": "100 50 19 10", "output": "100\n50\n19" }, { "input": "99 50 25 49", "output": "100\n99\n49" }, { "input": "3 2 1 1", "output": "4\n3\n1" }, { "input": "100 99 98 100", "output": "-1" }, { "input": "100 40 30 40", "output": "-1" }, { "input": "100 50 19 25", "output": "100\n51\n25" }, { "input": "100 50 19 30", "output": "100\n61\n30" }, { "input": "49 48 25 49", "output": "-1" }, { "input": "48 47 23 46", "output": "94\n93\n46" }, { "input": "37 23 16 20", "output": "42\n41\n20" }, { "input": "98 2 1 1", "output": "98\n3\n1" }, { "input": "99 22 13 14", "output": "99\n29\n14" }, { "input": "97 95 3 2", "output": "97\n95\n3" }, { "input": "27 3 2 3", "output": "-1" }, { "input": "13 7 6 2", "output": "-1" }, { "input": "19 17 11 6", "output": "19\n17\n11" }, { "input": "15 6 4 5", "output": "15\n11\n5" }, { "input": "21 3 1 3", "output": "-1" }, { "input": "100 99 98 97", "output": "196\n195\n98" }, { "input": "99 32 13 5", "output": "-1" }, { "input": "5 4 3 1", "output": "-1" }, { "input": "50 20 4 8", "output": "50\n20\n8" }, { "input": "60 30 10 1", "output": "-1" }, { "input": "100 50 10 1", "output": "-1" }, { "input": "40 30 20 10", "output": "40\n30\n20" }, { "input": "50 49 5 10", "output": "50\n49\n10" }, { "input": "99 98 50 97", "output": "196\n195\n97" }, { "input": "50 30 10 5", "output": "50\n30\n10" }, { "input": "4 3 2 1", "output": "4\n3\n2" }, { "input": "100 50 3 1", "output": "-1" } ]
1,573,786,748
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
bearSizesInput = input() bearSizesSplit = bearSizesInput.split() v1 = int(bearSizesSplit[0]) v2 = int(bearSizesSplit[1]) v3 = int(bearSizesSplit[2]) vm = int(bearSizesSplit[3]) bearSizes = [v1, v2, v3] selectedSizes = [] for bearSize in bearSizes: maxHeight = bearSize * 2 if maxHeight >= vm and vm <= bearSize: selectedSizes.append(bearSize) else: selectedSizes.clear() break if len(selectedSizes) == 0: print("-1") else: for selectedSize in selectedSizes: print(selectedSize)
Title: Masha and Bears Time Limit: None seconds Memory Limit: None megabytes Problem Description: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size *a* can climb into some car with size *b* if and only if *a*<=≤<=*b*, he or she likes it if and only if he can climb into this car and 2*a*<=≥<=*b*. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input Specification: You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=&gt;<=*V*2<=&gt;<=*V*3. Output Specification: Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Demo Input: ['50 30 10 10\n', '100 50 10 21\n'] Demo Output: ['50\n30\n10\n', '-1\n'] Note: In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
```python bearSizesInput = input() bearSizesSplit = bearSizesInput.split() v1 = int(bearSizesSplit[0]) v2 = int(bearSizesSplit[1]) v3 = int(bearSizesSplit[2]) vm = int(bearSizesSplit[3]) bearSizes = [v1, v2, v3] selectedSizes = [] for bearSize in bearSizes: maxHeight = bearSize * 2 if maxHeight >= vm and vm <= bearSize: selectedSizes.append(bearSize) else: selectedSizes.clear() break if len(selectedSizes) == 0: print("-1") else: for selectedSize in selectedSizes: print(selectedSize) ```
0
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "input": "2 3", "output": "2 0 4" }, { "input": "5 6", "output": "5 0 1" }, { "input": "4 4", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" }, { "input": "6 4", "output": "1 1 4" }, { "input": "1 4", "output": "2 0 4" }, { "input": "5 5", "output": "0 6 0" }, { "input": "4 5", "output": "4 0 2" }, { "input": "4 3", "output": "3 0 3" }, { "input": "1 5", "output": "2 1 3" }, { "input": "6 5", "output": "1 0 5" }, { "input": "2 2", "output": "0 6 0" }, { "input": "1 3", "output": "1 1 4" }, { "input": "3 6", "output": "4 0 2" }, { "input": "3 1", "output": "4 1 1" }, { "input": "3 2", "output": "4 0 2" }, { "input": "3 5", "output": "3 1 2" }, { "input": "3 3", "output": "0 6 0" }, { "input": "6 2", "output": "2 1 3" }, { "input": "4 1", "output": "4 0 2" }, { "input": "5 2", "output": "3 0 3" }, { "input": "4 2", "output": "3 1 2" }, { "input": "2 1", "output": "5 0 1" }, { "input": "6 1", "output": "3 0 3" }, { "input": "4 6", "output": "4 1 1" }, { "input": "2 6", "output": "3 1 2" }, { "input": "3 4", "output": "3 0 3" }, { "input": "1 2", "output": "1 0 5" }, { "input": "6 6", "output": "0 6 0" }, { "input": "5 4", "output": "2 0 4" }, { "input": "3 3", "output": "0 6 0" }, { "input": "1 1", "output": "0 6 0" } ]
1,594,458,300
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
6,656,000
a, b= list(map(int, input().split())) player1= 0 t= 0 player2= 0 for i in range(1,7): if abs(a- i) < abs(b-i): player1+=1 elif abs(a-i)> abs(b-i): player2+=1 elif a-i == -1 and b-i == 1: t+=1 print(player1 , t , player2)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python a, b= list(map(int, input().split())) player1= 0 t= 0 player2= 0 for i in range(1,7): if abs(a- i) < abs(b-i): player1+=1 elif abs(a-i)> abs(b-i): player2+=1 elif a-i == -1 and b-i == 1: t+=1 print(player1 , t , player2) ```
0
394
A
Counting Sticks
PROGRAMMING
0
[ "brute force", "implementation" ]
null
null
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type: Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*. We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =. We really aren't fabulous at arithmetics. Can you help us?
The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100.
If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.
[ "||+|=|||||\n", "|||||+||=||\n", "|+|=||||||\n", "||||+||=||||||\n" ]
[ "|||+|=||||\n", "Impossible\n", "Impossible\n", "||||+||=||||||\n" ]
In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
500
[ { "input": "||+|=|||||", "output": "|||+|=||||" }, { "input": "|||||+||=||", "output": "Impossible" }, { "input": "|+|=||||||", "output": "Impossible" }, { "input": "||||+||=||||||", "output": "||||+||=||||||" }, { "input": "||||||||||||+|||||||||||=||||||||||||||||||||||", "output": "Impossible" }, { "input": "||||||||||||||||||+||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||=|||||||||||||||||||||||||", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "|+|=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||=|", "output": "Impossible" }, { "input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+|=|", "output": "|+|=||" }, { "input": "|+||=|", "output": "|+|=||" }, { "input": "|+|=||", "output": "|+|=||" }, { "input": "|||+|=|", "output": "Impossible" }, { "input": "|||+|=|", "output": "Impossible" }, { "input": "|||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "||||||||||||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" }, { "input": "|+|=|||", "output": "Impossible" }, { "input": "|+|=||||", "output": "||+|=|||" }, { "input": "|+||=|", "output": "|+|=||" }, { "input": "|+||||||=|||||", "output": "|+|||||=||||||" }, { "input": "|+|||=||", "output": "|+||=|||" }, { "input": "|+||||=|||", "output": "|+|||=||||" }, { "input": "|+|||||=||||", "output": "|+||||=|||||" }, { "input": "||+||=||", "output": "|+||=|||" }, { "input": "||+|||=|||", "output": "|+|||=||||" }, { "input": "|||||+||=||||||||||", "output": "Impossible" }, { "input": "|||+|||=||||", "output": "||+|||=|||||" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "|||||+|||||=||||||||||||", "output": "||||||+|||||=|||||||||||" }, { "input": "||+|||||||=|||||||", "output": "|+|||||||=||||||||" }, { "input": "||||+||||=||||||", "output": "|||+||||=|||||||" }, { "input": "||||+|||=|||||", "output": "|||+|||=||||||" }, { "input": "||+|||=|||||||", "output": "|||+|||=||||||" }, { "input": "||+|=|", "output": "|+|=||" }, { "input": "|||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "||+|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" }, { "input": "||+|=||||||", "output": "Impossible" }, { "input": "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||+||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||=||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||", "output": "Impossible" } ]
1,524,645,638
2,147,483,647
Python 3
OK
TESTS
49
93
7,372,800
n = input() lth = len(n) a = n.find('+') b = n.find('=') - a - 1 c = len(n) - n.find('=') - 1 if a + b == c: print(n) elif a + b == c - 2: print('|',n[:lth-1],sep="") elif a + b == c + 2: if a >= 2: print(n[1:],'|',sep="") else: print(n[:a+1],n[a+2:],'|',sep="") else: print('Impossible')
Title: Counting Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type: Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*. We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =. We really aren't fabulous at arithmetics. Can you help us? Input Specification: The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. Output Specification: If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples. Demo Input: ['||+|=|||||\n', '|||||+||=||\n', '|+|=||||||\n', '||||+||=||||||\n'] Demo Output: ['|||+|=||||\n', 'Impossible\n', 'Impossible\n', '||||+||=||||||\n'] Note: In the first sample we can shift stick from the third group of sticks to the first one. In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign. There is no answer in the third sample because we cannot remove sticks from the expression. In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.
```python n = input() lth = len(n) a = n.find('+') b = n.find('=') - a - 1 c = len(n) - n.find('=') - 1 if a + b == c: print(n) elif a + b == c - 2: print('|',n[:lth-1],sep="") elif a + b == c + 2: if a >= 2: print(n[1:],'|',sep="") else: print(n[:a+1],n[a+2:],'|',sep="") else: print('Impossible') ```
3
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it.
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" }, { "input": "9", "output": "10" }, { "input": "1", "output": "0" }, { "input": "0", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "10" }, { "input": "7", "output": "10" }, { "input": "8", "output": "10" }, { "input": "19", "output": "20" }, { "input": "100", "output": "100" }, { "input": "997", "output": "1000" }, { "input": "9994", "output": "9990" }, { "input": "10002", "output": "10000" }, { "input": "100000", "output": "100000" }, { "input": "99999", "output": "100000" }, { "input": "999999999", "output": "1000000000" }, { "input": "999999998", "output": "1000000000" }, { "input": "999999995", "output": "999999990" }, { "input": "999999990", "output": "999999990" }, { "input": "1000000", "output": "1000000" }, { "input": "1000010", "output": "1000010" }, { "input": "10000010", "output": "10000010" }, { "input": "100000011", "output": "100000010" }, { "input": "400000003", "output": "400000000" }, { "input": "234234", "output": "234230" }, { "input": "675621", "output": "675620" }, { "input": "43532", "output": "43530" }, { "input": "4576453", "output": "4576450" }, { "input": "65754674", "output": "65754670" }, { "input": "3245526", "output": "3245530" }, { "input": "123445", "output": "123440" }, { "input": "234217", "output": "234220" }, { "input": "23451218", "output": "23451220" }, { "input": "1231239", "output": "1231240" }, { "input": "1923140", "output": "1923140" }, { "input": "307910310", "output": "307910310" }, { "input": "780961030", "output": "780961030" }, { "input": "103509421", "output": "103509420" }, { "input": "576560141", "output": "576560140" }, { "input": "48851642", "output": "48851640" }, { "input": "226935072", "output": "226935070" }, { "input": "844450763", "output": "844450760" }, { "input": "22534183", "output": "22534180" }, { "input": "640049874", "output": "640049870" }, { "input": "818133304", "output": "818133300" }, { "input": "730616285", "output": "730616280" }, { "input": "613732415", "output": "613732410" }, { "input": "380991216", "output": "380991220" }, { "input": "559074636", "output": "559074640" }, { "input": "176590327", "output": "176590330" }, { "input": "354673757", "output": "354673760" }, { "input": "267156738", "output": "267156740" }, { "input": "150272868", "output": "150272870" }, { "input": "62755859", "output": "62755860" }, { "input": "945871979", "output": "945871980" }, { "input": "46", "output": "50" }, { "input": "999", "output": "1000" }, { "input": "1397", "output": "1400" } ]
1,608,412,479
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
78
0
import math n=int(input()) if(n<10): print(n) elif(n%10==0): print(n) else: m=math.floor(n/10)*10 print(m)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. Input Specification: The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. Output Specification: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Demo Input: ['5\n', '113\n', '1000000000\n', '5432359\n'] Demo Output: ['0\n', '110\n', '1000000000\n', '5432360\n'] Note: In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
```python import math n=int(input()) if(n<10): print(n) elif(n%10==0): print(n) else: m=math.floor(n/10)*10 print(m) ```
0
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
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.
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), 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*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
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.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output": "12" }, { "input": "3555165 6693472\n1499112 556941 3075290", "output": "3089339" }, { "input": "0 0\n1000000000 1000000000 1000000000", "output": "7000000000" }, { "input": "1 1\n0 1 0", "output": "0" }, { "input": "117708228 562858833\n118004008 360437130 154015822", "output": "738362681" }, { "input": "999998118 700178721\n822106746 82987112 547955384", "output": "1753877029" }, { "input": "566568710 765371101\n60614022 80126928 809950465", "output": "1744607222" }, { "input": "448858599 829062060\n764716760 97644201 203890025", "output": "1178219122" }, { "input": "626115781 966381948\n395190569 820194184 229233367", "output": "1525971878" }, { "input": "803372962 103701834\n394260597 837711458 623172928", "output": "3426388098" }, { "input": "980630143 241021722\n24734406 928857659 312079781", "output": "1624075280" }, { "input": "862920032 378341609\n360240924 241342224 337423122", "output": "974174021" }, { "input": "40177212 515661496\n64343660 963892207 731362684", "output": "3694721078" }, { "input": "217434393 579352456\n694817470 981409480 756706026", "output": "4825785129" }, { "input": "394691574 716672343\n398920207 72555681 150645586", "output": "475704521" }, { "input": "276981463 853992230\n29394015 90072954 839552440", "output": "1754738044" }, { "input": "843552056 919184611\n341530221 423649259 101547519", "output": "263157645" }, { "input": "20809236 56504497\n972004030 441166533 495487081", "output": "4235488636" }, { "input": "198066417 825228166\n602477839 532312735 520830423", "output": "2808777834" }, { "input": "80356306 962548053\n601547868 549830008 914769984", "output": "4004161345" }, { "input": "257613487 394835231\n642087093 567347282 308709545", "output": "2692548667" }, { "input": "139903376 532155119\n641157122 289897263 629020178", "output": "3077110809" }, { "input": "612127849 669475006\n271630930 676010757 22959739", "output": "682559736" }, { "input": "0 0\n0 0 0", "output": "0" }, { "input": "1000000000 1000000000\n499999998 4 333333332", "output": "0" }, { "input": "1000000000 1000000000\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4 3\n1 0 1", "output": "0" }, { "input": "4 12\n1 2 3", "output": "0" }, { "input": "4 20\n1 2 1", "output": "0" }, { "input": "100 10\n2 3 4", "output": "5" }, { "input": "6 0\n1 1 1", "output": "4" }, { "input": "25 5\n3 3 3", "output": "7" }, { "input": "48 27\n22 39 20", "output": "107" }, { "input": "4 0\n1 1 1", "output": "4" } ]
1,681,511,351
2,147,483,647
Python 3
OK
TESTS
38
77
0
a, b = map(int, input().split()) x, y, z = map(int, input().split()) need_yellow = x * 2 + y need_blue = y + z * 3 yellow_diff = max(0, need_yellow - a) blue_diff = max(0, need_blue - b) total_diff = yellow_diff + blue_diff print(total_diff)
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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 Specification: The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), 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*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. Output Specification: Print a single integer — the minimum number of crystals that Grisha should acquire in addition. Demo Input: ['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n'] Demo Output: ['2\n', '1\n', '2147483648\n'] 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.
```python a, b = map(int, input().split()) x, y, z = map(int, input().split()) need_yellow = x * 2 + y need_blue = y + z * 3 yellow_diff = max(0, need_yellow - a) blue_diff = max(0, need_blue - b) total_diff = yellow_diff + blue_diff print(total_diff) ```
3
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "0\n0\n0\n0" }, { "input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "output": "0\n0\n0\n0\n0" }, { "input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "output": "0\n1\n0\n0\n0\n1" }, { "input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "output": "0\n0\n0\n0\n0\n0\n1" }, { "input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3", "output": "0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5", "output": "0\n1\n0\n0\n0\n0\n0\n1\n0" }, { "input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1", "output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0" }, { "input": "1 1\n-1\n1 1", "output": "0" }, { "input": "1 1\n1\n1 1", "output": "0" } ]
1,669,364,815
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
1,024,000
''' Евгений и массив ''' s = input() s = s.split() n = int(s[0]) m = int(s[1]) a = input() a_1 = a.count('-1') a1 = a.count('1') - a_1 for i in range(m): b = input() b = b.split() l = int(b[0]) r = int(b[1]) if (r-l) % 2 == 0: print( 0) continue k = (r-l+1) // 2 if k > a1 or k > a_1: print( 0) else: print( 1)
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the responses to Eugene's queries in the order they occur in the input. Demo Input: ['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n'] Demo Output: ['0\n1\n0\n', '0\n1\n0\n1\n0\n'] Note: none
```python ''' Евгений и массив ''' s = input() s = s.split() n = int(s[0]) m = int(s[1]) a = input() a_1 = a.count('-1') a1 = a.count('1') - a_1 for i in range(m): b = input() b = b.split() l = int(b[0]) r = int(b[1]) if (r-l) % 2 == 0: print( 0) continue k = (r-l+1) // 2 if k > a1 or k > a_1: print( 0) else: print( 1) ```
0
926
E
Merge Equal Elements
PROGRAMMING
1,900
[ "constructive algorithms", "data structures" ]
null
null
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both and insert a single integer *x*<=+<=1 on their place. This way the number of elements in the sequence is decreased by 1 on each step. You stop performing the operation when there is no pair of equal consecutive elements. For example, if the initial sequence is [5,<=2,<=1,<=1,<=2,<=2], then after the first operation you get [5,<=2,<=2,<=2,<=2], after the second — [5,<=3,<=2,<=2], after the third — [5,<=3,<=3], and finally after the fourth you get [5,<=4]. After that there are no equal consecutive elements left in the sequence, so you stop the process. Determine the final sequence after you stop performing the operation.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
In the first line print a single integer *k* — the number of elements in the sequence after you stop performing the operation. In the second line print *k* integers — the sequence after you stop performing the operation.
[ "6\n5 2 1 1 2 2\n", "4\n1000000000 1000000000 1000000000 1000000000\n", "7\n4 10 22 11 12 5 6\n" ]
[ "2\n5 4 ", "1\n1000000002 ", "7\n4 10 22 11 12 5 6 " ]
The first example is described in the statements. In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002]. In the third example there are no two equal consecutive elements initially, so the sequence does not change.
0
[ { "input": "6\n5 2 1 1 2 2", "output": "2\n5 4 " }, { "input": "4\n1000000000 1000000000 1000000000 1000000000", "output": "1\n1000000002 " }, { "input": "7\n4 10 22 11 12 5 6", "output": "7\n4 10 22 11 12 5 6 " }, { "input": "2\n1 1", "output": "1\n2 " }, { "input": "3\n2 1 1", "output": "1\n3 " }, { "input": "4\n3 2 1 1", "output": "1\n4 " }, { "input": "7\n5 5 4 4 5 6 7", "output": "3\n7 6 7 " } ]
1,552,407,552
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) a = list(map(int, input().split())) p = 1 def f(n, a): for _ in range(n): od = True x = len(a) for g in range(max(p - 1, 0),len(a) - 1): if a[g] == a[g + 1]: od = False p = g s = int(a[g]) del a[g] a[g] =str(s + 1) break if od: print(x) print(' '.join(list(map(str, a)))) break f(n, a)
Title: Merge Equal Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both and insert a single integer *x*<=+<=1 on their place. This way the number of elements in the sequence is decreased by 1 on each step. You stop performing the operation when there is no pair of equal consecutive elements. For example, if the initial sequence is [5,<=2,<=1,<=1,<=2,<=2], then after the first operation you get [5,<=2,<=2,<=2,<=2], after the second — [5,<=3,<=2,<=2], after the third — [5,<=3,<=3], and finally after the fourth you get [5,<=4]. After that there are no equal consecutive elements left in the sequence, so you stop the process. Determine the final sequence after you stop performing the operation. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: In the first line print a single integer *k* — the number of elements in the sequence after you stop performing the operation. In the second line print *k* integers — the sequence after you stop performing the operation. Demo Input: ['6\n5 2 1 1 2 2\n', '4\n1000000000 1000000000 1000000000 1000000000\n', '7\n4 10 22 11 12 5 6\n'] Demo Output: ['2\n5 4 ', '1\n1000000002 ', '7\n4 10 22 11 12 5 6 '] Note: The first example is described in the statements. In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002]. In the third example there are no two equal consecutive elements initially, so the sequence does not change.
```python n = int(input()) a = list(map(int, input().split())) p = 1 def f(n, a): for _ in range(n): od = True x = len(a) for g in range(max(p - 1, 0),len(a) - 1): if a[g] == a[g + 1]: od = False p = g s = int(a[g]) del a[g] a[g] =str(s + 1) break if od: print(x) print(' '.join(list(map(str, a)))) break f(n, a) ```
-1
0
none
none
none
0
[ "none" ]
null
null
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?"
The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$.
Print $q$ integers, one per line — the answers for the queries.
[ "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n" ]
[ "7\n5\n4\n" ]
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
0
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4" }, { "input": "2 2 0 1 1\n\n1\n1\n1 2 2 2", "output": "3" }, { "input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "output": "6\n4\n3\n5\n4" }, { "input": "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\n1 1 3 1\n2 1 7 1\n1 1 9 1\n7 1 4 1\n10 1 7 1\n2 1 7 1\n3 1 2 1\n5 1 2 1\n10 1 5 1\n6 1 9 1", "output": "3\n4\n4\n3\n3\n4\n3\n3\n4\n3" }, { "input": "2 5 1 0 1\n2\n\n1\n1 4 1 5", "output": "1" }, { "input": "2 10 1 1 1\n1\n10\n1\n1 5 1 8", "output": "3" }, { "input": "4 4 1 0 1\n1\n\n1\n1 2 1 4", "output": "2" }, { "input": "2 4 1 1 1\n1\n2\n1\n2 3 2 4", "output": "1" }, { "input": "1000 1000 1 1 10\n1\n2\n1\n1 900 1 1000", "output": "100" }, { "input": "2 4 1 1 1\n1\n4\n1\n1 2 1 3", "output": "1" }, { "input": "5 5 1 1 1\n3\n2\n1\n1 5 1 1", "output": "4" } ]
1,525,015,337
7,637
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
6
2,000
14,233,600
import bisect N,M,L,E,V = map(int,input().split()) sts = list(map(int,input().split())) els = list(map(int,input().split())) def solve(x1,y1,x2,y2): if x1 == x2: return abs(y1-y2) ans = N+M+9999 if y1 > y2: y1,y2 = y2,y1 if sts: i = bisect.bisect(sts,y1) if i == L: st = sts[-1] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) else: st = sts[i] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) if i < L-1: st = sts[i+1] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) if els: i = bisect.bisect(els,y1) if i == E: el = els[-1] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) else: el = els[i] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) if i < E-1: el = els[i+1] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) return ans Q = int(input()) for i in range(Q): print(solve(*tuple(map(int,input().split()))))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?" Input Specification: The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$. Output Specification: Print $q$ integers, one per line — the answers for the queries. Demo Input: ['5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n'] Demo Output: ['7\n5\n4\n'] Note: In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
```python import bisect N,M,L,E,V = map(int,input().split()) sts = list(map(int,input().split())) els = list(map(int,input().split())) def solve(x1,y1,x2,y2): if x1 == x2: return abs(y1-y2) ans = N+M+9999 if y1 > y2: y1,y2 = y2,y1 if sts: i = bisect.bisect(sts,y1) if i == L: st = sts[-1] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) else: st = sts[i] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) if i < L-1: st = sts[i+1] t = abs(st - y1) + abs(st - y2) + abs(x1 - x2) ans = min(ans, t) if els: i = bisect.bisect(els,y1) if i == E: el = els[-1] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) else: el = els[i] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) if i < E-1: el = els[i+1] t = abs(el - y1) + abs(el - y2) + (abs(x1-x2)-1)//V + 1 ans = min(ans, t) return ans Q = int(input()) for i in range(Q): print(solve(*tuple(map(int,input().split())))) ```
0
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,567,098,846
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
124
0
a, b = map(int, input().split()) print(1) while(1 == 0): print("questão bullshit")
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python a, b = map(int, input().split()) print(1) while(1 == 0): print("questão bullshit") ```
0
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 2 5 3 4", "output": "chest" }, { "input": "8\n7 2 9 10 3 8 10 6", "output": "chest" }, { "input": "9\n5 4 2 3 4 4 5 2 2", "output": "chest" }, { "input": "10\n4 9 8 5 3 8 8 10 4 2", "output": "biceps" }, { "input": "11\n10 9 7 6 1 3 9 7 1 3 5", "output": "chest" }, { "input": "12\n24 22 6 16 5 21 1 7 2 19 24 5", "output": "chest" }, { "input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "output": "chest" }, { "input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "output": "back" }, { "input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "output": "chest" }, { "input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "output": "biceps" }, { "input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "output": "chest" }, { "input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "output": "back" }, { "input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "output": "chest" }, { "input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "output": "chest" }, { "input": "1\n10", "output": "chest" }, { "input": "2\n15 3", "output": "chest" }, { "input": "3\n21 11 19", "output": "chest" }, { "input": "4\n19 24 13 15", "output": "chest" }, { "input": "5\n4 24 1 9 19", "output": "biceps" }, { "input": "6\n6 22 24 7 15 24", "output": "back" }, { "input": "7\n10 8 23 23 14 18 14", "output": "chest" }, { "input": "8\n5 16 8 9 17 16 14 7", "output": "biceps" }, { "input": "9\n12 3 10 23 6 4 22 13 12", "output": "chest" }, { "input": "10\n1 9 20 18 20 17 7 24 23 2", "output": "back" }, { "input": "11\n22 25 8 2 18 15 1 13 1 11 4", "output": "biceps" }, { "input": "12\n20 12 14 2 15 6 24 3 11 8 11 14", "output": "chest" }, { "input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "output": "back" }, { "input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "output": "biceps" }, { "input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "output": "back" }, { "input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "output": "chest" }, { "input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "output": "biceps" }, { "input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "output": "chest" }, { "input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "output": "back" }, { "input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "output": "back" }, { "input": "1\n19", "output": "chest" }, { "input": "2\n1 7", "output": "biceps" }, { "input": "3\n18 18 23", "output": "back" }, { "input": "4\n12 15 1 13", "output": "chest" }, { "input": "5\n11 14 25 21 21", "output": "biceps" }, { "input": "6\n11 9 12 11 22 18", "output": "biceps" }, { "input": "7\n11 1 16 20 21 25 20", "output": "chest" }, { "input": "8\n1 2 20 9 3 22 17 4", "output": "back" }, { "input": "9\n19 2 10 19 15 20 3 1 13", "output": "back" }, { "input": "10\n11 2 11 8 21 16 2 3 19 9", "output": "back" }, { "input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "output": "chest" }, { "input": "12\n4 24 21 3 13 24 22 13 12 21 1 15", "output": "back" }, { "input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "output": "biceps" }, { "input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "output": "biceps" }, { "input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "output": "back" }, { "input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "output": "chest" }, { "input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "output": "chest" }, { "input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "output": "chest" }, { "input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "output": "chest" }, { "input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "output": "biceps" }, { "input": "1\n19", "output": "chest" }, { "input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22", "output": "biceps" } ]
1,591,763,613
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
204,800
t = int(input()) l = list(map(int, input().split())) chest = 0 bicep = 0 back = 0 for i in range(1, len(l)+1): if(i%3==1): chest+=l[i-1] elif(i%3==2): bicep+=l[i-1] else: back+=l[i-1] m = max(chest, bicep, back) if(m==back): print("back") elif(m==chest): print("chest") else: print("bicep")
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. Output Specification: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Demo Input: ['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n'] Demo Output: ['biceps\n', 'back\n', 'chest\n'] Note: In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
```python t = int(input()) l = list(map(int, input().split())) chest = 0 bicep = 0 back = 0 for i in range(1, len(l)+1): if(i%3==1): chest+=l[i-1] elif(i%3==2): bicep+=l[i-1] else: back+=l[i-1] m = max(chest, bicep, back) if(m==back): print("back") elif(m==chest): print("chest") else: print("bicep") ```
0
242
E
XOR on Segment
PROGRAMMING
2,000
[ "bitmasks", "data structures" ]
null
null
You've got an array *a*, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. You are allowed to perform two operations on this array: 1. Calculate the sum of current array elements on the segment [*l*,<=*r*], that is, count value *a**l*<=+<=*a**l*<=+<=1<=+<=...<=+<=*a**r*. 1. Apply the xor operation with a given number *x* to each array element on the segment [*l*,<=*r*], that is, execute . This operation changes exactly *r*<=-<=*l*<=+<=1 array elements. Expression means applying bitwise xor operation to numbers *x* and *y*. The given operation exists in all modern programming languages, for example in language C++ and Java it is marked as "^", in Pascal — as "xor". You've got a list of *m* operations of the indicated type. Your task is to perform all given operations, for each sum query you should print the result you get.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=106) — the original array. The third line contains integer *m* (1<=≤<=*m*<=≤<=5·104) — the number of operations with the array. The *i*-th of the following *m* lines first contains an integer *t**i* (1<=≤<=*t**i*<=≤<=2) — the type of the *i*-th query. If *t**i*<==<=1, then this is the query of the sum, if *t**i*<==<=2, then this is the query to change array elements. If the *i*-th operation is of type 1, then next follow two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). If the *i*-th operation is of type 2, then next follow three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106). The numbers on the lines are separated by single spaces.
For each query of type 1 print in a single line the sum of numbers on the given segment. Print the answers to the queries in the order in which the queries go in the input. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.
[ "5\n4 10 3 13 7\n8\n1 2 4\n2 1 3 3\n1 2 4\n1 3 3\n2 2 5 5\n1 1 5\n2 1 2 10\n1 2 3\n", "6\n4 7 4 0 7 3\n5\n2 2 3 8\n1 1 5\n2 3 5 1\n2 4 5 6\n1 2 3\n" ]
[ "26\n22\n0\n34\n11\n", "38\n28\n" ]
none
2,500
[]
1,692,410,972
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
4,000
6,860,800
n = int(input()) a = list(map(int, input().split())) m = int(input()) for _ in range(m): op = list(map(int, input().split())) if op[0] == 1: print(sum(a[op[1]-1:op[2]])) else: for i in range(op[1]-1, op[2]): a[i] ^= op[3]
Title: XOR on Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. You are allowed to perform two operations on this array: 1. Calculate the sum of current array elements on the segment [*l*,<=*r*], that is, count value *a**l*<=+<=*a**l*<=+<=1<=+<=...<=+<=*a**r*. 1. Apply the xor operation with a given number *x* to each array element on the segment [*l*,<=*r*], that is, execute . This operation changes exactly *r*<=-<=*l*<=+<=1 array elements. Expression means applying bitwise xor operation to numbers *x* and *y*. The given operation exists in all modern programming languages, for example in language C++ and Java it is marked as "^", in Pascal — as "xor". You've got a list of *m* operations of the indicated type. Your task is to perform all given operations, for each sum query you should print the result you get. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=106) — the original array. The third line contains integer *m* (1<=≤<=*m*<=≤<=5·104) — the number of operations with the array. The *i*-th of the following *m* lines first contains an integer *t**i* (1<=≤<=*t**i*<=≤<=2) — the type of the *i*-th query. If *t**i*<==<=1, then this is the query of the sum, if *t**i*<==<=2, then this is the query to change array elements. If the *i*-th operation is of type 1, then next follow two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). If the *i*-th operation is of type 2, then next follow three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=106). The numbers on the lines are separated by single spaces. Output Specification: For each query of type 1 print in a single line the sum of numbers on the given segment. Print the answers to the queries in the order in which the queries go in the input. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. Demo Input: ['5\n4 10 3 13 7\n8\n1 2 4\n2 1 3 3\n1 2 4\n1 3 3\n2 2 5 5\n1 1 5\n2 1 2 10\n1 2 3\n', '6\n4 7 4 0 7 3\n5\n2 2 3 8\n1 1 5\n2 3 5 1\n2 4 5 6\n1 2 3\n'] Demo Output: ['26\n22\n0\n34\n11\n', '38\n28\n'] Note: none
```python n = int(input()) a = list(map(int, input().split())) m = int(input()) for _ in range(m): op = list(map(int, input().split())) if op[0] == 1: print(sum(a[op[1]-1:op[2]])) else: for i in range(op[1]-1, op[2]): a[i] ^= op[3] ```
0
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "0\n0\n0\n0" }, { "input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4", "output": "0\n0\n0\n0\n0" }, { "input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4", "output": "0\n1\n0\n0\n0\n1" }, { "input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7", "output": "0\n0\n0\n0\n0\n0\n1" }, { "input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3", "output": "0\n0\n0\n0\n0\n0\n0\n0" }, { "input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5", "output": "0\n1\n0\n0\n0\n0\n0\n1\n0" }, { "input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1", "output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0" }, { "input": "1 1\n-1\n1 1", "output": "0" }, { "input": "1 1\n1\n1 1", "output": "0" } ]
1,618,677,904
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n, m = list(map(int,input().split())) array = input().split() while(m): lower_idx, upper_idx = list(map(int,input().split())) flag = (upper_idx-lower_idx)%2 seg_len = (upper_idx-lower_idx) if(not flag): print(0) m -=1 continue else: pos_ones = array.count(1) neg_ones = array.count(-1) if(pos_ones >= seg_len//2 and neg_ones>=seg_len//2): print(1) else: print(0) m -=1
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print *m* integers — the responses to Eugene's queries in the order they occur in the input. Demo Input: ['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n'] Demo Output: ['0\n1\n0\n', '0\n1\n0\n1\n0\n'] Note: none
```python n, m = list(map(int,input().split())) array = input().split() while(m): lower_idx, upper_idx = list(map(int,input().split())) flag = (upper_idx-lower_idx)%2 seg_len = (upper_idx-lower_idx) if(not flag): print(0) m -=1 continue else: pos_ones = array.count(1) neg_ones = array.count(-1) if(pos_ones >= seg_len//2 and neg_ones>=seg_len//2): print(1) else: print(0) m -=1 ```
0
914
A
Perfect Squares
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square.
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
[ "2\n4 2\n", "8\n1 2 4 8 16 32 64 576\n" ]
[ "2\n", "32\n" ]
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.
500
[ { "input": "2\n4 2", "output": "2" }, { "input": "8\n1 2 4 8 16 32 64 576", "output": "32" }, { "input": "3\n-1 -4 -9", "output": "-1" }, { "input": "5\n918375 169764 598796 76602 538757", "output": "918375" }, { "input": "5\n804610 765625 2916 381050 93025", "output": "804610" }, { "input": "5\n984065 842724 127449 525625 573049", "output": "984065" }, { "input": "2\n226505 477482", "output": "477482" }, { "input": "2\n370881 659345", "output": "659345" }, { "input": "2\n4 5", "output": "5" }, { "input": "2\n3 4", "output": "3" }, { "input": "2\n999999 1000000", "output": "999999" }, { "input": "3\n-1 -2 -3", "output": "-1" }, { "input": "2\n-1000000 1000000", "output": "-1000000" }, { "input": "2\n-1 0", "output": "-1" }, { "input": "1\n2", "output": "2" }, { "input": "1\n-1", "output": "-1" }, { "input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462", "output": "-15745" }, { "input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322", "output": "-257875" }, { "input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209", "output": "-766506" }, { "input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259", "output": "748303" }, { "input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001", "output": "963781" }, { "input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304", "output": "940901" }, { "input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904", "output": "987533" }, { "input": "3\n-1 1 0", "output": "-1" }, { "input": "2\n0 -5", "output": "-5" }, { "input": "3\n-1 -2 0", "output": "-1" }, { "input": "2\n-5 0", "output": "-5" }, { "input": "1\n-439", "output": "-439" }, { "input": "1\n-1000000", "output": "-1000000" }, { "input": "1\n-917455", "output": "-917455" }, { "input": "3\n1 1 -1", "output": "-1" }, { "input": "2\n131073 1", "output": "131073" }, { "input": "2\n99999 3", "output": "99999" }, { "input": "2\n-524272 -1000000", "output": "-524272" }, { "input": "2\n15 131073", "output": "131073" } ]
1,592,748,386
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
108
204,800
from math import sqrt as s n=int(input()) a=sorted(list(map(int,input().split())),reverse=True) for i in range(n): # print(int(s(a[i]))*int(s(a[i]))) if a[i]>0: if (int(s(a[i]))*int(s(a[i]))==a[i]): pass else: print(a[i]) break else: print(a[i]) break
Title: Perfect Squares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square. A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. Output Specification: Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. Demo Input: ['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n'] Demo Output: ['2\n', '32\n'] Note: In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.
```python from math import sqrt as s n=int(input()) a=sorted(list(map(int,input().split())),reverse=True) for i in range(n): # print(int(s(a[i]))*int(s(a[i]))) if a[i]>0: if (int(s(a[i]))*int(s(a[i]))==a[i]): pass else: print(a[i]) break else: print(a[i]) break ```
0
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,698,140,851
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
n,k,l,c,d,p,nl,np=map(int,input().split()) a=k*l t=a/nl l=c*d s=p/np print(min(t,l,s)//n)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python n,k,l,c,d,p,nl,np=map(int,input().split()) a=k*l t=a/nl l=c*d s=p/np print(min(t,l,s)//n) ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,620,098,112
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
7,475,200
N = int(input()) arr = list(map(int,input().split())) M = int(input()) search = list(map(int,input().split())) vasya = 1 petya = 1 res1 = 0 res2 = 0 for i in search: for j in arr: if i == j: break else: vasya+=1 res1 += vasya vasya = 1 ## reverse search for i in search: for j in arr[::-1]: if i == j: break else: petya+=1 res2 += petya petya = 1 print(res1,res2)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python N = int(input()) arr = list(map(int,input().split())) M = int(input()) search = list(map(int,input().split())) vasya = 1 petya = 1 res1 = 0 res2 = 0 for i in search: for j in arr: if i == j: break else: vasya+=1 res1 += vasya vasya = 1 ## reverse search for i in search: for j in arr[::-1]: if i == j: break else: petya+=1 res2 += petya petya = 1 print(res1,res2) ```
0
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$.
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { "input": "100 33 100 100", "output": "100" }, { "input": "1000000000 1000000000 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 32428 1000000000 1000", "output": "1000000000" }, { "input": "1000000000 324934 1000 1000", "output": "4000" }, { "input": "1000000000000000000 32400093004 10000000 1000", "output": "40000000" }, { "input": "885 2 160 842", "output": "504" }, { "input": "216 137 202 208", "output": "202" }, { "input": "72 66 28 9", "output": "28" }, { "input": "294 4 13 8", "output": "80" }, { "input": "9 2 2 3", "output": "4" }, { "input": "31 3 2 8", "output": "10" }, { "input": "104 2 5 11", "output": "50" }, { "input": "1000000000000000000 1000000000000000000 1000 1000", "output": "1000" }, { "input": "1000000000000000000 100000000000000000 1 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 23925738098196565 1000", "output": "23925738098196565" }, { "input": "576460752303423488 576460752303423488 351082447248993993 1000", "output": "351082447248993993" }, { "input": "962768465676381898 72057594037927936 586039918340257175 256", "output": "586039918340257175" }, { "input": "1000000000000000000 1000000000000000000 10 1000", "output": "10" }, { "input": "23925738098196565 23925738098196565 1 1000", "output": "1" }, { "input": "1000000000000000000 1000000000000000000 1 1000", "output": "1" } ]
1,525,286,181
2,147,483,647
Python 3
OK
TESTS
25
109
7,065,600
n, k, m, d = map(int, input().split()) ans = int(0) for i in range(1, d + 1): l, r, mid = 1, m + 1, 0 while l + 1 < r: mid = (l + r) // 2 if (n - mid) // (k * mid) < i - 1: r = mid else: l = mid if (n - l) // (k * l) < i - 1: break ans = max(ans, l * i) print(ans)
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away. Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting. Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$. Input Specification: The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies. Output Specification: Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$. Demo Input: ['20 4 5 2\n', '30 9 4 1\n'] Demo Output: ['8\n', '4\n'] Note: In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total. Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times. In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.
```python n, k, m, d = map(int, input().split()) ans = int(0) for i in range(1, d + 1): l, r, mid = 1, m + 1, 0 while l + 1 < r: mid = (l + r) // 2 if (n - mid) // (k * mid) < i - 1: r = mid else: l = mid if (n - l) // (k * l) < i - 1: break ans = max(ans, l * i) print(ans) ```
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4", "output": "-1" }, { "input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4", "output": "-1" }, { "input": "1\n2 4", "output": "0" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n1 2", "output": "-1" }, { "input": "2\n1 1\n3 3", "output": "0" }, { "input": "2\n1 1\n2 2", "output": "-1" }, { "input": "2\n1 1\n1 2", "output": "-1" }, { "input": "5\n1 2\n6 6\n1 1\n3 3\n6 1", "output": "1" }, { "input": "5\n5 4\n2 6\n6 2\n1 4\n6 2", "output": "0" }, { "input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1", "output": "0" }, { "input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5", "output": "-1" }, { "input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1", "output": "1" }, { "input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4", "output": "-1" }, { "input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2", "output": "0" }, { "input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5", "output": "-1" }, { "input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4", "output": "-1" }, { "input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4", "output": "-1" }, { "input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6", "output": "1" }, { "input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5", "output": "1" }, { "input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3", "output": "1" }, { "input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5", "output": "1" }, { "input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5", "output": "-1" }, { "input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6", "output": "-1" }, { "input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1", "output": "-1" }, { "input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6", "output": "-1" }, { "input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4", "output": "1" }, { "input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6", "output": "-1" }, { "input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2", "output": "0" }, { "input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3", "output": "-1" }, { "input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3", "output": "-1" }, { "input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4", "output": "-1" }, { "input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5", "output": "1" }, { "input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1", "output": "1" }, { "input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5", "output": "-1" }, { "input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2", "output": "0" }, { "input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1", "output": "0" }, { "input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2", "output": "1" }, { "input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2", "output": "0" }, { "input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2", "output": "-1" }, { "input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5", "output": "0" }, { "input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1", "output": "-1" }, { "input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5", "output": "-1" }, { "input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3", "output": "-1" }, { "input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5", "output": "0" }, { "input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4", "output": "-1" }, { "input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2", "output": "-1" }, { "input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2", "output": "1" }, { "input": "1\n2 2", "output": "0" }, { "input": "3\n2 4\n6 6\n3 3", "output": "-1" }, { "input": "2\n3 6\n4 1", "output": "1" }, { "input": "3\n1 1\n1 1\n3 3", "output": "-1" }, { "input": "3\n2 3\n1 1\n2 3", "output": "1" }, { "input": "3\n2 2\n2 1\n1 2", "output": "1" }, { "input": "3\n1 1\n1 1\n1 1", "output": "-1" } ]
1,418,116,417
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
def main(): n = int(input()) l = [0, 0, 0, 0] for _ in range(n): x, y = map(int, input().split()) l[(x & 1) * 2 + (y & 1)] ^= 1 print((0, 0, -1, -1, -1, -1, 1, 0)[l[1] * 4 + l[2] * 2 + l[3]]) if __name__ == '__main__': main()
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. Output Specification: Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. Demo Input: ['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
```python def main(): n = int(input()) l = [0, 0, 0, 0] for _ in range(n): x, y = map(int, input().split()) l[(x & 1) * 2 + (y & 1)] ^= 1 print((0, 0, -1, -1, -1, -1, 1, 0)[l[1] * 4 + l[2] * 2 + l[3]]) if __name__ == '__main__': main() ```
0
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 54 " }, { "input": "4", "output": "2\n1 3 " }, { "input": "6", "output": "3\n1 2 3 " }, { "input": "7", "output": "3\n1 2 4 " }, { "input": "8", "output": "3\n1 2 5 " }, { "input": "10", "output": "4\n1 2 3 4 " }, { "input": "11", "output": "4\n1 2 3 5 " }, { "input": "12", "output": "4\n1 2 3 6 " }, { "input": "13", "output": "4\n1 2 3 7 " }, { "input": "14", "output": "4\n1 2 3 8 " }, { "input": "15", "output": "5\n1 2 3 4 5 " }, { "input": "16", "output": "5\n1 2 3 4 6 " }, { "input": "20", "output": "5\n1 2 3 4 10 " }, { "input": "21", "output": "6\n1 2 3 4 5 6 " }, { "input": "22", "output": "6\n1 2 3 4 5 7 " }, { "input": "27", "output": "6\n1 2 3 4 5 12 " }, { "input": "28", "output": "7\n1 2 3 4 5 6 7 " }, { "input": "29", "output": "7\n1 2 3 4 5 6 8 " }, { "input": "35", "output": "7\n1 2 3 4 5 6 14 " }, { "input": "36", "output": "8\n1 2 3 4 5 6 7 8 " }, { "input": "37", "output": "8\n1 2 3 4 5 6 7 9 " }, { "input": "44", "output": "8\n1 2 3 4 5 6 7 16 " }, { "input": "45", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "46", "output": "9\n1 2 3 4 5 6 7 8 10 " }, { "input": "230", "output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40 " }, { "input": "231", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 " }, { "input": "232", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 " }, { "input": "239", "output": "21\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 29 " }, { "input": "629", "output": "34\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 68 " }, { "input": "630", "output": "35\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 " }, { "input": "631", "output": "35\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 36 " }, { "input": "945", "output": "42\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 84 " }, { "input": "946", "output": "43\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 " }, { "input": "947", "output": "43\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 " }, { "input": "989", "output": "43\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 86 " }, { "input": "990", "output": "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 " }, { "input": "991", "output": "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 " }, { "input": "956", "output": "43\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 53 " }, { "input": "981", "output": "43\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 78 " }, { "input": "867", "output": "41\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 47 " }, { "input": "906", "output": "42\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 45 " }, { "input": "999", "output": "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 53 " }, { "input": "100", "output": "13\n1 2 3 4 5 6 7 8 9 10 11 12 22 " }, { "input": "126", "output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 21 " } ]
1,592,543,288
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
n=int(input()) i=1 l=[] while n>0: n-=i l.append(i) i+=1 l[0]+=n+i-1 print(len(l)-1) for i in range(len(l)-1): print(l[i],end=' ')
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. Input Specification: The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. Output Specification: Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them. Demo Input: ['5\n', '9\n', '2\n'] Demo Output: ['2\n2 3\n', '3\n3 5 1\n', '1\n2 \n'] Note: none
```python n=int(input()) i=1 l=[] while n>0: n-=i l.append(i) i+=1 l[0]+=n+i-1 print(len(l)-1) for i in range(len(l)-1): print(l[i],end=' ') ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,602,569,375
2,147,483,647
Python 3
OK
TESTS
102
108
0
num1=input() num2=input() list=[] for i in range(len(num1)): if num1[i]==num2[i]: list.append(0) else: list.append(1) for e in list: print(e,end="")
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python num1=input() num2=input() list=[] for i in range(len(num1)): if num1[i]==num2[i]: list.append(0) else: list.append(1) for e in list: print(e,end="") ```
3.973
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, { "input": "20\n44444444444444444444", "output": "YES" }, { "input": "2\n44", "output": "YES" }, { "input": "10\n4745474547", "output": "NO" }, { "input": "14\n77770004444444", "output": "NO" }, { "input": "10\n4747777744", "output": "YES" }, { "input": "10\n1234567890", "output": "NO" }, { "input": "50\n44444444444444444444444444444444444444444444444444", "output": "YES" }, { "input": "50\n44444444444444444444444444444444444444444444444447", "output": "NO" }, { "input": "50\n74444444444444444444444444444444444444444444444444", "output": "NO" }, { "input": "50\n07777777777777777777777777777777777777777777777770", "output": "NO" }, { "input": "50\n77777777777777777777777777777777777777777777777777", "output": "YES" }, { "input": "50\n44747747774474747747747447777447774747447477444474", "output": "YES" }, { "input": "48\n447474444777444474747747744774447444747474774474", "output": "YES" }, { "input": "32\n74474474777444474444747774474774", "output": "YES" }, { "input": "40\n4747777444447747777447447747447474774777", "output": "YES" }, { "input": "10\n4477477444", "output": "YES" }, { "input": "18\n447747474447744747", "output": "YES" }, { "input": "26\n44747744444774744774474447", "output": "YES" }, { "input": "50\n44707747774474747747747447777447774747447477444474", "output": "NO" }, { "input": "40\n4747777444447737777447447747447474774777", "output": "NO" }, { "input": "36\n764477744747444444447747747474744444", "output": "NO" }, { "input": "22\n4477407474777477744447", "output": "NO" }, { "input": "32\n74274474777444474444747774474774", "output": "NO" }, { "input": "16\n4744447974444747", "output": "NO" }, { "input": "2\n11", "output": "NO" }, { "input": "2\n22", "output": "NO" }, { "input": "2\n33", "output": "NO" }, { "input": "2\n74", "output": "NO" }, { "input": "2\n55", "output": "NO" }, { "input": "2\n66", "output": "NO" }, { "input": "2\n77", "output": "YES" }, { "input": "2\n88", "output": "NO" }, { "input": "2\n99", "output": "NO" }, { "input": "4\n4004", "output": "NO" }, { "input": "14\n00077774444444", "output": "NO" }, { "input": "6\n004444", "output": "NO" }, { "input": "4\n0044", "output": "NO" }, { "input": "14\n77771114444444", "output": "NO" }, { "input": "14\n44444447777000", "output": "NO" }, { "input": "6\n004774", "output": "NO" } ]
1,631,361,611
2,147,483,647
Python 3
OK
TESTS
46
124
6,963,200
n = int(input()) num = int(input()) lis = [i for i in str(num)] lis1 = lis[:int(n/2)] lis2 = lis[int(n/2):] lis11 = [int(x) for x in lis1] lis22 = [int(x) for x in lis2] if( lis.count('7') + lis.count('4')) == n and sum(lis11) == sum(lis22): print('YES') else: print('NO')
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python n = int(input()) num = int(input()) lis = [i for i in str(num)] lis1 = lis[:int(n/2)] lis2 = lis[int(n/2):] lis11 = [int(x) for x in lis1] lis22 = [int(x) for x in lis2] if( lis.count('7') + lis.count('4')) == n and sum(lis11) == sum(lis22): print('YES') else: print('NO') ```
3
450
B
Jzzhu and Sequences
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
[ "2 3\n3\n", "0 -1\n2\n" ]
[ "1\n", "1000000006\n" ]
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
1,000
[ { "input": "2 3\n3", "output": "1" }, { "input": "0 -1\n2", "output": "1000000006" }, { "input": "-9 -11\n12345", "output": "1000000005" }, { "input": "0 0\n1000000000", "output": "0" }, { "input": "-1000000000 1000000000\n2000000000", "output": "1000000000" }, { "input": "-12345678 12345678\n1912345678", "output": "12345678" }, { "input": "728374857 678374857\n1928374839", "output": "950000007" }, { "input": "278374837 992837483\n1000000000", "output": "721625170" }, { "input": "-693849384 502938493\n982838498", "output": "502938493" }, { "input": "-783928374 983738273\n992837483", "output": "16261734" }, { "input": "-872837483 -682738473\n999999999", "output": "190099010" }, { "input": "-892837483 -998273847\n999283948", "output": "892837483" }, { "input": "-283938494 738473848\n1999999999", "output": "716061513" }, { "input": "-278374857 819283838\n1", "output": "721625150" }, { "input": "-1000000000 123456789\n1", "output": "7" }, { "input": "-529529529 -524524524\n2", "output": "475475483" }, { "input": "1 2\n2000000000", "output": "2" }, { "input": "-1 -2\n2000000000", "output": "1000000005" }, { "input": "1 2\n1999999999", "output": "1" }, { "input": "1 2\n1999999998", "output": "1000000006" }, { "input": "1 2\n1999999997", "output": "1000000005" }, { "input": "1 2\n1999999996", "output": "1000000006" }, { "input": "69975122 366233206\n1189460676", "output": "703741923" }, { "input": "812229413 904420051\n806905621", "output": "812229413" }, { "input": "872099024 962697902\n1505821695", "output": "90598878" }, { "input": "887387283 909670917\n754835014", "output": "112612724" }, { "input": "37759824 131342932\n854621399", "output": "868657075" }, { "input": "-246822123 800496170\n626323615", "output": "753177884" }, { "input": "-861439463 974126967\n349411083", "output": "835566423" }, { "input": "-69811049 258093841\n1412447", "output": "741906166" }, { "input": "844509330 -887335829\n123329059", "output": "844509330" }, { "input": "83712471 -876177148\n1213284777", "output": "40110388" }, { "input": "598730524 -718984219\n1282749880", "output": "401269483" }, { "input": "-474244697 -745885656\n1517883612", "output": "271640959" }, { "input": "-502583588 -894906953\n1154189557", "output": "497416419" }, { "input": "-636523651 -873305815\n154879215", "output": "763217843" }, { "input": "721765550 594845720\n78862386", "output": "126919830" }, { "input": "364141461 158854993\n1337196589", "output": "364141461" }, { "input": "878985260 677031952\n394707801", "output": "798046699" }, { "input": "439527072 -24854079\n1129147002", "output": "464381151" }, { "input": "840435009 -612103127\n565968986", "output": "387896880" }, { "input": "875035447 -826471373\n561914518", "output": "124964560" }, { "input": "-342526698 305357084\n70776744", "output": "352116225" }, { "input": "-903244186 899202229\n1527859274", "output": "899202229" }, { "input": "-839482546 815166320\n1127472130", "output": "839482546" }, { "input": "-976992569 -958313041\n1686580818", "output": "981320479" }, { "input": "-497338894 -51069176\n737081851", "output": "502661113" }, { "input": "-697962643 -143148799\n1287886520", "output": "856851208" }, { "input": "-982572938 -482658433\n1259858332", "output": "982572938" }, { "input": "123123 78817\n2000000000", "output": "78817" }, { "input": "1000000000 -1000000000\n3", "output": "14" }, { "input": "-1000000000 1000000000\n6", "output": "14" }, { "input": "2 3\n6", "output": "1000000006" }, { "input": "0 -1\n6", "output": "1" }, { "input": "500000000 -1000000000\n600000003", "output": "500000014" }, { "input": "-1000000000 1000000000\n3", "output": "999999993" }, { "input": "1 3\n6", "output": "1000000005" }, { "input": "1 2\n12", "output": "1000000006" }, { "input": "7 -1000000000\n3", "output": "0" }, { "input": "-999999997 999999997\n6", "output": "20" }, { "input": "3 4\n6", "output": "1000000006" }, { "input": "-1 2\n6", "output": "1000000004" }, { "input": "2 3\n12", "output": "1000000006" }, { "input": "4 18\n6", "output": "999999993" }, { "input": "1 2\n6", "output": "1000000006" }, { "input": "1000000000 -1000000000\n6", "output": "999999993" }, { "input": "999999999 -999999999\n3", "output": "16" }, { "input": "-1 0\n1", "output": "1000000006" }, { "input": "1000000000 -1000000000\n9", "output": "14" }, { "input": "999999999 -1000000000\n12", "output": "999999992" }, { "input": "1000000000 -7\n3", "output": "0" }, { "input": "-5 5\n6", "output": "999999997" }, { "input": "5 9\n6", "output": "1000000003" }, { "input": "-15 -10\n1", "output": "999999992" } ]
1,666,971,757
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
x, y = tuple(map(int, input().split())) n = int(input()) MOD = 1000000007 if n%3 == 1 : if n%2==0: print(-(x%MOD)) else: print(x%MOD) elif n%3==2: if n%2==0: print(y%MOD) else: print(-(y%MOD)) elif n%3==0: if n%2==0: print((x-y)%MOD) else: print((y-x)%MOD)
Title: Jzzhu and Sequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu has invented a kind of sequences, they meet the following property: You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). Output Specification: Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). Demo Input: ['2 3\n3\n', '0 -1\n2\n'] Demo Output: ['1\n', '1000000006\n'] Note: In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1. In the second sample, *f*<sub class="lower-index">2</sub> =  - 1;  - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6).
```python x, y = tuple(map(int, input().split())) n = int(input()) MOD = 1000000007 if n%3 == 1 : if n%2==0: print(-(x%MOD)) else: print(x%MOD) elif n%3==2: if n%2==0: print(y%MOD) else: print(-(y%MOD)) elif n%3==0: if n%2==0: print((x-y)%MOD) else: print((y-x)%MOD) ```
0
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message.
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "output": "vyvvysyooysyo" }, { "input": "L\ngggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\ngggggggggggggggggggggggggggggggggggggggggg", "output": "ffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" }, { "input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, { "input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw", "output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge" }, { "input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym", "output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u," }, { "input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,", "output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm" }, { "input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd", "output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs" }, { "input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }, { "input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" }, { "input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "output": "...................................................................................................." }, { "input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", "output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" }, { "input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "L\nq", "output": "w" }, { "input": "L\no", "output": "p" }, { "input": "L\n,", "output": "." }, { "input": "L\nz", "output": "x" }, { "input": "R\n.", "output": "," }, { "input": "R\no", "output": "i" }, { "input": "R\nw", "output": "q" }, { "input": "R\nx", "output": "z" }, { "input": "R\n,./", "output": "m,." }, { "input": "R\nwertuk;;/", "output": "qweryjll." }, { "input": "L\n..", "output": "//" } ]
1,690,219,769
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
0
v="qwertyuiop";v11="asdfghjkl;";v111="zxcvbnm,./" v1=input();v2=input();v3='' for i in v2: for j in v,v11,v111: if i in j: if v1=="R": w=j.find(i) v3+=j[abs(w-1)] else: v3+=s[abs(w+1)] print(v3)
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input Specification: First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Specification: Print a line that contains the original message. Demo Input: ['R\ns;;upimrrfod;pbr\n'] Demo Output: ['allyouneedislove\n'] Note: none
```python v="qwertyuiop";v11="asdfghjkl;";v111="zxcvbnm,./" v1=input();v2=input();v3='' for i in v2: for j in v,v11,v111: if i in j: if v1=="R": w=j.find(i) v3+=j[abs(w-1)] else: v3+=s[abs(w+1)] print(v3) ```
-1
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }, { "input": "2\n8 2", "output": "1 1" }, { "input": "3\n6 8 4", "output": "1 2" }, { "input": "4\n4 3 2 8", "output": "3 1" }, { "input": "5\n1 9 8 2 7", "output": "2 3" }, { "input": "6\n1 4 7 3 2 1", "output": "3 3" }, { "input": "11\n7 9 1 8 7 1 7 1 4 8 1", "output": "4 7" }, { "input": "12\n4 2 7 1 9 5 6 2 7 8 5 7", "output": "7 5" }, { "input": "13\n9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "7 6" } ]
1,682,004,027
2,147,483,647
PyPy 3-64
OK
TESTS
40
248
14,131,200
import sys from math import * from collections import * from heapq import * from bisect import * input = sys.stdin.readline n = int(input()) arr = list(map(int, input().split())) i = 0 j = n - 1 a, al = 0, 0 b, bo = 0, 0 while i <= j: if al <= bo: al += arr[i] a += 1 i += 1 else: bo += arr[j] b += 1 j -= 1 print(a, b)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). Output Specification: Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. Demo Input: ['5\n2 9 8 2 7\n'] Demo Output: ['2 3\n'] Note: none
```python import sys from math import * from collections import * from heapq import * from bisect import * input = sys.stdin.readline n = int(input()) arr = list(map(int, input().split())) i = 0 j = n - 1 a, al = 0, 0 b, bo = 0, 0 while i <= j: if al <= bo: al += arr[i] a += 1 i += 1 else: bo += arr[j] b += 1 j -= 1 print(a, b) ```
3.832714
899
A
Splitting in Teams
PROGRAMMING
800
[ "constructive algorithms", "greedy", "math" ]
null
null
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Print the maximum number of teams of three people the coach can form.
[ "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "3\n1 1 1\n" ]
[ "1\n", "0\n", "3\n", "1\n" ]
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
500
[ { "input": "4\n1 1 2 1", "output": "1" }, { "input": "2\n2 2", "output": "0" }, { "input": "7\n2 2 2 1 1 1 1", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n2 2 1 1 1", "output": "2" }, { "input": "7\n1 1 2 2 1 2 1", "output": "3" }, { "input": "10\n1 2 2 1 2 2 1 2 1 1", "output": "5" }, { "input": "5\n2 2 2 1 2", "output": "1" }, { "input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2", "output": "10" }, { "input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2", "output": "34" }, { "input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2", "output": "32" }, { "input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2", "output": "9" }, { "input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1", "output": "11" }, { "input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2", "output": "100" }, { "input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2", "output": "123" }, { "input": "4\n2 2 2 2", "output": "0" }, { "input": "4\n1 1 1 1", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n1 2", "output": "1" }, { "input": "3\n1 1 2", "output": "1" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "3\n2 2 1", "output": "1" }, { "input": "4\n1 1 1 2", "output": "1" }, { "input": "4\n1 1 2 2", "output": "2" }, { "input": "4\n1 2 2 2", "output": "1" }, { "input": "4\n2 1 1 1", "output": "1" }, { "input": "5\n1 1 1 1 2", "output": "2" }, { "input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "1" }, { "input": "38\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 1", "output": "1" }, { "input": "30\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 1", "output": "1" }, { "input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1", "output": "1" }, { "input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2", "output": "1" }, { "input": "6\n1 1 1 2 2 2", "output": "3" }, { "input": "5\n2 1 1 1 1", "output": "2" }, { "input": "9\n1 1 1 1 1 1 2 2 2", "output": "4" }, { "input": "10\n2 2 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "6\n1 1 1 1 1 1", "output": "2" } ]
1,630,646,978
458
PyPy 3
WRONG_ANSWER
TESTS
1
77
20,172,800
n = int(input()) l = list(map(int,input().split())) t = l.count(2) o = l.count(1) ans = 0 if t <= o: ans += t o -= t ans += (o//3) else: print(o) print(ans)
Title: Splitting in Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. Output Specification: Print the maximum number of teams of three people the coach can form. Demo Input: ['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n'] Demo Output: ['1\n', '0\n', '3\n', '1\n'] Note: In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person).
```python n = int(input()) l = list(map(int,input().split())) t = l.count(2) o = l.count(1) ans = 0 if t <= o: ans += t o -= t ans += (o//3) else: print(o) print(ans) ```
0
501
B
Misha and Changing Handles
PROGRAMMING
1,100
[ "data structures", "dsu", "strings" ]
null
null
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order. Each user who changes the handle must occur exactly once in this description.
[ "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n" ]
[ "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n" ]
none
500
[ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123" }, { "input": "1\nMisha Vasya", "output": "1\nMisha Vasya" }, { "input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k", "output": "1\na k" }, { "input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha", "output": "2\n123abc 1A2B3C\n1 Misha" }, { "input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e", "output": "3\nM G\n1 R\nS e" }, { "input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV", "output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV" }, { "input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI", "output": "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9" }, { "input": "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6", "output": "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ" }, { "input": "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ", "output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ" } ]
1,599,593,132
2,147,483,647
Python 3
OK
TESTS
49
109
307,200
n=int(input()) a=[] for i in range(n): b=input().split() if b[0] in a: ind=a.index(b[0]) a.insert(ind,b[1]) a.pop(ind+1) else: a.append(b[0]) a.append(b[1]) print(len(a)//2) for i in range(len(a)//2): print(*a[:2]) a=a[2:]
Title: Misha and Changing Handles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. Input Specification: The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. Output Specification: In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Demo Input: ['5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n'] Demo Output: ['3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n'] Note: none
```python n=int(input()) a=[] for i in range(n): b=input().split() if b[0] in a: ind=a.index(b[0]) a.insert(ind,b[1]) a.pop(ind+1) else: a.append(b[0]) a.append(b[1]) print(len(a)//2) for i in range(len(a)//2): print(*a[:2]) a=a[2:] ```
3
656
D
Rosetta Problem
PROGRAMMING
2,100
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000).
Output a single integer.
[ "129\n" ]
[ "1\n" ]
none
0
[ { "input": "129", "output": "1" }, { "input": "0", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "0" }, { "input": "16", "output": "0" }, { "input": "299593", "output": "7" }, { "input": "398929", "output": "4" }, { "input": "860076", "output": "1" }, { "input": "262144", "output": "1" }, { "input": "1000000", "output": "2" }, { "input": "266305", "output": "4" }, { "input": "456910", "output": "2" }, { "input": "953086", "output": "0" }, { "input": "23982", "output": "0" }, { "input": "9852", "output": "1" }, { "input": "569", "output": "2" }, { "input": "11249", "output": "1" }, { "input": "73", "output": "3" }, { "input": "2122", "output": "2" }, { "input": "6218", "output": "3" }, { "input": "33345", "output": "4" }, { "input": "42705", "output": "2" }, { "input": "121", "output": "2" }, { "input": "67", "output": "1" }, { "input": "3593", "output": "2" } ]
1,679,112,009
2,147,483,647
PyPy 3-64
OK
TESTS
25
61
0
n = int(input()) c = 0 while n: c += n%8 == 1 n//=8 print(c)
Title: Rosetta Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The input contains a single integer *a* (0<=≤<=*a*<=≤<=1<=000<=000). Output Specification: Output a single integer. Demo Input: ['129\n'] Demo Output: ['1\n'] Note: none
```python n = int(input()) c = 0 while n: c += n%8 == 1 n//=8 print(c) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,595,847,899
2,147,483,647
PyPy 3
OK
TESTS
30
436
22,220,800
import string word = input() count_lower = 0 count_upper = 0 for i in word: if "a" <= i <= "z": count_lower +=1 else: count_upper +=1 if count_lower >= count_upper: print(word.lower()) else: print(word.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python import string word = input() count_lower = 0 count_upper = 0 for i in word: if "a" <= i <= "z": count_lower +=1 else: count_upper +=1 if count_lower >= count_upper: print(word.lower()) else: print(word.upper()) ```
3.849611
509
B
Painting Pebbles
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation" ]
null
null
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one. In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero.
The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles.
If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) . Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them.
[ "4 4\n1 2 3 4\n", "5 2\n3 2 4 1 3\n", "5 4\n3 2 4 3 5\n" ]
[ "YES\n1\n1 4\n1 2 4\n1 2 3 4\n", "NO\n", "YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n" ]
none
0
[ { "input": "4 4\n1 2 3 4", "output": "YES\n1 \n1 1 \n1 1 2 \n1 1 2 3 " }, { "input": "5 2\n3 2 4 1 3", "output": "NO" }, { "input": "5 4\n3 2 4 3 5", "output": "YES\n1 1 1 \n1 1 \n1 1 1 2 \n1 1 1 \n1 1 1 2 3 " }, { "input": "4 3\n5 6 7 8", "output": "YES\n1 1 1 1 1 \n1 1 1 1 1 1 \n1 1 1 1 1 1 2 \n1 1 1 1 1 1 2 3 " }, { "input": "5 6\n3 7 2 1 2", "output": "YES\n1 1 2 \n1 1 2 3 4 5 6 \n1 1 \n1 \n1 1 " }, { "input": "9 5\n5 8 7 3 10 1 4 6 3", "output": "NO" }, { "input": "2 1\n7 2", "output": "NO" }, { "input": "87 99\n90 28 93 18 80 94 68 58 72 45 93 72 11 54 54 48 74 63 73 7 4 54 42 67 8 13 89 32 2 26 13 94 28 46 77 95 94 63 60 7 16 55 90 91 97 80 7 97 8 12 1 32 43 20 79 38 48 22 97 11 92 97 100 41 72 2 93 68 26 2 79 36 19 96 31 47 52 21 12 86 90 83 57 1 4 81 87", "output": "YES\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5..." }, { "input": "5 92\n95 10 4 28 56", "output": "YES\n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n1 1 1 1 1 2 3 4 5 6 \n1 1 1 1 \n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43..." }, { "input": "96 99\n54 72 100 93 68 36 73 98 79 31 51 88 53 65 69 84 19 65 52 19 62 12 80 45 100 45 78 93 70 56 57 97 21 70 55 15 95 100 51 44 93 1 67 29 4 39 57 82 81 66 66 89 42 18 48 70 81 67 17 62 70 76 79 82 70 26 66 22 16 8 49 23 16 30 46 71 36 20 96 18 53 5 45 5 96 66 95 20 87 3 45 4 47 22 24 7", "output": "YES\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 5..." }, { "input": "56 97\n96 81 39 97 2 75 85 17 9 90 2 31 32 10 42 87 71 100 39 81 2 38 90 81 96 7 57 23 2 25 5 62 22 61 47 94 63 83 91 51 8 93 33 65 38 50 5 64 76 57 96 19 13 100 56 39", "output": "NO" }, { "input": "86 98\n27 94 18 86 16 11 74 59 62 64 37 84 100 4 48 6 37 11 50 73 11 30 87 14 89 55 35 8 99 63 54 16 99 20 40 91 75 18 28 36 31 76 98 40 90 41 83 32 81 61 81 43 5 36 33 35 63 15 86 38 63 27 21 2 68 67 12 55 36 79 93 93 29 5 22 52 100 17 81 50 6 42 59 57 83 20", "output": "YES\n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 4..." }, { "input": "21 85\n83 25 85 96 23 80 54 14 71 57 44 88 30 92 90 61 17 80 59 85 12", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 6..." }, { "input": "87 71\n44 88 67 57 57 80 69 69 40 32 92 54 64 51 69 54 31 53 29 42 32 85 100 90 46 56 40 46 68 81 60 42 99 89 61 96 48 42 78 95 71 67 30 42 57 82 41 76 29 79 32 62 100 89 81 55 88 90 86 54 54 31 28 67 69 49 45 54 68 77 64 32 60 60 66 66 83 57 56 89 57 82 73 86 60 61 62", "output": "NO" }, { "input": "63 87\n12 63 17 38 52 19 27 26 24 40 43 12 84 99 59 37 37 12 36 88 22 56 55 57 33 64 45 71 85 73 84 38 51 36 14 15 98 68 50 33 92 97 44 79 40 60 43 15 52 58 38 95 74 64 77 79 85 41 59 55 43 29 27", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 \n1 ..." }, { "input": "39 39\n87 88 86 86 96 70 79 64 85 80 81 74 64 65 90 64 83 78 96 63 78 80 62 62 76 89 69 73 100 100 99 69 69 89 97 64 94 94 71", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 67\n82 34 100 55 38 32 97 34 100 49 49 41 48 100 74 51 53 50 46 38 35 69 93 61 96 86 43 59 90 45 52 100 48 45 63 60 52 66 83 46 66 47 74 37 56 48 42 88 39 68 38 66 77 40 60 60 92 38 45 57 63 91 85 85 89 53 64 66 99 89 49 54 48 58 94 65 78 34 78 62 95 47 64 50 84 52 98 79 57 69 39 61 92 46 63 45 90 51 79 39", "output": "NO" }, { "input": "100 35\n99 90 67 85 68 67 76 75 77 78 81 85 98 88 70 77 89 87 68 91 83 74 70 65 74 86 82 79 81 93 80 66 93 72 100 99 96 66 89 71 93 80 74 97 73 80 93 81 70 68 80 72 75 70 78 67 73 79 76 75 77 78 85 96 72 84 100 68 77 71 79 91 75 100 67 94 73 79 88 73 92 71 68 66 81 68 81 73 69 75 76 84 70 82 66 83 89 90 79 91", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 15\n92 87 87 99 91 87 94 94 97 90 98 90 91 95 99 97 95 100 93 95 92 100 87 87 94 89 90 99 89 99 95 90 89 88 92 97 88 86 86 95 96 92 89 89 86 92 89 89 100 100 95 86 86 97 97 98 89 88 97 89 93 100 99 99 93 92 87 97 91 90 96 86 99 86 87 95 99 100 88 86 86 93 100 88 88 89 94 88 88 95 89 86 99 98 91 97 87 88 100 94", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..." }, { "input": "17 1\n79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 ..." }, { "input": "27 2\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..." }, { "input": "48 3\n85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85", "output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ..." }, { "input": "1 1\n1", "output": "YES\n1 " }, { "input": "1 100\n1", "output": "YES\n1 " } ]
1,596,118,938
2,147,483,647
PyPy 3
OK
TESTS
24
171
23,040,000
keeper=input() n, m=keeper.split(' ') keeper2=input() tp=keeper2.split(' ') map_object=map(int, tp) arr=list(map_object) if (max(arr))-(min(arr)) > int(m): print("NO") else: print("YES") for x in arr: for y in range(0,int(x)): print(int(y)%int(m)+1, end=" ") print()
Title: Painting Pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one. In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero. Input Specification: The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles. Output Specification: If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) . Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them. Demo Input: ['4 4\n1 2 3 4\n', '5 2\n3 2 4 1 3\n', '5 4\n3 2 4 3 5\n'] Demo Output: ['YES\n1\n1 4\n1 2 4\n1 2 3 4\n', 'NO\n', 'YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n'] Note: none
```python keeper=input() n, m=keeper.split(' ') keeper2=input() tp=keeper2.split(' ') map_object=map(int, tp) arr=list(map_object) if (max(arr))-(min(arr)) > int(m): print("NO") else: print("YES") for x in arr: for y in range(0,int(x)): print(int(y)%int(m)+1, end=" ") print() ```
3
39
J
Spelling Check
PROGRAMMING
1,500
[ "hashing", "implementation", "strings" ]
J. Spelling Check
2
256
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?
The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.
In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.
[ "abdrakadabra\nabrakadabra\n", "aa\na\n", "competition\ncodeforces\n" ]
[ "1\n3\n", "2\n1 2\n", "0\n" ]
none
0
[ { "input": "abdrakadabra\nabrakadabra", "output": "1\n3 " }, { "input": "aa\na", "output": "2\n1 2 " }, { "input": "competition\ncodeforces", "output": "0" }, { "input": "ab\na", "output": "1\n2 " }, { "input": "bb\nb", "output": "2\n1 2 " }, { "input": "aab\nab", "output": "2\n1 2 " }, { "input": "aabb\nabb", "output": "2\n1 2 " }, { "input": "babaacaacaa\nbbaacaacaa", "output": "1\n2 " }, { "input": "bccaabbcccc\nbccaabcccc", "output": "2\n6 7 " }, { "input": "ababcaabaaa\nabacaabaaa", "output": "1\n4 " }, { "input": "cccacaccacb\ncccacaccac", "output": "1\n11 " }, { "input": "aaaaaaaaaaa\naaaaaaaaaa", "output": "11\n1 2 3 4 5 6 7 8 9 10 11 " }, { "input": "lcaaxcbcjca\nccaaacccca", "output": "0" }, { "input": "babbbtaamba\nbabbbaabba", "output": "0" }, { "input": "xdfxmcnzpch\nazvotghvtk", "output": "0" }, { "input": "ki\nb", "output": "0" }, { "input": "vct\nie", "output": "0" }, { "input": "feee\nsnl", "output": "0" }, { "input": "cbxxxxzvks\ncbxxxzvks", "output": "4\n3 4 5 6 " }, { "input": "qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur", "output": "10\n11 12 13 14 15 16 17 18 19 20 " } ]
1,697,025,857
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
s = input() t = input() l = 0 r = 0 let = [] flag = 0 while l < len(s) and r < len(t): if s[l] != t[r]: let.append((s[l],l+1)) flag = 1 l += 1 else: l += 1 r += 1 if flag: if len(let) == 1: print(1) print(let[0][1]) else: print(0) else: new = [] f = 0 while l < len(s): new.append(l+1) l += 1 l = len(s)-1 r = len(t)-1 while l >= 0 and r >= 0: if s[l] != t[r]: new.append(l+1) f = 1 l -= 1 else: l -= 1 r -= 1 if not f: while l >= 0: new.append(l+1) l -= 1 if len(new) <= 2: print(2) new.sort() print(*new)
Title: Spelling Check Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete? Input Specification: The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one. Output Specification: In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0. Demo Input: ['abdrakadabra\nabrakadabra\n', 'aa\na\n', 'competition\ncodeforces\n'] Demo Output: ['1\n3\n', '2\n1 2\n', '0\n'] Note: none
```python s = input() t = input() l = 0 r = 0 let = [] flag = 0 while l < len(s) and r < len(t): if s[l] != t[r]: let.append((s[l],l+1)) flag = 1 l += 1 else: l += 1 r += 1 if flag: if len(let) == 1: print(1) print(let[0][1]) else: print(0) else: new = [] f = 0 while l < len(s): new.append(l+1) l += 1 l = len(s)-1 r = len(t)-1 while l >= 0 and r >= 0: if s[l] != t[r]: new.append(l+1) f = 1 l -= 1 else: l -= 1 r -= 1 if not f: while l >= 0: new.append(l+1) l -= 1 if len(new) <= 2: print(2) new.sort() print(*new) ```
0
980
A
Links and Pearls
PROGRAMMING
900
[ "implementation", "math" ]
null
null
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace.
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower).
[ "-o-o--", "-o---\n", "-o---o-\n", "ooo\n" ]
[ "YES", "YES", "NO", "YES\n" ]
none
500
[ { "input": "-o-o--", "output": "YES" }, { "input": "-o---", "output": "YES" }, { "input": "-o---o-", "output": "NO" }, { "input": "ooo", "output": "YES" }, { "input": "---", "output": "YES" }, { "input": "--o-o-----o----o--oo-o-----ooo-oo---o--", "output": "YES" }, { "input": "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--", "output": "NO" }, { "input": "-ooo--", "output": "YES" }, { "input": "---o--", "output": "YES" }, { "input": "oo-ooo", "output": "NO" }, { "input": "------o-o--o-----o--", "output": "YES" }, { "input": "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-------------oo-----o-------------o---o", "output": "YES" }, { "input": "----------------------------------------------------------------------------------------------------", "output": "YES" }, { "input": "-oo-oo------", "output": "YES" }, { "input": "---------------------------------o----------------------------oo------------------------------------", "output": "NO" }, { "input": "oo--o--o--------oo----------------o-----------o----o-----o----------o---o---o-----o---------ooo---", "output": "NO" }, { "input": "--o---oooo--o-o--o-----o----ooooo--o-oo--o------oooo--------------ooo-o-o----", "output": "NO" }, { "input": "-----------------------------o--o-o-------", "output": "YES" }, { "input": "o-oo-o--oo----o-o----------o---o--o----o----o---oo-ooo-o--o-", "output": "YES" }, { "input": "oooooooooo-ooo-oooooo-ooooooooooooooo--o-o-oooooooooooooo-oooooooooooooo", "output": "NO" }, { "input": "-----------------o-o--oo------o--------o---o--o----------------oooo-------------ooo-----ooo-----o", "output": "NO" }, { "input": "ooo-ooooooo-oo-ooooooooo-oooooooooooooo-oooo-o-oooooooooo--oooooooooooo-oooooooooo-ooooooo", "output": "NO" }, { "input": "oo-o-ooooo---oo---o-oo---o--o-ooo-o---o-oo---oo---oooo---o---o-oo-oo-o-ooo----ooo--oo--o--oo-o-oo", "output": "NO" }, { "input": "-----o-----oo-o-o-o-o----o---------oo---ooo-------------o----o---o-o", "output": "YES" }, { "input": "oo--o-o-o----o-oooo-ooooo---o-oo--o-o--ooo--o--oooo--oo----o----o-o-oooo---o-oooo--ooo-o-o----oo---", "output": "NO" }, { "input": "------oo----o----o-oo-o--------o-----oo-----------------------o------------o-o----oo---------", "output": "NO" }, { "input": "-o--o--------o--o------o---o-o----------o-------o-o-o-------oo----oo------o------oo--o--", "output": "NO" }, { "input": "------------------o----------------------------------o-o-------------", "output": "YES" }, { "input": "-------------o----ooo-----o-o-------------ooo-----------ooo------o----oo---", "output": "YES" }, { "input": "-------o--------------------o--o---------------o---o--o-----", "output": "YES" }, { "input": "------------------------o------------o-----o----------------", "output": "YES" }, { "input": "------oo----------o------o-----o---------o------------o----o--o", "output": "YES" }, { "input": "------------o------------------o-----------------------o-----------o", "output": "YES" }, { "input": "o---o---------------", "output": "YES" }, { "input": "----------------------o---o----o---o-----------o-o-----o", "output": "YES" }, { "input": "----------------------------------------------------------------------o-o---------------------", "output": "YES" }, { "input": "----o---o-------------------------", "output": "YES" }, { "input": "o----------------------oo----", "output": "NO" }, { "input": "-o-o--o-o--o-----o-----o-o--o-o---oooo-o", "output": "NO" }, { "input": "-o-ooo-o--o----o--o-o-oo-----------o-o-", "output": "YES" }, { "input": "o-------o-------o-------------", "output": "YES" }, { "input": "oo----------------------o--------------o--------------o-----", "output": "YES" }, { "input": "-----------------------------------o---------------------o--------------------------", "output": "YES" }, { "input": "--o--o----o-o---o--o----o-o--oo-----o-oo--o---o---ooo-o--", "output": "YES" }, { "input": "---------------o-o----", "output": "YES" }, { "input": "o------ooo--o-o-oo--o------o----ooo-----o-----o-----o-ooo-o---o----oo", "output": "YES" }, { "input": "----o----o", "output": "YES" }, { "input": "o--o--o--o--o--o--o--o--o--o--o--o--", "output": "YES" }, { "input": "o---o---o---o---o----o----o----o---o---o---o", "output": "YES" }, { "input": "o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-", "output": "YES" }, { "input": "-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o", "output": "YES" }, { "input": "o----------o----------o----------o----------o----------o----------o----------o----------o----------o", "output": "YES" }, { "input": "o---------o---------o---------o---------o---------o---------o---------o---------o", "output": "YES" }, { "input": "--------o--------o--------o--------o--------o--------o--------o--------o--------", "output": "YES" }, { "input": "o---o----", "output": "NO" }, { "input": "---o----o", "output": "NO" }, { "input": "-o-", "output": "YES" }, { "input": "------oooo", "output": "NO" }, { "input": "oo--", "output": "YES" }, { "input": "---o", "output": "YES" }, { "input": "ooo-", "output": "NO" }, { "input": "oooooooo----------", "output": "NO" }, { "input": "oooo--", "output": "NO" }, { "input": "o-ooooo", "output": "NO" }, { "input": "-oo", "output": "NO" }, { "input": "ooooo-", "output": "NO" }, { "input": "ooo---------", "output": "YES" }, { "input": "oo-", "output": "NO" }, { "input": "---ooo", "output": "YES" } ]
1,526,353,272
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
4
155
22,425,600
s = input() a = s.count('o') b = s.count('-') x = b / a if x - int(x) > 0: print("NO") else: print("YES")
Title: Links and Pearls Time Limit: None seconds Memory Limit: None megabytes Problem Description: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. Input Specification: The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. Output Specification: Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). Demo Input: ['-o-o--', '-o---\n', '-o---o-\n', 'ooo\n'] Demo Output: ['YES', 'YES', 'NO', 'YES\n'] Note: none
```python s = input() a = s.count('o') b = s.count('-') x = b / a if x - int(x) > 0: print("NO") else: print("YES") ```
-1
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1.
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..." }, { "input": "20 401", "output": "-1" }, { "input": "100 3574", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "1 1000000", "output": "-1" }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "1 2", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "1 2", "output": "-1" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "-1" }, { "input": "1 5", "output": "-1" }, { "input": "1 6", "output": "-1" }, { "input": "1 7", "output": "-1" }, { "input": "1 8", "output": "-1" }, { "input": "1 9", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 11", "output": "-1" }, { "input": "1 12", "output": "-1" }, { "input": "1 13", "output": "-1" }, { "input": "1 14", "output": "-1" }, { "input": "1 15", "output": "-1" }, { "input": "1 16", "output": "-1" }, { "input": "1 17", "output": "-1" }, { "input": "1 18", "output": "-1" }, { "input": "1 19", "output": "-1" }, { "input": "1 20", "output": "-1" }, { "input": "1 21", "output": "-1" }, { "input": "1 22", "output": "-1" }, { "input": "1 23", "output": "-1" }, { "input": "1 24", "output": "-1" }, { "input": "1 25", "output": "-1" }, { "input": "1 26", "output": "-1" }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "2 2", "output": "1 0 \n0 1 " }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "2 4", "output": "1 1 \n1 1 " }, { "input": "2 5", "output": "-1" }, { "input": "2 6", "output": "-1" }, { "input": "2 7", "output": "-1" }, { "input": "2 8", "output": "-1" }, { "input": "2 9", "output": "-1" }, { "input": "2 10", "output": "-1" }, { "input": "2 11", "output": "-1" }, { "input": "2 12", "output": "-1" }, { "input": "2 13", "output": "-1" }, { "input": "2 14", "output": "-1" }, { "input": "2 15", "output": "-1" }, { "input": "2 16", "output": "-1" }, { "input": "2 17", "output": "-1" }, { "input": "2 18", "output": "-1" }, { "input": "2 19", "output": "-1" }, { "input": "2 20", "output": "-1" }, { "input": "2 21", "output": "-1" }, { "input": "2 22", "output": "-1" }, { "input": "2 23", "output": "-1" }, { "input": "2 24", "output": "-1" }, { "input": "2 25", "output": "-1" }, { "input": "2 26", "output": "-1" }, { "input": "3 0", "output": "0 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 1", "output": "1 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "3 7", "output": "1 1 1 \n1 1 0 \n1 0 1 " }, { "input": "3 8", "output": "1 1 1 \n1 1 1 \n1 1 0 " }, { "input": "3 9", "output": "1 1 1 \n1 1 1 \n1 1 1 " }, { "input": "3 10", "output": "-1" }, { "input": "3 11", "output": "-1" }, { "input": "3 12", "output": "-1" }, { "input": "3 13", "output": "-1" }, { "input": "3 14", "output": "-1" }, { "input": "3 15", "output": "-1" }, { "input": "3 16", "output": "-1" }, { "input": "3 17", "output": "-1" }, { "input": "3 18", "output": "-1" }, { "input": "3 19", "output": "-1" }, { "input": "3 20", "output": "-1" }, { "input": "3 21", "output": "-1" }, { "input": "3 22", "output": "-1" }, { "input": "3 23", "output": "-1" }, { "input": "3 24", "output": "-1" }, { "input": "3 25", "output": "-1" }, { "input": "3 26", "output": "-1" }, { "input": "4 0", "output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 1", "output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 2", "output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 4", "output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 6", "output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 7", "output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 8", "output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 9", "output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 " }, { "input": "4 10", "output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 " }, { "input": "4 11", "output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 " }, { "input": "4 12", "output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 " }, { "input": "4 13", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 " }, { "input": "4 14", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 " }, { "input": "4 15", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 " }, { "input": "4 16", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 " }, { "input": "4 17", "output": "-1" }, { "input": "4 18", "output": "-1" }, { "input": "4 19", "output": "-1" }, { "input": "4 20", "output": "-1" }, { "input": "4 21", "output": "-1" }, { "input": "4 22", "output": "-1" }, { "input": "4 23", "output": "-1" }, { "input": "4 24", "output": "-1" }, { "input": "4 25", "output": "-1" }, { "input": "4 26", "output": "-1" }, { "input": "5 0", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 1", "output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 2", "output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 3", "output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 4", "output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 5", "output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 7", "output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 8", "output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 9", "output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 11", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 12", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 13", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 14", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 15", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 16", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 17", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 18", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 " }, { "input": "5 19", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 " }, { "input": "5 20", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 " }, { "input": "5 21", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 " }, { "input": "5 22", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 " }, { "input": "5 23", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "5 25", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 " }, { "input": "5 26", "output": "-1" }, { "input": "100 0", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 2", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 3", "output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 99", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 100", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 101", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 9999", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" } ]
1,698,130,485
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n, k = map(int, input().split()) matrix = [[0]*n for _ in range(n)] if k > n*n : print(-1) else: for i in range(n): for j in range(i,n): if k <= 0: break elif k == 1: matrix[max(i,j-1)][max(i,j-1)] =1 k -= 1 else: if i == j: matrix[i][j] = 1 k -= 1 else: matrix[i][j] = 1 matrix[j][i] = 1 k -= 2 for i in range(n): print(' '.join(map(str,matrix[i])))
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1. Input Specification: The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). Output Specification: If the answer exists then output resulting matrix. Otherwise output -1. Demo Input: ['2 1\n', '3 2\n', '2 5\n'] Demo Output: ['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n'] Note: none
```python n, k = map(int, input().split()) matrix = [[0]*n for _ in range(n)] if k > n*n : print(-1) else: for i in range(n): for j in range(i,n): if k <= 0: break elif k == 1: matrix[max(i,j-1)][max(i,j-1)] =1 k -= 1 else: if i == j: matrix[i][j] = 1 k -= 1 else: matrix[i][j] = 1 matrix[j][i] = 1 k -= 2 for i in range(n): print(' '.join(map(str,matrix[i]))) ```
0
285
A
Slightly Decreasing Permutations
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=&lt;<=*n*), that *p**i*<=&gt;<=*p**i*<=+<=1. You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*.
The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=&lt;<=*n*) — the permutation length and the decreasing coefficient.
In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.
[ "5 2\n", "3 0\n", "3 2\n" ]
[ "1 5 2 4 3\n", "1 2 3\n", "3 2 1\n" ]
none
500
[ { "input": "5 2", "output": "1 5 2 4 3" }, { "input": "3 0", "output": "1 2 3" }, { "input": "3 2", "output": "3 2 1" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "1 2" }, { "input": "2 1", "output": "2 1" }, { "input": "10 4", "output": "10 9 8 7 1 2 3 4 5 6" }, { "input": "56893 5084", "output": "56893 56892 56891 56890 56889 56888 56887 56886 56885 56884 56883 56882 56881 56880 56879 56878 56877 56876 56875 56874 56873 56872 56871 56870 56869 56868 56867 56866 56865 56864 56863 56862 56861 56860 56859 56858 56857 56856 56855 56854 56853 56852 56851 56850 56849 56848 56847 56846 56845 56844 56843 56842 56841 56840 56839 56838 56837 56836 56835 56834 56833 56832 56831 56830 56829 56828 56827 56826 56825 56824 56823 56822 56821 56820 56819 56818 56817 56816 56815 56814 56813 56812 56811 56810 56809 5..." }, { "input": "6 3", "output": "6 5 4 1 2 3" }, { "input": "1 0", "output": "1" }, { "input": "310 186", "output": "310 309 308 307 306 305 304 303 302 301 300 299 298 297 296 295 294 293 292 291 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183..." }, { "input": "726 450", "output": "726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599..." }, { "input": "438 418", "output": "438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311..." }, { "input": "854 829", "output": "854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727..." }, { "input": "214 167", "output": "214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 ..." }, { "input": "85705 56268", "output": "85705 85704 85703 85702 85701 85700 85699 85698 85697 85696 85695 85694 85693 85692 85691 85690 85689 85688 85687 85686 85685 85684 85683 85682 85681 85680 85679 85678 85677 85676 85675 85674 85673 85672 85671 85670 85669 85668 85667 85666 85665 85664 85663 85662 85661 85660 85659 85658 85657 85656 85655 85654 85653 85652 85651 85650 85649 85648 85647 85646 85645 85644 85643 85642 85641 85640 85639 85638 85637 85636 85635 85634 85633 85632 85631 85630 85629 85628 85627 85626 85625 85624 85623 85622 85621 8..." }, { "input": "11417 4583", "output": "11417 11416 11415 11414 11413 11412 11411 11410 11409 11408 11407 11406 11405 11404 11403 11402 11401 11400 11399 11398 11397 11396 11395 11394 11393 11392 11391 11390 11389 11388 11387 11386 11385 11384 11383 11382 11381 11380 11379 11378 11377 11376 11375 11374 11373 11372 11371 11370 11369 11368 11367 11366 11365 11364 11363 11362 11361 11360 11359 11358 11357 11356 11355 11354 11353 11352 11351 11350 11349 11348 11347 11346 11345 11344 11343 11342 11341 11340 11339 11338 11337 11336 11335 11334 11333 1..." }, { "input": "53481 20593", "output": "53481 53480 53479 53478 53477 53476 53475 53474 53473 53472 53471 53470 53469 53468 53467 53466 53465 53464 53463 53462 53461 53460 53459 53458 53457 53456 53455 53454 53453 53452 53451 53450 53449 53448 53447 53446 53445 53444 53443 53442 53441 53440 53439 53438 53437 53436 53435 53434 53433 53432 53431 53430 53429 53428 53427 53426 53425 53424 53423 53422 53421 53420 53419 53418 53417 53416 53415 53414 53413 53412 53411 53410 53409 53408 53407 53406 53405 53404 53403 53402 53401 53400 53399 53398 53397 5..." }, { "input": "79193 77281", "output": "79193 79192 79191 79190 79189 79188 79187 79186 79185 79184 79183 79182 79181 79180 79179 79178 79177 79176 79175 79174 79173 79172 79171 79170 79169 79168 79167 79166 79165 79164 79163 79162 79161 79160 79159 79158 79157 79156 79155 79154 79153 79152 79151 79150 79149 79148 79147 79146 79145 79144 79143 79142 79141 79140 79139 79138 79137 79136 79135 79134 79133 79132 79131 79130 79129 79128 79127 79126 79125 79124 79123 79122 79121 79120 79119 79118 79117 79116 79115 79114 79113 79112 79111 79110 79109 7..." }, { "input": "42607 42144", "output": "42607 42606 42605 42604 42603 42602 42601 42600 42599 42598 42597 42596 42595 42594 42593 42592 42591 42590 42589 42588 42587 42586 42585 42584 42583 42582 42581 42580 42579 42578 42577 42576 42575 42574 42573 42572 42571 42570 42569 42568 42567 42566 42565 42564 42563 42562 42561 42560 42559 42558 42557 42556 42555 42554 42553 42552 42551 42550 42549 42548 42547 42546 42545 42544 42543 42542 42541 42540 42539 42538 42537 42536 42535 42534 42533 42532 42531 42530 42529 42528 42527 42526 42525 42524 42523 4..." }, { "input": "100000 0", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..." }, { "input": "100000 99999", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "100000 53860", "output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..." }, { "input": "4 0", "output": "1 2 3 4" }, { "input": "4 1", "output": "4 1 2 3" }, { "input": "4 2", "output": "4 3 1 2" }, { "input": "4 3", "output": "4 3 2 1" }, { "input": "3 1", "output": "3 1 2" } ]
1,696,322,227
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, k = map(int, input().split()) perm = list(range(1, n + 1)) # Reverse the first k elements for i in range(k): perm[i] = n - i print(" ".join(map(str, perm)))
Title: Slightly Decreasing Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=&lt;<=*n*), that *p**i*<=&gt;<=*p**i*<=+<=1. You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. Input Specification: The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=&lt;<=*n*) — the permutation length and the decreasing coefficient. Output Specification: In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Demo Input: ['5 2\n', '3 0\n', '3 2\n'] Demo Output: ['1 5 2 4 3\n', '1 2 3\n', '3 2 1\n'] Note: none
```python n, k = map(int, input().split()) perm = list(range(1, n + 1)) # Reverse the first k elements for i in range(k): perm[i] = n - i print(" ".join(map(str, perm))) ```
0
177
E1
Space Voyage
PROGRAMMING
1,700
[ "binary search" ]
null
null
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit *n* planets. For planet *i* *a**i* is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and *b**i* is the number of citizens on the planet. The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, *x* presents in each. The Beaver will take to the ship exactly *a*1<=+<=...<=+<=*a**n* suitcases. As the Beaver lands on the *i*-th planet, he takes *a**i* suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens — each of the *b**i* citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel. The Beaver is going to spend exactly *c* days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer *x* so that the planned voyage will take exactly *c* days?
The first input line contains space-separated integers *n* and *c* — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next *n* lines contain pairs of space-separated integers *a**i*,<=*b**i* (1<=≤<=*i*<=≤<=*n*) — the number of suitcases he can bring to the *i*-th planet and the number of citizens of the *i*-th planet, correspondingly. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=100 - 1<=≤<=*a**i*<=≤<=100 - 1<=≤<=*b**i*<=≤<=100 - 1<=≤<=*c*<=≤<=100 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=104 - 0<=≤<=*a**i*<=≤<=109 - 1<=≤<=*b**i*<=≤<=109 - 1<=≤<=*c*<=≤<=109 Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Print a single number *k* — the number of ways to choose *x* so as to travel for exactly *c* days. If there are infinitely many possible values of *x*, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2 5\n1 5\n2 4\n" ]
[ "1\n" ]
In the first example there is only one suitable value *x* = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days — he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling. For *x* = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For *x* = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
30
[ { "input": "2 5\n1 5\n2 4", "output": "1" }, { "input": "1 97\n1 91", "output": "91" }, { "input": "2 79\n1 91\n1 77", "output": "42" }, { "input": "3 100\n8 46\n8 56\n77 98", "output": "1" }, { "input": "71 100\n1 92\n1 94\n1 97\n1 95\n1 100\n1 100\n1 98\n1 99\n1 98\n1 96\n1 97\n1 93\n1 97\n1 92\n1 91\n1 96\n1 97\n1 96\n1 92\n1 99\n1 92\n1 95\n1 93\n1 99\n1 99\n1 99\n1 97\n1 99\n1 95\n1 95\n1 95\n1 96\n1 95\n1 97\n1 93\n1 93\n1 93\n1 92\n1 94\n1 96\n1 100\n1 98\n1 96\n1 97\n1 96\n1 93\n1 94\n1 95\n1 100\n1 93\n1 93\n1 99\n1 100\n1 97\n1 95\n1 98\n1 91\n1 100\n1 98\n1 99\n1 100\n1 100\n1 94\n1 97\n1 99\n1 98\n1 95\n1 92\n1 98\n1 99\n1 98", "output": "1" }, { "input": "7 77\n2 95\n2 91\n3 95\n2 94\n3 96\n2 97\n2 91", "output": "9" }, { "input": "7 45\n1 1\n1 2\n1 4\n1 8\n1 16\n1 32\n1 64", "output": "1" }, { "input": "7 77\n2 95\n1 97\n1 100\n1 99\n1 99\n1 100\n4 100", "output": "10" }, { "input": "1 1\n3 89", "output": "29" }, { "input": "1 100\n1 100", "output": "100" }, { "input": "5 100\n1 95\n2 96\n3 97\n4 98\n5 99", "output": "3" }, { "input": "8 97\n23 45\n91 20\n100 18\n11 82\n33 58\n11 99\n3 9\n75 55", "output": "0" }, { "input": "23 100\n1 51\n3 35\n2 92\n1 8\n1 2\n1 50\n1 94\n1 64\n3 82\n3 91\n2 68\n1 100\n3 69\n2 83\n3 6\n1 38\n1 6\n1 35\n2 87\n2 29\n3 32\n3 54\n2 62", "output": "2" }, { "input": "55 100\n1 87\n2 84\n1 83\n3 88\n3 94\n1 82\n4 86\n4 96\n2 93\n1 98\n2 98\n4 93\n1 87\n1 81\n4 85\n4 85\n3 85\n4 88\n1 87\n4 96\n4 89\n2 86\n2 95\n2 99\n1 99\n2 84\n1 96\n1 99\n3 82\n4 89\n3 94\n3 98\n1 81\n3 90\n1 80\n1 92\n4 85\n4 90\n1 91\n2 92\n3 84\n4 94\n1 85\n2 85\n1 97\n2 87\n3 84\n2 98\n1 90\n1 97\n3 88\n1 97\n1 91\n1 85\n2 82", "output": "1" }, { "input": "15 100\n3 76\n2 98\n3 80\n2 97\n4 99\n2 81\n2 100\n4 77\n2 96\n2 78\n2 87\n2 80\n2 100\n3 95\n3 84", "output": "9" }, { "input": "2 2\n1 2\n1 3", "output": "1" } ]
1,599,069,571
2,147,483,647
Python 3
WRONG_ANSWER
TESTS1
4
186
307,200
def binary_search(arr, x): arr.sort() low = 0 high = len(arr) - 1 mid = 0 while low <= high: mid = low + (high-low)//2 if arr[mid] < x: low = mid + 1 elif arr[mid] > x: high = mid - 1 else: return mid return -1 def ternary_search(l, r, key, ar): if (r >= l): mid1 = l + (r - l) // 3 mid2 = r - (r - l) // 3 if (ar[mid1] == key): return mid1 if (ar[mid2] == key): return mid2 if (key < ar[mid1]): return ternary_search(l, mid1 - 1, key, ar) elif (key > ar[mid2]): return ternary_search(mid2 + 1, r, key, ar) else: return ternary_search(mid1 + 1, mid2 - 1, key, ar) return -1 def cheaker(x): cnt= 0 for i in range(n): cnt+= ((a[i]*x)//b[i] +1) return cnt def binary_search_answer(low,high): while((high - low )> 0): mid = (high+low)//2 if cheaker(mid)<c: low= mid+1 else: high = mid if cheaker(low)==c : return low else: return -1 def binary_search_answer2(low,high): while((high - low )> 0): mid = (high+low+1)//2 if cheaker(mid)<=c: low= mid else: high = mid-1 if cheaker(low )==c: return low else: return -1 if __name__ == "__main__": n,c= map(int,input().split()) a=[0 for i in range(n)] b= [0 for i in range(n)] flag=True for j in range(n): a[j],b[j]= map(int,input().split()) if a[j]!=0: flag=False z = 10**9 if flag and n==c : print(0) elif n== c: print(min(b)-1) elif flag : print(-1) elif n<c: an1=binary_search_answer(1,10**18) an2= binary_search_answer2(1,10**18) if an1 ==-1 or an2 == -1: print(0) else: print(an2-an1 +1) else: print(0)
Title: Space Voyage Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit *n* planets. For planet *i* *a**i* is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and *b**i* is the number of citizens on the planet. The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, *x* presents in each. The Beaver will take to the ship exactly *a*1<=+<=...<=+<=*a**n* suitcases. As the Beaver lands on the *i*-th planet, he takes *a**i* suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens — each of the *b**i* citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel. The Beaver is going to spend exactly *c* days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer *x* so that the planned voyage will take exactly *c* days? Input Specification: The first input line contains space-separated integers *n* and *c* — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next *n* lines contain pairs of space-separated integers *a**i*,<=*b**i* (1<=≤<=*i*<=≤<=*n*) — the number of suitcases he can bring to the *i*-th planet and the number of citizens of the *i*-th planet, correspondingly. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=100 - 1<=≤<=*a**i*<=≤<=100 - 1<=≤<=*b**i*<=≤<=100 - 1<=≤<=*c*<=≤<=100 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=104 - 0<=≤<=*a**i*<=≤<=109 - 1<=≤<=*b**i*<=≤<=109 - 1<=≤<=*c*<=≤<=109 Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations! Output Specification: Print a single number *k* — the number of ways to choose *x* so as to travel for exactly *c* days. If there are infinitely many possible values of *x*, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2 5\n1 5\n2 4\n'] Demo Output: ['1\n'] Note: In the first example there is only one suitable value *x* = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days — he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling. For *x* = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For *x* = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
```python def binary_search(arr, x): arr.sort() low = 0 high = len(arr) - 1 mid = 0 while low <= high: mid = low + (high-low)//2 if arr[mid] < x: low = mid + 1 elif arr[mid] > x: high = mid - 1 else: return mid return -1 def ternary_search(l, r, key, ar): if (r >= l): mid1 = l + (r - l) // 3 mid2 = r - (r - l) // 3 if (ar[mid1] == key): return mid1 if (ar[mid2] == key): return mid2 if (key < ar[mid1]): return ternary_search(l, mid1 - 1, key, ar) elif (key > ar[mid2]): return ternary_search(mid2 + 1, r, key, ar) else: return ternary_search(mid1 + 1, mid2 - 1, key, ar) return -1 def cheaker(x): cnt= 0 for i in range(n): cnt+= ((a[i]*x)//b[i] +1) return cnt def binary_search_answer(low,high): while((high - low )> 0): mid = (high+low)//2 if cheaker(mid)<c: low= mid+1 else: high = mid if cheaker(low)==c : return low else: return -1 def binary_search_answer2(low,high): while((high - low )> 0): mid = (high+low+1)//2 if cheaker(mid)<=c: low= mid else: high = mid-1 if cheaker(low )==c: return low else: return -1 if __name__ == "__main__": n,c= map(int,input().split()) a=[0 for i in range(n)] b= [0 for i in range(n)] flag=True for j in range(n): a[j],b[j]= map(int,input().split()) if a[j]!=0: flag=False z = 10**9 if flag and n==c : print(0) elif n== c: print(min(b)-1) elif flag : print(-1) elif n<c: an1=binary_search_answer(1,10**18) an2= binary_search_answer2(1,10**18) if an1 ==-1 or an2 == -1: print(0) else: print(an2-an1 +1) else: print(0) ```
0
293
A
Weird Game
PROGRAMMING
1,500
[ "games", "greedy" ]
null
null
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·*n*, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as *s*<==<=*s*1*s*2... *s*2*n*. Similarly, let's represent Andrey's word as *t*<==<=*t*1*t*2... *t*2*n*. Then, if Yaroslav choose number *k* during his move, then he is going to write out character *s**k* on the piece of paper. Similarly, if Andrey choose number *r* during his move, then he is going to write out character *t**r* on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings *s* and *t*. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well.
The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains string *s* — Yaroslav's word. The third line contains string *t* — Andrey's word. It is guaranteed that both words consist of 2·*n* characters "0" and "1".
Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes.
[ "2\n0111\n0001\n", "3\n110110\n001001\n", "3\n111000\n000111\n", "4\n01010110\n00101101\n", "4\n01100000\n10010011\n" ]
[ "First\n", "First\n", "Draw\n", "First\n", "Second\n" ]
none
500
[ { "input": "2\n0111\n0001", "output": "First" }, { "input": "3\n110110\n001001", "output": "First" }, { "input": "3\n111000\n000111", "output": "Draw" }, { "input": "4\n01010110\n00101101", "output": "First" }, { "input": "4\n01100000\n10010011", "output": "Second" }, { "input": "4\n10001001\n10101101", "output": "Draw" }, { "input": "3\n000000\n000100", "output": "Draw" }, { "input": "2\n0000\n1110", "output": "Second" }, { "input": "4\n11111111\n10100110", "output": "First" }, { "input": "4\n10100111\n11011000", "output": "First" }, { "input": "4\n00101011\n11110100", "output": "Draw" }, { "input": "4\n11000011\n00111100", "output": "Draw" }, { "input": "4\n11101111\n01000110", "output": "First" }, { "input": "4\n01110111\n00101110", "output": "First" }, { "input": "4\n11011111\n10110110", "output": "First" }, { "input": "4\n01101010\n11111110", "output": "Second" }, { "input": "4\n01111111\n10011001", "output": "First" }, { "input": "4\n01010100\n10011111", "output": "Second" }, { "input": "4\n01111011\n01001011", "output": "First" }, { "input": "4\n11011010\n11011001", "output": "Draw" }, { "input": "4\n11001101\n10001010", "output": "First" }, { "input": "4\n01101111\n10111101", "output": "Draw" }, { "input": "4\n10111100\n00000101", "output": "First" }, { "input": "4\n01111000\n11111010", "output": "Second" }, { "input": "4\n11001100\n00000111", "output": "First" }, { "input": "4\n01110111\n10101101", "output": "First" }, { "input": "4\n01001000\n11111100", "output": "Second" }, { "input": "4\n01011011\n01010010", "output": "First" }, { "input": "4\n00101101\n01001001", "output": "First" }, { "input": "4\n00110110\n10000100", "output": "First" }, { "input": "4\n10010000\n01000110", "output": "Draw" }, { "input": "4\n00000100\n10001111", "output": "Second" }, { "input": "4\n01110100\n01110100", "output": "Draw" }, { "input": "4\n11000001\n11010001", "output": "Draw" }, { "input": "4\n11001000\n00011000", "output": "First" }, { "input": "4\n10110011\n01011111", "output": "Draw" }, { "input": "4\n10000100\n11010100", "output": "Second" }, { "input": "4\n01011011\n10101110", "output": "Draw" }, { "input": "10\n00000000000111111111\n00000000011111111111", "output": "Draw" }, { "input": "1\n11\n11", "output": "Draw" }, { "input": "1\n11\n00", "output": "First" }, { "input": "1\n00\n01", "output": "Draw" }, { "input": "2\n0111\n1001", "output": "First" }, { "input": "1\n01\n11", "output": "Draw" } ]
1,516,822,818
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
122
5,632,000
n = input() s = input() t = input() fir = 0 sec = 0 same = 0 for (l, r) in zip(s, t): if l == '1': fir += 1 if r == 1: same += 1 elif r == '1': sec += 1 if fir > sec or same % 2 != 0: print("First") elif sec > fir + 1: print("Second") else: print("Draw")
Title: Weird Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·*n*, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as *s*<==<=*s*1*s*2... *s*2*n*. Similarly, let's represent Andrey's word as *t*<==<=*t*1*t*2... *t*2*n*. Then, if Yaroslav choose number *k* during his move, then he is going to write out character *s**k* on the piece of paper. Similarly, if Andrey choose number *r* during his move, then he is going to write out character *t**r* on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings *s* and *t*. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains string *s* — Yaroslav's word. The third line contains string *t* — Andrey's word. It is guaranteed that both words consist of 2·*n* characters "0" and "1". Output Specification: Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Demo Input: ['2\n0111\n0001\n', '3\n110110\n001001\n', '3\n111000\n000111\n', '4\n01010110\n00101101\n', '4\n01100000\n10010011\n'] Demo Output: ['First\n', 'First\n', 'Draw\n', 'First\n', 'Second\n'] Note: none
```python n = input() s = input() t = input() fir = 0 sec = 0 same = 0 for (l, r) in zip(s, t): if l == '1': fir += 1 if r == 1: same += 1 elif r == '1': sec += 1 if fir > sec or same % 2 != 0: print("First") elif sec > fir + 1: print("Second") else: print("Draw") ```
0
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer — the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { "input": "2 6 4 5 6 5 1 3", "output": "0" }, { "input": "1 7 3 5 3 6 2 1", "output": "6" }, { "input": "2 4 5 4 5 7 3 2", "output": "1" }, { "input": "2 3 6 5 7 8 2 1", "output": "4" }, { "input": "1 4 5 5 3 10 3 1", "output": "6" }, { "input": "1 4 6 7 3 5 1 3", "output": "1" }, { "input": "1 6 5 5 5 8 3 1", "output": "8" }, { "input": "1 7 5 3 3 9 2 1", "output": "9" }, { "input": "3 5 3 7 6 10 3 1", "output": "1" }, { "input": "3 6 3 5 3 6 3 1", "output": "2" }, { "input": "1 7 5 5 5 5 2 2", "output": "2" }, { "input": "2 5 3 5 6 9 2 1", "output": "3" }, { "input": "3 4 3 5 3 6 2 1", "output": "2" }, { "input": "1 5 5 4 7 6 3 1", "output": "6" }, { "input": "2 3 7 6 5 9 3 1", "output": "3" }, { "input": "2 6 5 3 3 8 1 1", "output": "4" }, { "input": "2 4 7 3 4 10 2 1", "output": "5" }, { "input": "1 1000 1000 1000 1000 1000 1 1", "output": "1000" }, { "input": "17 1000 1000 1000 1000 1000 3 7", "output": "8" }, { "input": "115 1000 1000 1000 1000 1000 17 15", "output": "0" }, { "input": "1 587 981 1 2 1 1 1", "output": "1" }, { "input": "1 1 2 1 2 2 1 1", "output": "2" } ]
1,670,478,528
2,147,483,647
Python 3
OK
TESTS
27
92
0
n,k,l,c,d,p,nl,dp = map(int,input().strip().split()) toasts = (k*l) // nl limes = c * d salt = p // dp print(min(toasts,min(limes,salt)) // n)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? Input Specification: The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. Output Specification: Print a single integer — the number of toasts each friend can make. Demo Input: ['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n'] Demo Output: ['2\n', '3\n', '0\n'] Note: A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
```python n,k,l,c,d,p,nl,dp = map(int,input().strip().split()) toasts = (k*l) // nl limes = c * d salt = p // dp print(min(toasts,min(limes,salt)) // n) ```
3
462
B
Appleman and Card Game
PROGRAMMING
1,300
[ "greedy" ]
null
null
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman. Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Print a single integer – the answer to the problem.
[ "15 10\nDZFDFZDFDDDDDDF\n", "6 4\nYJSNPI\n" ]
[ "82\n", "4\n" ]
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
1,000
[ { "input": "15 10\nDZFDFZDFDDDDDDF", "output": "82" }, { "input": "6 4\nYJSNPI", "output": "4" }, { "input": "5 3\nAOWBY", "output": "3" }, { "input": "1 1\nV", "output": "1" }, { "input": "2 1\nWT", "output": "1" }, { "input": "2 2\nBL", "output": "2" }, { "input": "5 1\nFACJT", "output": "1" }, { "input": "5 5\nMJDIJ", "output": "7" }, { "input": "15 5\nAZBIPTOFTJCJJIK", "output": "13" }, { "input": "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH", "output": "1" }, { "input": "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKIIKKKKKKTFKFKKIRKKKFKUUKIKUUUFFKKKKTUZKITUIKKIKUKKTIK", "output": "225" }, { "input": "100 50\nYYIYYAAAIEAAYAYAEAIIIAAEAAYEAEYYYIAEYAYAYYAAAIAYAEAAYAYYIYAAYYAAAAAAIYYYAAYAAEAAYAIEIYIYAYAYAYIIAAEY", "output": "1972" }, { "input": "100 90\nFAFAOOAOOAFAOTFAFAFFATAAAOFAAOAFBAAAFBOAOFFFOAOAFAPFOFAOFAAFOAAAAFAAFOFAAOFPPAAOOAAOOFFOFFFOFAOTOFAF", "output": "2828" }, { "input": "100 99\nBFFBBFBFBQFFFFFQBFFBFFBQFBFQFBBFQFFFBFFFBFQFQFBFFBBFYQFBFFFFFFFBQQFQBFBQBQFFFBQQFFFBQFYFBFBFFFBBBQQY", "output": "3713" }, { "input": "100 100\nMQSBDAJABILIBCUEOWGWCEXMUTEYQKAIWGINXVQEOFDUBSVULROQHQRZZAALVQFEFRAAAYUIMGCAFQGIAEFBETRECGSFQJNXHHDN", "output": "514" }, { "input": "100 50\nBMYIXQSJNHGFVFPJBIOBXIKSFNUFPVODCUBQYSIIQNVNXXCWXWRHKFEUPPIIDDGRDBJLZDCBMNJMYRMWFIHOSTDJJHXHPNRKWNFD", "output": "328" }, { "input": "100 50\nENFNEMLJEMDMFMNNGNIMNINALGLLLAEMENEMNLMMIEIJNAINBJEJMFJLLIMINELGFLAIAMJMHMGNLIEFJIEEFEFGLLLDLMEAEIMM", "output": "748" } ]
1,587,234,750
2,147,483,647
Python 3
OK
TESTS
41
155
614,400
firstLine = input(); n, k = firstLine.split(); n = int(n); k = int(k); s = input(); result = 0; count = [0] * 26 for i in range(0, len(s)): index = ord(s[i]) - 65; count[index] = count[index] + 1; count.sort(reverse=True) for j in range(0, len(count)): if(count[j] <= k): result = result + (count[j]*count[j]); k = k - count[j]; if(k==0): break else: result = result + (k*k); break print(result)
Title: Appleman and Card Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman. Given the description of Appleman's cards. What is the maximum number of coins Toastman can get? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. Output Specification: Print a single integer – the answer to the problem. Demo Input: ['15 10\nDZFDFZDFDDDDDDF\n', '6 4\nYJSNPI\n'] Demo Output: ['82\n', '4\n'] Note: In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
```python firstLine = input(); n, k = firstLine.split(); n = int(n); k = int(k); s = input(); result = 0; count = [0] * 26 for i in range(0, len(s)): index = ord(s[i]) - 65; count[index] = count[index] + 1; count.sort(reverse=True) for j in range(0, len(count)): if(count[j] <= k): result = result + (count[j]*count[j]); k = k - count[j]; if(k==0): break else: result = result + (k*k); break print(result) ```
3
616
D
Longest k-Good Segment
PROGRAMMING
1,600
[ "binary search", "data structures", "two pointers" ]
null
null
The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.
Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right.
[ "5 5\n1 2 3 4 5\n", "9 3\n6 5 1 2 3 2 1 4 5\n", "3 1\n1 2 3\n" ]
[ "1 5\n", "3 7\n", "1 1\n" ]
none
0
[ { "input": "5 5\n1 2 3 4 5", "output": "1 5" }, { "input": "9 3\n6 5 1 2 3 2 1 4 5", "output": "3 7" }, { "input": "3 1\n1 2 3", "output": "1 1" }, { "input": "1 1\n747391", "output": "1 1" }, { "input": "5 2\n171230 171230 171230 171230 171230", "output": "1 5" }, { "input": "10 3\n512008 512008 452221 512008 314256 123232 314256 512008 314256 123232", "output": "4 10" }, { "input": "6 1\n1 1 2 1 1 1", "output": "4 6" }, { "input": "5 4\n1 2 3 4 0", "output": "1 4" }, { "input": "5 4\n2 3 4 5 0", "output": "1 4" }, { "input": "2 2\n0 1", "output": "1 2" }, { "input": "2 2\n0 0", "output": "1 2" }, { "input": "5 4\n1 2 3 45 0", "output": "1 4" } ]
1,693,851,971
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
61,440,000
n, k = map(int, input().split()) a = list(map(int, input().split())) l, r = 0, k ll, rr = 0, 0 ans = a[l:r] while r < n: if a[r] in ans or len(set(ans)) < k : r += 1 else: if (rr - ll) < ((r - l)): ll, rr = l, r l += 1 ans = a[l:r] if (rr - ll) < ((r - l)): ll, rr = l, r print(ll + 1, rr)
Title: Longest k-Good Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: The array *a* with *n* integers is given. Let's call the sequence of one or more consecutive elements in *a* segment. Also let's call the segment k-good if it contains no more than *k* different values. Find any longest k-good segment. As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The first line contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·105) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=106) — the elements of the array *a*. Output Specification: Print two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in *a* are numbered from 1 to *n* from left to right. Demo Input: ['5 5\n1 2 3 4 5\n', '9 3\n6 5 1 2 3 2 1 4 5\n', '3 1\n1 2 3\n'] Demo Output: ['1 5\n', '3 7\n', '1 1\n'] Note: none
```python n, k = map(int, input().split()) a = list(map(int, input().split())) l, r = 0, k ll, rr = 0, 0 ans = a[l:r] while r < n: if a[r] in ans or len(set(ans)) < k : r += 1 else: if (rr - ll) < ((r - l)): ll, rr = l, r l += 1 ans = a[l:r] if (rr - ll) < ((r - l)): ll, rr = l, r print(ll + 1, rr) ```
0
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements.
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......*..", "output": "2 1" }, { "input": "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.", "output": "1 2" }, { "input": "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "2 100\n...................................................................................................*\n*..................................................................................................*", "output": "1 1" }, { "input": "2 2\n*.\n**", "output": "1 2" }, { "input": "2 2\n**\n.*", "output": "2 1" }, { "input": "2 3\n*.*\n..*", "output": "2 1" } ]
1,620,291,270
2,147,483,647
PyPy 3
OK
TESTS
36
218
21,811,200
N, M = [int(X) for X in input().split()] A = [] for i in range (N): B = input() A.append([i for i in B]) pts = [] for i in range (N): for j in range (M): if A[i][j] == '*': pts.append((i,j)) # print (pts) X = [] Y = [] for i in pts: X.append(i[0]) Y.append(i[1]) # print (X) # print (Y) x = None y = None for i in X: if X.count(i) == 1: x = i break for i in Y: if Y.count(i) == 1: y = i break print (x+1,y+1)
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Specification: Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Demo Input: ['3 2\n.*\n..\n**\n', '3 3\n*.*\n*..\n...\n'] Demo Output: ['1 1\n', '2 3\n'] Note: none
```python N, M = [int(X) for X in input().split()] A = [] for i in range (N): B = input() A.append([i for i in B]) pts = [] for i in range (N): for j in range (M): if A[i][j] == '*': pts.append((i,j)) # print (pts) X = [] Y = [] for i in pts: X.append(i[0]) Y.append(i[1]) # print (X) # print (Y) x = None y = None for i in X: if X.count(i) == 1: x = i break for i in Y: if Y.count(i) == 1: y = i break print (x+1,y+1) ```
3
291
A
Spyke Talks
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to *n* in some way.
Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
[ "6\n0 1 7 1 7 10\n", "3\n1 1 1\n", "1\n0\n" ]
[ "2\n", "-1\n", "0\n" ]
In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
500
[ { "input": "6\n0 1 7 1 7 10", "output": "2" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n2 2 1 1 3", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "10\n4 21 3 21 21 1 1 2 2 3", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "6\n6 6 0 8 0 0", "output": "1" }, { "input": "10\n0 0 0 0 0 1 0 1 0 1", "output": "-1" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 3 0 0 3 0 0 0 0 0 0 3 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0", "output": "-1" }, { "input": "1\n1000000000", "output": "0" }, { "input": "2\n1 0", "output": "0" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "5\n1 0 0 0 1", "output": "1" }, { "input": "15\n380515742 842209759 945171461 664384656 945171461 474872104 0 0 131648973 131648973 474872104 842209759 664384656 0 380515742", "output": "6" }, { "input": "123\n0 6361 8903 10428 0 258 0 10422 0 0 2642 1958 0 0 0 0 0 8249 1958 0 0 2642 0 0 0 11566 4709 1847 3998 0 1331 0 0 10289 2739 6135 3450 0 0 10994 6069 4337 5854 1331 5854 0 630 630 11244 5928 2706 0 683 214 0 9080 0 0 0 10422 683 11566 10994 0 0 3450 11244 11542 3998 1847 2708 9871 2739 2001 0 12216 6069 0 5928 0 10289 1307 0 1307 8903 0 6361 6135 6632 10428 0 0 632 258 9080 12216 4709 4967 2706 0 11542 2001 6632 0 8249 214 0 10301 4967 10301 7296 7296 10914 2708 4337 0 0 632 0 10914 0 9871 0", "output": "40" }, { "input": "10\n0 3 2 3 2 0 1 3 3 0", "output": "-1" }, { "input": "20\n0 1 2 0 0 0 0 5 3 4 0 0 1 1 3 0 4 0 1 0", "output": "-1" }, { "input": "47\n1 6 0 6 1 1 6 4 3 6 5 3 6 3 2 2 5 1 4 7 3 5 6 1 6 7 4 5 6 3 3 3 7 4 1 6 1 1 7 1 3 1 5 5 1 3 6", "output": "-1" }, { "input": "74\n0 0 0 0 0 37 0 0 0 0 0 0 0 8 0 0 9 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 9 0 7 0 0 0 0 0 0 19 19 0 0 0 0 0 0 0 0 0 0 0 0 17 0 30 0 0 0 0 0 0 30 0 0 0 0 0 0 0 37 0", "output": "5" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "2\n2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n10000 10000 1 1 10000", "output": "-1" } ]
1,536,576,661
2,147,483,647
Python 3
OK
TESTS
38
498
0
def cocktail_sort(a): n = len(a) swapped = True start = 0 end = n-1 while (swapped == True): # reset the swapped flag on entering the loop, # because it might be true from a previous # iteration. swapped = False # loop from left to right same as the bubble # sort for i in range (start, end): if (a[i] > a[i + 1]) : a[i], a[i + 1]= a[i + 1], a[i] swapped = True # if nothing moved, then array is sorted. if (swapped == False): break # otherwise, reset the swapped flag so that it # can be used in the next stage swapped = False # move the end point back by one, because # item at the end is in its rightful spot end = end-1 # from right to left, doing the same # comparison as in the previous stage for i in range(end-1, start-1, -1): if (a[i] > a[i + 1]): a[i], a[i + 1] = a[i + 1], a[i] swapped = True # increase the starting point, because # the last stage would have moved the next # smallest number to its rightful spot. start = start + 1 n = int(input()) x = list(map(int, input().split())) answer = 0 cocktail_sort(x) for i in range(len(x)-1): if (i+2)>= n: if (x[i] == x[i+1]) and (x[i] != 0): answer = answer + 1 i = i+1 else: if x[i] == x[i+1] and x[i] != 0 and x[i] !=x[i+2]: answer = answer + 1 i = i + 1 elif x[i] == x[i+1] and x[i] == x[i+2] and x[i]!= 0: answer = -1 break print(answer)
Title: Spyke Talks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≤<=*id**i*<=≤<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to *n* in some way. Output Specification: Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Demo Input: ['6\n0 1 7 1 7 10\n', '3\n1 1 1\n', '1\n0\n'] Demo Output: ['2\n', '-1\n', '0\n'] Note: In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
```python def cocktail_sort(a): n = len(a) swapped = True start = 0 end = n-1 while (swapped == True): # reset the swapped flag on entering the loop, # because it might be true from a previous # iteration. swapped = False # loop from left to right same as the bubble # sort for i in range (start, end): if (a[i] > a[i + 1]) : a[i], a[i + 1]= a[i + 1], a[i] swapped = True # if nothing moved, then array is sorted. if (swapped == False): break # otherwise, reset the swapped flag so that it # can be used in the next stage swapped = False # move the end point back by one, because # item at the end is in its rightful spot end = end-1 # from right to left, doing the same # comparison as in the previous stage for i in range(end-1, start-1, -1): if (a[i] > a[i + 1]): a[i], a[i + 1] = a[i + 1], a[i] swapped = True # increase the starting point, because # the last stage would have moved the next # smallest number to its rightful spot. start = start + 1 n = int(input()) x = list(map(int, input().split())) answer = 0 cocktail_sort(x) for i in range(len(x)-1): if (i+2)>= n: if (x[i] == x[i+1]) and (x[i] != 0): answer = answer + 1 i = i+1 else: if x[i] == x[i+1] and x[i] != 0 and x[i] !=x[i+2]: answer = answer + 1 i = i + 1 elif x[i] == x[i+1] and x[i] == x[i+2] and x[i]!= 0: answer = -1 break print(answer) ```
3
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
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. 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.
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.
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.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "1 0 7" }, { "input": "8 1 1 8", "output": "2 1 7" }, { "input": "7 7 6 6", "output": "2 1 1" }, { "input": "8 1 8 8", "output": "1 0 7" }, { "input": "1 8 1 1", "output": "1 0 7" }, { "input": "1 8 8 1", "output": "2 1 7" }, { "input": "1 8 8 8", "output": "1 0 7" }, { "input": "8 8 1 1", "output": "2 1 7" }, { "input": "8 8 1 8", "output": "1 0 7" }, { "input": "8 8 8 1", "output": "1 0 7" }, { "input": "1 3 1 6", "output": "1 0 3" }, { "input": "1 3 1 4", "output": "1 0 1" }, { "input": "1 3 1 5", "output": "1 2 2" }, { "input": "3 3 2 4", "output": "2 1 1" }, { "input": "3 3 1 5", "output": "2 1 2" }, { "input": "1 6 2 1", "output": "2 2 5" }, { "input": "1 5 6 4", "output": "2 2 5" }, { "input": "1 3 3 7", "output": "2 2 4" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 7 5 4", "output": "2 0 4" }, { "input": "1 5 2 7", "output": "2 0 2" }, { "input": "1 4 6 2", "output": "2 0 5" }, { "input": "1 2 3 5", "output": "2 0 3" }, { "input": "1 8 8 7", "output": "2 2 7" }, { "input": "6 5 6 2", "output": "1 0 3" }, { "input": "6 3 3 5", "output": "2 0 3" }, { "input": "6 1 7 8", "output": "2 2 7" }, { "input": "1 2 3 2", "output": "1 2 2" }, { "input": "3 8 7 2", "output": "2 2 6" }, { "input": "4 2 6 4", "output": "2 1 2" }, { "input": "1 1 1 3", "output": "1 2 2" }, { "input": "6 8 8 6", "output": "2 1 2" }, { "input": "6 7 4 1", "output": "2 2 6" }, { "input": "6 5 1 4", "output": "2 2 5" }, { "input": "3 2 7 6", "output": "2 1 4" }, { "input": "3 8 4 1", "output": "2 2 7" }, { "input": "3 6 1 4", "output": "2 1 2" } ]
1,389,971,516
2,147,483,647
Python 3
OK
TESTS
42
77
409,600
def stessocolore(x1,y1,x2,y2): if (x1+y1)%2 == (x2+y2)%2: return True else: return False x1, y1, x2, y2 = map(int, input().split()) if x1 == x2 or y1 == y2: rook = 1 else: rook = 2 king = max([abs(x1-x2),abs(y1-y2)]) if stessocolore(x1,y1,x2,y2): if (x1-y1) == (x2-y2) or x1+y1 == x2+y2: bish = 1 else: bish = 2 else: bish = 0 print(rook, bish, king)
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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. 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 Specification: 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 Specification: 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. Demo Input: ['4 3 1 6\n', '5 5 5 6\n'] Demo Output: ['2 1 3\n', '1 0 1\n'] Note: none
```python def stessocolore(x1,y1,x2,y2): if (x1+y1)%2 == (x2+y2)%2: return True else: return False x1, y1, x2, y2 = map(int, input().split()) if x1 == x2 or y1 == y2: rook = 1 else: rook = 2 king = max([abs(x1-x2),abs(y1-y2)]) if stessocolore(x1,y1,x2,y2): if (x1-y1) == (x2-y2) or x1+y1 == x2+y2: bish = 1 else: bish = 2 else: bish = 0 print(rook, bish, king) ```
3
767
C
Garland
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "greedy", "trees" ]
null
null
Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the number of lamps. There was something unusual about the garland. Each lamp had its own brightness which depended on the temperature of the lamp. Temperatures could be positive, negative or zero. Dima has two friends, so he decided to share the garland with them. He wants to cut two different wires so that the garland breaks up into three parts. Each part of the garland should shine equally, i. e. the sums of lamps' temperatures should be equal in each of the parts. Of course, each of the parts should be non-empty, i. e. each part should contain at least one lamp. Help Dima to find a suitable way to cut the garland, or determine that this is impossible. While examining the garland, Dima lifted it up holding by one of the lamps. Thus, each of the lamps, except the one he is holding by, is now hanging on some wire. So, you should print two lamp ids as the answer which denote that Dima should cut the wires these lamps are hanging on. Of course, the lamp Dima is holding the garland by can't be included in the answer.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=106) — the number of lamps in the garland. Then *n* lines follow. The *i*-th of them contain the information about the *i*-th lamp: the number lamp *a**i*, it is hanging on (and 0, if is there is no such lamp), and its temperature *t**i* (<=-<=100<=≤<=*t**i*<=≤<=100). The lamps are numbered from 1 to *n*.
If there is no solution, print -1. Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them.
[ "6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2\n", "6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2\n" ]
[ "1 4\n", "-1\n" ]
The garland and cuts scheme for the first example:
1,500
[ { "input": "6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2", "output": "1 4" }, { "input": "6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2", "output": "-1" }, { "input": "6\n2 4\n0 -1\n4 2\n2 3\n1 2\n4 5", "output": "6 4" }, { "input": "3\n2 1\n0 1\n2 1", "output": "1 3" }, { "input": "5\n0 5\n4 1\n2 1\n1 3\n1 5", "output": "4 5" }, { "input": "10\n5 8\n5 3\n8 7\n8 1\n0 4\n5 3\n1 1\n1 1\n3 1\n1 1", "output": "8 1" }, { "input": "49\n2 1\n43 1\n31 1\n0 34\n14 1\n29 1\n40 1\n40 1\n39 1\n1 1\n28 1\n43 1\n44 1\n44 1\n43 1\n12 5\n12 5\n28 1\n7 1\n15 1\n43 1\n4 49\n15 1\n8 1\n17 9\n5 1\n43 1\n43 1\n40 1\n2 1\n7 2\n24 1\n12 1\n27 1\n2 1\n43 1\n28 1\n5 1\n27 1\n28 1\n37 1\n27 1\n4 1\n28 1\n31 1\n40 1\n21 1\n38 1\n44 1", "output": "-1" }, { "input": "4\n0 1\n1 -1\n2 1\n3 -1", "output": "-1" }, { "input": "4\n0 0\n1 0\n1 1\n1 -1", "output": "-1" }, { "input": "4\n0 0\n1 1\n1 -1\n1 0", "output": "-1" }, { "input": "3\n0 -1\n1 1\n1 0", "output": "-1" }, { "input": "4\n0 0\n1 0\n2 1\n2 -1", "output": "-1" }, { "input": "5\n0 0\n1 -7\n1 7\n3 -7\n4 7", "output": "-1" }, { "input": "3\n0 0\n1 1\n2 -1", "output": "-1" }, { "input": "3\n0 2\n1 -1\n1 -1", "output": "-1" }, { "input": "3\n0 0\n1 1\n1 2", "output": "-1" }, { "input": "4\n0 -1\n1 -1\n1 -1\n1 -1", "output": "-1" }, { "input": "3\n0 -6\n1 6\n1 0", "output": "-1" } ]
1,625,117,065
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
93
0
import sys input = sys.stdin.readline n = int(input()) G = [[] for _ in range(n+1)] T = [-1]*n root = -1 for i in range(n): a,t = map(int,input().split()) if a != 0: G[a-1].append(i) else: root = i T[i] = t A = [0]*n stk = [root] vis = [False]*n while stk: x = stk[-1] if not vis[x]: vis[x] = True for y in G[x]: if not vis[y]: stk.append(y) else: stk.pop() for y in G[x]: A[x] += A[y] A[x] += T[x] s = A[root] if s%3: print(-1) exit() target = s//3 B = [False]*n stk = [root] while stk: x = stk[-1] if vis[x]: vis[x] = False for y in G[x]: if vis[y]: stk.append(y) else: stk.pop() tmp = [] for y in G[x]: if B[y]: tmp.append(y) if len(tmp) >= 2: print(tmp.pop()+1 ,tmp.pop()+1) exit() if tmp and A[x] == 2*target: print(x+1,tmp.pop()) exit() B[x] = (len(tmp) > 0) or A[x] == target print(-1) exit()
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the number of lamps. There was something unusual about the garland. Each lamp had its own brightness which depended on the temperature of the lamp. Temperatures could be positive, negative or zero. Dima has two friends, so he decided to share the garland with them. He wants to cut two different wires so that the garland breaks up into three parts. Each part of the garland should shine equally, i. e. the sums of lamps' temperatures should be equal in each of the parts. Of course, each of the parts should be non-empty, i. e. each part should contain at least one lamp. Help Dima to find a suitable way to cut the garland, or determine that this is impossible. While examining the garland, Dima lifted it up holding by one of the lamps. Thus, each of the lamps, except the one he is holding by, is now hanging on some wire. So, you should print two lamp ids as the answer which denote that Dima should cut the wires these lamps are hanging on. Of course, the lamp Dima is holding the garland by can't be included in the answer. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=106) — the number of lamps in the garland. Then *n* lines follow. The *i*-th of them contain the information about the *i*-th lamp: the number lamp *a**i*, it is hanging on (and 0, if is there is no such lamp), and its temperature *t**i* (<=-<=100<=≤<=*t**i*<=≤<=100). The lamps are numbered from 1 to *n*. Output Specification: If there is no solution, print -1. Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them. Demo Input: ['6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2\n', '6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2\n'] Demo Output: ['1 4\n', '-1\n'] Note: The garland and cuts scheme for the first example:
```python import sys input = sys.stdin.readline n = int(input()) G = [[] for _ in range(n+1)] T = [-1]*n root = -1 for i in range(n): a,t = map(int,input().split()) if a != 0: G[a-1].append(i) else: root = i T[i] = t A = [0]*n stk = [root] vis = [False]*n while stk: x = stk[-1] if not vis[x]: vis[x] = True for y in G[x]: if not vis[y]: stk.append(y) else: stk.pop() for y in G[x]: A[x] += A[y] A[x] += T[x] s = A[root] if s%3: print(-1) exit() target = s//3 B = [False]*n stk = [root] while stk: x = stk[-1] if vis[x]: vis[x] = False for y in G[x]: if vis[y]: stk.append(y) else: stk.pop() tmp = [] for y in G[x]: if B[y]: tmp.append(y) if len(tmp) >= 2: print(tmp.pop()+1 ,tmp.pop()+1) exit() if tmp and A[x] == 2*target: print(x+1,tmp.pop()) exit() B[x] = (len(tmp) > 0) or A[x] == target print(-1) exit() ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,683,437,425
2,147,483,647
Python 3
OK
TESTS
20
46
0
s = input().split() n = int(s[0]) m = int(s[1]) a = int(s[2]) vert = 0 hor = 0 if n % a == 0: vert = n // a else: vert = n // a + 1 if m % a == 0: hor = m // a else: hor = m // a + 1 print(vert*hor)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python s = input().split() n = int(s[0]) m = int(s[1]) a = int(s[2]) vert = 0 hor = 0 if n % a == 0: vert = n // a else: vert = n // a + 1 if m % a == 0: hor = m // a else: hor = m // a + 1 print(vert*hor) ```
3.977
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "1 1 1 1 1 1", "output": "Elephant" }, { "input": "9 9 9 9 9 9", "output": "Elephant" }, { "input": "1 8 9 1 1 1", "output": "Bear" }, { "input": "9 9 9 1 9 9", "output": "Bear" }, { "input": "1 2 3 8 9 7", "output": "Alien" }, { "input": "5 5 5 6 6 6", "output": "Alien" }, { "input": "1 1 2 2 3 4", "output": "Alien" }, { "input": "4 4 4 4 4 2", "output": "Bear" }, { "input": "2 2 3 3 4 4", "output": "Alien" }, { "input": "4 4 4 4 4 5", "output": "Bear" }, { "input": "1 1 2 2 2 2", "output": "Elephant" }, { "input": "1 2 5 5 5 5", "output": "Bear" }, { "input": "4 4 2 2 2 2", "output": "Elephant" }, { "input": "1 1 1 1 1 2", "output": "Bear" }, { "input": "2 2 4 4 4 4", "output": "Elephant" }, { "input": "4 4 4 4 4 3", "output": "Bear" }, { "input": "4 4 5 6 7 8", "output": "Alien" }, { "input": "4 4 4 4 2 2", "output": "Elephant" }, { "input": "1 1 1 1 2 2", "output": "Elephant" }, { "input": "1 1 3 3 3 5", "output": "Alien" }, { "input": "1 2 2 3 3 3", "output": "Alien" }, { "input": "1 2 2 2 2 2", "output": "Bear" }, { "input": "1 3 3 3 4 5", "output": "Alien" }, { "input": "5 1 1 1 1 1", "output": "Bear" } ]
1,571,184,339
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
size_sticks = input().replace(' ','') stick_rep = [size_sticks.count(i) > 3 for i in size_sticks] try: get_leg = stick_rep.index(True) stick_remain = size_sticks.replace(size_sticks[get_leg],'') print(['Elephant' if len(stick_remain) == 0 or (stick_remain[0] == stick_remain[1]) else 'Bear']) except ValueError: print('Alien')
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. Input Specification: The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. Output Specification: If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). Demo Input: ['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n'] Demo Output: ['Bear', 'Elephant', 'Alien'] Note: If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
```python size_sticks = input().replace(' ','') stick_rep = [size_sticks.count(i) > 3 for i in size_sticks] try: get_leg = stick_rep.index(True) stick_remain = size_sticks.replace(size_sticks[get_leg],'') print(['Elephant' if len(stick_remain) == 0 or (stick_remain[0] == stick_remain[1]) else 'Bear']) except ValueError: print('Alien') ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,669,215,183
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
92
0
# B. Напитки # # n = int(input()) # s = input().split() # s = [int(x) for x in s] # r = sum(s) / n # print(r) # A. Выбор команд # n, k = map(int, input().split()) # s = input().split() # s = [int(x) for x in s] # b = [] # for i in s: # if i + k <= 5: # b.append(i) # print(len(b) // 3) # decompress-run-length-encoded-list/ # s = input().split() # s = [int(x) for x in s] # b = [] # for i in range(0, len(s), 2): # for j in range(s[i]): # b.append(s[i + 1]) # print(b) # A. Быстрый математик # a = input() # b = input() # c = '' # for i in range(len(a)): # c += str(int(a[i]) + int(b[i])) # print(c.replace('2', '0')) # A. Ваня и забор # n, h = map(int, input().split()) # s = input().split() # s = [int(x) for x in s] # count = 0 # for i in s: # if i > h: # count += 2 # else: # count += 1 # print(count) # A. Башни # n = int(input()) # s = input().split() # s = [int(x) for x in s] # b = [] # c = [] # for i in range(n): # if s[i] not in b: # b.append(s[i]) # towers count # else: # c.append(s.count(s[i])) # if len(c) == 0: # print(1, len(b)) # else: # print(max(c), len(b)) # A. Антон и Даник # n = int(input()) # s = input() # dan = 0 # ant = 0 # for i in s: # if i == 'D': # dan += 1 # else: # ant += 1 # if ant > dan: # print('Anton') # elif ant < dan: # print('Danik') # else: # print('Friendship') n = int(input()) x = '' c = 1 for i in range(n): s = input() if s == x: c += 1 x = s print(c)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python # B. Напитки # # n = int(input()) # s = input().split() # s = [int(x) for x in s] # r = sum(s) / n # print(r) # A. Выбор команд # n, k = map(int, input().split()) # s = input().split() # s = [int(x) for x in s] # b = [] # for i in s: # if i + k <= 5: # b.append(i) # print(len(b) // 3) # decompress-run-length-encoded-list/ # s = input().split() # s = [int(x) for x in s] # b = [] # for i in range(0, len(s), 2): # for j in range(s[i]): # b.append(s[i + 1]) # print(b) # A. Быстрый математик # a = input() # b = input() # c = '' # for i in range(len(a)): # c += str(int(a[i]) + int(b[i])) # print(c.replace('2', '0')) # A. Ваня и забор # n, h = map(int, input().split()) # s = input().split() # s = [int(x) for x in s] # count = 0 # for i in s: # if i > h: # count += 2 # else: # count += 1 # print(count) # A. Башни # n = int(input()) # s = input().split() # s = [int(x) for x in s] # b = [] # c = [] # for i in range(n): # if s[i] not in b: # b.append(s[i]) # towers count # else: # c.append(s.count(s[i])) # if len(c) == 0: # print(1, len(b)) # else: # print(max(c), len(b)) # A. Антон и Даник # n = int(input()) # s = input() # dan = 0 # ant = 0 # for i in s: # if i == 'D': # dan += 1 # else: # ant += 1 # if ant > dan: # print('Anton') # elif ant < dan: # print('Danik') # else: # print('Friendship') n = int(input()) x = '' c = 1 for i in range(n): s = input() if s == x: c += 1 x = s print(c) ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,594,020,034
2,147,483,647
Python 3
OK
TESTS
81
218
6,758,400
n=int(input()) a_1=[] b_1=[] c_1=[] for i in range(n): a,b,c=map(int,input().split()) a_1.append(a) b_1.append(b) c_1.append(c) if sum(a_1)==0 and sum(b_1)==0 and sum(c_1)==0: print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n=int(input()) a_1=[] b_1=[] c_1=[] for i in range(n): a,b,c=map(int,input().split()) a_1.append(a) b_1.append(b) c_1.append(c) if sum(a_1)==0 and sum(b_1)==0 and sum(c_1)==0: print("YES") else: print("NO") ```
3.932911