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
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,697,035,415
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<iostream> using namespace std; int main() { string a; cin >> a; int counter = 0; for(int i = 0; i < a.size(); i++) { if(a[i] == '4' || '7') { counter += 1; } } if(counter == 4 || 7) { cout << "YES"; } else { cout << "NO"; } return 0; }
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python #include<iostream> using namespace std; int main() { string a; cin >> a; int counter = 0; for(int i = 0; i < a.size(); i++) { if(a[i] == '4' || '7') { counter += 1; } } if(counter == 4 || 7) { cout << "YES"; } else { cout << "NO"; } return 0; } ```
-1
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,587,022,295
2,147,483,647
Python 3
OK
TESTS
102
109
0
a = input() b = input() ans = "" for i in range(0,len(a)): if a[i]==b[i]=="0" or a[i]==b[i]=="1": ans += "0" else: ans += "1" print(ans)
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 a = input() b = input() ans = "" for i in range(0,len(a)): if a[i]==b[i]=="0" or a[i]==b[i]=="1": ans += "0" else: ans += "1" print(ans) ```
3.97275
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B.
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "A>C\nA>B\nB<C", "output": "BCA" }, { "input": "C<B\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nA>B\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nA<C", "output": "ABC" }, { "input": "C<B\nB<A\nC>A", "output": "Impossible" }, { "input": "B<C\nC<A\nA>B", "output": "BCA" }, { "input": "A>B\nC<B\nC<A", "output": "CBA" }, { "input": "B>A\nC>B\nA>C", "output": "Impossible" }, { "input": "B<A\nC>B\nC>A", "output": "BAC" }, { "input": "A<B\nC>B\nA<C", "output": "ABC" }, { "input": "A<B\nC<A\nB<C", "output": "Impossible" }, { "input": "A>C\nC<B\nB>A", "output": "CAB" }, { "input": "C>A\nA<B\nB>C", "output": "ACB" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "B>C\nB>A\nA<C", "output": "ACB" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA<B\nB>C", "output": "ACB" }, { "input": "B>A\nA>C\nB>C", "output": "CAB" }, { "input": "B<A\nA<C\nC<B", "output": "Impossible" }, { "input": "A<C\nB>C\nA>B", "output": "Impossible" }, { "input": "B>A\nC<A\nC>B", "output": "Impossible" }, { "input": "A>C\nC>B\nB<A", "output": "BCA" }, { "input": "B<C\nB<A\nA>C", "output": "BCA" }, { "input": "A>B\nC>B\nA<C", "output": "BAC" }, { "input": "C<B\nC<A\nB<A", "output": "CBA" }, { "input": "A<C\nA>B\nB>C", "output": "Impossible" }, { "input": "B>A\nB>C\nA<C", "output": "ACB" }, { "input": "B>C\nC<A\nB<A", "output": "CBA" }, { "input": "C>A\nB>A\nB>C", "output": "ACB" }, { "input": "B<A\nB>C\nA<C", "output": "Impossible" }, { "input": "B<C\nA<B\nC>A", "output": "ABC" }, { "input": "C<B\nB>A\nA>C", "output": "CAB" }, { "input": "A>B\nC>A\nB<C", "output": "BAC" }, { "input": "A>B\nB>C\nC<A", "output": "CBA" }, { "input": "B>C\nC>A\nA>B", "output": "Impossible" }, { "input": "B<A\nB>C\nC<A", "output": "CBA" }, { "input": "C>B\nB>A\nC>A", "output": "ABC" }, { "input": "A>C\nA>B\nB>C", "output": "CBA" }, { "input": "B<C\nA>B\nA<C", "output": "BAC" }, { "input": "C>A\nC<B\nB>A", "output": "ACB" }, { "input": "C>B\nA<B\nC<A", "output": "Impossible" }, { "input": "A<C\nC<B\nA>B", "output": "Impossible" }, { "input": "B>C\nA<B\nA<C", "output": "ACB" }, { "input": "C>A\nA<B\nC>B", "output": "ABC" } ]
1,643,133,039
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
def Coins(): a ,b, c= 0,0,0 d = {"A":0 , "B":0 , "C":0} for _ in range(3): data = input() if data == "A>B" or data == "B<A" : d["A"] += 1 d["B"] -= 1 elif data == "A<B" or data == "B>A": d["A"] -= 1 d["B"] += 1 elif data == "B>C" or data == "C<B": d["B"] += 1 d["C"] -= 1 elif data == "B<C" or data == "C>B": d["C"] += 1 d["B"] -= 1 elif data == "A>C" or data == "C<A": d["A"] += 1 d["C"] -= 1 elif data == "A<C" or data == "C>A": d["A"] -= 1 d["C"] += 1 sort_d = dict(sorted(d.items(), key=lambda x: x[1], reverse=False)) final = "" for i in sort_d.keys(): final += i return final print(Coins())
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. Input Specification: The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B. Output Specification: It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. Demo Input: ['A&gt;B\nC&lt;B\nA&gt;C\n', 'A&lt;B\nB&gt;C\nC&gt;A\n'] Demo Output: ['CBA', 'ACB'] Note: none
```python def Coins(): a ,b, c= 0,0,0 d = {"A":0 , "B":0 , "C":0} for _ in range(3): data = input() if data == "A>B" or data == "B<A" : d["A"] += 1 d["B"] -= 1 elif data == "A<B" or data == "B>A": d["A"] -= 1 d["B"] += 1 elif data == "B>C" or data == "C<B": d["B"] += 1 d["C"] -= 1 elif data == "B<C" or data == "C>B": d["C"] += 1 d["B"] -= 1 elif data == "A>C" or data == "C<A": d["A"] += 1 d["C"] -= 1 elif data == "A<C" or data == "C>A": d["A"] -= 1 d["C"] += 1 sort_d = dict(sorted(d.items(), key=lambda x: x[1], reverse=False)) final = "" for i in sort_d.keys(): final += i return final print(Coins()) ```
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,631,639,495
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
29,491,200
def gcd(a,b): while b!=0: a, b = b, a%b return a a, b = map(int, input().split()) c=0 k=0 numb=[] for i in range(a, b+1): for j in range(a, b+1): numb.append(gcd(i,j)) for elem in numb: for i in range(a, b+1): if i%elem!=0: numb = list(filter((elem).__ne__, numb)) print(*list(set(numb)))
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 def gcd(a,b): while b!=0: a, b = b, a%b return a a, b = map(int, input().split()) c=0 k=0 numb=[] for i in range(a, b+1): for j in range(a, b+1): numb.append(gcd(i,j)) for elem in numb: for i in range(a, b+1): if i%elem!=0: numb = list(filter((elem).__ne__, numb)) print(*list(set(numb))) ```
0
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..." }, { "input": "84817 1 33457", "output": "-1" }, { "input": "21 37 99", "output": "16 53 " }, { "input": "78 7 15", "output": "-1" }, { "input": "74 17 27", "output": "-1" }, { "input": "79 23 43", "output": "-1" }, { "input": "32 33 3", "output": "-1" }, { "input": "55 49 44", "output": "-1" }, { "input": "64 59 404", "output": "54 113 172 231 290 " }, { "input": "61 69 820", "output": "8 77 146 215 284 353 422 491 560 629 698 " }, { "input": "17 28 532", "output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 " }, { "input": "46592 52 232", "output": "-1" }, { "input": "1541 58 648", "output": "-1" }, { "input": "15946 76 360", "output": "-1" }, { "input": "30351 86 424", "output": "-1" }, { "input": "1 2 37493", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "1 3 27764", "output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..." }, { "input": "10 4 9174", "output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..." }, { "input": "33 7 4971", "output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..." }, { "input": "981 1 3387", "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": "386 1 2747", "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": "123 2 50000", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..." }, { "input": "3123 100 10000000", "output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..." }, { "input": "2 10000 1000000000", "output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..." }, { "input": "3 10000 1000000000", "output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..." }, { "input": "12312223 10000 1000000000", "output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..." }, { "input": "500000000 1000000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 1000000000", "output": "999999999 " }, { "input": "10 6 11", "output": "-1" }, { "input": "2 100 10", "output": "-1" }, { "input": "1 100000007 1000000000", "output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 " }, { "input": "1 999999999 1000000000", "output": "999999998 " }, { "input": "100000000 1000000000 1000000000", "output": "900000000 " }, { "input": "11 2 12", "output": "1 " }, { "input": "31 10 39", "output": "-1" }, { "input": "48 6 50", "output": "-1" }, { "input": "500000000 500000000 1000000000", "output": "500000000 " }, { "input": "1 1000000000 999999999", "output": "-1" }, { "input": "4 2 10", "output": "2 4 6 " }, { "input": "1000000000 1 1", "output": "-1" }, { "input": "1000000000 1 100000", "output": "-1" }, { "input": "1000000000 1 10", "output": "-1" }, { "input": "10 5 14", "output": "-1" }, { "input": "500000000 499999999 1000000000", "output": "499999998 " }, { "input": "1 999999997 1000000000", "output": "999999996 " } ]
1,676,475,819
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
29
248
8,806,400
l=list(map(int,input().split())) y,k,n=l[0],l[1],l[2] kittymin=k*int(y/k)+k kittymax=l[2] if kittymin>=kittymax: print(-1) for i in range(kittymin,kittymax+1,k): print(i-y,end=" ")
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. Input Specification: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). Output Specification: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Demo Input: ['10 1 10\n', '10 6 40\n'] Demo Output: ['-1\n', '2 8 14 20 26 \n'] Note: none
```python l=list(map(int,input().split())) y,k,n=l[0],l[1],l[2] kittymin=k*int(y/k)+k kittymax=l[2] if kittymin>=kittymax: print(-1) for i in range(kittymin,kittymax+1,k): print(i-y,end=" ") ```
0
868
C
Qualification Rounds
PROGRAMMING
1,500
[ "bitmasks", "brute force", "constructive algorithms", "dp" ]
null
null
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n", "3 2\n1 0\n1 1\n0 1\n" ]
[ "NO\n", "YES\n" ]
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
1,000
[ { "input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO" }, { "input": "3 2\n1 0\n1 1\n0 1", "output": "YES" }, { "input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "output": "YES" }, { "input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1\n1 0 0\n1 1 0\n0 0 0", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 0 1\n1 0 1 0\n0 0 0 0\n0 0 1 0\n1 0 1 0\n0 0 1 1", "output": "YES" }, { "input": "2 2\n0 0\n1 0", "output": "YES" }, { "input": "3 3\n1 0 1\n1 0 0\n1 1 1", "output": "NO" }, { "input": "4 4\n0 0 0 0\n1 1 0 0\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "4 1\n1\n1\n0\n0", "output": "YES" }, { "input": "1 4\n0 0 0 0", "output": "YES" }, { "input": "3 3\n0 0 1\n0 1 1\n1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n1 0 0", "output": "YES" }, { "input": "1 1\n0", "output": "YES" }, { "input": "2 4\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 0 1\n1 1 1 1", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 1 1 0\n1 1 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 0\n0 0 1 0", "output": "YES" }, { "input": "2 4\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 0 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "1 2\n0 0", "output": "YES" }, { "input": "6 3\n0 1 1\n1 0 1\n1 1 1\n0 1 0\n1 0 1\n1 1 0", "output": "YES" }, { "input": "1 4\n0 0 1 1", "output": "NO" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 1", "output": "YES" }, { "input": "3 2\n0 0\n0 0\n0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n1 0 1 1", "output": "NO" }, { "input": "2 4\n0 0 0 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "4 4\n1 1 1 1\n0 0 0 1\n0 0 1 1\n1 0 1 1", "output": "NO" }, { "input": "6 3\n1 0 0\n1 1 1\n1 1 1\n0 1 0\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 1 0 0\n1 1 1 1\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "1 3\n0 0 0", "output": "YES" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 0", "output": "YES" }, { "input": "2 4\n0 1 1 0\n0 0 0 0", "output": "YES" }, { "input": "1 4\n0 0 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 1", "output": "YES" }, { "input": "3 2\n0 1\n0 1\n1 0", "output": "YES" }, { "input": "4 3\n1 1 0\n1 1 1\n0 0 1\n0 0 1", "output": "YES" }, { "input": "2 1\n0\n0", "output": "YES" }, { "input": "2 4\n1 1 1 0\n0 0 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n1 1 0 0", "output": "NO" }, { "input": "3 4\n0 1 1 0\n0 1 0 1\n0 0 1 1", "output": "NO" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "2 3\n1 1 0\n0 0 1", "output": "YES" }, { "input": "3 3\n0 0 1\n1 1 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 1 1 1\n1 0 1 0\n1 1 0 1\n1 0 1 0", "output": "NO" }, { "input": "3 3\n1 0 0\n0 0 0\n1 0 0", "output": "YES" }, { "input": "3 4\n1 1 0 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 1\n0 0 1 0", "output": "YES" }, { "input": "2 4\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n0 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 0", "output": "YES" }, { "input": "3 2\n1 0\n0 1\n0 1", "output": "YES" }, { "input": "3 4\n1 1 0 1\n0 0 1 1\n1 0 1 0", "output": "NO" }, { "input": "3 4\n0 0 1 1\n0 1 1 0\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 0 1\n0 0 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 1 1 0\n1 1 0 1\n0 0 1 0", "output": "YES" }, { "input": "8 4\n0 0 0 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 0 1 1\n1 1 1 0\n0 1 0 1", "output": "NO" }, { "input": "2 4\n1 1 0 0\n0 0 0 1", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 1 0\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 0 0 1\n0 1 1 1\n0 0 0 1\n1 1 1 1\n1 0 1 0", "output": "YES" }, { "input": "2 4\n0 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "3 3\n1 1 0\n1 0 1\n0 1 1", "output": "NO" }, { "input": "3 3\n1 1 0\n0 0 1\n1 1 1", "output": "YES" }, { "input": "4 4\n1 1 0 0\n1 0 1 0\n0 1 1 0\n0 0 1 1", "output": "YES" }, { "input": "4 4\n1 0 0 0\n1 0 0 1\n1 0 0 1\n0 1 1 1", "output": "YES" }, { "input": "4 3\n1 0 0\n1 0 0\n1 0 0\n0 1 1", "output": "YES" }, { "input": "2 4\n0 0 1 0\n0 1 0 0", "output": "YES" }, { "input": "1 2\n0 1", "output": "NO" }, { "input": "3 4\n1 1 1 0\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n0 1 0 1\n1 0 1 0", "output": "YES" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "YES" }, { "input": "2 4\n0 0 0 0\n0 0 0 0", "output": "YES" }, { "input": "3 4\n0 1 0 1\n0 1 1 0\n1 0 0 1", "output": "YES" }, { "input": "3 4\n0 1 1 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1", "output": "YES" }, { "input": "10 4\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 3\n1 1 0\n0 1 1\n1 0 1", "output": "NO" }, { "input": "2 3\n0 0 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 0 0 1\n0 0 1 1\n1 1 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n0 0 1 1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 0", "output": "YES" } ]
1,507,196,426
9,326
Python 3
WRONG_ANSWER
PRETESTS
3
46
0
n, k=map(int, input().split()) arr=[] for i in range(n): a=[int(x) for x in input().split()] arr.append(a) #print(arr) ans=[] cnt=0 col=0 for i in range(k): for j in range(n): #print(arr[j][i]) if(arr[j][i]==1): cnt+=1 if(cnt==n): print("NO") exit(0) ans.append(cnt) cnt=0 #print(ans) #print(ans.count(ans[0])) if(ans.count(ans[0])==len(ans)): print("YES") else: print("NO")
Title: Qualification Rounds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset! Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise. Output Specification: Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n', '3 2\n1 0\n1 1\n0 1\n'] Demo Output: ['NO\n', 'YES\n'] Note: In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
```python n, k=map(int, input().split()) arr=[] for i in range(n): a=[int(x) for x in input().split()] arr.append(a) #print(arr) ans=[] cnt=0 col=0 for i in range(k): for j in range(n): #print(arr[j][i]) if(arr[j][i]==1): cnt+=1 if(cnt==n): print("NO") exit(0) ans.append(cnt) cnt=0 #print(ans) #print(ans.count(ans[0])) if(ans.count(ans[0])==len(ans)): print("YES") else: print("NO") ```
0
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" }, { "input": "1024", "output": "10" }, { "input": "99999", "output": "11" }, { "input": "10007", "output": "1" }, { "input": "4096", "output": "12" }, { "input": "65536", "output": "16" }, { "input": "40320", "output": "95" }, { "input": "30030", "output": "63" }, { "input": "161", "output": "3" }, { "input": "1000", "output": "15" }, { "input": "10000", "output": "24" }, { "input": "777", "output": "7" }, { "input": "121", "output": "2" }, { "input": "25", "output": "2" }, { "input": "40000", "output": "34" }, { "input": "99990", "output": "47" }, { "input": "98765", "output": "3" }, { "input": "56789", "output": "3" }, { "input": "13579", "output": "3" }, { "input": "97531", "output": "3" }, { "input": "12345", "output": "7" }, { "input": "54321", "output": "7" }, { "input": "83160", "output": "127" }, { "input": "9", "output": "2" }, { "input": "21", "output": "3" }, { "input": "11", "output": "1" }, { "input": "15", "output": "3" } ]
1,648,161,539
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
62
0
n=int(input()) nb=bin(n).replace("0b","") lnb=len(nb) x=lnb-1 print(x)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. Input Specification: The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. Output Specification: Print a single integer representing the answer to the problem. Demo Input: ['2\n', '10\n'] Demo Output: ['1\n', '3\n'] Note: In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
```python n=int(input()) nb=bin(n).replace("0b","") lnb=len(nb) x=lnb-1 print(x) ```
0
161
A
Dress'em in Vests!
PROGRAMMING
1,300
[ "binary search", "brute force", "greedy", "two pointers" ]
null
null
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the *i*-th soldier indicated size *a**i*. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from *a**i*<=-<=*x* to *a**i*<=+<=*y*, inclusive (numbers *x*,<=*y*<=≥<=0 are specified). The Two-dimensional kingdom has *m* vests at its disposal, the *j*-th vest's size equals *b**j*. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The *i*-th soldier can put on the *j*-th vest, if *a**i*<=-<=*x*<=≤<=*b**j*<=≤<=*a**i*<=+<=*y*.
The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) in non-decreasing order, separated by single spaces — the desired sizes of vests. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=109) in non-decreasing order, separated by single spaces — the sizes of the available vests.
In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests. In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them.
[ "5 3 0 0\n1 2 3 3 4\n1 3 5\n", "3 3 2 2\n1 5 9\n3 5 7\n" ]
[ "2\n1 1\n3 2\n", "3\n1 1\n2 2\n3 3\n" ]
In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one. In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.
1,000
[ { "input": "5 3 0 0\n1 2 3 3 4\n1 3 5", "output": "2\n1 1\n3 2" }, { "input": "3 3 2 2\n1 5 9\n3 5 7", "output": "3\n1 1\n2 2\n3 3" }, { "input": "1 1 0 0\n1\n1", "output": "1\n1 1" }, { "input": "1 1 0 0\n1\n2", "output": "0" }, { "input": "2 3 1 4\n1 5\n1 2 2", "output": "1\n1 1" }, { "input": "20 30 1 4\n1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22" }, { "input": "33 23 17 2\n1 1 2 2 2 3 3 3 3 3 3 4 4 4 4 4 5 5 5 6 6 7 7 7 8 8 8 8 8 9 9 10 10\n1 1 3 3 4 4 4 5 5 6 6 6 7 8 8 8 8 8 8 9 9 10 10", "output": "23\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n12 10\n13 11\n14 12\n17 13\n20 14\n21 15\n22 16\n23 17\n24 18\n25 19\n26 20\n27 21\n28 22\n29 23" }, { "input": "2 2 1 4\n1 4\n3 6", "output": "2\n1 1\n2 2" }, { "input": "20 20 1 4\n1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 5 5\n3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 6 6 7 7", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20" }, { "input": "33 23 17 2\n1 1 1 2 3 3 3 3 3 4 4 4 4 5 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 8 10 10\n10 10 10 11 12 12 12 12 12 13 13 13 13 14 15 15 15 15 15 15 16 16 16", "output": "5\n26 1\n27 2\n28 3\n32 4\n33 5" }, { "input": "1 1 1 2\n783266931\n783266932", "output": "1\n1 1" }, { "input": "2 3 1 4\n1 1\n3 3 4", "output": "2\n1 1\n2 2" }, { "input": "20 30 1 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20" }, { "input": "33 23 17 2\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5\n10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13", "output": "0" }, { "input": "10 1 1 1\n1 1 1 5 5 7 7 8 8 8\n3", "output": "0" }, { "input": "10 1 2 1\n1 2 5 8 9 9 9 10 10 10\n7", "output": "1\n4 1" }, { "input": "1 1 2 1\n7\n8", "output": "1\n1 1" }, { "input": "1 1 0 2\n9\n7", "output": "0" }, { "input": "2 2 0 2\n2 8\n3 5", "output": "1\n1 1" }, { "input": "2 2 1 0\n5 5\n6 7", "output": "0" }, { "input": "2 2 3 0\n8 9\n1 5", "output": "1\n1 2" } ]
1,546,267,457
2,147,483,647
Python 3
OK
TESTS
84
1,028
15,155,200
# 161A-sua bai >> accepted # n: num of solder # m: num of vest # x: margin duoi # y: margin tren # chu giai giai thuat: i chay tu 0>>n, neu ao vest b[j] nho hon (a[i]-x), thi tang j (xet bo ao vest tiep theo) cho toi khi tim # thay j phu hop, sau do xet xem ung voi j do, ao vest co phu hop voi soldier i ko (b[j]<(a[i]+y)), neu phu hop thi luu cap i,j # do lai, neu khong phu hop thi tang i (bang vong for) n,m,x,y = map(int,input().split()) a = list(map(int,input().split())) # list size soldier b = list(map(int,input().split())) # list cac size ao j=0 u = [] for i in range (n): if (j==m): break # print (b[j]) # print (a[i]-x) while ((b[j]<(a[i]-x))): # print ('i=',i) # print ('j=',j) j+=1 if (j==m): break if (j==m): break if (b[j]<=(a[i]+y)): u.append([i+1,j+1]) j+=1 print (len(u)) for i in range (len(u)): print ('%d %d'%(u[i][0],u[i][1]))
Title: Dress'em in Vests! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the *i*-th soldier indicated size *a**i*. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from *a**i*<=-<=*x* to *a**i*<=+<=*y*, inclusive (numbers *x*,<=*y*<=≥<=0 are specified). The Two-dimensional kingdom has *m* vests at its disposal, the *j*-th vest's size equals *b**j*. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The *i*-th soldier can put on the *j*-th vest, if *a**i*<=-<=*x*<=≤<=*b**j*<=≤<=*a**i*<=+<=*y*. Input Specification: The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) in non-decreasing order, separated by single spaces — the desired sizes of vests. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=109) in non-decreasing order, separated by single spaces — the sizes of the available vests. Output Specification: In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests. In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them. Demo Input: ['5 3 0 0\n1 2 3 3 4\n1 3 5\n', '3 3 2 2\n1 5 9\n3 5 7\n'] Demo Output: ['2\n1 1\n3 2\n', '3\n1 1\n2 2\n3 3\n'] Note: In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one. In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.
```python # 161A-sua bai >> accepted # n: num of solder # m: num of vest # x: margin duoi # y: margin tren # chu giai giai thuat: i chay tu 0>>n, neu ao vest b[j] nho hon (a[i]-x), thi tang j (xet bo ao vest tiep theo) cho toi khi tim # thay j phu hop, sau do xet xem ung voi j do, ao vest co phu hop voi soldier i ko (b[j]<(a[i]+y)), neu phu hop thi luu cap i,j # do lai, neu khong phu hop thi tang i (bang vong for) n,m,x,y = map(int,input().split()) a = list(map(int,input().split())) # list size soldier b = list(map(int,input().split())) # list cac size ao j=0 u = [] for i in range (n): if (j==m): break # print (b[j]) # print (a[i]-x) while ((b[j]<(a[i]-x))): # print ('i=',i) # print ('j=',j) j+=1 if (j==m): break if (j==m): break if (b[j]<=(a[i]+y)): u.append([i+1,j+1]) j+=1 print (len(u)) for i in range (len(u)): print ('%d %d'%(u[i][0],u[i][1])) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,663,362,589
2,147,483,647
Python 3
OK
TESTS
35
92
0
m,n = map(int,input().split()) aria = m * n if aria %2 != 0: aria-=1 print(int(aria/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python m,n = map(int,input().split()) aria = m * n if aria %2 != 0: aria-=1 print(int(aria/2)) ```
3.977
177
A1
Good Matrix Elements
PROGRAMMING
800
[ "implementation" ]
null
null
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix.
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101
Print a single integer — the sum of good matrix elements.
[ "3\n1 2 3\n4 5 6\n7 8 9\n", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n" ]
[ "45\n", "17\n" ]
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
30
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "45" }, { "input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "output": "17" }, { "input": "1\n3", "output": "3" }, { "input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33", "output": "756" }, { "input": "3\n19 7 16\n12 15 5\n15 15 5", "output": "109" }, { "input": "3\n36 4 33\n11 46 32\n20 49 34", "output": "265" }, { "input": "3\n79 91 74\n33 82 22\n18 28 54", "output": "481" }, { "input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6", "output": "65" }, { "input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6", "output": "225" }, { "input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6", "output": "495" }, { "input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6", "output": "705" }, { "input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83", "output": "708" }, { "input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "5" }, { "input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "3\n0 0 0\n0 0 0\n0 0 0", "output": "0" } ]
1,563,706,195
2,147,483,647
Python 3
OK
TESTS1
17
218
0
#import sys #sys.stdin = open("input.in","r") #sys.stdout = open("test.out","w") n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))) c=0 for i in range(n): for j in range(n): if(i==j or i==n//2 or j==n//2 or i==n-1-j): c+=l[i][j] print(c)
Title: Good Matrix Elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good: - Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. Help the Smart Beaver count the sum of good elements of the given matrix. Input Specification: The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: - 1<=≤<=*n*<=≤<=5 The input limitations for getting 100 points are: - 1<=≤<=*n*<=≤<=101 Output Specification: Print a single integer — the sum of good matrix elements. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n'] Demo Output: ['45\n', '17\n'] Note: In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.
```python #import sys #sys.stdin = open("input.in","r") #sys.stdout = open("test.out","w") n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))) c=0 for i in range(n): for j in range(n): if(i==j or i==n//2 or j==n//2 or i==n-1-j): c+=l[i][j] 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,614,718,348
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
s=[100] for i in range(3): s=input() c = s.lower() print(c) print()
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 s=[100] for i in range(3): s=input() c = s.lower() print(c) print() ```
-1
577
B
Modulo Sum
PROGRAMMING
1,900
[ "combinatorics", "data structures", "dp", "two pointers" ]
null
null
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*. Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
[ "3 5\n1 2 3\n", "1 6\n5\n", "4 6\n3 1 1 3\n", "6 6\n5 5 5 5 5 5\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5. In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist. In the third sample test you need to choose two numbers 3 on the ends. In the fourth sample test you can take the whole subsequence.
1,250
[ { "input": "3 5\n1 2 3", "output": "YES" }, { "input": "1 6\n5", "output": "NO" }, { "input": "4 6\n3 1 1 3", "output": "YES" }, { "input": "6 6\n5 5 5 5 5 5", "output": "YES" }, { "input": "4 5\n1 1 1 1", "output": "NO" }, { "input": "5 5\n1 1 1 1 1", "output": "YES" }, { "input": "4 7\n1 2 3 3", "output": "YES" }, { "input": "1 47\n0", "output": "YES" }, { "input": "2 47\n1 0", "output": "YES" }, { "input": "9 11\n8 8 8 8 8 8 8 8 5", "output": "NO" }, { "input": "10 11\n8 8 8 8 8 8 8 8 7 8", "output": "YES" }, { "input": "3 5\n2 1 3", "output": "YES" }, { "input": "100 968\n966 966 967 966 967 967 967 967 966 966 966 967 966 966 966 967 967 966 966 967 967 967 967 966 967 967 967 967 563 967 967 967 600 967 967 966 967 966 967 966 967 966 967 966 966 966 967 966 967 966 966 967 967 193 966 966 967 966 967 967 967 966 967 966 966 580 966 967 966 966 967 966 966 966 967 967 967 967 966 967 967 966 966 966 967 967 966 966 967 966 966 966 967 966 966 967 966 967 966 966", "output": "YES" }, { "input": "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 949 949 496 949 950 949 950 159 950 949 949 950 950 949 950 949 949 950 949 950 949 949 950 949 950 950 950 950 949 949 949 949 949 950 950 950 950 950 950 950 949 950 949 949 950 949 950 950 949 950 950 950 949 950 949 950 950 950 950 949 949 950 950 949 950 950 950 950 949 950 950 949 949 635 612 949 949 949 949 949 949 949 950 949 949 950 949 950", "output": "YES" }, { "input": "100 940\n1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 1 403 2 2 1 1 1 2 2 2 1 2 2 1 1 2 2 1 1 1 1 2 1 2 691 1 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 1 2 786 1", "output": "YES" }, { "input": "100 917\n2 1 2 2 2 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 340 2 399 2 1 2 2 2 2 178 1 1 2 1 1 1 2 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 1 2 2 2 2", "output": "YES" }, { "input": "1 2\n1000000000", "output": "YES" } ]
1,691,375,165
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
93
3,072,000
def subset_sum(nums, total): dp = [False] * (total + 1) dp[0] = True n = len(nums) for i in range(1, n + 1): for j in range(total, -1, -1): if j - nums[i - 1] >= 0: dp[j] |= dp[j - nums[i - 1]] return dp[total] def solve(tc): n, m = map(int, input().split()) v = list(map(int, input().split())) def sum_vector(vec): return sum(vec) sum_val = sum_vector(v) ans = False v.sort() if v[0] == 0: print("yes") return subset_sum(v, m * (sum_val // m)) for i in range(1, (sum_val // m) + 1): if i * m < sum_val: ans |= dp[i * m] if ans: print("yes") else: print("no") def main(): t = 1 # t = int(input()) for i in range(1, t + 1): solve(i) if __name__ == "__main__": main()
Title: Modulo Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*. Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*. Input Specification: The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist. Demo Input: ['3 5\n1 2 3\n', '1 6\n5\n', '4 6\n3 1 1 3\n', '6 6\n5 5 5 5 5 5\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'YES\n'] Note: In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5. In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist. In the third sample test you need to choose two numbers 3 on the ends. In the fourth sample test you can take the whole subsequence.
```python def subset_sum(nums, total): dp = [False] * (total + 1) dp[0] = True n = len(nums) for i in range(1, n + 1): for j in range(total, -1, -1): if j - nums[i - 1] >= 0: dp[j] |= dp[j - nums[i - 1]] return dp[total] def solve(tc): n, m = map(int, input().split()) v = list(map(int, input().split())) def sum_vector(vec): return sum(vec) sum_val = sum_vector(v) ans = False v.sort() if v[0] == 0: print("yes") return subset_sum(v, m * (sum_val // m)) for i in range(1, (sum_val // m) + 1): if i * m < sum_val: ans |= dp[i * m] if ans: print("yes") else: print("no") def main(): t = 1 # t = int(input()) for i in range(1, t + 1): solve(i) if __name__ == "__main__": main() ```
-1
522
A
Reposts
PROGRAMMING
1,200
[ "*special", "dfs and similar", "dp", "graphs", "trees" ]
null
null
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
[ "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n", "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n", "1\nSoMeStRaNgEgUe reposted PoLyCaRp\n" ]
[ "6\n", "2\n", "2\n" ]
none
500
[ { "input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya", "output": "6" }, { "input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp", "output": "2" }, { "input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp", "output": "2" }, { "input": "1\niuNtwVf reposted POlYcarP", "output": "2" }, { "input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS", "output": "11" }, { "input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl", "output": "6" }, { "input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj", "output": "9" }, { "input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI", "output": "3" } ]
1,674,908,553
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
102,400
from collections import defaultdict, deque n = int(input()) g = {} for _ in range(n): p = input().split() g[p[2].lower()] = g.get(p[0].lower(),[]) + [p[0].lower()] ans = -float('inf') elem = g.keys() dp = 0 que = deque(['polycarp']) while que: l = len(que) for _ in range(l): temp = que.popleft() if temp in g: for nb in g[temp]: que.append(nb) dp+=1 print(dp)
Title: Reposts Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on. These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed. Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. Output Specification: Print a single integer — the maximum length of a repost chain. Demo Input: ['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n'] Demo Output: ['6\n', '2\n', '2\n'] Note: none
```python from collections import defaultdict, deque n = int(input()) g = {} for _ in range(n): p = input().split() g[p[2].lower()] = g.get(p[0].lower(),[]) + [p[0].lower()] ans = -float('inf') elem = g.keys() dp = 0 que = deque(['polycarp']) while que: l = len(que) for _ in range(l): temp = que.popleft() if temp in g: for nb in g[temp]: que.append(nb) dp+=1 print(dp) ```
0
748
B
Santa Claus and Keyboard Check
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
[ "helloworld\nehoolwlroz\n", "hastalavistababy\nhastalavistababy\n", "merrychristmas\nchristmasmerry\n" ]
[ "3\nh e\nl o\nd z\n", "0\n", "-1\n" ]
none
1,000
[ { "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z" }, { "input": "hastalavistababy\nhastalavistababy", "output": "0" }, { "input": "merrychristmas\nchristmasmerry", "output": "-1" }, { "input": "kusyvdgccw\nkusyvdgccw", "output": "0" }, { "input": "bbbbbabbab\naaaaabaaba", "output": "1\nb a" }, { "input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx", "output": "-1" }, { "input": "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc", "output": "1\nd b" }, { "input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd", "output": "0" }, { "input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak", "output": "5\ng f\nn i\nd h\ne o\nb k" }, { "input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc", "output": "0" }, { "input": "ab\naa", "output": "-1" }, { "input": "a\nz", "output": "1\na z" }, { "input": "zz\nzy", "output": "-1" }, { "input": "as\ndf", "output": "2\na d\ns f" }, { "input": "abc\nbca", "output": "-1" }, { "input": "rtfg\nrftg", "output": "1\nt f" }, { "input": "y\ny", "output": "0" }, { "input": "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz", "output": "-1" }, { "input": "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm", "output": "-1" }, { "input": "aaaaaa\nabcdef", "output": "-1" }, { "input": "qwerty\nffffff", "output": "-1" }, { "input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh", "output": "0" }, { "input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe", "output": "-1" }, { "input": "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba", "output": "0" }, { "input": "dbadbddddb\nacbacaaaac", "output": "-1" }, { "input": "dacbdbbbdd\nadbdadddaa", "output": "-1" }, { "input": "bbbbcbcbbc\ndaddbabddb", "output": "-1" }, { "input": "dddddbcdbd\nbcbbbdacdb", "output": "-1" }, { "input": "cbadcbcdaa\nabbbababbb", "output": "-1" }, { "input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk", "output": "-1" }, { "input": "acbbccabaa\nabbbbbabaa", "output": "-1" }, { "input": "ccccaccccc\naaaabaaaac", "output": "-1" }, { "input": "acbacacbbb\nacbacacbbb", "output": "0" }, { "input": "abbababbcc\nccccccccbb", "output": "-1" }, { "input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh", "output": "-1" }, { "input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage", "output": "-1" }, { "input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai", "output": "-1" }, { "input": "z\nz", "output": "0" }, { "input": "a\nz", "output": "1\na z" }, { "input": "z\na", "output": "1\nz a" }, { "input": "aa\nzz", "output": "1\na z" }, { "input": "az\nza", "output": "1\na z" }, { "input": "aa\nza", "output": "-1" }, { "input": "za\nzz", "output": "-1" }, { "input": "aa\nab", "output": "-1" }, { "input": "hehe\nheeh", "output": "-1" }, { "input": "bd\ncc", "output": "-1" }, { "input": "he\nhh", "output": "-1" }, { "input": "hee\nheh", "output": "-1" }, { "input": "aa\nac", "output": "-1" }, { "input": "ab\naa", "output": "-1" }, { "input": "hello\nehlol", "output": "-1" }, { "input": "ac\naa", "output": "-1" }, { "input": "aaabbb\nbbbaab", "output": "-1" }, { "input": "aa\nfa", "output": "-1" }, { "input": "hg\nee", "output": "-1" }, { "input": "helloworld\nehoolwlrow", "output": "-1" }, { "input": "abb\nbab", "output": "-1" }, { "input": "aaa\naae", "output": "-1" }, { "input": "aba\nbaa", "output": "-1" }, { "input": "aa\nba", "output": "-1" }, { "input": "da\naa", "output": "-1" }, { "input": "aaa\naab", "output": "-1" }, { "input": "xy\nzz", "output": "-1" } ]
1,603,609,883
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
13
140
0
# # Created by Polusummator on 25.10.2020 # --------- Little PyPy Squad --------- # Verdict: # orig = input() s = input() d = {} z = True for i in range(len(orig)): # print(d.get(orig[i]), d.get(s[i])) if orig[i] != s[i]: if (d.get(orig[i]) is None and d.get(s[i])) is None: d[orig[i]] = s[i] d[s[i]] = orig[i] elif d.get(orig[i]) == s[i] and d.get(s[i]) == orig[i]: pass else: z = False break if not z: print(-1) else: keys = list(d.keys()) print(len(keys) // 2) b = set() for i in keys: if i not in b and d[i] not in b: b.add(i) b.add(d[i]) print(i, d[i])
Title: Santa Claus and Keyboard Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. Input Specification: The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. Output Specification: If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. Demo Input: ['helloworld\nehoolwlroz\n', 'hastalavistababy\nhastalavistababy\n', 'merrychristmas\nchristmasmerry\n'] Demo Output: ['3\nh e\nl o\nd z\n', '0\n', '-1\n'] Note: none
```python # # Created by Polusummator on 25.10.2020 # --------- Little PyPy Squad --------- # Verdict: # orig = input() s = input() d = {} z = True for i in range(len(orig)): # print(d.get(orig[i]), d.get(s[i])) if orig[i] != s[i]: if (d.get(orig[i]) is None and d.get(s[i])) is None: d[orig[i]] = s[i] d[s[i]] = orig[i] elif d.get(orig[i]) == s[i] and d.get(s[i]) == orig[i]: pass else: z = False break if not z: print(-1) else: keys = list(d.keys()) print(len(keys) // 2) b = set() for i in keys: if i not in b and d[i] not in b: b.add(i) b.add(d[i]) print(i, d[i]) ```
0
0
none
none
none
0
[ "none" ]
null
null
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination. Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet. Determine for which values $d$ Natasha can make the Martians happy. Natasha can use only her banknotes. Martians don't give her change.
The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars. All numbers are given in decimal notation.
On the first line output the number of values $d$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
[ "2 8\n12 20\n", "3 10\n10 20 30\n" ]
[ "2\n0 4 ", "1\n0 " ]
Consider the first test case. It uses the octal number system. If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$. If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$. If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$. No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways. The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.
0
[ { "input": "2 8\n12 20", "output": "2\n0 4 " }, { "input": "3 10\n10 20 30", "output": "1\n0 " }, { "input": "5 10\n20 16 4 16 2", "output": "5\n0 2 4 6 8 " }, { "input": "10 5\n4 6 8 6 4 10 2 10 8 6", "output": "5\n0 1 2 3 4 " }, { "input": "20 25\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 20 20 20", "output": "5\n0 5 10 15 20 " }, { "input": "30 30\n11 23 7 30 13 6 25 29 1 15 20 5 28 15 19 22 21 5 27 25 29 10 1 4 12 19 1 5 8 10", "output": "30\n0 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 " }, { "input": "40 30\n16 12 12 22 18 28 32 24 36 26 12 30 22 16 32 30 36 18 20 16 12 24 28 20 16 28 8 34 18 18 18 4 4 36 18 10 30 38 18 10", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "50 30\n15 9 21 39 42 39 3 42 42 39 6 48 39 30 12 39 27 45 30 48 18 33 18 36 27 3 48 12 36 27 15 12 42 39 18 21 48 39 15 42 24 36 33 48 6 48 15 12 30 18", "output": "10\n0 3 6 9 12 15 18 21 24 27 " }, { "input": "1 10\n1", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 2\n1", "output": "2\n0 1 " }, { "input": "60 30\n10 30 45 15 25 60 10 40 35 25 5 40 35 40 15 5 15 35 10 60 25 15 60 10 30 10 5 25 10 15 60 20 30 5 50 50 40 20 55 40 35 15 15 10 60 40 50 50 30 15 25 45 35 40 15 5 5 20 60 45", "output": "6\n0 5 10 15 20 25 " }, { "input": "70 30\n54 30 12 48 42 24 42 60 54 6 36 42 54 66 12 48 54 42 24 54 30 18 30 54 18 60 24 30 54 48 48 60 18 60 60 66 54 18 54 30 24 30 60 54 36 36 60 48 12 60 6 60 42 66 6 42 18 60 54 48 42 18 48 66 18 42 48 30 12 66", "output": "5\n0 6 12 18 24 " }, { "input": "80 30\n30 80 40 40 60 60 40 80 70 80 30 30 60 80 30 70 60 10 10 30 70 60 70 20 40 20 30 10 60 70 70 50 60 70 70 30 70 60 60 70 20 60 10 60 70 80 20 30 30 20 60 50 40 40 80 70 70 20 40 80 30 50 40 10 40 20 70 10 80 10 50 40 50 70 40 80 10 40 60 60", "output": "3\n0 10 20 " }, { "input": "90 30\n90 45 75 75 90 90 45 30 90 15 45 90 15 30 45 60 30 15 30 45 45 45 45 15 45 60 15 60 45 75 45 75 90 60 30 15 60 30 90 75 15 60 15 30 45 30 45 15 30 15 45 30 15 75 90 15 45 15 75 15 75 30 75 45 60 75 15 45 30 75 45 90 45 60 90 45 75 30 30 30 15 15 75 60 75 90 75 60 90 45", "output": "2\n0 15 " }, { "input": "100 30\n30 30 30 90 30 30 90 90 30 90 30 90 90 30 30 30 60 60 60 30 30 60 90 90 90 60 30 90 60 60 90 60 60 60 30 60 60 60 60 90 60 30 60 90 90 90 60 60 90 60 60 60 60 30 30 60 30 60 60 90 30 60 60 60 90 60 90 30 30 60 30 90 90 90 90 60 90 30 30 60 60 30 60 60 60 30 90 60 60 60 90 60 30 90 60 30 30 60 90 90", "output": "1\n0 " }, { "input": "1 10\n2", "output": "5\n0 2 4 6 8 " }, { "input": "1 10\n3", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "5 2\n1 1 1 1 1", "output": "2\n0 1 " }, { "input": "2 30\n6 10", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "1 10\n10", "output": "1\n0 " }, { "input": "1 10\n20", "output": "1\n0 " }, { "input": "1 2\n1000000000", "output": "1\n0 " }, { "input": "2 6\n2 3", "output": "6\n0 1 2 3 4 5 " }, { "input": "1 5\n4", "output": "5\n0 1 2 3 4 " }, { "input": "2 5\n2 4", "output": "5\n0 1 2 3 4 " }, { "input": "3 30\n6 10 15", "output": "30\n0 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 " }, { "input": "2 7\n3 6", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "2 15\n3 5", "output": "15\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 " }, { "input": "2 12\n4 6", "output": "6\n0 2 4 6 8 10 " }, { "input": "2 10\n3 6", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 100000\n2 4", "output": "50000\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278..." }, { "input": "1 14\n4", "output": "7\n0 2 4 6 8 10 12 " }, { "input": "1 13\n5", "output": "13\n0 1 2 3 4 5 6 7 8 9 10 11 12 " }, { "input": "2 420\n412 363", "output": "420\n0 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 ..." }, { "input": "2 30\n10 6", "output": "15\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 " }, { "input": "1 5\n3", "output": "5\n0 1 2 3 4 " }, { "input": "1 8\n6", "output": "4\n0 2 4 6 " }, { "input": "3 10\n6 6 6", "output": "5\n0 2 4 6 8 " }, { "input": "1 7\n6", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "1 9\n6", "output": "3\n0 3 6 " }, { "input": "2 10\n7 7", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 8\n5", "output": "8\n0 1 2 3 4 5 6 7 " }, { "input": "2 50\n3 15", "output": "50\n0 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": "1 6\n4", "output": "3\n0 2 4 " }, { "input": "1 7\n4", "output": "7\n0 1 2 3 4 5 6 " }, { "input": "1 10\n7", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "1 3\n2", "output": "3\n0 1 2 " }, { "input": "2 10\n2 5", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 50\n15 3", "output": "50\n0 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": "1 5\n2", "output": "5\n0 1 2 3 4 " }, { "input": "2 10\n6 5", "output": "10\n0 1 2 3 4 5 6 7 8 9 " }, { "input": "2 35\n5 7", "output": "35\n0 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 " }, { "input": "2 300\n3 10", "output": "300\n0 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 ..." }, { "input": "1 100000\n47", "output": "100000\n0 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 1..." }, { "input": "2 54\n6 9", "output": "18\n0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 " } ]
1,579,386,636
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
18
202
10,547,200
def hcfnaive(a,b): if(b==0): return a else: return hcfnaive(b,a%b) n,k=map(int,input().split()) a=input().split() ls=[] for i in range(n): ls.append(int(a[i])%k) ls=list(set(ls)) if(len(ls)==1): if(ls[0]==0): print(1) print(0) else: ans=[] for i in range(k): if(i%ls[0]==0): ans.append(i) print(len(ans)) print(*ans) else: gcd=hcfnaive(ls[0],ls[1]) for i in range(2,len(ls)): gcd=hcfnaive(gcd,ls[i]) ans=[] for i in range(k): if(i%gcd==0): ans.append(i) print(len(ans)) print(*ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are $n$ banknote denominations on Mars: the value of $i$-th banknote is $a_i$. Natasha has an infinite number of banknotes of each denomination. Martians have $k$ fingers on their hands, so they use a number system with base $k$. In addition, the Martians consider the digit $d$ (in the number system with base $k$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $k$ is $d$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet. Determine for which values $d$ Natasha can make the Martians happy. Natasha can use only her banknotes. Martians don't give her change. Input Specification: The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars. All numbers are given in decimal notation. Output Specification: On the first line output the number of values $d$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation. Demo Input: ['2 8\n12 20\n', '3 10\n10 20 30\n'] Demo Output: ['2\n0 4 ', '1\n0 '] Note: Consider the first test case. It uses the octal number system. If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$. If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it is $40_8$. The last digit is $0_8$. If you take two banknotes with the value of $20$, the total value will be $40$, this is $50_8$ in the octal system. The last digit is $0_8$. No other digits other than $0_8$ and $4_8$ can be obtained. Digits $0_8$ and $4_8$ could also be obtained in other ways. The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.
```python def hcfnaive(a,b): if(b==0): return a else: return hcfnaive(b,a%b) n,k=map(int,input().split()) a=input().split() ls=[] for i in range(n): ls.append(int(a[i])%k) ls=list(set(ls)) if(len(ls)==1): if(ls[0]==0): print(1) print(0) else: ans=[] for i in range(k): if(i%ls[0]==0): ans.append(i) print(len(ans)) print(*ans) else: gcd=hcfnaive(ls[0],ls[1]) for i in range(2,len(ls)): gcd=hcfnaive(gcd,ls[i]) ans=[] for i in range(k): if(i%gcd==0): ans.append(i) print(len(ans)) print(*ans) ```
0
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2", "output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10" }, { "input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6", "output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4" }, { "input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9", "output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6" }, { "input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2", "output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4" } ]
1,655,730,584
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
import sys, collections, numpy m,n,k = map(int, sys.stdin.readline().split()) grid = [] for i in range(m): s = sys.stdin.readline() grid.append(list(s)) counts = {} # counts[k]: number of pictures in component k def bfs(r, c, cId): Q = collections.deque() Q.append((r,c)) grid[r][c] = cId picture = 0 while Q: r,c = Q.pop() for nr, nc in (r-1, c), (r+1,c), (r, c-1), (r, c+1): if grid[nr][nc] == '*': picture += 1 continue elif grid[nr][nc] == '.': grid[nr][nc] = cId Q.appendleft((nr,nc)) counts[cId] = picture compNum = 0 for _ in range(k): r,c = map(int, sys.stdin.readline().split()) r -= 1 c -= 1 if grid[r][c] == '.': bfs(r,c, compNum) compNum += 1 compId = grid[r][c] print(counts[compId])
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. Input Specification: First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. Output Specification: Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. Demo Input: ['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n'] Demo Output: ['6\n4\n10\n', '8\n'] Note: none
```python import sys, collections, numpy m,n,k = map(int, sys.stdin.readline().split()) grid = [] for i in range(m): s = sys.stdin.readline() grid.append(list(s)) counts = {} # counts[k]: number of pictures in component k def bfs(r, c, cId): Q = collections.deque() Q.append((r,c)) grid[r][c] = cId picture = 0 while Q: r,c = Q.pop() for nr, nc in (r-1, c), (r+1,c), (r, c-1), (r, c+1): if grid[nr][nc] == '*': picture += 1 continue elif grid[nr][nc] == '.': grid[nr][nc] = cId Q.appendleft((nr,nc)) counts[cId] = picture compNum = 0 for _ in range(k): r,c = map(int, sys.stdin.readline().split()) r -= 1 c -= 1 if grid[r][c] == '.': bfs(r,c, compNum) compNum += 1 compId = grid[r][c] print(counts[compId]) ```
-1
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,686,766,590
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def l_string(string): if len(string)<=2: return string count=len(string)-2 s=string[0]+str(count)+string[-1] return s t=int(input()) for i in range(t): string=input() a_string=l_string(string) print(a_string)
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 def l_string(string): if len(string)<=2: return string count=len(string)-2 s=string[0]+str(count)+string[-1] return s t=int(input()) for i in range(t): string=input() a_string=l_string(string) print(a_string) ```
0
716
A
Crazy Computer
PROGRAMMING
800
[ "implementation" ]
null
null
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
[ "6 5\n1 3 8 14 19 20\n", "6 1\n1 3 5 7 9 10\n" ]
[ "3", "2" ]
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
500
[ { "input": "6 5\n1 3 8 14 19 20", "output": "3" }, { "input": "6 1\n1 3 5 7 9 10", "output": "2" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 7 12 13 14", "output": "4" }, { "input": "2 1000000000\n1 1000000000", "output": "2" }, { "input": "3 5\n1 10 20", "output": "1" }, { "input": "3 10\n1 2 3", "output": "3" }, { "input": "2 1\n1 100", "output": "1" }, { "input": "3 1\n1 2 10", "output": "1" }, { "input": "2 1\n1 2", "output": "2" } ]
1,677,455,539
2,147,483,647
PyPy 3
OK
TESTS
81
202
10,854,400
n, c = map(int, input().split()) lst = list(map(int, input().split())) curr = 0 for i in range(len(lst)): if i == 0: curr += 1 elif abs(lst[i-1] - lst[i]) > c: curr = 1 else: curr += 1 print(curr)
Title: Crazy Computer Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. Input Specification: The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. Output Specification: Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. Demo Input: ['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n'] Demo Output: ['3', '2'] Note: The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
```python n, c = map(int, input().split()) lst = list(map(int, input().split())) curr = 0 for i in range(len(lst)): if i == 0: curr += 1 elif abs(lst[i-1] - lst[i]) > c: curr = 1 else: curr += 1 print(curr) ```
3
1,006
C
Three Parts of the Array
PROGRAMMING
1,200
[ "binary search", "data structures", "two pointers" ]
null
null
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then: $$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$ The sum of an empty array is $0$. Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$. The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met. Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
[ "5\n1 3 1 1 4\n", "5\n1 3 2 1 4\n", "3\n4 1 2\n" ]
[ "5\n", "4\n", "0\n" ]
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$. In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$. In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.
0
[ { "input": "5\n1 3 1 1 4", "output": "5" }, { "input": "5\n1 3 2 1 4", "output": "4" }, { "input": "3\n4 1 2", "output": "0" }, { "input": "1\n1000000000", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "5\n1 3 5 4 5", "output": "9" } ]
1,609,162,418
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
2,150,400
n=int(input()) l1=list(map(int,input().split())) sum1=0 for i in range (n): index=i sum1+=l1[i] l2=l1[i+1:] if(sum1>sum(l2)): break sum1-=l1[index] sum2=0 for i in range (n): sum2+=l2[len(l2)-1-i] if(sum2==sum1): break if(sum2>sum1): print(0) else: print(sum1)
Title: Three Parts of the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then: $$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$ The sum of an empty array is $0$. Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. Input Specification: The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$. The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. Output Specification: Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met. Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). Demo Input: ['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n'] Demo Output: ['5\n', '4\n', '0\n'] Note: In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$. In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$. In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.
```python n=int(input()) l1=list(map(int,input().split())) sum1=0 for i in range (n): index=i sum1+=l1[i] l2=l1[i+1:] if(sum1>sum(l2)): break sum1-=l1[index] sum2=0 for i in range (n): sum2+=l2[len(l2)-1-i] if(sum2==sum1): break if(sum2>sum1): print(0) else: print(sum1) ```
-1
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on.
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1010\n0100\n1101", "output": "YES" }, { "input": "2 5\n10101\n11111", "output": "YES" }, { "input": "5 5\n10000\n11000\n11100\n11110\n11111", "output": "YES" }, { "input": "2 5\n10000\n11111", "output": "YES" }, { "input": "4 5\n01000\n10100\n00010\n10101", "output": "YES" }, { "input": "2 2\n10\n11", "output": "YES" }, { "input": "2 5\n00100\n11111", "output": "YES" }, { "input": "4 5\n00000\n11000\n00110\n00011", "output": "YES" }, { "input": "4 3\n000\n010\n001\n100", "output": "YES" }, { "input": "4 5\n10000\n10101\n01000\n00111", "output": "YES" }, { "input": "4 5\n10000\n01000\n10101\n00111", "output": "YES" }, { "input": "2 2\n01\n11", "output": "YES" }, { "input": "3 3\n010\n101\n000", "output": "YES" }, { "input": "2 2\n11\n00", "output": "YES" }, { "input": "3 5\n10110\n11000\n00111", "output": "YES" }, { "input": "3 8\n00111111\n01011100\n11000000", "output": "YES" }, { "input": "4 6\n100000\n110000\n001100\n000011", "output": "YES" }, { "input": "2 5\n11111\n00000", "output": "YES" }, { "input": "2 3\n101\n111", "output": "YES" }, { "input": "2 5\n01000\n11111", "output": "YES" }, { "input": "2 2\n00\n11", "output": "YES" }, { "input": "4 15\n111110100011010\n111111011010110\n101000001011001\n100110000111011", "output": "YES" }, { "input": "2 3\n010\n111", "output": "YES" }, { "input": "4 5\n10100\n11000\n00110\n00101", "output": "YES" }, { "input": "4 4\n1111\n0000\n0000\n0000", "output": "YES" }, { "input": "3 5\n11100\n00110\n00011", "output": "YES" }, { "input": "2 1\n0\n1", "output": "YES" }, { "input": "4 4\n1000\n1001\n0010\n0100", "output": "YES" }, { "input": "3 5\n00110\n10011\n01100", "output": "YES" }, { "input": "3 5\n10101\n00111\n01000", "output": "NO" }, { "input": "4 5\n00101\n00011\n01000\n10010", "output": "YES" }, { "input": "3 3\n100\n110\n111", "output": "YES" }, { "input": "2 2\n11\n01", "output": "YES" }, { "input": "3 3\n100\n100\n111", "output": "YES" }, { "input": "4 2\n10\n01\n10\n01", "output": "YES" }, { "input": "3 3\n111\n000\n000", "output": "YES" }, { "input": "3 3\n010\n100\n011", "output": "YES" }, { "input": "2 3\n111\n000", "output": "YES" }, { "input": "3 4\n0001\n1101\n1010", "output": "YES" }, { "input": "3 4\n1010\n0101\n1000", "output": "YES" }, { "input": "3 4\n0001\n1101\n0110", "output": "YES" }, { "input": "3 3\n111\n101\n001", "output": "YES" }, { "input": "4 5\n10001\n10010\n01010\n00101", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "YES" }, { "input": "2 3\n100\n111", "output": "YES" }, { "input": "3 10\n1111011100\n0001100011\n1111010101", "output": "YES" }, { "input": "3 4\n0110\n1010\n0101", "output": "YES" }, { "input": "3 3\n100\n001\n011", "output": "YES" }, { "input": "3 3\n100\n010\n001", "output": "NO" }, { "input": "3 3\n010\n100\n001", "output": "NO" }, { "input": "3 5\n10101\n01010\n01010", "output": "YES" }, { "input": "2 6\n111111\n000000", "output": "YES" }, { "input": "3 5\n00000\n10101\n01010", "output": "YES" }, { "input": "4 6\n111000\n100100\n010010\n001001", "output": "YES" } ]
1,527,137,382
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
62
0
a=list(map(int,input().split())) n=a[0] m=a[1] a=[] b=[0 for i in range(m)] for i in range(n): c=list(map(int,list(input()))) a.append(c) for j in range(m): b[j]+=a[i][j] for i in range(m): c=[1 for j in range(m) if b[j]-a[i][j] > 0 ] if(len(c)==m): print("YES") break else: print("NO")
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on. Output Specification: Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. Demo Input: ['4 5\n10101\n01000\n00111\n10000\n', '4 5\n10100\n01000\n00110\n00101\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a=list(map(int,input().split())) n=a[0] m=a[1] a=[] b=[0 for i in range(m)] for i in range(n): c=list(map(int,list(input()))) a.append(c) for j in range(m): b[j]+=a[i][j] for i in range(m): c=[1 for j in range(m) if b[j]-a[i][j] > 0 ] if(len(c)==m): print("YES") break else: print("NO") ```
-1
203
C
Photographer
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*d*<=≤<=109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=104) — the size of one low quality photo and of one high quality photo, correspondingly. Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=105) — the number of low quality photos and high quality photos the *i*-th client wants, correspondingly. All numbers on all lines are separated by single spaces.
On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
[ "3 10\n2 3\n1 4\n2 1\n1 0\n", "3 6\n6 6\n1 1\n1 0\n1 0\n" ]
[ "2\n3 2 ", "1\n2 " ]
none
1,500
[ { "input": "3 10\n2 3\n1 4\n2 1\n1 0", "output": "2\n3 2 " }, { "input": "3 6\n6 6\n1 1\n1 0\n1 0", "output": "1\n2 " }, { "input": "4 5\n6 8\n1 2\n3 0\n10 2\n0 4", "output": "0" }, { "input": "4 10\n6 6\n1 2\n2 2\n0 0\n0 0", "output": "2\n3 4 " }, { "input": "10 10\n1 1\n0 3\n6 4\n3 3\n6 3\n5 2\n6 4\n1 3\n5 5\n2 6\n6 4", "output": "2\n1 7 " }, { "input": "5 5\n1 1\n2 0\n3 2\n4 4\n10 0\n0 1", "output": "2\n5 1 " }, { "input": "4 10\n1 2\n1 0\n0 0\n2 0\n1 3", "output": "4\n2 1 3 4 " }, { "input": "1 22\n3 5\n1 3", "output": "1\n1 " }, { "input": "10 20\n3 5\n3 0\n0 3\n1 2\n1 3\n1 1\n3 0\n0 3\n0 3\n3 1\n3 1", "output": "2\n5 1 " }, { "input": "10 50\n1 1\n7 10\n6 6\n1 0\n2 5\n2 6\n9 7\n3 5\n7 6\n7 10\n7 7", "output": "6\n3 4 5 7 2 8 " }, { "input": "15 30\n13 19\n10 20\n9 0\n11 15\n10 8\n18 3\n13 15\n2 14\n9 16\n8 4\n13 10\n19 2\n13 19\n6 17\n16 4\n15 6", "output": "0" }, { "input": "30 50\n1 3\n2 2\n3 2\n3 3\n0 1\n0 2\n1 3\n1 3\n1 1\n0 1\n0 2\n1 3\n1 0\n1 0\n2 1\n0 1\n0 0\n0 3\n2 3\n2 2\n0 1\n2 3\n2 3\n0 3\n0 3\n3 3\n1 2\n2 1\n1 3\n3 1\n0 3", "output": "13\n16 12 13 4 9 15 20 8 14 27 5 10 29 " }, { "input": "50 50\n6 10\n10 0\n1 9\n8 2\n4 9\n0 7\n2 0\n7 5\n4 8\n10 7\n2 4\n5 6\n6 8\n3 2\n4 6\n7 8\n6 9\n7 7\n7 3\n9 5\n3 10\n7 2\n4 3\n2 0\n6 5\n5 3\n1 7\n1 7\n9 1\n10 4\n10 5\n4 2\n10 10\n0 7\n1 2\n10 1\n1 7\n3 7\n8 7\n5 2\n6 1\n3 1\n4 7\n7 10\n1 5\n10 8\n5 5\n5 1\n3 3\n1 6\n2 1", "output": "3\n6 23 50 " }, { "input": "1 100\n6 10\n14 19", "output": "0" }, { "input": "2 160\n6 9\n11 9\n6 6", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n50000 50000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 0\n100000 100000", "output": "1\n1 " }, { "input": "1 1000000000\n1 1\n1 1", "output": "1\n1 " }, { "input": "6 1000000000\n9999 10000\n10000 9998\n10000 10000\n10000 10000\n70000 70000\n10000 10000\n10000 10000", "output": "5\n1 2 3 5 6 " }, { "input": "3 10\n1 10\n0 1\n3 0\n3 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n0 100000\n100000 100000", "output": "1\n1 " }, { "input": "3 3\n1 1\n3 0\n1 0\n1 0", "output": "2\n2 3 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n50000 50000", "output": "1\n2 " }, { "input": "2 1000000000\n10000 10000\n0 90000\n100000 100000", "output": "1\n1 " }, { "input": "3 1000000000\n10000 10000\n100000 0\n100000 100000\n0 0", "output": "2\n3 1 " }, { "input": "2 1000000000\n10000 10000\n10000 10000\n100000 100000", "output": "1\n1 " }, { "input": "2 1000000000\n10000 10000\n100000 100000\n100000 0", "output": "1\n2 " }, { "input": "3 1000000000\n10000 10000\n99999 0\n100000 100000\n100000 100000", "output": "1\n1 " } ]
1,446,284,366
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
16
2,000
15,462,400
class Pair: def __init__(self,sumOfNumber,index): self.sumOfNumber=sumOfNumber self.index=index def __lt__(self, other): return self.sumOfNumber < other.sumOfNumber n,d=map(int,input().split()) a,b=map(int,input().split()) s=[None]*n for i in range(n): x,y=map(int,input().split()) cur=Pair(0,0) cur.sumOfNumber=(a*x)+(b*y) cur.index=i+1 s[i]=cur s.sort() cur=0 while cur<n and d-s[cur].sumOfNumber >= 0: d-=s[cur].sumOfNumber cur+=1 print(cur) for i in range(cur): print(s[i].index,end=" ")
Title: Photographer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is *d* megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes *a* megabytes of memory, one high quality photo take *b* megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the *i*-th client asks to make *x**i* low quality photos and *y**i* high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the *i*-th client, Valera needs to give him everything he wants, that is, to make *x**i* low quality photos and *y**i* high quality photos. To make one low quality photo, the camera must have at least *a* megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least *b* megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients. Input Specification: The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*d*<=≤<=109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=104) — the size of one low quality photo and of one high quality photo, correspondingly. Next *n* lines describe the clients. The *i*-th line contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=105) — the number of low quality photos and high quality photos the *i*-th client wants, correspondingly. All numbers on all lines are separated by single spaces. Output Specification: On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data. Demo Input: ['3 10\n2 3\n1 4\n2 1\n1 0\n', '3 6\n6 6\n1 1\n1 0\n1 0\n'] Demo Output: ['2\n3 2 ', '1\n2 '] Note: none
```python class Pair: def __init__(self,sumOfNumber,index): self.sumOfNumber=sumOfNumber self.index=index def __lt__(self, other): return self.sumOfNumber < other.sumOfNumber n,d=map(int,input().split()) a,b=map(int,input().split()) s=[None]*n for i in range(n): x,y=map(int,input().split()) cur=Pair(0,0) cur.sumOfNumber=(a*x)+(b*y) cur.index=i+1 s[i]=cur s.sort() cur=0 while cur<n and d-s[cur].sumOfNumber >= 0: d-=s[cur].sumOfNumber cur+=1 print(cur) for i in range(cur): print(s[i].index,end=" ") ```
0
628
A
Tennis Tournament
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement.
Print two integers *x* and *y* — the number of bottles and towels need for the tournament.
[ "5 2 3\n", "8 2 4\n" ]
[ "20 15\n", "35 32\n" ]
In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
0
[ { "input": "5 2 3", "output": "20 15" }, { "input": "8 2 4", "output": "35 32" }, { "input": "10 1 500", "output": "27 5000" }, { "input": "20 500 1", "output": "19019 20" }, { "input": "100 123 99", "output": "24453 9900" }, { "input": "500 1 1", "output": "1497 500" }, { "input": "500 500 500", "output": "499499 250000" }, { "input": "500 237 474", "output": "237025 237000" }, { "input": "1 2 3", "output": "0 3" }, { "input": "1 2 133", "output": "0 133" }, { "input": "1 2 100", "output": "0 100" }, { "input": "1 3 4", "output": "0 4" }, { "input": "1 10 15", "output": "0 15" }, { "input": "1 1 1", "output": "0 1" }, { "input": "1 2 5", "output": "0 5" }, { "input": "1 500 500", "output": "0 500" }, { "input": "1 3 8", "output": "0 8" }, { "input": "10 10 10", "output": "189 100" }, { "input": "1 3 5", "output": "0 5" }, { "input": "1 2 1", "output": "0 1" }, { "input": "1 2 4", "output": "0 4" }, { "input": "1 10 10", "output": "0 10" }, { "input": "1 345 345", "output": "0 345" }, { "input": "7 12 13", "output": "150 91" }, { "input": "1 500 1", "output": "0 1" }, { "input": "1 12 13", "output": "0 13" }, { "input": "1 500 499", "output": "0 499" }, { "input": "1 100 90", "output": "0 90" }, { "input": "2 100 90", "output": "201 180" }, { "input": "53 1 1", "output": "156 53" }, { "input": "73 73 73", "output": "10584 5329" }, { "input": "67 1 1", "output": "198 67" }, { "input": "63 1 1", "output": "186 63" }, { "input": "59 1 1", "output": "174 59" }, { "input": "57 1 1", "output": "168 57" }, { "input": "13 1 1", "output": "36 13" }, { "input": "349 2 5", "output": "1740 1745" }, { "input": "456 456 456", "output": "415415 207936" } ]
1,455,904,238
2,147,483,647
PyPy 3
OK
TESTS
38
108
0
n,b,p = map(int,input().split()) print((n-1)*(2*b+1),n*p)
Title: Tennis Tournament Time Limit: None seconds Memory Limit: None megabytes Problem Description: A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, *m* is the number of the participants of the current round): - let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes. Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament. Find the number of bottles and towels needed for the tournament. Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). Input Specification: The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. Output Specification: Print two integers *x* and *y* — the number of bottles and towels need for the tournament. Demo Input: ['5 2 3\n', '8 2 4\n'] Demo Output: ['20 15\n', '35 32\n'] Note: In the first example will be three rounds: 1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water. In the second example no participant will move on to some round directly.
```python n,b,p = map(int,input().split()) print((n-1)*(2*b+1),n*p) ```
3
570
A
Elections
PROGRAMMING
1,100
[ "implementation" ]
null
null
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections.
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*. It is guaranteed that the total number of people in all the cities does not exceed 109.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
[ "3 3\n1 2 3\n2 3 1\n1 2 1\n", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n" ]
[ "2", "1" ]
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
500
[ { "input": "3 3\n1 2 3\n2 3 1\n1 2 1", "output": "2" }, { "input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7", "output": "1" }, { "input": "1 3\n5\n3\n2", "output": "1" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "3 1\n100 100 100", "output": "1" }, { "input": "2 2\n1 2\n2 1", "output": "1" }, { "input": "2 2\n2 1\n2 1", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "3 3\n0 0 0\n1 1 1\n2 2 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9", "output": "5" }, { "input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0", "output": "1" }, { "input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0", "output": "1" }, { "input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100", "output": "1" }, { "input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10", "output": "1" }, { "input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "1" }, { "input": "100 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", "output": "1" }, { "input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892", "output": "1" }, { "input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718", "output": "54" }, { "input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738", "output": "1" }, { "input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346", "output": "34" }, { "input": "100 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 2", "output": "100" }, { "input": "1 1\n0", "output": "1" }, { "input": "2 1\n0 0", "output": "1" }, { "input": "2 2\n0 0\n0 0", "output": "1" }, { "input": "2 2\n1 2\n0 0", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 3\n0 0\n0 0\n0 1", "output": "1" }, { "input": "3 2\n1 1 3\n0 0 0", "output": "1" }, { "input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0", "output": "1" }, { "input": "2 4\n2 1\n1 2\n0 0\n1 2", "output": "1" }, { "input": "2 2\n0 1\n0 1", "output": "2" }, { "input": "2 3\n1 2\n0 0\n2 1", "output": "1" }, { "input": "2 2\n0 0\n4 5", "output": "1" }, { "input": "3 2\n10 15 20\n0 0 0", "output": "1" }, { "input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3", "output": "1" }, { "input": "3 3\n0 0 0\n0 0 0\n0 0 1", "output": "1" }, { "input": "3 3\n0 0 0\n1 2 3\n1 3 2", "output": "1" }, { "input": "3 1\n0 0 0", "output": "1" }, { "input": "3 3\n0 0 1\n0 0 0\n0 0 0", "output": "1" } ]
1,640,247,833
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
n,m=[int(x) for x in input().split()] a=[0]*n mmax,ppos=0,-1 for i in range(m): b=[int(x) for x in input().split()] a[b.index(max(b))]+=1 if a[b.index(max(b))]>mmax: mmax=a[b.index(max(b))] ppos=b.index(max(b)) print(ppos+1)
Title: Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input Specification: The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively. Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Specification: Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Demo Input: ['3 3\n1 2 3\n2 3 1\n1 2 1\n', '3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n'] Demo Output: ['2', '1'] Note: Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
```python n,m=[int(x) for x in input().split()] a=[0]*n mmax,ppos=0,-1 for i in range(m): b=[int(x) for x in input().split()] a[b.index(max(b))]+=1 if a[b.index(max(b))]>mmax: mmax=a[b.index(max(b))] ppos=b.index(max(b)) print(ppos+1) ```
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20 1 80", "output": "1 20 40 60 80 100 " }, { "input": "10\n10 8 6 7 5 3 4 2 9 1", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 " }, { "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": "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 100 " }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 1 2 3 4 6 7 7 8 9 " }, { "input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59", "output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 " }, { "input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12", "output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 " }, { "input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84", "output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 " }, { "input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1", "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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 3 3 3 " }, { "input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52", "output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 " }, { "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1", "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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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\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": "1 1 1 1 1 1 1 1 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "100\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": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 " }, { "input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3", "output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 " }, { "input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32", "output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 " }, { "input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41", "output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 " }, { "input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82", "output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 " }, { "input": "100\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 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", "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": "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": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 " }, { "input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 " }, { "input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88", "output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 " }, { "input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 51 100 " }, { "input": "10\n100 90 80 70 60 50 40 30 20 10", "output": "10 20 30 40 50 60 70 80 90 100 " }, { "input": "1\n10", "output": "10 " } ]
1,699,454,502
2,147,483,647
Python 3
OK
TESTS
32
46
0
n=int(input()) a=input().split() for i in range (n) : a[i]=int(a[i]) a.sort(); for i in range (n) : print(a[i],end=' ')
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! Input Specification: The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. Output Specification: Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. Demo Input: ['4\n3 2 1 2\n', '3\n2 3 8\n'] Demo Output: ['1 2 2 3 \n', '2 3 8 \n'] Note: The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
```python n=int(input()) a=input().split() for i in range (n) : a[i]=int(a[i]) a.sort(); for i in range (n) : print(a[i],end=' ') ```
3
553
A
Kyoya and Colored Balls
PROGRAMMING
1,500
[ "combinatorics", "dp", "math" ]
null
null
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i*<=+<=1 for all *i* from 1 to *k*<=-<=1. Now he wonders how many different ways this can happen.
The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors. Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000). The total number of balls doesn't exceed 1000.
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007.
[ "3\n2\n2\n1\n", "4\n1\n2\n3\n4\n" ]
[ "3\n", "1680\n" ]
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
250
[ { "input": "3\n2\n2\n1", "output": "3" }, { "input": "4\n1\n2\n3\n4", "output": "1680" }, { "input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "12520708" }, { "input": "5\n10\n10\n10\n10\n10", "output": "425711769" }, { "input": "11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2", "output": "902382672" }, { "input": "1\n1", "output": "1" }, { "input": "13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76", "output": "232242896" }, { "input": "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33", "output": "362689152" }, { "input": "47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n21\n25\n28\n24\n21\n21\n17\n28\n20\n20\n31\n19", "output": "295545118" }, { "input": "3\n343\n317\n337", "output": "691446102" }, { "input": "1\n5", "output": "1" } ]
1,670,374,283
2,147,483,647
Python 3
OK
TESTS
27
46
0
from math import comb dec=10**9 + 7 k =int(input()) color_counts = [0] * k for i in range(0, k): color_counts[i] = int(input()) result = 1 curr = color_counts[0] for i in range(1,k): result = result * comb(curr + color_counts[i] - 1 , color_counts[i] - 1) % dec curr = curr + color_counts[i] print(result)
Title: Kyoya and Colored Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i*<=+<=1 for all *i* from 1 to *k*<=-<=1. Now he wonders how many different ways this can happen. Input Specification: The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors. Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000). The total number of balls doesn't exceed 1000. Output Specification: A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. Demo Input: ['3\n2\n2\n1\n', '4\n1\n2\n3\n4\n'] Demo Output: ['3\n', '1680\n'] Note: In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
```python from math import comb dec=10**9 + 7 k =int(input()) color_counts = [0] * k for i in range(0, k): color_counts[i] = int(input()) result = 1 curr = color_counts[0] for i in range(1,k): result = result * comb(curr + color_counts[i] - 1 , color_counts[i] - 1) % dec curr = curr + color_counts[i] print(result) ```
3
768
A
Oath of the Night's Watch
PROGRAMMING
900
[ "constructive algorithms", "sortings" ]
null
null
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath. With that begins the watch of Jon Snow. He is assigned the task to support the stewards. This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him. Can you find how many stewards will Jon support?
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow. Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output a single integer representing the number of stewards which Jon will feed.
[ "2\n1 5\n", "3\n1 2 5\n" ]
[ "0", "1" ]
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5. In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
500
[ { "input": "2\n1 5", "output": "0" }, { "input": "3\n1 2 5", "output": "1" }, { "input": "4\n1 2 3 4", "output": "2" }, { "input": "8\n7 8 9 4 5 6 1 2", "output": "6" }, { "input": "1\n1", "output": "0" }, { "input": "1\n100", "output": "0" }, { "input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1", "output": "174" }, { "input": "4\n1000000000 99999999 1000000000 1000000000", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "5\n1 1 1 1 1", "output": "0" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "6\n1 1 3 3 2 2", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0" }, { "input": "4\n1 1 2 5", "output": "1" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "5\n1 1 1 1 5", "output": "0" }, { "input": "5\n1 1 2 3 3", "output": "1" }, { "input": "3\n1 1 3", "output": "0" }, { "input": "3\n2 2 3", "output": "0" }, { "input": "1\n6", "output": "0" }, { "input": "5\n1 5 3 5 1", "output": "1" }, { "input": "7\n1 2 2 2 2 2 3", "output": "5" }, { "input": "4\n2 2 2 2", "output": "0" }, { "input": "9\n2 2 2 3 4 5 6 6 6", "output": "3" }, { "input": "10\n1 1 1 2 3 3 3 3 3 3", "output": "1" }, { "input": "6\n1 1 1 1 1 1", "output": "0" }, { "input": "3\n0 0 1", "output": "0" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "3" }, { "input": "3\n1 2 2", "output": "0" }, { "input": "6\n2 2 2 2 2 2", "output": "0" }, { "input": "5\n2 2 2 2 2", "output": "0" }, { "input": "5\n5 5 5 5 5", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "6\n1 2 5 5 5 5", "output": "1" }, { "input": "5\n1 2 3 3 3", "output": "1" }, { "input": "3\n1 1 2", "output": "0" }, { "input": "6\n1 1 1 1 1 2", "output": "0" }, { "input": "5\n1 1 2 4 4", "output": "1" }, { "input": "3\n999999 5999999 9999999", "output": "1" }, { "input": "4\n1 1 5 5", "output": "0" }, { "input": "9\n1 1 1 2 2 2 4 4 4", "output": "3" }, { "input": "5\n1 3 4 5 1", "output": "2" }, { "input": "5\n3 3 3 3 3", "output": "0" }, { "input": "5\n1 1 2 2 2", "output": "0" }, { "input": "5\n2 1 1 1 3", "output": "1" }, { "input": "5\n0 0 0 1 2", "output": "1" }, { "input": "4\n2 2 2 3", "output": "0" }, { "input": "7\n1 1 1 1 5 5 5", "output": "0" }, { "input": "5\n1 2 3 4 4", "output": "2" }, { "input": "2\n5 4", "output": "0" }, { "input": "4\n5 5 5 5", "output": "0" }, { "input": "5\n1 1 1 5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "1\n3", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "4\n1 2 2 2", "output": "0" }, { "input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998", "output": "3" }, { "input": "5\n1 1 3 4 4", "output": "1" }, { "input": "6\n1 1 2 2 3 3", "output": "2" }, { "input": "4\n1 1 1 1", "output": "0" }, { "input": "9\n1 2 3 4 1 5 6 7 8", "output": "6" }, { "input": "8\n5 4 4 6 6 4 4 3", "output": "5" }, { "input": "8\n4 3 3 3 3 3 3 3", "output": "0" }, { "input": "7\n4 3 3 3 3 3 3", "output": "0" }, { "input": "6\n4 3 3 3 3 3", "output": "0" }, { "input": "5\n4 3 3 3 3", "output": "0" } ]
1,659,488,186
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
13
109
8,396,800
# ridiculous n = int(input()) a = sorted(list(map(int,input().split()))) print(n - a.count(a[0]) - a.count(a[-1])) # bruh, wtf, runtime error # @ isn't looking at your submission it cheating, what? # You won't be able to see the tests before the contest ends, but if you've done the problem in practice you can see tests by clicking on the number of your ...
Title: Oath of the Night's Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath. With that begins the watch of Jon Snow. He is assigned the task to support the stewards. This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him. Can you find how many stewards will Jon support? Input Specification: First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow. Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. Output Specification: Output a single integer representing the number of stewards which Jon will feed. Demo Input: ['2\n1 5\n', '3\n1 2 5\n'] Demo Output: ['0', '1'] Note: In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5. In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.
```python # ridiculous n = int(input()) a = sorted(list(map(int,input().split()))) print(n - a.count(a[0]) - a.count(a[-1])) # bruh, wtf, runtime error # @ isn't looking at your submission it cheating, what? # You won't be able to see the tests before the contest ends, but if you've done the problem in practice you can see tests by clicking on the number of your ... ```
0
812
B
Sagheer, the Hausmeister
PROGRAMMING
1,600
[ "bitmasks", "brute force", "dp" ]
null
null
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.
Print a single integer — the minimum total time needed to turn off all the lights.
[ "2 2\n0010\n0100\n", "3 4\n001000\n000010\n000010\n", "4 3\n01110\n01110\n01110\n01110\n" ]
[ "5\n", "12\n", "18\n" ]
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
1,000
[ { "input": "2 2\n0010\n0100", "output": "5" }, { "input": "3 4\n001000\n000010\n000010", "output": "12" }, { "input": "4 3\n01110\n01110\n01110\n01110", "output": "18" }, { "input": "3 2\n0000\n0100\n0100", "output": "4" }, { "input": "1 89\n0000000000000000000000000000000100000000000000010000000000010000000000000000000000000000000", "output": "59" }, { "input": "2 73\n000000000000000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000100000010000000000000000000000000000", "output": "46" }, { "input": "3 61\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "4 53\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "5 93\n00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000001010\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000010000000000000000000100000000000000000000000000000000000000000000\n00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", "output": "265" }, { "input": "6 77\n0000000000000000100000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000010000000000000\n0000000000010000000000000000000000000000000000000000000000000000000000000000010\n0000000000000000000001000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000100000000000000000000000000000", "output": "311" }, { "input": "7 65\n0000000001000000000000000010000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000001000001000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000", "output": "62" }, { "input": "8 57\n00000000100000000000000000000000000000000000000000000000000\n00000000000000010000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000010000000000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000001000000000", "output": "277" }, { "input": "12 13\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n010000000000000\n000000000000000\n000000000000000\n000000000000000\n000010000000000\n000000000000000", "output": "14" }, { "input": "13 1\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000", "output": "0" }, { "input": "1 33\n00000100101110001101000000110100010", "output": "33" }, { "input": "2 21\n00100110100010010010010\n01000001111001010000000", "output": "43" }, { "input": "3 5\n0001010\n0100000\n0100000", "output": "11" }, { "input": "4 45\n00010000101101100000101101000000100000001101100\n01110000100111010011000000100000000001000001100\n00000000001000100110100001000010011010001010010\n01111110100100000101101010011000100100001000000", "output": "184" }, { "input": "5 37\n010100000000000000000110000110010000010\n001101100010110011101000001010101101110\n010000001000100010010100000000001010000\n000000000100101000000101100001000001110\n000010000000000000100001001000011100110", "output": "193" }, { "input": "6 25\n011001000100111010000101000\n000000000010000010001000010\n011001100001100001001001010\n000000100000010000000000110\n010001100001000001000000010\n011000001001010111110000100", "output": "160" }, { "input": "7 61\n010000111100010100001000011010100001000000000011100000100010000\n000010011000001000000100110101010001000000010001100000100100100\n000010001000001000000100001000000100100011001110000111000000100\n000000000101000011010000011000000101000001011001000011101010010\n000010010011000000100000110000001000000101000000101000010000010\n000010010101101100100100100011001011101010000101000010000101010\n000100001100001001000000001000000001011000110010100000000010110", "output": "436" }, { "input": "8 49\n000100100000000111110010011100110100010010000011000\n001000000101111000000001111100010010100000010000000\n000000010000011100001000000000101000110010000100100\n000000000001000110000011101101000000100000101010000\n000000110001000101101000000001000000110001000110000\n000100000000000000100100010011000001111101010100110\n000000001000000010101111000100001100000000010111000\n001000010000110000011100000000100110000010001000000", "output": "404" }, { "input": "9 41\n0011000000000101001101001000000001110000010\n0000110000001010110010110010110010010001000\n0001100010100000000001110100100001101000100\n0001010101111010000000010010001001011111000\n0101000101000011101011000000001100110010000\n0001010000000000000001011000000100010101000\n0000010011000000001000110001000010110001000\n0000100010000110100001000000100010001111100\n0000001110100001000001000110001110000100000", "output": "385" }, { "input": "10 29\n0000000000101001100001001011000\n0001110100000000000000100010000\n0010001001000011000100010001000\n0001000010101000000010100010100\n0111000000000000100100100010100\n0001000100011111000100010100000\n0000000000000001000001001011000\n0000101110000001010001011001110\n0000001000101010011000001100100\n0100010000101011010000000000000", "output": "299" }, { "input": "1 57\n00011101100001110001111000000100101111000111101100111001000", "output": "55" }, { "input": "2 32\n0011110111011011011101111101011110\n0111000110111111011110011101011110", "output": "65" }, { "input": "3 20\n0110011111110101101100\n0111110000111010100100\n0110111110010100011110", "output": "63" }, { "input": "4 4\n011100\n001010\n010000\n011110", "output": "22" }, { "input": "5 44\n0001010010001111111001111111000010100100000010\n0001111001111001101111011111010110001001111110\n0111111010111111011101100011101010100101110110\n0011010011101011101111001001010110000111111100\n0110100111011100110101110010010011011101100100", "output": "228" }, { "input": "6 36\n01110101111111110101011000011111110010\n00011101100010110111111111110001100100\n00001111110010111111101110101110111110\n00110110011100100111011110000000000010\n01100101101001010001011111100111101100\n00011111111011001000011001011110011110", "output": "226" }, { "input": "7 24\n01111001111001011010010100\n00111011010101000111101000\n01001110110010010110011110\n00000101111011011111111000\n01111111101111001001010010\n01110000111101011111111010\n00000100011100110000110000", "output": "179" }, { "input": "8 8\n0011101110\n0110010100\n0100111110\n0111111100\n0011010100\n0001101110\n0111100000\n0110111000", "output": "77" }, { "input": "9 48\n00011010111110111011111001111111111101001111110010\n01000101000101101101111110111101011100001011010010\n00110111110110101110101110111111011011101111011000\n00110111111100010110110110111001001111011010101110\n01111111100101010011111100100111110011001101110100\n01111011110011111101010101010100001110111111111000\n01110101101101110001000010110100010110101111111100\n00111101001010110010110100000111110101010100001000\n00011011010110011111001100111100100011100110110100", "output": "448" }, { "input": "10 40\n010011001001111011011011101111010001010010\n011000000110000010001011111010100000110000\n011010101001110010110110011111010101101000\n000111111010101111000110011111011011011010\n010110101110001001001111111000110011101010\n010011010100111110010100100111100111011110\n001111101100111111111111001010111010000110\n001111110010101100110100101110001011100110\n010111010010001111110101111111111110111000\n011101101111000100111111111001111100111010", "output": "418" }, { "input": "11 28\n011100111101101001011111001110\n010001111110011101101011001000\n001010011011011010101101101100\n001100011001101011011001110100\n010111110011101110000110111100\n010010001111110000011111010100\n001011111111110011101101111010\n001101101011100100011011001110\n001111110110100110101011000010\n000101101011100001101101100100\n010011101101111011100111110100", "output": "328" }, { "input": "1 68\n0101111110111111111111111111110111111111111111111110111111101111111110", "output": "68" }, { "input": "2 56\n0011111111111110111111111111111111011111111111011111011110\n0111111111010111111111110111111111111110111111010111111110", "output": "113" }, { "input": "3 17\n0111111101111111110\n0111111111101011110\n0101111111111111110", "output": "55" }, { "input": "4 4\n011110\n010110\n010110\n011110", "output": "22" }, { "input": "5 89\n0011111111111101110110111111111101111011111011101110111111111111111111111111111111111111110\n0111111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n0111111111111011111111111111111111101111011111111111111111110110111101111111111111111011010\n0111111111111111011011111111111011111111111111111111111111111111111111111111111110111111010\n0111111101111011111110101011111111110111100100101111111011111111111111011011101111111111110", "output": "453" }, { "input": "6 77\n0111111110101011111111111111111111111111111111111111100111111111101111111111110\n0111111111111111111101111101111111111011111111011111111001011111111111101111110\n0111101111111111111111111111111111111110110011111111111011111111101111111111110\n0111110111111111111111111111111111111111111111111111011011111111111111111111110\n0101111110111111111111111111111111111111111011111111111111111111101111011011110\n0110111111101111110111111111111011111111101011111101111111111111111111110111100", "output": "472" }, { "input": "7 20\n0111111111111111111100\n0111110111111111111110\n0111111111111111111100\n0111111011111111111110\n0111111111111011101110\n0111101011110111111010\n0111111111111111111010", "output": "151" }, { "input": "8 8\n0111111110\n0111101110\n0111111110\n0111111110\n0111111110\n0110111100\n0101111110\n0110111110", "output": "78" }, { "input": "11 24\n01111111111101111111111110\n01111111111111111111111110\n01110111111111111111111110\n01111111111111111111011110\n01111111111111111110111110\n01111010111111100111101110\n01111111111111010101111100\n01111111111111110111111110\n01011101111111111101111110\n00111111011111111110111110\n01111111101111111101111110", "output": "284" }, { "input": "12 12\n01111111111000\n01101111110110\n01111110111110\n01111111111110\n01111111111010\n01011111110110\n01111111111110\n01101101011110\n01111111111110\n01111101011110\n00111111111110\n01111111011110", "output": "166" }, { "input": "15 28\n011111111101011111111101111110\n011111111111111111111111111110\n011101110111011011101111011110\n011111111011111011110111111110\n011111111110101111111111111110\n011111011111110011111111011010\n011110111111001101111111111110\n011111111110111111111011111110\n011111111111111111111111011110\n011111011111111111111011001010\n011111111101111111111101111110\n011111111110111111101111011110\n010111111111101111111111111110\n011111111111111111011111111110\n011011111111111110110111110110", "output": "448" }, { "input": "2 11\n0100000000000\n0000000010000", "output": "18" }, { "input": "1 100\n010010010011100001101101110111101010000101010001111001001101011110000011101110101000100111111001101110", "output": "100" }, { "input": "15 1\n010\n010\n010\n010\n010\n010\n000\n000\n000\n010\n000\n010\n000\n000\n000", "output": "29" }, { "input": "3 3\n00010\n00000\n00010", "output": "7" } ]
1,579,170,756
2,147,483,647
PyPy 3
OK
TESTS
72
155
1,228,800
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n,m=map(int,input().strip().split()) a=[] L=[] R=[] t={} for i in range(n): b=input() a.append(b) L.append(9000000) R.append(0) t[i]=0 a.reverse() for i in range(n): for j in range(m+2): if a[i][j]=='1': L[i]=min(L[i],j) R[i]=max(R[i],j) t[i]=1 L1=0 R1=9000000 ans=0 for i in range(n): if t[i]==0: L1+=1 R1+=1 continue ans=min(L1+R[i],R1+m+1-L[i]) L2=min(L1+R[i]*2+1,R1+m+2) R2=min(R1+(m+1-L[i])*2+1,m+2+L1) L1=L2 R1=R2 print(ans)
Title: Sagheer, the Hausmeister Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0. Output Specification: Print a single integer — the minimum total time needed to turn off all the lights. Demo Input: ['2 2\n0010\n0100\n', '3 4\n001000\n000010\n000010\n', '4 3\n01110\n01110\n01110\n01110\n'] Demo Output: ['5\n', '12\n', '18\n'] Note: In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- n,m=map(int,input().strip().split()) a=[] L=[] R=[] t={} for i in range(n): b=input() a.append(b) L.append(9000000) R.append(0) t[i]=0 a.reverse() for i in range(n): for j in range(m+2): if a[i][j]=='1': L[i]=min(L[i],j) R[i]=max(R[i],j) t[i]=1 L1=0 R1=9000000 ans=0 for i in range(n): if t[i]==0: L1+=1 R1+=1 continue ans=min(L1+R[i],R1+m+1-L[i]) L2=min(L1+R[i]*2+1,R1+m+2) R2=min(R1+(m+1-L[i])*2+1,m+2+L1) L1=L2 R1=R2 print(ans) ```
3
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii".
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { "input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "output": "0" }, { "input": "3\nxxx", "output": "1" }, { "input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz", "output": "0" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx", "output": "41" }, { "input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc", "output": "49" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx", "output": "41" }, { "input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "5\nfcyju", "output": "0" }, { "input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx", "output": "2" } ]
1,699,200,292
2,147,483,647
Python 3
OK
TESTS
13
31
0
n = int(input()) file_name = input() count_x,removals = 0,0 for i in range(n): if file_name[i] == 'x': count_x += 1 if count_x >= 3:removals += 1 else:count_x = 0 print(removals)
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". Input Specification: The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. Output Specification: Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Demo Input: ['6\nxxxiii\n', '5\nxxoxx\n', '10\nxxxxxxxxxx\n'] Demo Output: ['1\n', '0\n', '8\n'] Note: In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
```python n = int(input()) file_name = input() count_x,removals = 0,0 for i in range(n): if file_name[i] == 'x': count_x += 1 if count_x >= 3:removals += 1 else:count_x = 0 print(removals) ```
3
355
A
Vasya and Digital Root
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist.
The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9).
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes.
[ "4 4\n", "5 1\n", "1 0\n" ]
[ "5881\n", "36172\n", "0\n" ]
For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
500
[ { "input": "4 4", "output": "5881" }, { "input": "5 1", "output": "36172" }, { "input": "1 0", "output": "0" }, { "input": "8 7", "output": "49722154" }, { "input": "487 0", "output": "No solution" }, { "input": "1000 5", "output": "8541939554067890866522280268745476436249986028349767396372181155840878549622667946850256234534972693110974918858266403731194206972478044933297639886527448596769215803533001453375065914421371731616055420973164037664278812596299678416020519508892847037891229851414508562230407367486468987019052183250172396304562086008837592345867873765321840214188417303688776985319268802181355472294386101622570417737061113209187893810568585166094583478900129912239498334853726870963804475563182775380744565964067602555515611220..." }, { "input": "22 9", "output": "1583569962049529809017" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "13 5", "output": "1381199538344" }, { "input": "100 4", "output": "6334594910586850938286642284598905674550356974741186703111536643493065423553455569335256292313330478" }, { "input": "123 6", "output": "928024873067884441426263446866614165147002631091527531801777528825238463822318502518751375671158771476735217071878592158343" }, { "input": "1000 1", "output": "8286301124628812353504240076754144327937426329149605334362213339655339076564408659154706137278060590992944494591503606137350736487608756923833530346502466262820452589925067370165968733865814927433418675056573256434073937686361155637721866942352171450747045834987797118866710087297111065178077368748085213082452303815796793489599773148508108295035303578345492871662297456131736137780231762177312635688688714815857818196180724774924848693916003108422682889382923194020205691379066085156078824413573001257245677878..." }, { "input": "2 0", "output": "No solution" }, { "input": "734 9", "output": "5509849803670339733829077693143634799621955270111335907079347964026719040571586127009915057683769302171314977999063915868539391500563742827163274052101515706840652002966522709635011152141196057419086708927225560622675363856445980167733179728663010064912099615416068178748694469047950713834326493597331720572208847439692450327661109751421257198843242305082523510866664350537162158359215265173356615680034808012842300294492281197211603826994471586252822908597603049772690875861970190564793056757768783375525854981..." }, { "input": "678 8", "output": "3301967993506605598118564082793505826927835671912383741219911930496842130418974223636865915672261642456247377827650506657877850580145623499927271391838907804651235401527392426584047219626357010023552497909436550723659221336486898100975437974320483591226280567200180225706948265372905918038750624429412331582504280650041845010449084641487447573160867860208332424835101416924485616494780952529083292227777966546236453553361466209621076748915774965082618181512654546592160909206650552581723190500273752213154329310..." }, { "input": "955 7", "output": "4875434946733568640983465009954221247849488705968833681097920555785434899849497268074436910608289709905212840964404347113134616236366794383005890642796609027376389191650656756216171636192669456464756898600086886269167613161503734300581107122411830728903919402846291350458047685924037685489537178939190129043010338580479169957795695942333133962326316127076129681213167918954090336000635320714955444899171270809399782177230616239894234246885245402806465700760528496316658100834632585364274381823984214942419830421..." }, { "input": "893 3", "output": "3154491812688062338683413382839715419754844054478504300541293341098785797116419835470049101334759365561276155814822131363018164033585874216523127145546903121862283071300185033613164338905028463571111541628115658108609505120357131336651371062955497690723492519748325195227665653129911625684144804656937323976632567108677478936761775342496303735237936919652618323430255701996987753367609559178855599470625167628439986055634187527493497208780060336400261449926469512996188738133678473883670714775784527941804249702..." }, { "input": "998 2", "output": "8948712698877635315965401396781625629035528026219922557326466734622505808493494219669540192792500692387387200924494124219975316993592377253517258369463882172533672158172302951620486954085880606055358057621166471042557383036617719864238933843342304818076672889894622975857106353903546493307325157763617269195570831067239463586554245706859061059010215520785892192165179414199200952765077228454366556358805840526959104496983177402562569401945586771345953166346316987259989961516385311376707950154520512125143059966..." }, { "input": "960 6", "output": "7291446744949293530598651243840704118065364362420848463900543089429494124955982767375712583398715647208330285855809398453361266463042342917037983463277320070057956978767965467358862479678812136400444143489366786562672928727263605336304125661306952421127807059398289873947797478996261161224877129724944902005212399176751167053423457968483336961277157597291131065544350665072172392437597673561840137077580044817979332136630042866681837917711758227272499659805765131669208911408670581308412686469802437930679571593..." } ]
1,587,392,158
2,147,483,647
PyPy 3
OK
TESTS
20
140
0
k,d = input().split() k,d = int(k), int(d) if k==1: print(d) elif d!=0: s = '1'*(k-1) m = int(s) m = 9*m + d print(m) else: print("No solution")
Title: Vasya and Digital Root Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. Input Specification: The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). Output Specification: In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. Demo Input: ['4 4\n', '5 1\n', '1 0\n'] Demo Output: ['5881\n', '36172\n', '0\n'] Note: For the first test sample *dr*(5881)  =  *dr*(22)  =  4. For the second test sample *dr*(36172)  =  *dr*(19)  =  *dr*(10)  =  1.
```python k,d = input().split() k,d = int(k), int(d) if k==1: print(d) elif d!=0: s = '1'*(k-1) m = int(s) m = 9*m + d print(m) else: print("No solution") ```
3
687
A
NP-Hard Problem
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
[ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "1\n2 \n2\n1 3 \n", "-1\n" ]
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
500
[ { "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 " }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "-1" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1" }, { "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1" }, { "input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1", "output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 " }, { "input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3", "output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 " }, { "input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1", "output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 " }, { "input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8", "output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 " }, { "input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9", "output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 " }, { "input": "2 1\n1 2", "output": "1\n2 \n1\n1 " }, { "input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10", "output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 " }, { "input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20", "output": "-1" }, { "input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15", "output": "-1" }, { "input": "1000 1\n839 771", "output": "1\n839 \n1\n771 " }, { "input": "1000 1\n195 788", "output": "1\n788 \n1\n195 " }, { "input": "100000 1\n42833 64396", "output": "1\n64396 \n1\n42833 " }, { "input": "100000 1\n26257 21752", "output": "1\n26257 \n1\n21752 " }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "-1" } ]
1,657,204,646
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
14
467
20,582,400
from re import I import sys input = sys.stdin.readline from math import * def mrd(): return [int(x) for x in input().split()] def rd(): return int(input()) MAXN = 2 * 10**5 + 5 INF = 10**16 * 2 mod = 10**9 + 7 #----------------------------------------------------------------------------------# def solve(): n,m = mrd() adj = [[] for _ in range(n + 1)] for _ in range(m): u,v = mrd() adj[u].append(v) adj[v].append(u) col = [0 for _ in range(n + 1)] def chk(u,c): col[u] = c for v in adj[u]: if col[u] == col[v]: return False if not col[v] and not chk(v,3 - c): return False return True for i in range(1,n + 1): if not col[i]: if not chk(i,1): print(-1) return def wr(c): ans = [i for i in range(1,n + 1) if col[i] == c] print(len(ans)) for x in ans: print(x,end=" ") print("") wr(1) wr(2) if __name__ == "__main__": solve()
Title: NP-Hard Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. Output Specification: If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. Demo Input: ['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n'] Demo Output: ['1\n2 \n2\n1 3 \n', '-1\n'] Note: In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
```python from re import I import sys input = sys.stdin.readline from math import * def mrd(): return [int(x) for x in input().split()] def rd(): return int(input()) MAXN = 2 * 10**5 + 5 INF = 10**16 * 2 mod = 10**9 + 7 #----------------------------------------------------------------------------------# def solve(): n,m = mrd() adj = [[] for _ in range(n + 1)] for _ in range(m): u,v = mrd() adj[u].append(v) adj[v].append(u) col = [0 for _ in range(n + 1)] def chk(u,c): col[u] = c for v in adj[u]: if col[u] == col[v]: return False if not col[v] and not chk(v,3 - c): return False return True for i in range(1,n + 1): if not col[i]: if not chk(i,1): print(-1) return def wr(c): ans = [i for i in range(1,n + 1) if col[i] == c] print(len(ans)) for x in ans: print(x,end=" ") print("") wr(1) wr(2) if __name__ == "__main__": solve() ```
-1
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,678,493,057
2,147,483,647
Python 3
OK
TESTS
20
46
0
inp = input() inp = inp.split() for i in range(3): inp[i] = int(inp[i]) D1 = inp[0]/inp[2] if D1 > int(D1): D1 = int(D1)+1 else: D1 = int(D1) D2 = inp[1]/inp[2] if D2 > int(D2): D2 = int(D2)+1 else: D2 = int(D2) num_b = D1*D2 print(num_b)
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 inp = input() inp = inp.split() for i in range(3): inp[i] = int(inp[i]) D1 = inp[0]/inp[2] if D1 > int(D1): D1 = int(D1)+1 else: D1 = int(D1) D2 = inp[1]/inp[2] if D2 > int(D2): D2 = int(D2)+1 else: D2 = int(D2) num_b = D1*D2 print(num_b) ```
3.977
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,693,639,838
2,147,483,647
Python 3
OK
TESTS
32
46
0
n, l = map(int, input().split()) lanterns = list(map(int, input().split())) lanterns.sort() max_gap = 0 for i in range(1, n): max_gap = max(max_gap, lanterns[i] - lanterns[i - 1]) radius = max(max(lanterns[0], l - lanterns[-1]), max_gap / 2) print("{:.10f}".format(radius))
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python n, l = map(int, input().split()) lanterns = list(map(int, input().split())) lanterns.sort() max_gap = 0 for i in range(1, n): max_gap = max(max_gap, lanterns[i] - lanterns[i - 1]) radius = max(max(lanterns[0], l - lanterns[-1]), max_gap / 2) print("{:.10f}".format(radius)) ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,679,140,462
2,147,483,647
PyPy 3
OK
TESTS
96
935
4,608,000
n, k = map(int, input().split()) div = set() for i in range(1, int(n**0.5)+1): if n%i == 0: div.add(i) div.add(n//i) if len(div) >= k: div = sorted(div) print(div[k-1]) else: print("-1")
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python n, k = map(int, input().split()) div = set() for i in range(1, int(n**0.5)+1): if n%i == 0: div.add(i) div.add(n//i) if len(div) >= k: div = sorted(div) print(div[k-1]) else: print("-1") ```
3
597
B
Restaurant
PROGRAMMING
1,600
[ "dp", "greedy", "sortings" ]
null
null
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept? No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109).
Print the maximal number of orders that can be accepted.
[ "2\n7 11\n4 7\n", "5\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n" ]
[ "1\n", "3\n", "2\n" ]
none
1,000
[ { "input": "2\n7 11\n4 7", "output": "1" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "3" }, { "input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8", "output": "2" }, { "input": "1\n1 1", "output": "1" }, { "input": "2\n4 6\n4 8", "output": "1" }, { "input": "3\n22 22\n14 21\n9 25", "output": "2" }, { "input": "4\n20 59\n30 62\n29 45\n29 32", "output": "1" }, { "input": "5\n40 124\n40 117\n67 106\n36 121\n38 102", "output": "1" }, { "input": "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179", "output": "2" }, { "input": "7\n94 113\n54 248\n64 325\n280 306\n62 328\n49 341\n90 324", "output": "2" }, { "input": "8\n116 416\n104 472\n84 476\n100 486\n199 329\n169 444\n171 487\n134 441", "output": "1" }, { "input": "9\n90 667\n366 539\n155 462\n266 458\n323 574\n101 298\n90 135\n641 661\n122 472", "output": "3" }, { "input": "10\n195 443\n229 602\n200 948\n229 876\n228 904\n296 656\n189 818\n611 626\n215 714\n403 937", "output": "2" }, { "input": "1\n28 74", "output": "1" }, { "input": "2\n28 92\n2 59", "output": "1" }, { "input": "3\n5 92\n1 100\n39 91", "output": "1" }, { "input": "4\n4 92\n29 43\n13 73\n10 79", "output": "1" }, { "input": "5\n64 86\n61 61\n46 54\n83 94\n19 46", "output": "3" }, { "input": "6\n80 84\n21 24\n44 80\n14 53\n5 10\n61 74", "output": "4" }, { "input": "7\n32 92\n32 86\n13 25\n45 75\n16 65\n1 99\n17 98", "output": "2" }, { "input": "8\n3 59\n22 94\n26 97\n18 85\n7 84\n1 100\n4 100\n26 93", "output": "1" }, { "input": "9\n11 90\n8 95\n62 95\n43 96\n16 84\n3 70\n23 93\n4 96\n11 86", "output": "1" }, { "input": "10\n30 45\n5 8\n51 83\n37 52\n49 75\n28 92\n94 99\n4 13\n61 83\n36 96", "output": "4" }, { "input": "11\n38 92\n16 85\n32 43\n65 84\n63 100\n21 45\n13 92\n29 58\n56 94\n18 83\n50 81", "output": "2" }, { "input": "12\n66 78\n41 97\n55 69\n55 61\n36 64\n14 97\n96 99\n28 58\n44 93\n2 100\n42 88\n1 2", "output": "4" }, { "input": "13\n50 85\n38 65\n5 51\n50 96\n4 92\n23 94\n2 99\n2 84\n1 98\n2 100\n12 100\n21 97\n7 84", "output": "1" }, { "input": "14\n17 92\n7 96\n49 96\n10 99\n7 98\n12 85\n10 52\n2 99\n23 75\n4 98\n7 100\n2 69\n6 99\n20 87", "output": "1" }, { "input": "15\n1 58\n15 21\n53 55\n59 90\n68 71\n29 51\n52 81\n32 52\n38 44\n57 59\n47 60\n27 32\n49 86\n26 94\n44 45", "output": "6" }, { "input": "16\n4 80\n16 46\n15 16\n60 63\n8 54\n18 49\n67 99\n72 80\n1 8\n19 64\n1 54\n46 94\n2 89\n67 78\n21 47\n5 29", "output": "5" }, { "input": "17\n34 42\n31 84\n8 96\n63 88\n11 99\n80 99\n1 96\n11 12\n27 28\n4 30\n1 79\n16 86\n15 86\n13 80\n3 98\n37 89\n59 88", "output": "4" }, { "input": "18\n11 94\n12 85\n25 90\n7 61\n63 88\n6 87\n49 88\n16 76\n12 78\n61 84\n3 84\n20 91\n1 84\n17 100\n43 80\n8 86\n9 98\n35 97", "output": "2" }, { "input": "19\n24 63\n23 86\n5 89\n10 83\n31 92\n8 96\n21 63\n1 83\n2 100\n5 96\n18 98\n9 77\n11 91\n44 95\n1 98\n22 60\n5 98\n22 91\n1 96", "output": "1" }, { "input": "20\n22 77\n13 50\n55 64\n16 52\n67 96\n49 51\n59 95\n2 25\n69 91\n2 24\n4 46\n50 74\n45 63\n39 55\n31 33\n9 33\n6 72\n14 67\n56 98\n69 94", "output": "5" }, { "input": "1\n1 1000000000", "output": "1" }, { "input": "4\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000", "output": "1" }, { "input": "2\n1000000000 1000000000\n1 1", "output": "2" }, { "input": "4\n1 10000\n2 3\n4 5\n6 7", "output": "3" }, { "input": "3\n1 10\n2 4\n6 8", "output": "2" }, { "input": "2\n1 4\n2 3", "output": "1" }, { "input": "3\n1 100\n2 3\n4 5", "output": "2" }, { "input": "4\n1 10\n2 3\n4 5\n6 7", "output": "3" }, { "input": "3\n1 5\n2 3\n4 4", "output": "2" }, { "input": "3\n1 1000\n1 5\n6 1000", "output": "2" }, { "input": "3\n1 10000\n3 5\n7 8", "output": "2" }, { "input": "4\n1 5\n6 15\n8 10\n11 17", "output": "3" }, { "input": "4\n1 3\n6 800\n7 9\n10 11", "output": "3" }, { "input": "5\n1 10\n2 3\n4 5\n6 7\n8 9", "output": "4" }, { "input": "3\n1 5\n1 3\n4 6", "output": "2" }, { "input": "3\n1 10\n2 3\n4 5", "output": "2" }, { "input": "2\n1 3\n2 4", "output": "1" } ]
1,600,145,559
2,147,483,647
Python 3
OK
TESTS
70
2,324
40,857,600
n=int(input()) lis=[] for i in range(n): s,f=map(int,input().split()) lis.append([f,s]) lis.sort() #now we get sorted wrt b and sorted with a aequentially count=1 #count is already 1 maxl=lis[0][0] #taking b as max ,strating with b for i in range(1,len(lis)): if lis[i][1]>maxl: #checking for a count=count+1 maxl=lis[i][0] #updating b print(count)
Title: Restaurant Time Limit: None seconds Memory Limit: None megabytes Problem Description: A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept? No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). Output Specification: Print the maximal number of orders that can be accepted. Demo Input: ['2\n7 11\n4 7\n', '5\n1 2\n2 3\n3 4\n4 5\n5 6\n', '6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n'] Demo Output: ['1\n', '3\n', '2\n'] Note: none
```python n=int(input()) lis=[] for i in range(n): s,f=map(int,input().split()) lis.append([f,s]) lis.sort() #now we get sorted wrt b and sorted with a aequentially count=1 #count is already 1 maxl=lis[0][0] #taking b as max ,strating with b for i in range(1,len(lis)): if lis[i][1]>maxl: #checking for a count=count+1 maxl=lis[i][0] #updating b print(count) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,571,737,924
2,147,483,647
Python 3
OK
TESTS
32
124
0
a,b,c,d,e=map(int,input().split()) sum1=sum2=0 sum1=(2*d)+(b*a) sum2=(c*a)+(2*e) if(sum1<sum2): print("First") elif sum1==sum2: print("Friendship") else: print("Second")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python a,b,c,d,e=map(int,input().split()) sum1=sum2=0 sum1=(2*d)+(b*a) sum2=(c*a)+(2*e) if(sum1<sum2): print("First") elif sum1==sum2: print("Friendship") else: print("Second") ```
3
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,540,764,926
2,147,483,647
Python 3
OK
TESTS
45
124
0
l=int(input()) p=int(input()) q=int(input()) t=1+q/p x=l/t print(x)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python l=int(input()) p=int(input()) q=int(input()) t=1+q/p x=l/t print(x) ```
3
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input": "2\n100 100", "output": "2" }, { "input": "3\n100 100 100", "output": "3" }, { "input": "11\n1 2 3 4 5 6 5 4 3 2 1", "output": "11" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 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 1 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": "61" }, { "input": "100\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 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 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1", "output": "81" }, { "input": "100\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 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 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1", "output": "85" }, { "input": "100\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 1 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 100 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\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 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 100 8 7 6 1 4 3 2 1", "output": "96" }, { "input": "100\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 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 100 10 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\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 45 46 47 48 49 50 51 52 53 54 1 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 100 11 10 9 8 7 6 5 4 3 2 1", "output": "55" }, { "input": "100\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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1", "output": "59" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "86" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 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": "83" }, { "input": "100\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 100 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 1 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": "74" }, { "input": "100\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 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 100 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 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 1 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": "52" }, { "input": "100\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 100 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 1 2 1", "output": "98" }, { "input": "10\n1 4 4 4 4 4 1 2 4 3", "output": "7" } ]
1,587,633,640
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
218
307,200
n=int(input()) a=list(map(int,input().split())) ans=1 low=set() high=set() for i in range(len(a)-1): t=a[i] j=i-1 k=i+1 p=1 while j!=-1 and a[j]<t: j-=1 p+=1 while k!=n and a[k]<t: k+=1 p+=1 ans=max(ans,p) print(ans)
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. Output Specification: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Demo Input: ['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n'] Demo Output: ['1\n', '3\n', '6\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) ans=1 low=set() high=set() for i in range(len(a)-1): t=a[i] j=i-1 k=i+1 p=1 while j!=-1 and a[j]<t: j-=1 p+=1 while k!=n and a[k]<t: k+=1 p+=1 ans=max(ans,p) print(ans) ```
0
716
B
Complete the Word
PROGRAMMING
1,300
[ "greedy", "two pointers" ]
null
null
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.
[ "ABC??FGHIJK???OPQR?TUVWXY?\n", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n", "??????????????????????????\n", "AABCDEFGHIJKLMNOPQRSTUVW??M\n" ]
[ "ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1" ]
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
1,000
[ { "input": "ABC??FGHIJK???OPQR?TUVWXY?", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "output": "-1" }, { "input": "??????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AABCDEFGHIJKLMNOPQRSTUVW??M", "output": "-1" }, { "input": "QWERTYUIOPASDFGHJKL???????", "output": "QWERTYUIOPASDFGHJKLBCMNVXZ" }, { "input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z", "output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ" }, { "input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N", "output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN" }, { "input": "???????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZA" }, { "input": "EJMGJAXCHXYIKZSQKUGRCLSTWDLNCVZIGXGWILAVFBEIGOHWGVEPRJTHWEDQRPOVZUQOSRVTIHFFHJMCLOWGHCIGJBCAAVBJFMJEFTEGFXZFVRZOXAFOFVXRAIZEWIKILFLYDZVDADYWYWYJXAGDFGNZBQKKKTGWPINLCDBZVULROGAKEKXXTWNYKQBMLQMQRUYOWUTWMNTJVGUXENHXWMFWMSBKVNGXSNFFTRTTGEGBBHMFZTKNJQDYUQOXVDWTDHZCCQNYYIOFPMKYQIGEEYBCKBAYVCTWARVMHIENKXKFXNXEFUHUNRQPEDFUBMKNQOYCQHGTLRHLWUAVZJDRBRTSVQHBKRDJFKKYEZAJWJKATRFZLNELPYGFUIWBXLIWVTHUILJHTQKDGRNCFTFELCOQPJDBYSPYJOUDKIFRCKEMJPUXTTAMHVENEVMNTZLUYSUALQOUPPRLZHCYICXAQFFRQZAAJNFKVRJDMDXFTBRJSAAHTSVG", "output": "-1" }, { "input": "SVBWLLLPMPJUQVIGVXPCKMPEBPWMYORVTYELJOQGKEOJVCRBUJOOKQZQBYJIBCSHGSDBTIIMNGAXAQJRHHKQFAJSOJLAYRKWBASMLBQVUPPQWDGAVKDLFHEHVVWGSYQHYCPDIECHBTOIFYUFGKWIIMCKEBLECHCETBQMJPBPPGDHRLJIIMVJBZDRSDWWEJASQFRSCLOBAOLZQDPEZWDLMYTGDLUHCJMTXVURWQFCFDIGSUADTFMNGVHRYHQKWBGWWLQJQSFSWXGWIYUTSBUNZFDONBCFTGWTTQIISXJZUWSZWXXFMNB?UWPOWVWIWMBAPXYMGTRSGWMQRXULCMDTUKZS?CNMBRIYDZCUQWAKYQLLJLTXSVMUAYZHVBZFYBABBECIADQPUPZVVYHTGKOWKDNEUYPBTNUSQLLQRODUXFMSYUYIQGERINAPZWL?VKBVQJQLUJGDPFHNVXXSNOWHBZPMLOXVC?IEUMVLIBYLEATFUTILPPTP", "output": "-1" }, { "input": "DMWSBHPGSJJD?EEV?CYAXQCCGNNQWNN?OMEDD?VC?CTKNQQPYXKKJFAYMJ?FMPXXCLKOL?OTRCE", "output": "-1" }, { "input": "EOYJRKFABJIUOZILSHHCXIFQTXAVXJOVTQCDHXPNYPW?RVRKTB?OVXEL?NQHMZZXJLGSA?OTFSZQBV?SBHGKPJPCIQMLRSYDCFPYMEMXUEVHANXELHKSKNLGHGDCYMURXQRWMHEYXXCMGMUFZIPVOZQQBJGVKESTCDZCWFUCSGGIRWMXYXJLFLGUXQAWLZIKFUTVYDGKBVKBKXTICIKHXWFVJRHNMYRJZYNNYXMUOFERZPY?AJKSMUCTLOFH?LV?EHHCHKBHOJZAHFKJHHZJKZIEYAOAPDQRIUWDBMJGOOSNWN?CBKUXJCTEWVTRBDCNFMGBJUAODCCZVPZBQJNIRJVVF?QBWBV?AXOVOYNAWSKUVPHWJK?YPYOKTVFBWAGCC?JOWPPCAZDOYETAYYECWWURYHY?SJHMSJXDIMXFOTUWJLYDKCHOAPLFYPMFYFRNRKWY?CBPLQJJJ?BJYGBJT?FV?VDQEQAUFWZSOJHZFBVEALMMT?XP", "output": "-1" }, { "input": "E?BIVQUPQQEJNMINFD?NKV?IROHPTGUIPMEVYPII?LZJMRI?FTKKKBHPOVQZZSAPDDWVSPVHOBT", "output": "-1" }, { "input": "FDQHJSNDDXHJLWVZVXJZUGKVHWCZVRWVZTIURLMJNGAMCUBDGVSIDEYRJZOLDISDNTOEKLSNLBSOQZLJVPAMLEBAVUNBXNKMLZBGJJQCGCSKBFSEEDXEVSWGZHFJIZJESPZIKIONJWTFFYYZKIDBSDNPJVAUHQMRFKIJWCEGTBVZHWZEKLPHGZVKZFAFAQRNKHGACNRTSXQKKCYBMEMKNKKSURKHOSMEVUXNGOCVCLVVSKULGBKFPCEKVRAJMBWCFFFSCCNDOSEKXEFFZETTUZHMQETWCVZASTTULYOPBNMOMXMVUEEEYZHSMRPAEIHUKNPNJTARJKQKIOXDJASSQPQQHEQIQJQLVPIJRCFVOVECHBOCRYWQEDXZLJXUDZUBFTRWEWNYTSKGDBEBWFFLMUYWELNVAAXSMKYEZXQFKKHJTZKMKMYOBTVXAOVBRMAMHTBDDYMDGQYEEBYZUBMUCKLKXCZGTWVZAYJOXZVGUYNXOVAPXQVE", "output": "-1" }, { "input": "KMNTIOJTLEKZW?JALAZYWYMKWRXTLAKNMDJLICZMETAKHVPTDOLAPCGHOEYSNIUJZVLPBTZ?YSR", "output": "-1" }, { "input": "?MNURVAKIVSOGITVJZEZCAOZEFVNZERAHVNCVCYKTJVEHK?ZMDL?CROLIDFSG?EIFHYKELMQRBVLE?CERELHDVFODJ?LBGJVFPO?CVMPBW?DPGZMVA?BKPXQQCRMKHJWDNAJSGOTGLBNSWMXMKAQ?MWMXCNRSGHTL?LGLAHSDHAGZRGTNDFI?KJ?GSAWOEPOENXTJCVJGMYOFIQKKDWOCIKPGCMFEKNEUPFGBCBYQCM?EQSAX?HZ?MFKAUHOHRKZZSIVZCAKYIKBDJYOCZJRYNLSOKGAEGQRQ?TBURXXLHAFCNVGAUVWBXZILMHWSBYJTIMWPNEGATPURPTJYFWKHRL?QPYUQ?HKDDHWAHOWUSONQKSZFIYFMFUJAMIYAMPNBGVPJSDFDFSAHDWWGEAKXLHBURNTIMCUZIAFAOCVNKPJRNLNGSJVMGKQ?IFQSRHTZGKHGXFJBDGPLCUUMEWNOSCONIVCLAOAPPSFFLCPRIXTKNBSSOVM", "output": "-1" }, { "input": "MRHKVVRBFEIFWIZGWCATJPBSZWNYANEWSSEVFQUUVNJKQOKVIGYBPFSZFTBUCNQEJEYVOWSPYER", "output": "-1" }, { "input": "CNRFBWKRTQTDFOMIGPPGDBHPRNRXFASDDBCZXHORGXDRSIORLJEROJBLLEHLNBILBPX?KHQLCOUPTKUADCDNHNBWMVNUUVUFPIRXSPNUCCRLJTDSUIUDLBKNKMXSAVBJDUGWIMNBIUWJX?TCBDEBNDYUGPS?MQSSEIIUGEE?XXKW?CMFQMWUAEXTSZNNOCPHBAEAKWALYBBMUMQZXUKTQPWNMZKIDECWIZFHKQIUJZRSBZPQFUQNVKQZMYJDHXZWXFHIZ?HWPIPIWV?JMIYKEJDNPMKTTOY?NTOMZZXTNMWQENYRWFYM?WLJJFCIJSETZSJORBZZHAFWYKGQJAPYQQXUWROOZUDOJJLNCDRSGUKYAZLLENGUICGOYPLJQ?POSKHPMOFJMAOXCITWWL?LOEDKHZPQFZZCTB?JYZNXZSDREAMGGXHMCFTQNOUALEYHULSDQVOXZIWFHNNHHG?FYUOCQNKBLFGGZ?YNFNVLRMENYBDWMDSP", "output": "-1" }, { "input": "KSRVTPFVRJWNPYUZMXBRLKVXIQPPBYVSYKRQPNGKTKRPFMKLIYFACFKBIQGPAXLEUESVGPBBXLY", "output": "-1" }, { "input": "LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSRBYREOZKHEXTBAXPTISPGIPOYBFFEJNAKKXAEPNGKWYGEJTNEZIXAWRSCEIRTKNEWSKSGKNIKDEOVXGYVEVFRGTNDFNWIFDRZQEJQZYIWNZXCONVZAKKKETPTPPXZMIVDWPGXOFODRNJZBATKGXAPXYHTUUFFASCHOLSMVSWBIJBAENEGNQTWKKOJUYQNXWDCDXBXBJOOWETWLQMGKHAJEMGXMYNVEHRAEGZOJJQPZGYRHXRNKMSWFYDIZLIBUTSKIKGQJZLGZQFJVIMNOHNZJKWVVPFMFACVXKJKTBZRXRZDJKSWSXBBKWIKEICSZEIPTOJCKJQYYPNUPRNPQNNCVITNXPLAKQBYAIQGNAHXDUQWQLYN", "output": "-1" }, { "input": "PVCKCT?KLTFPIBBIHODCAABEQLJKQECRUJUSHSXPMBEVBKHQTIKQLBLTIRQZPOGPWMMNWWCUKAD", "output": "-1" }, { "input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L", "output": "-1" }, { "input": "TESTEIGHTYFOUR", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "-1" }, { "input": "?????????????????????????", "output": "-1" }, { "input": "Q?RYJPGLNQ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYS" }, { "input": "AACDEFGHIJKLMNOPQRZTUVWXYS", "output": "-1" }, { "input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY" }, { "input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC", "output": "-1" }, { "input": "????", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA" }, { "input": "A", "output": "-1" }, { "input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY", "output": "-1" }, { "input": "AA", "output": "-1" }, { "input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ", "output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "???DEFGHIJKL??L?PQRSTUVW???", "output": "-1" }, { "input": "?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A", "output": "-1" }, { "input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????", "output": "-1" }, { "input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP", "output": "-1" }, { "input": "ABCA???????????????????????", "output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AB", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ", "output": "-1" }, { "input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "-1" }, { "input": "???AA????????????????????BB???", "output": "-1" }, { "input": "ABC??FGAHIJ??MNOPQRST??WXYZ", "output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN", "output": "-1" }, { "input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????", "output": "-1" } ]
1,663,786,007
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
def st(i) : chk = [chr(i+65) for i in range(26)]; chk.sort() alph = [chr(i+65) for i in range(26)]; ss = list(s[i:i+27]); j= 0 for x in ss : if x in alph: alph.remove(x) for x in range(26) : if ss[x] == '?' : ss[x] = alph[j]; j+=1 ss.sort() if ss == chk : return ''.join(ss) else : return 0 s=input(); n=len(s) for i in range(n-25) : n=st(i) if n : print(n); break else : print(-1)
Title: Complete the Word Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input Specification: The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output Specification: If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Demo Input: ['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n'] Demo Output: ['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1'] Note: In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
```python def st(i) : chk = [chr(i+65) for i in range(26)]; chk.sort() alph = [chr(i+65) for i in range(26)]; ss = list(s[i:i+27]); j= 0 for x in ss : if x in alph: alph.remove(x) for x in range(26) : if ss[x] == '?' : ss[x] = alph[j]; j+=1 ss.sort() if ss == chk : return ''.join(ss) else : return 0 s=input(); n=len(s) for i in range(n-25) : n=st(i) if n : print(n); break else : print(-1) ```
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into?
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "output": "49" }, { "input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "output": "50" }, { "input": "ijvxljt", "output": "7" }, { "input": "fyhcncnchyf", "output": "10" }, { "input": "ffffffffffff", "output": "0" }, { "input": "fyhcncfsepqj", "output": "12" }, { "input": "ybejrrlbcinttnicblrrjeby", "output": "23" }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyy", "output": "0" }, { "input": "ybejrrlbcintahovgjddrqatv", "output": "25" }, { "input": "oftmhcmclgyqaojljoaqyglcmchmtfo", "output": "30" }, { "input": "oooooooooooooooooooooooooooooooo", "output": "0" }, { "input": "oftmhcmclgyqaojllbotztajglsmcilv", "output": "32" }, { "input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg", "output": "35" }, { "input": "gggggggggggggggggggggggggggggggggggg", "output": "0" }, { "input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk", "output": "36" }, { "input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf", "output": "40" }, { "input": "fffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy", "output": "43" }, { "input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "0" }, { "input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy", "output": "49" }, { "input": "a", "output": "0" }, { "input": "abca", "output": "4" }, { "input": "aaaaabaaaaa", "output": "10" }, { "input": "aba", "output": "2" }, { "input": "asaa", "output": "4" }, { "input": "aabaa", "output": "4" }, { "input": "aabbaa", "output": "5" }, { "input": "abcdaaa", "output": "7" }, { "input": "aaholaa", "output": "7" }, { "input": "abcdefghijka", "output": "12" }, { "input": "aaadcba", "output": "7" }, { "input": "aaaabaaaa", "output": "8" }, { "input": "abaa", "output": "4" }, { "input": "abcbaa", "output": "6" }, { "input": "ab", "output": "2" }, { "input": "l", "output": "0" }, { "input": "aaaabcaaaa", "output": "10" }, { "input": "abbaaaaaabba", "output": "11" }, { "input": "abaaa", "output": "5" }, { "input": "baa", "output": "3" }, { "input": "aaaaaaabbba", "output": "11" }, { "input": "ccbcc", "output": "4" }, { "input": "bbbaaab", "output": "7" }, { "input": "abaaaaaaaa", "output": "10" }, { "input": "abaaba", "output": "5" }, { "input": "aabsdfaaaa", "output": "10" }, { "input": "aaaba", "output": "5" }, { "input": "aaabaaa", "output": "6" }, { "input": "baaabbb", "output": "7" }, { "input": "ccbbabbcc", "output": "8" }, { "input": "cabc", "output": "4" }, { "input": "aabcd", "output": "5" }, { "input": "abcdea", "output": "6" }, { "input": "bbabb", "output": "4" }, { "input": "aaaaabababaaaaa", "output": "14" }, { "input": "bbabbb", "output": "6" }, { "input": "aababd", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaaaaaaabbba", "output": "12" }, { "input": "aabca", "output": "5" }, { "input": "aaabccbaaa", "output": "9" }, { "input": "aaaaaaaaaaaaaaaaaaaab", "output": "21" }, { "input": "babb", "output": "4" }, { "input": "abcaa", "output": "5" }, { "input": "qwqq", "output": "4" }, { "input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa", "output": "48" }, { "input": "aaab", "output": "4" }, { "input": "aaaaaabaaaaa", "output": "12" }, { "input": "wwuww", "output": "4" }, { "input": "aaaaabcbaaaaa", "output": "12" }, { "input": "aaabbbaaa", "output": "8" }, { "input": "aabcbaa", "output": "6" }, { "input": "abccdefccba", "output": "11" }, { "input": "aabbcbbaa", "output": "8" }, { "input": "aaaabbaaaa", "output": "9" }, { "input": "aabcda", "output": "6" }, { "input": "abbca", "output": "5" }, { "input": "aaaaaabbaaa", "output": "11" }, { "input": "sssssspssssss", "output": "12" }, { "input": "sdnmsdcs", "output": "8" }, { "input": "aaabbbccbbbaaa", "output": "13" }, { "input": "cbdbdc", "output": "6" }, { "input": "abb", "output": "3" }, { "input": "abcdefaaaa", "output": "10" }, { "input": "abbbaaa", "output": "7" }, { "input": "v", "output": "0" }, { "input": "abccbba", "output": "7" }, { "input": "axyza", "output": "5" }, { "input": "abcdefgaaaa", "output": "11" }, { "input": "aaabcdaaa", "output": "9" }, { "input": "aaaacaaaa", "output": "8" }, { "input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa", "output": "42" }, { "input": "abbbaa", "output": "6" }, { "input": "abcdee", "output": "6" }, { "input": "oom", "output": "3" }, { "input": "aabcaa", "output": "6" }, { "input": "abba", "output": "3" }, { "input": "aaca", "output": "4" }, { "input": "aacbca", "output": "6" }, { "input": "ababa", "output": "4" }, { "input": "abcda", "output": "5" }, { "input": "cccaaccc", "output": "7" }, { "input": "aaabcda", "output": "7" }, { "input": "aa", "output": "0" }, { "input": "aabaaaa", "output": "7" }, { "input": "abbaaaa", "output": "7" }, { "input": "aaabcbaaa", "output": "8" }, { "input": "aabba", "output": "5" }, { "input": "xyxx", "output": "4" }, { "input": "aaaaaaaaaaaabc", "output": "14" }, { "input": "bbaaaabb", "output": "7" }, { "input": "aaabaa", "output": "6" }, { "input": "sssssabsssss", "output": "12" }, { "input": "bbbaaaabbb", "output": "9" }, { "input": "abbbbaaaa", "output": "9" }, { "input": "wwufuww", "output": "6" }, { "input": "oowoo", "output": "4" }, { "input": "cccaccc", "output": "6" }, { "input": "aaa", "output": "0" }, { "input": "bbbcc", "output": "5" }, { "input": "abcdef", "output": "6" }, { "input": "abbba", "output": "4" }, { "input": "aab", "output": "3" }, { "input": "aaba", "output": "4" }, { "input": "azbyaaa", "output": "7" }, { "input": "oooooiooooo", "output": "10" }, { "input": "aabbbbbaaaaaa", "output": "13" } ]
1,633,626,055
2,147,483,647
Python 3
OK
TESTS
133
77
6,758,400
s = input() print((len(s) - (s == s[::-1])) * (len(set(s)) > 1))
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? Input Specification: The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. Output Specification: If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. Demo Input: ['mew\n', 'wuffuw\n', 'qqqqqqqq\n'] Demo Output: ['3\n', '5\n', '0\n'] Note: "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
```python s = input() print((len(s) - (s == s[::-1])) * (len(set(s)) > 1)) ```
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,587,874,995
2,147,483,647
PyPy 3
OK
TESTS
102
155
0
def xr(f,s): return int(f)^int(s) def nn(v): f,s=v n=len(f) for x in range(n): yield(xr(f[x],s[x])) v=[input() for _ in range(2)] for x in nn(v): print(x,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 def xr(f,s): return int(f)^int(s) def nn(v): f,s=v n=len(f) for x in range(n): yield(xr(f[x],s[x])) v=[input() for _ in range(2)] for x in nn(v): print(x,end='') ```
3.96125
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "output": "NO" }, { "input": "3 3\n1 1\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n1 2\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n2 2\n1 2 3\n1 2 3", "output": "NO" }, { "input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "output": "YES" }, { "input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100", "output": "YES" }, { "input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99", "output": "YES" }, { "input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81", "output": "YES" }, { "input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10", "output": "NO" }, { "input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "1 1\n1 1\n-1000000000\n30", "output": "YES" }, { "input": "3 3\n1 3\n1 3 3\n3 3 3", "output": "YES" }, { "input": "3 3\n1 1\n3 3 3\n2 2 2", "output": "NO" }, { "input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7", "output": "NO" }, { "input": "3 4\n2 2\n5 6 7\n1 2 3 4", "output": "NO" }, { "input": "3 3\n3 3\n1 2 3\n4 5 6", "output": "YES" }, { "input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9", "output": "YES" } ]
1,554,495,580
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
0
m=input().split() x=input().split() a=int(x[0]) b=int(x[1]) emon=input().split() emon.sort() emon1=[] mishu=input().split() mishu.sort() mishu1=[] for i in range(a): c=int(emon[i]) emon1.append(c) for i in range(b): c=int(mishu[i]) mishu1.append(c) a=0 m=max(emon1) n=min(mishu1) if (n>m): print("YES") else : print("NO")
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. Input Specification: The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. Output Specification: Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). Demo Input: ['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python m=input().split() x=input().split() a=int(x[0]) b=int(x[1]) emon=input().split() emon.sort() emon1=[] mishu=input().split() mishu.sort() mishu1=[] for i in range(a): c=int(emon[i]) emon1.append(c) for i in range(b): c=int(mishu[i]) mishu1.append(c) a=0 m=max(emon1) n=min(mishu1) if (n>m): print("YES") else : print("NO") ```
0
414
A
Mashmokh and Numbers
PROGRAMMING
1,500
[ "constructive algorithms", "number theory" ]
null
null
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers *x* and *y* from the board, he gets *gcd*(*x*,<=*y*) points. At the beginning of the game Bimokh has zero points. Mashmokh wants to win in the game. For this reason he wants his boss to get exactly *k* points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* such that his boss will score exactly *k* points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108).
If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
[ "5 2\n", "5 3", "7 2\n" ]
[ "1 2 3 4 5\n", "2 4 3 7 1", "-1\n" ]
*gcd*(*x*, *y*) is greatest common divisor of *x* and *y*.
500
[ { "input": "5 2", "output": "1 2 3 4 5" }, { "input": "5 3", "output": "2 4 5 6 7" }, { "input": "7 2", "output": "-1" }, { "input": "1 1", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 0", "output": "1" }, { "input": "7 3", "output": "1 2 3 4 5 6 7" }, { "input": "7 6", "output": "4 8 1 2 5 6 7" }, { "input": "7 7", "output": "5 10 1 2 3 4 6" }, { "input": "100000 100000000", "output": "99950001 199900002 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 ..." }, { "input": "3455 2792393", "output": "2790667 5581334 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..." }, { "input": "74086 16504611", "output": "16467569 32935138 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 1..." }, { "input": "28515 44887064", "output": "44872808 89745616 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 1..." }, { "input": "21324 73830196", "output": "73819535 147639070 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 ..." }, { "input": "90212 5921828", "output": "5876723 11753446 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 15..." }, { "input": "25095 2372924", "output": "2360378 4720756 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..." }, { "input": "92977 95851971", "output": "95805484 191610968 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 ..." }, { "input": "39095 77350428", "output": "77330882 154661764 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 ..." }, { "input": "785 70908164", "output": "70907773 141815546 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 ..." }, { "input": "28051 5506872", "output": "5492848 10985696 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 15..." }, { "input": "74077 37498088", "output": "37461051 74922102 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 1..." }, { "input": "58284 12998910", "output": "12969769 25939538 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 1..." }, { "input": "28768 33384329", "output": "33369946 66739892 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 1..." }, { "input": "6357 92661202", "output": "92658025 185316050 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 ..." }, { "input": "80996 61457012", "output": "61416515 122833030 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 ..." }, { "input": "60752 21494069", "output": "21463694 42927388 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 1..." }, { "input": "95065 81120597", "output": "81073066 162146132 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 ..." }, { "input": "77240 1683376", "output": "1644757 3289514 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..." }, { "input": "35136 35044765", "output": "35027198 70054396 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 1..." }, { "input": "98218 71868966", "output": "71819858 143639716 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 ..." }, { "input": "45671 48503349", "output": "48480515 96961030 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 1..." }, { "input": "7081 26961063", "output": "26957524 53915048 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 1..." }, { "input": "69213 98333912", "output": "98299307 196598614 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 ..." }, { "input": "91055 20775941", "output": "20730415 41460830 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 1..." }, { "input": "14106 71280052", "output": "71273000 142546000 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 ..." }, { "input": "17599 34327121", "output": "34318323 68636646 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 1..." }, { "input": "74244 96611492", "output": "96574371 193148742 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 ..." }, { "input": "77554 5672752", "output": "5633976 11267952 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 15..." }, { "input": "51040 32015531", "output": "31990012 63980024 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 1..." }, { "input": "95593 16086029", "output": "16038234 32076468 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 1..." }, { "input": "44405 95772109", "output": "95749908 191499816 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 ..." }, { "input": "46297 84634875", "output": "84611728 169223456 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 ..." }, { "input": "3842 99757561", "output": "99755641 199511282 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 ..." }, { "input": "90252 19406877", "output": "19361752 38723504 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 1..." }, { "input": "13321 67580511", "output": "67573852 135147704 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 ..." }, { "input": "19919 79287791", "output": "79277833 158555666 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 ..." }, { "input": "58499 59427255", "output": "59398007 118796014 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 ..." }, { "input": "34423 86770315", "output": "86753105 173506210 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 ..." }, { "input": "21460 11888516", "output": "11877787 23755574 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 1..." }, { "input": "57534 85681593", "output": "85652827 171305654 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 ..." }, { "input": "28652 18840000", "output": "18825675 37651350 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 1..." }, { "input": "18247 23541343", "output": "23532221 47064442 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 1..." }, { "input": "89529 95022203", "output": "94977440 189954880 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 ..." }, { "input": "42775 89315917", "output": "89294531 178589062 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 ..." }, { "input": "946 93333203", "output": "93332731 186665462 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 ..." }, { "input": "93595 48782905", "output": "48736109 97472218 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 1..." }, { "input": "87371 60145723", "output": "60102039 120204078 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 ..." }, { "input": "7695 94816808", "output": "94812962 189625924 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 ..." }, { "input": "21846 16967905", "output": "16956983 33913966 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 1..." }, { "input": "10 3", "output": "-1" }, { "input": "6 1000003", "output": "1000001 2000002 1 2 3 4" }, { "input": "100000 549999", "output": "500000 1000000 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 ..." }, { "input": "10 4", "output": "-1" }, { "input": "8 10", "output": "7 14 1 2 3 4 5 6" }, { "input": "6 10000003", "output": "10000001 20000002 1 2 3 4" }, { "input": "50 50000030", "output": "50000006 100000012 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" }, { "input": "7 11", "output": "9 18 1 2 3 4 5" }, { "input": "2 96996900", "output": "96996900 193993800" }, { "input": "3 99999997", "output": "99999997 199999994 1" }, { "input": "10000 10", "output": "-1" }, { "input": "5 100000000", "output": "99999999 199999998 1 2 3" }, { "input": "20 15", "output": "6 12 1 2 3 4 7 8 9 10 13 14 15 16 17 18 19 20 21 22" }, { "input": "10 50000006", "output": "50000002 100000004 1 2 3 4 5 6 7 8" }, { "input": "4 1257", "output": "1256 2512 1 2" }, { "input": "100 1", "output": "-1" }, { "input": "6 1", "output": "-1" }, { "input": "10 1000004", "output": "1000000 2000000 1 2 3 4 5 6 7 8" }, { "input": "100000 100000", "output": "50001 100002 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 15..." }, { "input": "10 3000004", "output": "3000000 6000000 1 2 3 4 5 6 7 8" }, { "input": "99999 149998", "output": "100000 200000 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 1..." }, { "input": "11 1434567", "output": "1434563 2869126 1 2 3 4 5 6 7 8 9" }, { "input": "205 110", "output": "9 18 1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 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": "11 14342267", "output": "14342263 28684526 1 2 3 4 5 6 7 8 9" } ]
1,420,654,222
2,147,483,647
Python 3
OK
TESTS
84
343
102,400
# 414A from sys import stdin __author__ = 'artyom' n, k = list(map(int, stdin.readline().strip().split())) if n == 1: if k == 0: print(1) else: print(-1) exit() pairs = n // 2 if k < pairs: print(-1) exit() x, y = 1, 2 if k > pairs: x = k - pairs + 1 y = x * 2 print(x, end=' ') print(y, end=' ') if n > 2: for i in range(y + 1, y + n - 2): print(i, end=' ') print(y + n - 2)
Title: Mashmokh and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers *x* and *y* from the board, he gets *gcd*(*x*,<=*y*) points. At the beginning of the game Bimokh has zero points. Mashmokh wants to win in the game. For this reason he wants his boss to get exactly *k* points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* such that his boss will score exactly *k* points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109. Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108). Output Specification: If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Demo Input: ['5 2\n', '5 3', '7 2\n'] Demo Output: ['1 2 3 4 5\n', '2 4 3 7 1', '-1\n'] Note: *gcd*(*x*, *y*) is greatest common divisor of *x* and *y*.
```python # 414A from sys import stdin __author__ = 'artyom' n, k = list(map(int, stdin.readline().strip().split())) if n == 1: if k == 0: print(1) else: print(-1) exit() pairs = n // 2 if k < pairs: print(-1) exit() x, y = 1, 2 if k > pairs: x = k - pairs + 1 y = x * 2 print(x, end=' ') print(y, end=' ') if n > 2: for i in range(y + 1, y + n - 2): print(i, end=' ') print(y + n - 2) ```
3
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern.
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########" }, { "input": "3 5", "output": "#####\n....#\n#####" }, { "input": "3 6", "output": "######\n.....#\n######" }, { "input": "7 3", "output": "###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "7 4", "output": "####\n...#\n####\n#...\n####\n...#\n####" }, { "input": "49 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 27", "output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................." }, { "input": "11 15", "output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############" }, { "input": "11 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "19 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "23 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "49 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "33 43", "output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................." }, { "input": "33 44", "output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......." }, { "input": "45 45", "output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..." }, { "input": "45 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "45 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###" }, { "input": "45 4", "output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####" }, { "input": "5 4", "output": "####\n...#\n####\n#...\n####" }, { "input": "5 5", "output": "#####\n....#\n#####\n#....\n#####" }, { "input": "5 6", "output": "######\n.....#\n######\n#.....\n######" }, { "input": "7 5", "output": "#####\n....#\n#####\n#....\n#####\n....#\n#####" }, { "input": "7 6", "output": "######\n.....#\n######\n#.....\n######\n.....#\n######" }, { "input": "7 7", "output": "#######\n......#\n#######\n#......\n#######\n......#\n#######" } ]
1,685,625,967
2,147,483,647
PyPy 3-64
OK
TESTS
28
62
0
r,c = map(int, input().split()) for i in range(1, r+1): if i % 2 != 0: print(c * "#") else: if (i / 2) % 2 == 1: print((c-1) * "." + "#") else: print("#"+ (c-1) * ".")
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern. Input Specification: The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number. Output Specification: Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. Demo Input: ['3 3\n', '3 4\n', '5 3\n', '9 9\n'] Demo Output: ['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n'] Note: none
```python r,c = map(int, input().split()) for i in range(1, r+1): if i % 2 != 0: print(c * "#") else: if (i / 2) % 2 == 1: print((c-1) * "." + "#") else: print("#"+ (c-1) * ".") ```
3
697
A
Pineapple Incident
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time.
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
[ "3 10 4\n", "3 10 3\n", "3 8 51\n", "3 8 52\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
500
[ { "input": "3 10 4", "output": "NO" }, { "input": "3 10 3", "output": "YES" }, { "input": "3 8 51", "output": "YES" }, { "input": "3 8 52", "output": "YES" }, { "input": "456947336 740144 45", "output": "NO" }, { "input": "33 232603 599417964", "output": "YES" }, { "input": "4363010 696782227 701145238", "output": "YES" }, { "input": "9295078 2 6", "output": "NO" }, { "input": "76079 281367 119938421", "output": "YES" }, { "input": "93647 7 451664565", "output": "YES" }, { "input": "5 18553 10908", "output": "NO" }, { "input": "6 52 30", "output": "NO" }, { "input": "6431 855039 352662", "output": "NO" }, { "input": "749399100 103031711 761562532", "output": "NO" }, { "input": "21 65767 55245", "output": "NO" }, { "input": "4796601 66897 4860613", "output": "NO" }, { "input": "8 6728951 860676", "output": "NO" }, { "input": "914016 6 914019", "output": "NO" }, { "input": "60686899 78474 60704617", "output": "NO" }, { "input": "3 743604 201724", "output": "NO" }, { "input": "571128 973448796 10", "output": "NO" }, { "input": "688051712 67 51", "output": "NO" }, { "input": "74619 213344 6432326", "output": "NO" }, { "input": "6947541 698167 6", "output": "NO" }, { "input": "83 6 6772861", "output": "NO" }, { "input": "251132 67561 135026988", "output": "NO" }, { "input": "8897216 734348516 743245732", "output": "YES" }, { "input": "50 64536 153660266", "output": "YES" }, { "input": "876884 55420 971613604", "output": "YES" }, { "input": "0 6906451 366041903", "output": "YES" }, { "input": "11750 8 446010134", "output": "YES" }, { "input": "582692707 66997 925047377", "output": "YES" }, { "input": "11 957526890 957526901", "output": "YES" }, { "input": "556888 514614196 515171084", "output": "YES" }, { "input": "6 328006 584834704", "output": "YES" }, { "input": "4567998 4 204966403", "output": "YES" }, { "input": "60 317278 109460971", "output": "YES" }, { "input": "906385 342131991 685170368", "output": "YES" }, { "input": "1 38 902410512", "output": "YES" }, { "input": "29318 787017 587931018", "output": "YES" }, { "input": "351416375 243431 368213115", "output": "YES" }, { "input": "54 197366062 197366117", "output": "YES" }, { "input": "586389 79039 850729874", "output": "YES" }, { "input": "723634470 2814619 940360134", "output": "YES" }, { "input": "0 2 0", "output": "YES" }, { "input": "0 2 1", "output": "NO" }, { "input": "0 2 2", "output": "YES" }, { "input": "0 2 3", "output": "YES" }, { "input": "0 2 1000000000", "output": "YES" }, { "input": "0 10 23", "output": "NO" }, { "input": "0 2 999999999", "output": "YES" }, { "input": "10 5 11", "output": "NO" }, { "input": "1 2 1000000000", "output": "YES" }, { "input": "1 10 20", "output": "NO" }, { "input": "1 2 999999937", "output": "YES" }, { "input": "10 3 5", "output": "NO" }, { "input": "3 2 5", "output": "YES" }, { "input": "0 4 0", "output": "YES" }, { "input": "0 215 403", "output": "NO" }, { "input": "5 2 10", "output": "YES" }, { "input": "0 2 900000000", "output": "YES" }, { "input": "0 79 4000", "output": "NO" }, { "input": "5 1000 1000", "output": "NO" }, { "input": "1 5 103", "output": "NO" }, { "input": "5 2 6", "output": "NO" }, { "input": "120 2 1000000000", "output": "YES" }, { "input": "2 2 1000000000", "output": "YES" }, { "input": "5 5 13", "output": "NO" }, { "input": "10 5 15", "output": "YES" }, { "input": "11 2 0", "output": "NO" }, { "input": "3 8 53", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "4 4 0", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "5 3 9", "output": "YES" }, { "input": "5 6 19", "output": "NO" }, { "input": "3 10 125", "output": "NO" }, { "input": "5 3 8", "output": "YES" }, { "input": "6 3 9", "output": "YES" }, { "input": "0 3 5", "output": "NO" }, { "input": "5 3 300000035", "output": "YES" }, { "input": "5 2 7", "output": "YES" }, { "input": "1 5 6", "output": "YES" }, { "input": "4 2 6", "output": "YES" }, { "input": "0 3 999999998", "output": "NO" }, { "input": "0 10001 0", "output": "YES" }, { "input": "6 5 3", "output": "NO" }, { "input": "1 5 1000000000", "output": "NO" }, { "input": "1 3 6", "output": "NO" }, { "input": "3 3 1000000000", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "3 3 5", "output": "NO" }, { "input": "3 3 0", "output": "NO" }, { "input": "1 2 4", "output": "YES" }, { "input": "5 5 10", "output": "YES" } ]
1,519,400,228
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
62
5,632,000
t,s,x = map(int,input().split()) if (x == t+1) or (x<t) :print('NO') elif ((x - t) % s) or ((x - t - 1) % s):print('YES') else:print('NO')
Title: Pineapple Incident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. Input Specification: The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. Output Specification: Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. Demo Input: ['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n'] Note: In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
```python t,s,x = map(int,input().split()) if (x == t+1) or (x<t) :print('NO') elif ((x - t) % s) or ((x - t - 1) % s):print('YES') else:print('NO') ```
0
298
B
Sail
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1). Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)?
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
500
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE", "output": "4" }, { "input": "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "output": "41" }, { "input": "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE", "output": "-1" }, { "input": "1 0 0 0 -1\nS", "output": "1" }, { "input": "1 5 5 5 6\nE", "output": "-1" }, { "input": "15 1 1 1 2\nNNNNNNNNNNNNNNN", "output": "1" }, { "input": "11 1 1 1 2\nNNNNNNNNNNN", "output": "1" } ]
1,594,208,356
2,147,483,647
PyPy 3
OK
TESTS
43
310
22,630,400
t,sx,sy,ex,ey=map(int,input().split()) s=input() vert,hori="","" if ey>sy: vert='N' else: vert='S' if ex>sx: hori='E' else: hori='W' x,y=abs(ex-sx),abs(ey-sy) cnt=0 for i in range(0,len(s)): if s[i]==vert: y-=1 if s[i]==hori: x-=1 if x<=0 and y<=0: print(i+1) break else: print(-1)
Title: Sail Time Limit: None seconds Memory Limit: None megabytes Problem Description: The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1). Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)? Input Specification: The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). Output Specification: If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). Demo Input: ['5 0 0 1 1\nSESNW\n', '10 5 3 3 6\nNENSWESNEE\n'] Demo Output: ['4\n', '-1\n'] Note: In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
```python t,sx,sy,ex,ey=map(int,input().split()) s=input() vert,hori="","" if ey>sy: vert='N' else: vert='S' if ex>sx: hori='E' else: hori='W' x,y=abs(ex-sx),abs(ey-sy) cnt=0 for i in range(0,len(s)): if s[i]==vert: y-=1 if s[i]==hori: x-=1 if x<=0 and y<=0: print(i+1) break else: print(-1) ```
3
34
A
Reconnaissance 2
PROGRAMMING
800
[ "implementation" ]
A. Reconnaissance 2
2
256
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
[ "5\n10 12 13 15 10\n", "4\n10 20 30 40\n" ]
[ "5 1\n", "1 2\n" ]
none
500
[ { "input": "5\n10 12 13 15 10", "output": "5 1" }, { "input": "4\n10 20 30 40", "output": "1 2" }, { "input": "6\n744 359 230 586 944 442", "output": "2 3" }, { "input": "5\n826 747 849 687 437", "output": "1 2" }, { "input": "5\n999 999 993 969 999", "output": "1 2" }, { "input": "5\n4 24 6 1 15", "output": "3 4" }, { "input": "2\n511 32", "output": "1 2" }, { "input": "3\n907 452 355", "output": "2 3" }, { "input": "4\n303 872 764 401", "output": "4 1" }, { "input": "10\n684 698 429 694 956 812 594 170 937 764", "output": "1 2" }, { "input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695", "output": "7 8" }, { "input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000", "output": "12 13" }, { "input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58", "output": "16 17" }, { "input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000", "output": "1 2" }, { "input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4", "output": "1 2" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "86 87" }, { "input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25", "output": "7 8" }, { "input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964", "output": "1 2" }, { "input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967", "output": "81 82" }, { "input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17", "output": "36 37" } ]
1,629,267,387
2,147,483,647
Python 3
OK
TESTS
20
154
6,963,200
n = int(input()) soldiers = list(map(int, input().split())) soldiers.append(soldiers[0]) m = float('inf') i1, i2 = 0, 1 for i in range(1,n+1): x = abs(soldiers[i]-soldiers[i-1]) if x<m: m = x i1, i2 = i-1, i if i2==n: i2 = 0 print(i1+1, i2+1)
Title: Reconnaissance 2 Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. Output Specification: Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. Demo Input: ['5\n10 12 13 15 10\n', '4\n10 20 30 40\n'] Demo Output: ['5 1\n', '1 2\n'] Note: none
```python n = int(input()) soldiers = list(map(int, input().split())) soldiers.append(soldiers[0]) m = float('inf') i1, i2 = 0, 1 for i in range(1,n+1): x = abs(soldiers[i]-soldiers[i-1]) if x<m: m = x i1, i2 = i-1, i if i2==n: i2 = 0 print(i1+1, i2+1) ```
3.94853
108
A
Palindromic Times
PROGRAMMING
1,000
[ "implementation", "strings" ]
A. Palindromic Times
2
256
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.
The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.
Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.
[ "12:21\n", "23:59\n" ]
[ "13:31\n", "00:00\n" ]
none
500
[ { "input": "12:21", "output": "13:31" }, { "input": "23:59", "output": "00:00" }, { "input": "15:51", "output": "20:02" }, { "input": "10:44", "output": "11:11" }, { "input": "04:02", "output": "04:40" }, { "input": "02:11", "output": "02:20" }, { "input": "12:15", "output": "12:21" }, { "input": "07:07", "output": "10:01" }, { "input": "00:17", "output": "01:10" }, { "input": "04:55", "output": "05:50" }, { "input": "02:17", "output": "02:20" }, { "input": "07:56", "output": "10:01" }, { "input": "00:29", "output": "01:10" }, { "input": "23:31", "output": "23:32" }, { "input": "19:30", "output": "20:02" }, { "input": "12:14", "output": "12:21" }, { "input": "17:32", "output": "20:02" }, { "input": "03:44", "output": "04:40" }, { "input": "07:15", "output": "10:01" }, { "input": "18:42", "output": "20:02" }, { "input": "08:56", "output": "10:01" }, { "input": "04:50", "output": "05:50" }, { "input": "14:32", "output": "14:41" }, { "input": "23:23", "output": "23:32" }, { "input": "08:35", "output": "10:01" }, { "input": "03:32", "output": "04:40" }, { "input": "07:59", "output": "10:01" }, { "input": "14:12", "output": "14:41" }, { "input": "23:52", "output": "00:00" }, { "input": "16:36", "output": "20:02" }, { "input": "17:50", "output": "20:02" }, { "input": "06:59", "output": "10:01" }, { "input": "16:50", "output": "20:02" }, { "input": "00:00", "output": "01:10" }, { "input": "23:59", "output": "00:00" }, { "input": "23:33", "output": "00:00" } ]
1,647,223,278
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
a = input() b = list(map(int, a.split(":"))) while True: b[1] += 1 if b[1] > 59: b[1] = 0 b[0] += 1 if b[0] > 23: b[1] = 0 b[0] = 0 if str(b[0] + b[1]) == str(b[0] + b[1]): print(str(b[0]) + ":" + str(b[1])) break
Title: Palindromic Times Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him. Input Specification: The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. Output Specification: Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. Demo Input: ['12:21\n', '23:59\n'] Demo Output: ['13:31\n', '00:00\n'] Note: none
```python a = input() b = list(map(int, a.split(":"))) while True: b[1] += 1 if b[1] > 59: b[1] = 0 b[0] += 1 if b[0] > 23: b[1] = 0 b[0] = 0 if str(b[0] + b[1]) == str(b[0] + b[1]): print(str(b[0]) + ":" + str(b[1])) break ```
0
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,687,166,221
2,147,483,647
Python 3
OK
TESTS
54
46
0
k, r = [int(x) for x in input().split()] a = 1 b = k while True: if k%10==0: print(a) break elif (k-r)%10==0: print(a) break else: k+=b a+=1
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python k, r = [int(x) for x in input().split()] a = 1 b = k while True: if k%10==0: print(a) break elif (k-r)%10==0: print(a) break else: k+=b a+=1 ```
3
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,680,076,803
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
a = input().split() lenth = int(a[0]) width = int(a[1]) flagstone = int(a[2]) if flagstone == 1: print(lenth * width) elif flagstone ** 2 >= lenth * width: print(1) else: baghi = lenth % flagstone if baghi != 0: lenth += (flagstone - baghi) baghi = width % flagstone if baghi != 0: width += (flagstone - baghi) number = (lenth * width) // flagstone ** 2 print(number)
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 a = input().split() lenth = int(a[0]) width = int(a[1]) flagstone = int(a[2]) if flagstone == 1: print(lenth * width) elif flagstone ** 2 >= lenth * width: print(1) else: baghi = lenth % flagstone if baghi != 0: lenth += (flagstone - baghi) baghi = width % flagstone if baghi != 0: width += (flagstone - baghi) number = (lenth * width) // flagstone ** 2 print(number) ```
0
875
B
Sorting the Coins
PROGRAMMING
1,500
[ "dsu", "implementation", "sortings", "two pointers" ]
null
null
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation. For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following: 1. He looks through all the coins from left to right; 1. If he sees that the *i*-th coin is still in circulation, and (*i*<=+<=1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (*i*<=+<=1)-th. Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one. Today Sasha invited Dima and proposed him a game. First he puts *n* coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for *n* times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence. The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=300<=000) — number of coins that Sasha puts behind Dima. Second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position *p*1, then coin located at position *p*2 and so on. Coins are numbered from left to right.
Print *n*<=+<=1 numbers *a*0,<=*a*1,<=...,<=*a**n*, where *a*0 is a hardness of ordering at the beginning, *a*1 is a hardness of ordering after the first replacement and so on.
[ "4\n1 3 4 2\n", "8\n6 8 3 4 7 2 1 5\n" ]
[ "1 2 3 2 1\n", "1 2 2 3 4 3 4 5 1\n" ]
Let's denote as O coin out of circulation, and as X — coin is circulation. At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges. After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process. XOOO  →  OOOX After replacement of the third coin, Dima's actions look this way: XOXO  →  OXOX  →  OOXX After replacement of the fourth coin, Dima's actions look this way: XOXX  →  OXXX Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
1,000
[ { "input": "4\n1 3 4 2", "output": "1 2 3 2 1" }, { "input": "8\n6 8 3 4 7 2 1 5", "output": "1 2 2 3 4 3 4 5 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "11\n10 8 9 4 6 3 5 1 11 7 2", "output": "1 2 3 4 5 6 7 8 9 6 2 1" }, { "input": "11\n10 8 9 4 3 5 1 11 7 2 6", "output": "1 2 3 4 5 6 7 8 5 5 6 1" }, { "input": "100\n1 72 43 50 58 87 10 94 29 51 99 86 92 80 36 31 9 100 85 59 66 30 3 78 17 73 93 37 57 71 45 15 24 2 64 44 65 22 38 79 23 8 16 52 98 97 96 95 91 90 89 88 84 83 82 81 77 76 75 74 70 69 68 67 63 62 61 60 56 55 54 53 49 48 47 46 42 41 40 39 35 34 33 32 28 27 26 25 21 20 19 18 14 13 12 11 7 6 5 4", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 43 43 43 40 40 40 40 37 37 37 37 34 34 34 34 31 31 31 31 28 28 28 28 25 25 25 25 22 22 22 22 19 19 19 19 16 16 16 16 13 13 13 13 10 10 10 10 7 7 7 7 4 4 4 4 1" }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 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 70 71 72 73 74 75 76 77 78 71 39 1" } ]
1,677,194,656
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n=int(input()) pyt= list(map(int, input().split(maxsplit = n))) hod=[1] arr=[0 for i in range(n)] nul=n ed=0 pyt.pop() for i in pyt: arr[i-1]=1 ed+=1 if i==nul: arr.reverse() nul=n-arr.index(0) arr.reverse() hod.append(ed-(n-nul-1)) hod.append(1) print(hod)
Title: Sorting the Coins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation. For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following: 1. He looks through all the coins from left to right; 1. If he sees that the *i*-th coin is still in circulation, and (*i*<=+<=1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (*i*<=+<=1)-th. Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one. Today Sasha invited Dima and proposed him a game. First he puts *n* coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for *n* times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence. The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=300<=000) — number of coins that Sasha puts behind Dima. Second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position *p*1, then coin located at position *p*2 and so on. Coins are numbered from left to right. Output Specification: Print *n*<=+<=1 numbers *a*0,<=*a*1,<=...,<=*a**n*, where *a*0 is a hardness of ordering at the beginning, *a*1 is a hardness of ordering after the first replacement and so on. Demo Input: ['4\n1 3 4 2\n', '8\n6 8 3 4 7 2 1 5\n'] Demo Output: ['1 2 3 2 1\n', '1 2 2 3 4 3 4 5 1\n'] Note: Let's denote as O coin out of circulation, and as X — coin is circulation. At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges. After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process. XOOO  →  OOOX After replacement of the third coin, Dima's actions look this way: XOXO  →  OXOX  →  OOXX After replacement of the fourth coin, Dima's actions look this way: XOXX  →  OXXX Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
```python n=int(input()) pyt= list(map(int, input().split(maxsplit = n))) hod=[1] arr=[0 for i in range(n)] nul=n ed=0 pyt.pop() for i in pyt: arr[i-1]=1 ed+=1 if i==nul: arr.reverse() nul=n-arr.index(0) arr.reverse() hod.append(ed-(n-nul-1)) hod.append(1) print(hod) ```
0
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,694,449,918
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
a = input() # Initialize pointers for both strings i = 0 # Pointer for "hello" for char in a: if char == 'h' and i == 0: i += 1 elif char == 'e' and i == 1: i += 1 elif char == 'l' and i == 2: i += 1 elif char == 'l' and i == 3: i += 1 elif char == 'o' and i == 4: i += 1 # Check if all characters in "hello" have been found in order if i == 5: 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 a = input() # Initialize pointers for both strings i = 0 # Pointer for "hello" for char in a: if char == 'h' and i == 0: i += 1 elif char == 'e' and i == 1: i += 1 elif char == 'l' and i == 2: i += 1 elif char == 'l' and i == 3: i += 1 elif char == 'o' and i == 4: i += 1 # Check if all characters in "hello" have been found in order if i == 5: print("YES") else: print("NO") ```
3.969
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" } ]
1,663,664,368
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) s = [[int(x) for x in input().split()] for _ in range(n)] s.sort(reverse=True) for i in s[1:]: if i[1] > s[0][1]: print('Happy Alex') break s[0][1] = i[1] else: print('Poor Alex')
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python n = int(input()) s = [[int(x) for x in input().split()] for _ in range(n)] s.sort(reverse=True) for i in s[1:]: if i[1] > s[0][1]: print('Happy Alex') break s[0][1] = i[1] else: print('Poor Alex') ```
-1
883
F
Lost in Transliteration
PROGRAMMING
1,300
[ "implementation" ]
null
null
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are *n* users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u"  "oo" and "h"  "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: - "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" "kuuper" and "kuooper" "kuuper". - "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" "khoon" and "kkkhoon" "kkhoon" "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name.
The first line contains integer number *n* (2<=≤<=*n*<=≤<=400) — number of the words in the list. The following *n* lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
[ "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "2\nalex\nalex\n" ]
[ "4\n", "5\n", "1\n" ]
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 1. "oolyana", "ulyana" 1. "kooooper", "koouper" 1. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 1. "hkariton" 1. "buoi", "boooi", "boui" 1. "bui" 1. "boi" In the third example the words are equal, so they denote the same name.
0
[ { "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4" }, { "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5" }, { "input": "2\nalex\nalex", "output": "1" }, { "input": "40\nuok\nkuu\nku\no\nkku\nuh\nu\nu\nhh\nk\nkh\nh\nh\nou\nokh\nukk\nou\nuhk\nuo\nuko\nu\nuu\nh\nh\nhk\nuhu\nuoh\nooo\nk\nh\nuk\nk\nkku\nh\nku\nok\nk\nkuu\nou\nhh", "output": "21" }, { "input": "40\noooo\nhu\no\nhoh\nkhk\nuuh\nhu\nou\nuuoh\no\nkouk\nuouo\nu\nok\nuu\nuuuo\nhoh\nuu\nkuu\nh\nu\nkkoh\nkhh\nuoh\nouuk\nkuo\nk\nu\nuku\nh\nu\nk\nhuho\nku\nh\noo\nuh\nk\nuo\nou", "output": "25" }, { "input": "100\nuh\nu\nou\nhk\nokh\nuou\nk\no\nuhh\nk\noku\nk\nou\nhuh\nkoo\nuo\nkk\nkok\nhhu\nuu\noou\nk\nk\noh\nhk\nk\nu\no\nuo\no\no\no\nhoh\nkuo\nhuh\nkhu\nuu\nk\noku\nk\nh\nuu\nuo\nhuo\noo\nhu\nukk\nok\no\noh\nuo\nkko\nok\nouh\nkoh\nhhu\nku\nko\nhho\nkho\nkho\nkhk\nho\nhk\nuko\nukh\nh\nkh\nkk\nuku\nkkk\no\nuo\no\nouh\nou\nuhk\nou\nk\nh\nkko\nuko\no\nu\nho\nu\nooo\nuo\no\nko\noh\nkh\nuk\nohk\noko\nuko\nh\nh\noo\no", "output": "36" }, { "input": "101\nukuu\nh\nouuo\no\nkkuo\nko\nu\nh\nhku\nh\nh\nhuo\nuhoh\nkuu\nhu\nhkko\nuhuk\nkoho\nh\nhukk\noohu\nkk\nkko\nou\noou\nh\nuuu\nuh\nkhuk\nokoo\nouou\nuo\nkk\noo\nhuok\no\nu\nhok\nhu\nhhuu\nkuu\nooho\noku\nhuoh\nhhkh\nuuuh\nouo\nhou\nhhu\nh\no\nokou\nuo\nh\nukk\nu\nhook\nh\noouk\nokuo\nkuuu\nk\nuuk\nu\nukk\nkk\nu\nuhk\nh\nk\nokuu\nuoho\nkhuk\nhukk\nhoo\nouko\nu\nuu\nu\nh\nhuo\nh\nukk\nhk\nk\nuoh\nhk\nko\nou\nho\nu\nhhhk\nkuo\nhuo\nhkh\nku\nhok\nho\nkok\nhk\nouuh", "output": "50" }, { "input": "2\nkkkhkkh\nhh", "output": "1" }, { "input": "2\nkkhookkhoo\nhuhu", "output": "1" } ]
1,556,883,505
4,705
PyPy 3
RUNTIME_ERROR
TESTS
3
171
1,024,000
def k(s): a = '' for i in range(len(s)): if s[i] == 'k' and s[i-1] != 'k': temp = i elif s[i] == 'k' and s[i-1] == 'k': continue elif s[i] == 'h' and s[i-1] == 'k': a += s[i] elif s[i] != 'h' and s[i-1] == 'k': a += s[temp:i+1] else: a += s[i] return a def u(s): a = '' for i in s: if i == 'u': a += 'oo' else: a += i return a n = int(input()) s = set() for i in range(n): temp = input() s.add(u(k(temp))) print(len(s))
Title: Lost in Transliteration Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are *n* users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u"  "oo" and "h"  "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: - "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" "kuuper" and "kuooper" "kuuper". - "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" "khoon" and "kkkhoon" "kkhoon" "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input Specification: The first line contains integer number *n* (2<=≤<=*n*<=≤<=400) — number of the words in the list. The following *n* lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Specification: Print the minimal number of groups where the words in each group denote the same name. Demo Input: ['10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n', '9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n', '2\nalex\nalex\n'] Demo Output: ['4\n', '5\n', '1\n'] Note: There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 1. "oolyana", "ulyana" 1. "kooooper", "koouper" 1. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 1. "hkariton" 1. "buoi", "boooi", "boui" 1. "bui" 1. "boi" In the third example the words are equal, so they denote the same name.
```python def k(s): a = '' for i in range(len(s)): if s[i] == 'k' and s[i-1] != 'k': temp = i elif s[i] == 'k' and s[i-1] == 'k': continue elif s[i] == 'h' and s[i-1] == 'k': a += s[i] elif s[i] != 'h' and s[i-1] == 'k': a += s[temp:i+1] else: a += s[i] return a def u(s): a = '' for i in s: if i == 'u': a += 'oo' else: a += i return a n = int(input()) s = set() for i in range(n): temp = input() s.add(u(k(temp))) print(len(s)) ```
-1
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,685,873,225
2,147,483,647
Python 3
OK
TESTS
26
46
0
tm = input().split() n, m = int(tm[0]), int(tm[1]) it = n p = 0 while it // m - p > 0: l = p p = it // m it += it // m - l print(it)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python tm = input().split() n, m = int(tm[0]), int(tm[1]) it = n p = 0 while it // m - p > 0: l = p p = it // m it += it // m - l print(it) ```
3
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,655,841,908
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
n, m = map(int, input().split()) count = 0 c=((((n//m)+n)//m)+n) while c > 0: c=c-1 count+=1 print(count)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python n, m = map(int, input().split()) count = 0 c=((((n//m)+n)//m)+n) while c > 0: c=c-1 count+=1 print(count) ```
0
577
A
Multiplication Table
PROGRAMMING
1,000
[ "implementation", "number theory" ]
null
null
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Print a single number: the number of times *x* occurs in the table.
[ "10 5\n", "6 12\n", "5 13\n" ]
[ "2\n", "4\n", "0\n" ]
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
500
[ { "input": "10 5", "output": "2" }, { "input": "6 12", "output": "4" }, { "input": "5 13", "output": "0" }, { "input": "1 1", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "100000 1", "output": "1" }, { "input": "1 1000000000", "output": "0" }, { "input": "100000 1000000000", "output": "16" }, { "input": "100000 362880", "output": "154" }, { "input": "1 4", "output": "0" }, { "input": "9 12", "output": "4" }, { "input": "10 123", "output": "0" }, { "input": "9551 975275379", "output": "0" }, { "input": "17286 948615687", "output": "0" }, { "input": "58942 936593001", "output": "0" }, { "input": "50000 989460910", "output": "4" }, { "input": "22741 989460910", "output": "0" }, { "input": "22740 989460910", "output": "0" }, { "input": "100000 989460910", "output": "4" }, { "input": "100000 98280", "output": "128" }, { "input": "100000 997920", "output": "222" }, { "input": "100000 720720", "output": "226" }, { "input": "100000 2162160", "output": "282" }, { "input": "100000 4324320", "output": "320" }, { "input": "100000 8648640", "output": "348" }, { "input": "100000 183783600", "output": "438" }, { "input": "100000 551350800", "output": "392" }, { "input": "40000 551350800", "output": "150" }, { "input": "20000 400000000", "output": "1" }, { "input": "19999 400000000", "output": "0" }, { "input": "19999 399960001", "output": "1" }, { "input": "31621 999887641", "output": "1" }, { "input": "31622 999887641", "output": "1" }, { "input": "31620 999887641", "output": "0" }, { "input": "100000 999887641", "output": "3" }, { "input": "100000 25", "output": "3" }, { "input": "100000 1", "output": "1" }, { "input": "100000 3628800", "output": "220" }, { "input": "100000 39916800", "output": "328" }, { "input": "100000 479001600", "output": "254" }, { "input": "4 9", "output": "1" }, { "input": "2 6", "output": "0" }, { "input": "20 100", "output": "3" }, { "input": "10 3", "output": "2" }, { "input": "4 4", "output": "3" }, { "input": "2 4", "output": "1" }, { "input": "89874 1", "output": "1" } ]
1,676,319,580
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
0
n, x = map(int,input().split()) r = n i = 1 j = 0 c = 1 if n * n >= x: while r <= n * n: if i == x: j += 1 i += c if i == r: if i == x: j += 1 c += 1 i = c r = r + n print(j)
Title: Multiplication Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. Input Specification: The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. Output Specification: Print a single number: the number of times *x* occurs in the table. Demo Input: ['10 5\n', '6 12\n', '5 13\n'] Demo Output: ['2\n', '4\n', '0\n'] Note: A table for the second sample test is given below. The occurrences of number 12 are marked bold.
```python n, x = map(int,input().split()) r = n i = 1 j = 0 c = 1 if n * n >= x: while r <= n * n: if i == x: j += 1 i += c if i == r: if i == x: j += 1 c += 1 i = c r = r + n print(j) ```
0
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game.
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, { "input": "8 8 1 1 1", "output": "Second" }, { "input": "15 14 32 65 28", "output": "First" }, { "input": "894 197 325 232 902", "output": "First" }, { "input": "1 2 8 8 5", "output": "Friendship" }, { "input": "37 261 207 1 1000", "output": "Friendship" }, { "input": "29 344 406 900 1", "output": "Friendship" }, { "input": "1 2 8 9 8", "output": "First" }, { "input": "2 9 8 8 9", "output": "Friendship" }, { "input": "213 480 811 134 745", "output": "First" }, { "input": "2 313 856 964 421", "output": "Friendship" }, { "input": "1 10 2 6 10", "output": "Friendship" }, { "input": "2 7 6 2 3", "output": "Friendship" }, { "input": "637 324 69 612 998", "output": "Second" }, { "input": "13 849 819 723 918", "output": "Friendship" }, { "input": "9 5 7 8 7", "output": "First" }, { "input": "6 5 7 10 4", "output": "Friendship" }, { "input": "61 464 623 89 548", "output": "First" }, { "input": "641 31 29 161 802", "output": "Friendship" }, { "input": "3 3 1 6 9", "output": "Friendship" }, { "input": "2 3 9 8 2", "output": "Friendship" }, { "input": "485 117 368 567 609", "output": "First" }, { "input": "4 202 512 995 375", "output": "Friendship" }, { "input": "424 41 41 909 909", "output": "Friendship" }, { "input": "884 913 263 641 265", "output": "Second" }, { "input": "12 462 8 311 327", "output": "Second" }, { "input": "436 306 266 493 580", "output": "Second" }, { "input": "69 1 2 1 2", "output": "First" } ]
1,653,536,231
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
s, v1, v2, t1, t2 = list(map(int, input().split())) print(s,v1,v2,t1,t2) def calc(s, t, v): result = s * v + 2 * t return result first = calc(s, t1, v1) second = calc(s, t2, v2) if first > second: print('Second') elif second > first: print('First') else: print('Friendship')
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *t*2 milliseconds. If connection ping (delay) is *t* milliseconds, the competition passes for a participant as follows: 1. Exactly after *t* milliseconds after the start of the competition the participant receives the text to be entered. 1. Right after that he starts to type it. 1. Exactly *t* milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input Specification: The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output Specification: If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Demo Input: ['5 1 2 1 2\n', '3 3 1 1 1\n', '4 5 3 1 5\n'] Demo Output: ['First\n', 'Second\n', 'Friendship\n'] Note: In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
```python s, v1, v2, t1, t2 = list(map(int, input().split())) print(s,v1,v2,t1,t2) def calc(s, t, v): result = s * v + 2 * t return result first = calc(s, t1, v1) second = calc(s, t2, v2) if first > second: print('Second') elif second > first: print('First') else: print('Friendship') ```
0
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,579,252,859
2,147,483,647
Python 3
OK
TESTS
53
310
6,656,000
S1, S2, Dif = input(), input() , [] if len(S1) != len(S2): print("NO"); exit() for i in zip(S1 , S2): if i[0] != i[1]: Dif.append(sorted(i)) print("YES" if len(Dif)==2 and Dif[0]==Dif[1] else "NO") # Show you deserve being the best to whom doesn't believe in you.
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 S1, S2, Dif = input(), input() , [] if len(S1) != len(S2): print("NO"); exit() for i in zip(S1 , S2): if i[0] != i[1]: Dif.append(sorted(i)) print("YES" if len(Dif)==2 and Dif[0]==Dif[1] else "NO") # Show you deserve being the best to whom doesn't believe in you. ```
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,611,046,087
2,147,483,647
PyPy 3
OK
TESTS
34
248
0
n = int(input()) d = {} for i in range(n): x = input() if x not in d: d[x] = 1 else: d[x] += 1 print(max(d, key = d.get))
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) d = {} for i in range(n): x = input() if x not in d: d[x] = 1 else: d[x] += 1 print(max(d, key = d.get)) ```
3.938
916
C
Jamie and Interesting Graph
PROGRAMMING
1,600
[ "constructive algorithms", "graphs", "shortest paths" ]
null
null
Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number. - The graph contains no loops or multi-edges. If you are not familiar with some terms from the statement you can find definitions of them in notes section. Help Jamie construct any graph with given number of vertices and edges that is interesting!
First line of input contains 2 integers *n*, *m*  — the required number of vertices and edges.
In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) describing the edge connecting *u* and *v* and having weight *w*.
[ "4 4\n", "5 4\n" ]
[ "7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n", "7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n" ]
The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shortest path in an undirected graph is a sequence of vertices (*v*<sub class="lower-index">1</sub>, *v*<sub class="lower-index">2</sub>, ... , *v*<sub class="lower-index">*k*</sub>) such that *v*<sub class="lower-index">*i*</sub> is adjacent to *v*<sub class="lower-index">*i* + 1</sub> 1 ≤ *i* &lt; *k* and the sum of weight <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e7f62cfd5c2c3b81dc80aaf2f512898495354f03.png" style="max-width: 100.0%;max-height: 100.0%;"/> is minimized where *w*(*i*, *j*) is the edge weight between *i* and *j*. ([https://en.wikipedia.org/wiki/Shortest_path_problem](https://en.wikipedia.org/wiki/Shortest_path_problem)) A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ([https://en.wikipedia.org/wiki/Prime_number](https://en.wikipedia.org/wiki/Prime_number)) A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. ([https://en.wikipedia.org/wiki/Minimum_spanning_tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)) [https://en.wikipedia.org/wiki/Multiple_edges](https://en.wikipedia.org/wiki/Multiple_edges)
1,500
[ { "input": "4 4", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000" }, { "input": "5 4", "output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1" }, { "input": "2 1", "output": "100003 100003\n1 2 100003" }, { "input": "10 19", "output": "100003 100003\n1 2 99995\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n2 4 1000000000\n2 5 1000000000" }, { "input": "9 18", "output": "100003 100003\n1 2 99996\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n2 4 1000000000\n2 5 1000000000\n2 6 1000000000" }, { "input": "92 280", "output": "100003 100003\n1 2 99913\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "89 3439", "output": "100003 100003\n1 2 99916\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "926 31057", "output": "100003 100003\n1 2 99079\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "753 98686", "output": "100003 100003\n1 2 99252\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9724 31045", "output": "100003 100003\n1 2 90281\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "8732 93395", "output": "100003 100003\n1 2 91273\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "80297 83088", "output": "100003 100003\n1 2 19708\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "86549 98929", "output": "100003 100003\n1 2 13456\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "87 109", "output": "100003 100003\n1 2 99918\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "95 3582", "output": "100003 100003\n1 2 99910\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "96 557", "output": "100003 100003\n1 2 99909\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "85 3106", "output": "100003 100003\n1 2 99920\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "98 367", "output": "100003 100003\n1 2 99907\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "77 2344", "output": "100003 100003\n1 2 99928\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 286", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4665", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94 350", "output": "100003 100003\n1 2 99911\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 4309", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "88 666", "output": "100003 100003\n1 2 99917\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93 4075", "output": "100003 100003\n1 2 99912\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "100 342", "output": "100003 100003\n1 2 99905\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "84 3482", "output": "100003 100003\n1 2 99921\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 51645", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "808 63768", "output": "100003 100003\n1 2 99197\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "898 1882", "output": "100003 100003\n1 2 99107\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "662 76813", "output": "100003 100003\n1 2 99343\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "681 13806", "output": "100003 100003\n1 2 99324\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "991 92176", "output": "100003 100003\n1 2 99014\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "745 4986", "output": "100003 100003\n1 2 99260\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "954 94880", "output": "100003 100003\n1 2 99051\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "965 5451", "output": "100003 100003\n1 2 99040\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "943 95302", "output": "100003 100003\n1 2 99062\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "879 8524", "output": "100003 100003\n1 2 99126\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "953 98192", "output": "100003 100003\n1 2 99052\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "806 1771", "output": "100003 100003\n1 2 99199\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "790 97497", "output": "100003 100003\n1 2 99215\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9492 36483", "output": "100003 100003\n1 2 90513\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5839 48668", "output": "100003 100003\n1 2 94166\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9029 15632", "output": "100003 100003\n1 2 90976\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "5127 53185", "output": "100003 100003\n1 2 94878\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7044 33010", "output": "100003 100003\n1 2 92961\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9637 98924", "output": "100003 100003\n1 2 90368\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "7837 45130", "output": "100003 100003\n1 2 92168\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9603 99398", "output": "100003 100003\n1 2 90402\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9204 11722", "output": "100003 100003\n1 2 90801\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "6996 90227", "output": "100003 100003\n1 2 93009\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9897 21204", "output": "100003 100003\n1 2 90108\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9051 92600", "output": "100003 100003\n1 2 90954\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9880 13424", "output": "100003 100003\n1 2 90125\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "9811 89446", "output": "100003 100003\n1 2 90194\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "90498 92256", "output": "100003 100003\n1 2 9507\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99840 99968", "output": "100003 100003\n1 2 165\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "92340 92571", "output": "100003 100003\n1 2 7665\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99019 99681", "output": "100003 100003\n1 2 986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "93750 94653", "output": "100003 100003\n1 2 6255\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "99831 99956", "output": "100003 100003\n1 2 174\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1..." }, { "input": "95373 95859", "output": "100003 100003\n1 2 4632\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "95519 99837", "output": "100003 100003\n1 2 4486\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "94183 94638", "output": "100003 100003\n1 2 5822\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "84935 98326", "output": "100003 100003\n1 2 15070\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "94995 95821", "output": "100003 100003\n1 2 5010\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "88804 99911", "output": "100003 100003\n1 2 11201\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "93394 94036", "output": "100003 100003\n1 2 6611\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "97796 99885", "output": "100003 100003\n1 2 2209\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 ..." }, { "input": "3 2", "output": "100003 100003\n1 2 100002\n2 3 1" }, { "input": "3 3", "output": "100003 100003\n1 2 100002\n2 3 1\n1 3 1000000000" }, { "input": "4 3", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1" }, { "input": "4 5", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000" }, { "input": "4 6", "output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000\n1 4 1000000000\n2 4 1000000000" }, { "input": "100000 100000", "output": "100003 100003\n1 2 5\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58 1\n..." }, { "input": "50000 100000", "output": "100003 100003\n1 2 50005\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "1415 100000", "output": "100003 100003\n1 2 98590\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n19 20 1\n20 21 1\n21 22 1\n22 23 1\n23 24 1\n24 25 1\n25 26 1\n26 27 1\n27 28 1\n28 29 1\n29 30 1\n30 31 1\n31 32 1\n32 33 1\n33 34 1\n34 35 1\n35 36 1\n36 37 1\n37 38 1\n38 39 1\n39 40 1\n40 41 1\n41 42 1\n42 43 1\n43 44 1\n44 45 1\n45 46 1\n46 47 1\n47 48 1\n48 49 1\n49 50 1\n50 51 1\n51 52 1\n52 53 1\n53 54 1\n54 55 1\n55 56 1\n56 57 1\n57 58..." }, { "input": "13 17", "output": "100003 100003\n1 2 99992\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000" }, { "input": "19 31", "output": "100003 100003\n1 2 99986\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 8 1\n8 9 1\n9 10 1\n10 11 1\n11 12 1\n12 13 1\n13 14 1\n14 15 1\n15 16 1\n16 17 1\n17 18 1\n18 19 1\n1 3 1000000000\n1 4 1000000000\n1 5 1000000000\n1 6 1000000000\n1 7 1000000000\n1 8 1000000000\n1 9 1000000000\n1 10 1000000000\n1 11 1000000000\n1 12 1000000000\n1 13 1000000000\n1 14 1000000000\n1 15 1000000000" } ]
1,528,189,682
2,147,483,647
Python 3
OK
TESTS
79
841
7,270,400
def doit(n, m): if (n == 2): print(2, 2) print(1, 2, 2) return sp = 2 mstw = 100003 print(sp, mstw) print(1, n, sp) print(2, n, mstw - n + 3 - sp) for i in range(3, n): print(i, n, 1) for i in range(2, n): for j in range(1, i): if (m == n - 1): return print(i, j, mstw) m -= 1 n, m = input().split() doit(int(n), int(m))
Title: Jamie and Interesting Graph Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie has recently found undirected weighted graphs with the following properties very interesting: - The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number. - The graph contains no loops or multi-edges. If you are not familiar with some terms from the statement you can find definitions of them in notes section. Help Jamie construct any graph with given number of vertices and edges that is interesting! Input Specification: First line of input contains 2 integers *n*, *m*  — the required number of vertices and edges. Output Specification: In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) describing the edge connecting *u* and *v* and having weight *w*. Demo Input: ['4 4\n', '5 4\n'] Demo Output: ['7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n', '7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n'] Note: The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*). Definition of terms used in the problem statement: A shortest path in an undirected graph is a sequence of vertices (*v*<sub class="lower-index">1</sub>, *v*<sub class="lower-index">2</sub>, ... , *v*<sub class="lower-index">*k*</sub>) such that *v*<sub class="lower-index">*i*</sub> is adjacent to *v*<sub class="lower-index">*i* + 1</sub> 1 ≤ *i* &lt; *k* and the sum of weight <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e7f62cfd5c2c3b81dc80aaf2f512898495354f03.png" style="max-width: 100.0%;max-height: 100.0%;"/> is minimized where *w*(*i*, *j*) is the edge weight between *i* and *j*. ([https://en.wikipedia.org/wiki/Shortest_path_problem](https://en.wikipedia.org/wiki/Shortest_path_problem)) A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ([https://en.wikipedia.org/wiki/Prime_number](https://en.wikipedia.org/wiki/Prime_number)) A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. ([https://en.wikipedia.org/wiki/Minimum_spanning_tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)) [https://en.wikipedia.org/wiki/Multiple_edges](https://en.wikipedia.org/wiki/Multiple_edges)
```python def doit(n, m): if (n == 2): print(2, 2) print(1, 2, 2) return sp = 2 mstw = 100003 print(sp, mstw) print(1, n, sp) print(2, n, mstw - n + 3 - sp) for i in range(3, n): print(i, n, 1) for i in range(2, n): for j in range(1, i): if (m == n - 1): return print(i, j, mstw) m -= 1 n, m = input().split() doit(int(n), int(m)) ```
3
621
B
Wet Shark and Bishops
PROGRAMMING
1,300
[ "combinatorics", "implementation" ]
null
null
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.
The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position.
Output one integer — the number of pairs of bishops which attack each other.
[ "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "3\n1 1\n2 3\n3 5\n" ]
[ "6\n", "0\n" ]
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
1,000
[ { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5", "output": "6" }, { "input": "3\n1 1\n2 3\n3 5", "output": "0" }, { "input": "3\n859 96\n634 248\n808 72", "output": "0" }, { "input": "3\n987 237\n891 429\n358 145", "output": "0" }, { "input": "3\n411 81\n149 907\n611 114", "output": "0" }, { "input": "3\n539 221\n895 89\n673 890", "output": "0" }, { "input": "3\n259 770\n448 54\n926 667", "output": "0" }, { "input": "3\n387 422\n898 532\n988 636", "output": "0" }, { "input": "10\n515 563\n451 713\n537 709\n343 819\n855 779\n457 60\n650 359\n631 42\n788 639\n710 709", "output": "0" }, { "input": "10\n939 407\n197 191\n791 486\n30 807\n11 665\n600 100\n445 496\n658 959\n510 389\n729 950", "output": "0" }, { "input": "10\n518 518\n71 971\n121 862\n967 607\n138 754\n513 337\n499 873\n337 387\n647 917\n76 417", "output": "0" }, { "input": "10\n646 171\n816 449\n375 934\n950 299\n702 232\n657 81\n885 306\n660 304\n369 371\n798 657", "output": "0" }, { "input": "10\n70 311\n74 927\n732 711\n126 583\n857 118\n97 928\n975 843\n175 221\n284 929\n816 602", "output": "0" }, { "input": "2\n1 1\n1 1000", "output": "0" }, { "input": "2\n1 1\n1000 1", "output": "0" }, { "input": "2\n1 1\n1000 1000", "output": "1" }, { "input": "2\n1000 1\n1 1000", "output": "1" }, { "input": "2\n1000 1\n1000 1000", "output": "0" }, { "input": "2\n1 1000\n1000 1000", "output": "0" }, { "input": "1\n6 3", "output": "0" }, { "input": "1\n1 1", "output": "0" }, { "input": "1\n1 1000", "output": "0" }, { "input": "1\n1000 1", "output": "0" }, { "input": "1\n1000 1000", "output": "0" }, { "input": "2\n1 1\n3 1", "output": "0" }, { "input": "2\n999 1\n1000 2", "output": "1" }, { "input": "5\n1 1000\n2 999\n3 998\n4 997\n5 996", "output": "10" } ]
1,571,686,941
2,147,483,647
PyPy 3
OK
TESTS
68
1,560
9,728,000
size = 10 n = int(input()) cnt = 0 dp1, dp2 = {}, {} for i in range(n): i, j = map(int, input().split()) s, d = i + j, i - j if not s in dp1.keys(): dp1[s] = 0 if not d in dp2.keys(): dp2[d] = 0 dp1[s] += 1 dp2[d] += 1 for v in dp1.values(): cnt += (v * (v - 1)) // 2 for v in dp2.values(): cnt += (v * (v - 1)) // 2 print(cnt)
Title: Wet Shark and Bishops Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. Input Specification: The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position. Output Specification: Output one integer — the number of pairs of bishops which attack each other. Demo Input: ['5\n1 1\n1 5\n3 3\n5 1\n5 5\n', '3\n1 1\n2 3\n3 5\n'] Demo Output: ['6\n', '0\n'] Note: In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
```python size = 10 n = int(input()) cnt = 0 dp1, dp2 = {}, {} for i in range(n): i, j = map(int, input().split()) s, d = i + j, i - j if not s in dp1.keys(): dp1[s] = 0 if not d in dp2.keys(): dp2[d] = 0 dp1[s] += 1 dp2[d] += 1 for v in dp1.values(): cnt += (v * (v - 1)) // 2 for v in dp2.values(): cnt += (v * (v - 1)) // 2 print(cnt) ```
3
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 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", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 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", "output": "YES" } ]
1,665,471,594
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
31
0
a,b=map(int,input().split()) z=[] for i in range(a): c=input().split() for v in c: z.append(v) f=set(z) if len(f)==b: print('YES') else: print('NO')
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. Input Specification: The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. Output Specification: If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". Demo Input: ['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
```python a,b=map(int,input().split()) z=[] for i in range(a): c=input().split() for v in c: z.append(v) f=set(z) if len(f)==b: print('YES') else: print('NO') ```
0
585
D
Lizard Era: Beginning
PROGRAMMING
2,300
[ "meet-in-the-middle" ]
null
null
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has *n* mandatory quests. To perform each of them, you need to take exactly two companions. The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction. Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=25) — the number of important tasks. Next *n* lines contain the descriptions of the tasks — the *i*-th line contains three integers *l**i*,<=*m**i*,<=*w**i* — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the *i*-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.
If there is no solution, print in the first line "Impossible". Otherwise, print *n* lines, two characters is each line — in the *i*-th line print the first letters of the companions' names that hero should take to complete the *i*-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.
[ "3\n1 0 0\n0 1 0\n0 0 1\n", "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7\n", "2\n1 0 0\n1 1 0\n" ]
[ "LM\nMW\nMW\n", "LM\nMW\nLM\nLW\nMW\nLM\nLW\n", "Impossible\n" ]
none
1,750
[ { "input": "3\n1 0 0\n0 1 0\n0 0 1", "output": "LM\nMW\nMW" }, { "input": "7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7", "output": "LM\nMW\nLM\nLW\nMW\nLM\nLW" }, { "input": "2\n1 0 0\n1 1 0", "output": "Impossible" }, { "input": "25\n26668 10412 12658\n25216 11939 10247\n28514 22515 5833\n4955 19029 22405\n12552 6903 19634\n12315 1671 505\n20848 9175 6060\n12990 5827 16433\n9184 30621 25596\n31818 7826 11221\n18090 4476 30078\n30915 11014 16950\n3119 29529 21390\n775 4290 11723\n29679 14840 3566\n4491 29480 2079\n24129 5496 6381\n20849 25772 9299\n10825 30424 11842\n18290 14728 30342\n24893 27064 11604\n26248 7490 18116\n17182 32158 12518\n23145 4288 7754\n18544 25694 18784", "output": "LW\nLM\nLW\nMW\nMW\nLW\nMW\nLW\nMW\nLW\nLW\nLW\nLM\nMW\nMW\nMW\nLW\nLM\nLM\nMW\nMW\nLW\nMW\nMW\nLW" }, { "input": "1\n0 0 0", "output": "MW" }, { "input": "1\n1 0 0", "output": "MW" }, { "input": "1\n0 1 0", "output": "LW" }, { "input": "1\n0 0 1", "output": "LM" }, { "input": "7\n-925 88 -550\n205 406 -957\n-596 259 -448\n857 635 719\n-149 -487 -85\n245 -59 78\n-870 -959 -733", "output": "LM\nMW\nMW\nLW\nMW\nLW\nLM" }, { "input": "8\n697 78 -270\n17 240 64\n615 6 967\n565 486 -862\n517 -17 -852\n958 949 505\n199 -866 711\n251 -177 549", "output": "LW\nMW\nMW\nMW\nLM\nMW\nLW\nLW" }, { "input": "9\n-477 504 222\n30 698 346\n-142 168 -322\n162 371 219\n-470 417 -102\n-104 -236 785\n131 -686 870\n420 -289 -333\n743 -611 111", "output": "LM\nLW\nMW\nLM\nMW\nLW\nLM\nMW\nLW" }, { "input": "10\n-134 5 -71\n-615 -591 -548\n626 -787 -682\n-392 -689 900\n-93 789 194\n-657 438 806\n308 219 129\n-247 -220 -358\n-720 -841 -974\n833 -845 -268", "output": "LW\nLM\nMW\nLM\nLM\nMW\nLW\nLM\nLW\nLW" }, { "input": "11\n-368 775 -959\n-281 483 -979\n685 902 211\n-336 63 458\n116 -957 -802\n-856 751 -608\n956 -636 -17\n561 186 228\n-301 -807 304\n-103 -476 18\n-579 116 850", "output": "LW\nLM\nLM\nMW\nLM\nLW\nMW\nLM\nLM\nLM\nLM" }, { "input": "12\n-749 66 -780\n293 440 891\n-404 -787 -159\n454 68 -675\n105 116 -121\n516 849 470\n603 208 -583\n333 110 17\n-591 818 252\n-313 -131 -370\n-865 61 309\n583 306 536", "output": "LM\nLM\nMW\nLM\nLW\nLW\nLM\nLW\nLM\nMW\nLW\nLW" }, { "input": "13\n-495 262 21\n148 188 374\n935 67 567\n-853 -862 -164\n-878 990 -80\n824 536 934\n254 -436 -310\n355 803 -627\n30 409 -624\n-212 -950 182\n582 96 738\n316 221 -341\n-178 691 3", "output": "LW\nLM\nMW\nMW\nMW\nLW\nMW\nMW\nLW\nLM\nMW\nMW\nLW" }, { "input": "14\n167 -30 -195\n-8 604 701\n592 -402 168\n-982 12 592\n929 999 -200\n-37 645 615\n512 -553 515\n-830 743 -574\n436 -815 180\n-787 420 906\n733 226 -650\n295 -571 7\n-879 739 369\n-124 801 -253", "output": "MW\nLM\nLM\nMW\nLW\nLM\nLM\nLM\nMW\nLW\nLM\nLM\nMW\nMW" }, { "input": "15\n74 716 -568\n-958 -441 167\n-716 -554 -403\n-364 934 395\n-673 36 945\n-102 -227 69\n979 -721 -132\n790 -494 292\n-781 -478 -545\n-591 -274 965\n-46 -983 -835\n37 -540 -375\n-417 139 -761\n772 969 -197\n-74 -975 -662", "output": "LM\nLW\nMW\nLW\nMW\nLW\nLM\nLM\nLW\nMW\nLW\nLM\nLW\nMW\nLW" }, { "input": "16\n-885 -621 -319\n500 705 -709\n-376 -884 -102\n346 176 448\n611 954 -23\n-372 -993 177\n-288 -977 -777\n-966 -644 867\n834 -561 984\n-868 545 789\n340 0 782\n754 -263 518\n112 -747 -944\n-760 -624 383\n353 -654 -341\n-451 477 -819", "output": "LW\nLM\nLW\nLM\nLM\nLM\nLW\nMW\nLW\nLM\nMW\nLW\nMW\nLM\nLW\nMW" }, { "input": "17\n881 984 -560\n-272 527 537\n944 135 782\n265 652 73\n340 995 -116\n-625 -197 -859\n-515 584 416\n709 -144 -5\n-187 -95 228\n646 -711 -647\n892 -824 -177\n442 -258 622\n-527 -715 155\n-110 -417 857\n-72 -547 531\n86 597 454\n-332 57 -731", "output": "MW\nMW\nMW\nLW\nMW\nMW\nMW\nLW\nLM\nLW\nLW\nLW\nLM\nMW\nMW\nMW\nLM" }, { "input": "18\n59 502 341\n-464 -595 655\n161 617 569\n179 284 -667\n418 430 239\n803 105 385\n770 -807 -223\n-154 47 560\n-886 -907 -533\n-723 -728 -584\n676 715 460\n779 26 -894\n26 989 -364\n-390 738 241\n246 683 220\n-716 -752 722\n913 528 926\n229 -813 485", "output": "LW\nMW\nMW\nMW\nLW\nLM\nLW\nLW\nLM\nLW\nLM\nLM\nLW\nMW\nMW\nLW\nLM\nLW" }, { "input": "16\n4642484 -2788746 9992951\n5803062 8109045 72477\n6993256 5860518 -5298508\n2983494 5924807 9075779\n9616987 -7580870 -2342882\n2620968 -2619488 2599421\n1318060 -7292211 3454517\n-7018501 -2464950 9497459\n2254377 -2500546 -1888489\n-20354 -7510645 173023\n619811 -861516 -6346093\n38813 3848272 -8558276\n6409071 4528454 -9768150\n-9344900 3107745 4779111\n5984141 2896281 2888362\n-9097994 -8937736 -419949", "output": "LW\nMW\nLM\nMW\nLW\nMW\nMW\nLM\nLW\nLM\nMW\nMW\nLM\nLW\nLM\nLW" }, { "input": "17\n3461788 -7190737 790707\n-3979181 -7527409 1464659\n3368847 -7475254 -7377314\n-2469024 9316013 6583991\n8223943 9596309 7549117\n1525938 3840013 -9805857\n2489326 7215738 -5874041\n-6183012 596945 5059562\n3412087 6788437 939017\n9690067 -2007875 -1424714\n834164 5247338 -6872328\n3860491 8096731 -2390366\n8174160 7465170 4040376\n-5138898 -2348036 -9154464\n1527659 -4375219 -2725794\n-5350381 -8411693 214736\n-5832848 -6704847 4997762", "output": "MW\nLW\nLW\nLW\nMW\nLM\nMW\nLW\nLW\nLM\nLW\nLM\nLW\nLM\nLW\nMW\nLW" }, { "input": "16\n6742718 -9848759 -3874332\n-8128485 -6617274 1575011\n-1740148 623444 9963227\n3629451 -2414107 -9704466\n7753671 7021614 7248025\n-5420494 6909667 5118838\n4090028 3512092 -6413023\n282544 8907950 5863326\n-9977956 -7405023 8905548\n-7480107 6149899 3468303\n-5494025 2101036 8801937\n-5351537 7051449 69239\n137681 -9994993 -2053076\n-4251695 8203962 -4620459\n8897087 -7891039 5515252\n916961 2371338 -6986487", "output": "MW\nLM\nLM\nMW\nLM\nLW\nLW\nLM\nMW\nLW\nLM\nMW\nMW\nLW\nLW\nLW" }, { "input": "17\n8003952 1945229 -824287\n-2548751 860618 589233\n4195712 -3840408 7878690\n-3178201 -1509129 6136806\n-1406078 3402700 -3298516\n-2639343 -7312210 -7052356\n5744330 -228480 5806356\n-7992147 -9663118 6294695\n-4197990 8982179 4355332\n-406724 -362338 -3609437\n-6459171 -4710527 6551785\n4054102 -9505148 2215175\n-2286309 728140 -2206363\n7183109 -8393962 -5369491\n-7303376 328150 5437901\n8549874 8031324 -4716139\n-5998559 -3896390 2664375", "output": "MW\nLM\nMW\nLM\nMW\nMW\nLM\nLW\nLM\nLW\nLM\nLW\nMW\nLW\nMW\nLW\nLM" }, { "input": "16\n2033906 6164819 -3535254\n-7271523 -1386302 -5832930\n7664268 -7927384 -8316758\n-5929014 6352246 8535844\n-5992054 -3159960 5973202\n8477561 5763594 7527604\n-1611804 3925028 -9320743\n-3732863 -7513881 7445368\n7044279 6186756 -87415\n6810089 -9828741 -8531792\n2105994 -4192310 -1962547\n4522049 5717418 -2009682\n-5638994 7361890 -2071446\n-6518199 -670199 3519089\n-5881880 3506792 -7813715\n3774507 -5501152 2112631", "output": "MW\nLW\nLW\nLW\nMW\nLW\nMW\nMW\nMW\nMW\nLM\nLM\nLW\nLW\nLM\nLM" }, { "input": "17\n5145283 -2753062 -2936514\n-2127587 9440797 -4470168\n4109762 -1351398 1013844\n-5272277 -916706 -402190\n-7510148 -8867866 -2714993\n2254647 7293040 7375284\n-3027010 -8436598 -585941\n9910514 4179567 -7552626\n4295472 -8584445 -5072169\n6661724 9675368 7315049\n-3327283 -7829466 -4900987\n-6243053 -2828295 -6456626\n7489319 -7983760 -3082241\n-8134992 -6899104 -2317283\n9790680 -3222471 2050981\n-8211631 2874090 544657\n-4219486 848554 -287544", "output": "LM\nLM\nMW\nLW\nLM\nLW\nLM\nLW\nLW\nLW\nLW\nLW\nLW\nLW\nMW\nLM\nLW" }, { "input": "16\n-3253484 -6513322 5617669\n-8870526 9976385 -7313669\n5682511 -1202928 -7057533\n4747064 475782 7416790\n-4387656 3965849 9530503\n-8224426 4339650 181725\n1012598 -8651198 -222828\n-1012251 -9099337 719019\n-903577 -1340167 -8701346\n-4502739 736866 -5741036\n-6125650 9410041 948124\n-8344882 3820318 3738053\n5202105 524964 2938536\n752123 2136713 -3095341\n545090 -6807501 -5000825\n5921735 5822186 4106753", "output": "LW\nMW\nLW\nMW\nMW\nMW\nLM\nMW\nLM\nMW\nLW\nLW\nLM\nLW\nMW\nLM" }, { "input": "17\n-9095076 8052666 -1032018\n2681359 -9998418 -3163796\n5865270 -1926467 -6480441\n-2780849 5921425 -7844112\n2813688 -9288645 -8474670\n8145658 -5741326 9011572\n9364418 -8442485 -8888763\n3473152 -1301704 -2502205\n4201907 8497194 9692725\n8874792 537379 8954057\n2083242 -3975356 -62337\n-3654609 2243771 8422585\n7822816 9702585 -3007717\n-6801114 -3025102 -6129158\n7033485 7157201 -6012950\n-7895796 -6052792 9119000\n-932955 4934837 -873726", "output": "LM\nLM\nLM\nMW\nLM\nLM\nMW\nLW\nMW\nMW\nLM\nLM\nMW\nLM\nLM\nLW\nMW" }, { "input": "3\n7089544 9134148 -5332724\n368810 1638695 7889905\n-3866235 -4257263 5802154", "output": "Impossible" }, { "input": "15\n-3682462 -194732 9446852\n-4405738 6933459 -9496709\n9422280 7851074 -9960800\n1002721 -4735302 -6724485\n-9025771 7592049 106547\n2508567 -9291847 8728657\n-558387 1839538 -8263150\n9066346 1788798 -111846\n3033903 -7178126 -2777630\n9282416 2652252 -8446308\n-7520805 -9819190 -9526851\n6504744 3375811 8450106\n-9694972 5307787 622433\n1364366 -7259170 5463805\n8696617 5410821 5813911", "output": "Impossible" }, { "input": "6\n1 0 1\n1 1 0\n0 1 1\n0 1 1\n1 1 0\n1 0 1", "output": "LW\nLM\nMW\nMW\nLM\nLW" } ]
1,585,368,873
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
261,529,600
from itertools import combinations def solve(): for I in range(N // 2 + 2): X[I] = list(combinations(RX, I)) for I in range(N - N // 2): Z[I] = list(combinations(RZ, I)) LX = [] LY = [] MX = [] MY = [] for I in range(len(X)): for J in range(len(X[I])): XL = XM = 0 for A in X[I][J]: XL += L[A] XM += M[A] LX.append([XL, I, J]) MX.append([XM, I, J]) for I in range(len(Z)): for J in range(len(Z[I])): YL = YM = 0 for B in Z[I][J]: YL += L[B] YM += M[B] LY.append([YL, I, J]) MY.append([YM, I, J]) LXY = [] MXY = [] PS = set() MS = set() for I in range(len(LX)): for J in range(len(LY)): if I | J: P = LX[I][0] + LY[J][0] LXY.append([P, I, J]) PS.add(P) for I in range(len(MX)): for J in range(len(MY)): if I | J: P = MX[I][0] + MY[J][0] if P in PS: MXY.append([P, I, J]) MS.add(P) DS = '' MAX = -10**10 for I in LXY: for J in MXY: if I[0] == J[0]: S1 = set(X[LX[I[1]][1]][LX[I[1]][2]]+Z[LY[I[2]][1]][LY[I[2]][2]]) S2 = set(X[MX[J[1]][1]][MX[J[1]][2]]+Z[MY[J[2]][1]][MY[J[2]][2]]) S3 = (S1-S2).union(S2-S1) S3S = 0 for U in S3: S3S+=W[U] if S3S == I[0]: if S1.intersection(S2).union(S2.intersection(S3)).union(S3.intersection(S1)) == S: D = '' T = 0 for Q in range(N): if Q in S1: D+='L' T+=L[Q] if Q in S2: D+='M' T+=M[Q] if Q in S3: D+='W' T+=W[Q] D+='\n' if T > MAX: DS = D MAX = T if DS: print(DS) else: print('Impossible') N = int(input()) L = list(range(N)) M = list(range(N)) W = list(range(N)) S = set(L) X = list(range(N//2+2)) Z = list(range(N-N//2)) RX = list(range(N//2+1)) RZ = list(range(N//2+1, N)) for I in range(N): L[I], M[I], W[I] = map(int, input().split()) solve()
Title: Lizard Era: Beginning Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has *n* mandatory quests. To perform each of them, you need to take exactly two companions. The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction. Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible. Input Specification: The first line contains positive integer *n* (1<=≤<=*n*<=≤<=25) — the number of important tasks. Next *n* lines contain the descriptions of the tasks — the *i*-th line contains three integers *l**i*,<=*m**i*,<=*w**i* — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the *i*-th task. All the numbers in the input are integers and do not exceed 107 in absolute value. Output Specification: If there is no solution, print in the first line "Impossible". Otherwise, print *n* lines, two characters is each line — in the *i*-th line print the first letters of the companions' names that hero should take to complete the *i*-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them. Demo Input: ['3\n1 0 0\n0 1 0\n0 0 1\n', '7\n0 8 9\n5 9 -2\n6 -8 -7\n9 4 5\n-4 -9 9\n-4 5 2\n-6 8 -7\n', '2\n1 0 0\n1 1 0\n'] Demo Output: ['LM\nMW\nMW\n', 'LM\nMW\nLM\nLW\nMW\nLM\nLW\n', 'Impossible\n'] Note: none
```python from itertools import combinations def solve(): for I in range(N // 2 + 2): X[I] = list(combinations(RX, I)) for I in range(N - N // 2): Z[I] = list(combinations(RZ, I)) LX = [] LY = [] MX = [] MY = [] for I in range(len(X)): for J in range(len(X[I])): XL = XM = 0 for A in X[I][J]: XL += L[A] XM += M[A] LX.append([XL, I, J]) MX.append([XM, I, J]) for I in range(len(Z)): for J in range(len(Z[I])): YL = YM = 0 for B in Z[I][J]: YL += L[B] YM += M[B] LY.append([YL, I, J]) MY.append([YM, I, J]) LXY = [] MXY = [] PS = set() MS = set() for I in range(len(LX)): for J in range(len(LY)): if I | J: P = LX[I][0] + LY[J][0] LXY.append([P, I, J]) PS.add(P) for I in range(len(MX)): for J in range(len(MY)): if I | J: P = MX[I][0] + MY[J][0] if P in PS: MXY.append([P, I, J]) MS.add(P) DS = '' MAX = -10**10 for I in LXY: for J in MXY: if I[0] == J[0]: S1 = set(X[LX[I[1]][1]][LX[I[1]][2]]+Z[LY[I[2]][1]][LY[I[2]][2]]) S2 = set(X[MX[J[1]][1]][MX[J[1]][2]]+Z[MY[J[2]][1]][MY[J[2]][2]]) S3 = (S1-S2).union(S2-S1) S3S = 0 for U in S3: S3S+=W[U] if S3S == I[0]: if S1.intersection(S2).union(S2.intersection(S3)).union(S3.intersection(S1)) == S: D = '' T = 0 for Q in range(N): if Q in S1: D+='L' T+=L[Q] if Q in S2: D+='M' T+=M[Q] if Q in S3: D+='W' T+=W[Q] D+='\n' if T > MAX: DS = D MAX = T if DS: print(DS) else: print('Impossible') N = int(input()) L = list(range(N)) M = list(range(N)) W = list(range(N)) S = set(L) X = list(range(N//2+2)) Z = list(range(N-N//2)) RX = list(range(N//2+1)) RZ = list(range(N//2+1, N)) for I in range(N): L[I], M[I], W[I] = map(int, input().split()) solve() ```
0
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,579,615,942
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
109
0
l,r,a=map(int,input().split()) if l==r: print(2*l+(a//2)*2) else: if l>r: l,r=r,l if r-l>=a: print((l+a)*2) else: print(2*r+(a//2)*2)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python l,r,a=map(int,input().split()) if l==r: print(2*l+(a//2)*2) else: if l>r: l,r=r,l if r-l>=a: print((l+a)*2) else: print(2*r+(a//2)*2) ```
0
342
A
Xenia and Divisors
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held: - *a*<=&lt;<=*b*<=&lt;<=*c*; - *a* divides *b*, *b* divides *c*. Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three. Help Xenia, find the required partition or else say that it doesn't exist.
The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7. It is guaranteed that *n* is divisible by 3.
If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them. If there is no solution, print -1.
[ "6\n1 1 1 2 2 2\n", "6\n2 2 1 1 4 6\n" ]
[ "-1\n", "1 2 4\n1 2 6\n" ]
none
500
[ { "input": "6\n1 1 1 2 2 2", "output": "-1" }, { "input": "6\n2 2 1 1 4 6", "output": "1 2 4\n1 2 6" }, { "input": "3\n1 2 3", "output": "-1" }, { "input": "3\n7 5 7", "output": "-1" }, { "input": "3\n1 3 4", "output": "-1" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "9\n1 3 6 6 3 1 3 1 6", "output": "1 3 6\n1 3 6\n1 3 6" }, { "input": "6\n1 2 4 1 3 5", "output": "-1" }, { "input": "3\n1 3 7", "output": "-1" }, { "input": "3\n1 1 1", "output": "-1" }, { "input": "9\n1 2 4 1 2 4 1 3 6", "output": "1 2 4\n1 2 4\n1 3 6" }, { "input": "12\n3 6 1 1 3 6 1 1 2 6 2 6", "output": "1 3 6\n1 3 6\n1 2 6\n1 2 6" }, { "input": "9\n1 1 1 4 4 4 6 2 2", "output": "-1" }, { "input": "9\n1 2 4 6 3 1 3 1 5", "output": "-1" }, { "input": "15\n2 1 2 1 3 6 1 2 1 6 1 3 4 6 4", "output": "1 2 4\n1 2 4\n1 3 6\n1 3 6\n1 2 6" }, { "input": "3\n2 3 6", "output": "-1" }, { "input": "3\n2 4 6", "output": "-1" }, { "input": "3\n2 5 6", "output": "-1" }, { "input": "3\n2 4 7", "output": "-1" }, { "input": "6\n1 2 3 4 5 6", "output": "-1" }, { "input": "3\n7 7 7", "output": "-1" }, { "input": "6\n1 2 4 7 7 7", "output": "-1" }, { "input": "6\n1 1 2 6 6 6", "output": "-1" }, { "input": "9\n1 1 1 3 3 2 4 4 6", "output": "-1" }, { "input": "6\n1 2 4 5 5 5", "output": "-1" }, { "input": "15\n1 1 1 1 1 2 2 2 2 4 4 6 6 6 6", "output": "-1" }, { "input": "6\n1 1 5 5 7 7", "output": "-1" }, { "input": "9\n1 1 1 2 3 4 5 6 7", "output": "-1" }, { "input": "6\n1 1 4 4 7 7", "output": "-1" }, { "input": "24\n1 1 1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 4 4 4 6 6 6", "output": "-1" }, { "input": "3\n1 7 6", "output": "-1" }, { "input": "6\n1 1 2 4 7 7", "output": "-1" }, { "input": "9\n1 1 1 7 7 7 7 7 7", "output": "-1" }, { "input": "9\n1 1 1 2 3 4 6 5 5", "output": "-1" } ]
1,625,060,524
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
test_list = [] res = [sub for sub in test_list if all(ele % 3 == 0 for ele in sub)] print("tuples : " + str(res))
Title: Xenia and Divisors Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held: - *a*<=&lt;<=*b*<=&lt;<=*c*; - *a* divides *b*, *b* divides *c*. Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has groups of three. Help Xenia, find the required partition or else say that it doesn't exist. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7. It is guaranteed that *n* is divisible by 3. Output Specification: If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them. If there is no solution, print -1. Demo Input: ['6\n1 1 1 2 2 2\n', '6\n2 2 1 1 4 6\n'] Demo Output: ['-1\n', '1 2 4\n1 2 6\n'] Note: none
```python test_list = [] res = [sub for sub in test_list if all(ele % 3 == 0 for ele in sub)] print("tuples : " + str(res)) ```
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,623,408,883
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
466
10,240,000
from fractions import Fraction n=input().split() s=max(n) p=6-int(s)+1 s=p/6 if type(s)=="int": print(s) else: print(Fraction(s))
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 from fractions import Fraction n=input().split() s=max(n) p=6-int(s)+1 s=p/6 if type(s)=="int": print(s) else: print(Fraction(s)) ```
0
819
B
Mister B and PR Shifts
PROGRAMMING
1,900
[ "data structures", "implementation", "math" ]
null
null
Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation. Let's define the deviation of a permutation *p* as . Find a cyclic shift of permutation *p* with minimum possible deviation. If there are multiple solutions, print any of them. Let's denote id *k* (0<=≤<=*k*<=&lt;<=*n*) of a cyclic shift of permutation *p* as the number of right shifts needed to reach this shift, for example: - *k*<==<=0: shift *p*1,<=*p*2,<=... *p**n*, - *k*<==<=1: shift *p**n*,<=*p*1,<=... *p**n*<=-<=1, - ..., - *k*<==<=*n*<=-<=1: shift *p*2,<=*p*3,<=... *p**n*,<=*p*1.
First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation. The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct.
Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them.
[ "3\n1 2 3\n", "3\n2 3 1\n", "3\n3 2 1\n" ]
[ "0 0\n", "0 1\n", "2 1\n" ]
In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well. In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift. In the third sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts.
1,000
[ { "input": "3\n1 2 3", "output": "0 0" }, { "input": "3\n2 3 1", "output": "0 1" }, { "input": "3\n3 2 1", "output": "2 1" }, { "input": "2\n1 2", "output": "0 0" }, { "input": "2\n2 1", "output": "0 1" }, { "input": "10\n10 1 9 2 8 3 7 4 6 5", "output": "24 7" }, { "input": "108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40 22 79 103 25 101 35 51 15 98 67 5 34 69 54 27 45 88 56 16 46 60 74 108 21 41 73 39 107 59 3 8 28 49 7 38", "output": "3428 30" }, { "input": "4\n1 2 3 4", "output": "0 0" }, { "input": "4\n1 2 4 3", "output": "2 0" }, { "input": "4\n1 3 2 4", "output": "2 0" }, { "input": "4\n1 3 4 2", "output": "2 1" }, { "input": "4\n1 4 2 3", "output": "4 0" }, { "input": "4\n1 4 3 2", "output": "4 0" }, { "input": "4\n2 1 3 4", "output": "2 0" }, { "input": "4\n2 1 4 3", "output": "4 0" }, { "input": "4\n2 3 1 4", "output": "4 0" }, { "input": "4\n2 3 4 1", "output": "0 1" }, { "input": "4\n2 4 1 3", "output": "2 2" }, { "input": "4\n2 4 3 1", "output": "2 1" }, { "input": "4\n3 1 2 4", "output": "2 3" }, { "input": "4\n3 1 4 2", "output": "4 1" }, { "input": "4\n3 2 1 4", "output": "4 0" }, { "input": "4\n3 2 4 1", "output": "2 1" }, { "input": "4\n3 4 1 2", "output": "0 2" }, { "input": "4\n3 4 2 1", "output": "2 2" }, { "input": "4\n4 1 2 3", "output": "0 3" }, { "input": "4\n4 1 3 2", "output": "2 3" }, { "input": "4\n4 2 1 3", "output": "2 3" }, { "input": "4\n4 2 3 1", "output": "4 1" }, { "input": "4\n4 3 1 2", "output": "2 2" }, { "input": "4\n4 3 2 1", "output": "4 1" }, { "input": "10\n1 2 3 4 6 5 7 9 10 8", "output": "6 0" }, { "input": "10\n1 2 10 9 7 4 8 3 6 5", "output": "26 5" }, { "input": "10\n1 3 10 9 4 7 5 8 6 2", "output": "22 1" }, { "input": "10\n1 4 10 8 9 2 3 6 7 5", "output": "20 5" }, { "input": "10\n1 5 10 8 4 3 9 2 7 6", "output": "26 6" }, { "input": "10\n1 6 10 7 9 5 3 8 4 2", "output": "24 4" }, { "input": "10\n1 7 10 6 5 2 3 8 9 4", "output": "26 6" }, { "input": "10\n1 8 10 6 2 4 9 3 7 5", "output": "24 6" }, { "input": "10\n1 9 10 5 6 7 3 8 4 2", "output": "26 1" }, { "input": "10\n1 10 9 5 3 2 4 7 8 6", "output": "20 7" }, { "input": "10\n2 1 10 5 8 4 9 3 7 6", "output": "28 0" }, { "input": "10\n2 3 10 5 4 8 6 9 7 1", "output": "14 1" }, { "input": "10\n2 4 10 3 9 1 5 7 8 6", "output": "28 0" }, { "input": "10\n2 5 10 3 6 4 9 1 8 7", "output": "28 0" }, { "input": "10\n2 6 10 1 9 7 4 8 5 3", "output": "28 1" }, { "input": "10\n2 7 10 1 6 3 4 8 9 5", "output": "20 7" } ]
1,691,243,538
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691243538.4798694")# 1691243538.479886
Title: Mister B and PR Shifts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation *p* of length *n* or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation. Let's define the deviation of a permutation *p* as . Find a cyclic shift of permutation *p* with minimum possible deviation. If there are multiple solutions, print any of them. Let's denote id *k* (0<=≤<=*k*<=&lt;<=*n*) of a cyclic shift of permutation *p* as the number of right shifts needed to reach this shift, for example: - *k*<==<=0: shift *p*1,<=*p*2,<=... *p**n*, - *k*<==<=1: shift *p**n*,<=*p*1,<=... *p**n*<=-<=1, - ..., - *k*<==<=*n*<=-<=1: shift *p*2,<=*p*3,<=... *p**n*,<=*p*1. Input Specification: First line contains single integer *n* (2<=≤<=*n*<=≤<=106) — the length of the permutation. The second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation. It is guaranteed that all elements are distinct. Output Specification: Print two integers: the minimum deviation of cyclic shifts of permutation *p* and the id of such shift. If there are multiple solutions, print any of them. Demo Input: ['3\n1 2 3\n', '3\n2 3 1\n', '3\n3 2 1\n'] Demo Output: ['0 0\n', '0 1\n', '2 1\n'] Note: In the first sample test the given permutation *p* is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well. In the second sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift. In the third sample test the deviation of *p* equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts.
```python print("_RANDOM_GUESS_1691243538.4798694")# 1691243538.479886 ```
0
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,665,206,048
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
15,155,200
#By Anan instagram: anan.ssw from math import factorial A,B=map(int, input().split()) a,b=factorial(A),factorial(B) if A==B: print(A) elif a<b: i=1 ans=a while ans>=a/2: if b%ans==0 and a%ans==0: break ans-=1 print([1,ans][ans>=a/2]) else: i=1 ans=b while ans>=b/2: if b%ans==0 and a%ans==0: break ans-=1 print([1,ans][ans>=b/2])
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python #By Anan instagram: anan.ssw from math import factorial A,B=map(int, input().split()) a,b=factorial(A),factorial(B) if A==B: print(A) elif a<b: i=1 ans=a while ans>=a/2: if b%ans==0 and a%ans==0: break ans-=1 print([1,ans][ans>=a/2]) else: i=1 ans=b while ans>=b/2: if b%ans==0 and a%ans==0: break ans-=1 print([1,ans][ans>=b/2]) ```
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,543,353,810
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
def add_cconnection(new_change, data): old, new = new_change.split(" ") value = data.get(old) if value: del data[old] data[new] = value else: data[new] = old num = int(input()) data = {} _input = input().split("\n") print(_input) for line in _input: add_cconnection(line, data) results = list(data.items()) results.reverse() for new, old in results: print(old, new)
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 def add_cconnection(new_change, data): old, new = new_change.split(" ") value = data.get(old) if value: del data[old] data[new] = value else: data[new] = old num = int(input()) data = {} _input = input().split("\n") print(_input) for line in _input: add_cconnection(line, data) results = list(data.items()) results.reverse() for new, old in results: print(old, new) ```
0
637
B
Chat Order
PROGRAMMING
1,200
[ "*special", "binary search", "constructive algorithms", "data structures", "sortings" ]
null
null
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
[ "4\nalex\nivan\nroman\nivan\n", "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n" ]
[ "ivan\nroman\nalex\n", "alina\nmaria\nekaterina\ndarya\n" ]
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
1,000
[ { "input": "4\nalex\nivan\nroman\nivan", "output": "ivan\nroman\nalex" }, { "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina", "output": "alina\nmaria\nekaterina\ndarya" }, { "input": "1\nwdi", "output": "wdi" }, { "input": "2\nypg\nypg", "output": "ypg" }, { "input": "3\nexhll\nexhll\narruapexj", "output": "arruapexj\nexhll" }, { "input": "3\nfv\nle\nle", "output": "le\nfv" }, { "input": "8\nm\nm\nm\nm\nm\nm\nm\nm", "output": "m" }, { "input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr", "output": "r\nu\nb\nk\nw\ni" }, { "input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok", "output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne" }, { "input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe", "output": "we\nklrj" }, { "input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh", "output": "zncybqmh\naeebef\nn" }, { "input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo", "output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj" }, { "input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn", "output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy" }, { "input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg", "output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg" }, { "input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh", "output": "vhh\nfa" }, { "input": "2\naa\nbb", "output": "bb\naa" }, { "input": "2\naa\na", "output": "a\naa" }, { "input": "3\naa\naa\naa", "output": "aa" }, { "input": "5\naa\na\naa\na\naa", "output": "aa\na" }, { "input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa", "output": "aaa\naaaaaaa\naa\na\naaaa" }, { "input": "5\na\naa\naaa\naaaa\na", "output": "a\naaaa\naaa\naa" }, { "input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa", "output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa" }, { "input": "3\na\naa\naaa", "output": "aaa\naa\na" }, { "input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz", "output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz" } ]
1,636,613,200
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
12
3,000
46,694,400
n = int(input()) s = [] for i in range(n): if len(s) == 0: s.append(input()) else: v = input() if v in s: s.remove(v) s1 = s[:] s = [v] + s1[:] else: s1 = s[:] s = [v] + s1[:] [print(x) for x in s]
Title: Chat Order Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list. Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. Output Specification: Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. Demo Input: ['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n'] Demo Output: ['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n'] Note: In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows: 1. alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows: 1. ivan 1. alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows: 1. roman 1. ivan 1. alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows: 1. ivan 1. roman 1. alex
```python n = int(input()) s = [] for i in range(n): if len(s) == 0: s.append(input()) else: v = input() if v in s: s.remove(v) s1 = s[:] s = [v] + s1[:] else: s1 = s[:] s = [v] + s1[:] [print(x) for x in s] ```
0
195
B
After Training
PROGRAMMING
1,300
[ "data structures", "implementation", "math" ]
null
null
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.
The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly.
Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball.
[ "4 3\n", "3 1\n" ]
[ "2\n1\n3\n2\n", "1\n1\n1\n" ]
none
1,000
[ { "input": "4 3", "output": "2\n1\n3\n2" }, { "input": "3 1", "output": "1\n1\n1" }, { "input": "10 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2" }, { "input": "6 5", "output": "3\n2\n4\n1\n5\n3" }, { "input": "2 6", "output": "3\n4" }, { "input": "5 2", "output": "1\n2\n1\n2\n1" }, { "input": "85702 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "9 2", "output": "1\n2\n1\n2\n1\n2\n1\n2\n1" }, { "input": "45 88", "output": "44\n45\n43\n46\n42\n47\n41\n48\n40\n49\n39\n50\n38\n51\n37\n52\n36\n53\n35\n54\n34\n55\n33\n56\n32\n57\n31\n58\n30\n59\n29\n60\n28\n61\n27\n62\n26\n63\n25\n64\n24\n65\n23\n66\n22" }, { "input": "61 51", "output": "26\n25\n27\n24\n28\n23\n29\n22\n30\n21\n31\n20\n32\n19\n33\n18\n34\n17\n35\n16\n36\n15\n37\n14\n38\n13\n39\n12\n40\n11\n41\n10\n42\n9\n43\n8\n44\n7\n45\n6\n46\n5\n47\n4\n48\n3\n49\n2\n50\n1\n51\n26\n25\n27\n24\n28\n23\n29\n22\n30\n21" }, { "input": "21 57", "output": "29\n28\n30\n27\n31\n26\n32\n25\n33\n24\n34\n23\n35\n22\n36\n21\n37\n20\n38\n19\n39" }, { "input": "677 787", "output": "394\n393\n395\n392\n396\n391\n397\n390\n398\n389\n399\n388\n400\n387\n401\n386\n402\n385\n403\n384\n404\n383\n405\n382\n406\n381\n407\n380\n408\n379\n409\n378\n410\n377\n411\n376\n412\n375\n413\n374\n414\n373\n415\n372\n416\n371\n417\n370\n418\n369\n419\n368\n420\n367\n421\n366\n422\n365\n423\n364\n424\n363\n425\n362\n426\n361\n427\n360\n428\n359\n429\n358\n430\n357\n431\n356\n432\n355\n433\n354\n434\n353\n435\n352\n436\n351\n437\n350\n438\n349\n439\n348\n440\n347\n441\n346\n442\n345\n443\n344\n444\n343\n4..." }, { "input": "37 849", "output": "425\n424\n426\n423\n427\n422\n428\n421\n429\n420\n430\n419\n431\n418\n432\n417\n433\n416\n434\n415\n435\n414\n436\n413\n437\n412\n438\n411\n439\n410\n440\n409\n441\n408\n442\n407\n443" }, { "input": "453 855", "output": "428\n427\n429\n426\n430\n425\n431\n424\n432\n423\n433\n422\n434\n421\n435\n420\n436\n419\n437\n418\n438\n417\n439\n416\n440\n415\n441\n414\n442\n413\n443\n412\n444\n411\n445\n410\n446\n409\n447\n408\n448\n407\n449\n406\n450\n405\n451\n404\n452\n403\n453\n402\n454\n401\n455\n400\n456\n399\n457\n398\n458\n397\n459\n396\n460\n395\n461\n394\n462\n393\n463\n392\n464\n391\n465\n390\n466\n389\n467\n388\n468\n387\n469\n386\n470\n385\n471\n384\n472\n383\n473\n382\n474\n381\n475\n380\n476\n379\n477\n378\n478\n377\n4..." }, { "input": "165 374", "output": "187\n188\n186\n189\n185\n190\n184\n191\n183\n192\n182\n193\n181\n194\n180\n195\n179\n196\n178\n197\n177\n198\n176\n199\n175\n200\n174\n201\n173\n202\n172\n203\n171\n204\n170\n205\n169\n206\n168\n207\n167\n208\n166\n209\n165\n210\n164\n211\n163\n212\n162\n213\n161\n214\n160\n215\n159\n216\n158\n217\n157\n218\n156\n219\n155\n220\n154\n221\n153\n222\n152\n223\n151\n224\n150\n225\n149\n226\n148\n227\n147\n228\n146\n229\n145\n230\n144\n231\n143\n232\n142\n233\n141\n234\n140\n235\n139\n236\n138\n237\n137\n238\n1..." }, { "input": "328 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3\n2\n1\n3..." }, { "input": "8 80", "output": "40\n41\n39\n42\n38\n43\n37\n44" }, { "input": "90 544", "output": "272\n273\n271\n274\n270\n275\n269\n276\n268\n277\n267\n278\n266\n279\n265\n280\n264\n281\n263\n282\n262\n283\n261\n284\n260\n285\n259\n286\n258\n287\n257\n288\n256\n289\n255\n290\n254\n291\n253\n292\n252\n293\n251\n294\n250\n295\n249\n296\n248\n297\n247\n298\n246\n299\n245\n300\n244\n301\n243\n302\n242\n303\n241\n304\n240\n305\n239\n306\n238\n307\n237\n308\n236\n309\n235\n310\n234\n311\n233\n312\n232\n313\n231\n314\n230\n315\n229\n316\n228\n317" }, { "input": "85 60", "output": "30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18\n43\n17\n44\n16\n45\n15\n46\n14\n47\n13\n48\n12\n49\n11\n50\n10\n51\n9\n52\n8\n53\n7\n54\n6\n55\n5\n56\n4\n57\n3\n58\n2\n59\n1\n60\n30\n31\n29\n32\n28\n33\n27\n34\n26\n35\n25\n36\n24\n37\n23\n38\n22\n39\n21\n40\n20\n41\n19\n42\n18" }, { "input": "392 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "8 87", "output": "44\n43\n45\n42\n46\n41\n47\n40" }, { "input": "6 358", "output": "179\n180\n178\n181\n177\n182" }, { "input": "501 70", "output": "35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n66\n4\n67\n3\n68\n2\n69\n1\n70\n35\n36\n34\n37\n33\n38\n32\n39\n31\n40\n30\n41\n29\n42\n28\n43\n27\n44\n26\n45\n25\n46\n24\n47\n23\n48\n22\n49\n21\n50\n20\n51\n19\n52\n18\n53\n17\n54\n16\n55\n15\n56\n14\n57\n13\n58\n12\n59\n11\n60\n10\n61\n9\n62\n8\n63\n7\n64\n6\n65\n5\n6..." }, { "input": "3834 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "1 8828", "output": "4414" }, { "input": "69230 89906", "output": "44953\n44954\n44952\n44955\n44951\n44956\n44950\n44957\n44949\n44958\n44948\n44959\n44947\n44960\n44946\n44961\n44945\n44962\n44944\n44963\n44943\n44964\n44942\n44965\n44941\n44966\n44940\n44967\n44939\n44968\n44938\n44969\n44937\n44970\n44936\n44971\n44935\n44972\n44934\n44973\n44933\n44974\n44932\n44975\n44931\n44976\n44930\n44977\n44929\n44978\n44928\n44979\n44927\n44980\n44926\n44981\n44925\n44982\n44924\n44983\n44923\n44984\n44922\n44985\n44921\n44986\n44920\n44987\n44919\n44988\n44918\n44989\n44917\n..." }, { "input": "27646 59913", "output": "29957\n29956\n29958\n29955\n29959\n29954\n29960\n29953\n29961\n29952\n29962\n29951\n29963\n29950\n29964\n29949\n29965\n29948\n29966\n29947\n29967\n29946\n29968\n29945\n29969\n29944\n29970\n29943\n29971\n29942\n29972\n29941\n29973\n29940\n29974\n29939\n29975\n29938\n29976\n29937\n29977\n29936\n29978\n29935\n29979\n29934\n29980\n29933\n29981\n29932\n29982\n29931\n29983\n29930\n29984\n29929\n29985\n29928\n29986\n29927\n29987\n29926\n29988\n29925\n29989\n29924\n29990\n29923\n29991\n29922\n29992\n29921\n29993\n..." }, { "input": "37006 54783", "output": "27392\n27391\n27393\n27390\n27394\n27389\n27395\n27388\n27396\n27387\n27397\n27386\n27398\n27385\n27399\n27384\n27400\n27383\n27401\n27382\n27402\n27381\n27403\n27380\n27404\n27379\n27405\n27378\n27406\n27377\n27407\n27376\n27408\n27375\n27409\n27374\n27410\n27373\n27411\n27372\n27412\n27371\n27413\n27370\n27414\n27369\n27415\n27368\n27416\n27367\n27417\n27366\n27418\n27365\n27419\n27364\n27420\n27363\n27421\n27362\n27422\n27361\n27423\n27360\n27424\n27359\n27425\n27358\n27426\n27357\n27427\n27356\n27428\n..." }, { "input": "1 100000", "output": "50000" }, { "input": "100000 1", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1..." }, { "input": "100000 100000", "output": "50000\n50001\n49999\n50002\n49998\n50003\n49997\n50004\n49996\n50005\n49995\n50006\n49994\n50007\n49993\n50008\n49992\n50009\n49991\n50010\n49990\n50011\n49989\n50012\n49988\n50013\n49987\n50014\n49986\n50015\n49985\n50016\n49984\n50017\n49983\n50018\n49982\n50019\n49981\n50020\n49980\n50021\n49979\n50022\n49978\n50023\n49977\n50024\n49976\n50025\n49975\n50026\n49974\n50027\n49973\n50028\n49972\n50029\n49971\n50030\n49970\n50031\n49969\n50032\n49968\n50033\n49967\n50034\n49966\n50035\n49965\n50036\n49964\n..." }, { "input": "100000 13", "output": "7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n13\n7\n6\n8\n5\n9\n4\n10\n3\n11\n2\n12\n1\n..." }, { "input": "100000 44", "output": "22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21\n24\n20\n25\n19\n26\n18\n27\n17\n28\n16\n29\n15\n30\n14\n31\n13\n32\n12\n33\n11\n34\n10\n35\n9\n36\n8\n37\n7\n38\n6\n39\n5\n40\n4\n41\n3\n42\n2\n43\n1\n44\n22\n23\n21..." }, { "input": "100000 37820", "output": "18910\n18911\n18909\n18912\n18908\n18913\n18907\n18914\n18906\n18915\n18905\n18916\n18904\n18917\n18903\n18918\n18902\n18919\n18901\n18920\n18900\n18921\n18899\n18922\n18898\n18923\n18897\n18924\n18896\n18925\n18895\n18926\n18894\n18927\n18893\n18928\n18892\n18929\n18891\n18930\n18890\n18931\n18889\n18932\n18888\n18933\n18887\n18934\n18886\n18935\n18885\n18936\n18884\n18937\n18883\n18938\n18882\n18939\n18881\n18940\n18880\n18941\n18879\n18942\n18878\n18943\n18877\n18944\n18876\n18945\n18875\n18946\n18874\n..." }, { "input": "99999 77777", "output": "38889\n38888\n38890\n38887\n38891\n38886\n38892\n38885\n38893\n38884\n38894\n38883\n38895\n38882\n38896\n38881\n38897\n38880\n38898\n38879\n38899\n38878\n38900\n38877\n38901\n38876\n38902\n38875\n38903\n38874\n38904\n38873\n38905\n38872\n38906\n38871\n38907\n38870\n38908\n38869\n38909\n38868\n38910\n38867\n38911\n38866\n38912\n38865\n38913\n38864\n38914\n38863\n38915\n38862\n38916\n38861\n38917\n38860\n38918\n38859\n38919\n38858\n38920\n38857\n38921\n38856\n38922\n38855\n38923\n38854\n38924\n38853\n38925\n..." }, { "input": "1991 1935", "output": "968\n967\n969\n966\n970\n965\n971\n964\n972\n963\n973\n962\n974\n961\n975\n960\n976\n959\n977\n958\n978\n957\n979\n956\n980\n955\n981\n954\n982\n953\n983\n952\n984\n951\n985\n950\n986\n949\n987\n948\n988\n947\n989\n946\n990\n945\n991\n944\n992\n943\n993\n942\n994\n941\n995\n940\n996\n939\n997\n938\n998\n937\n999\n936\n1000\n935\n1001\n934\n1002\n933\n1003\n932\n1004\n931\n1005\n930\n1006\n929\n1007\n928\n1008\n927\n1009\n926\n1010\n925\n1011\n924\n1012\n923\n1013\n922\n1014\n921\n1015\n920\n1016\n919\n1017..." }, { "input": "17 812", "output": "406\n407\n405\n408\n404\n409\n403\n410\n402\n411\n401\n412\n400\n413\n399\n414\n398" }, { "input": "30078 300", "output": "150\n151\n149\n152\n148\n153\n147\n154\n146\n155\n145\n156\n144\n157\n143\n158\n142\n159\n141\n160\n140\n161\n139\n162\n138\n163\n137\n164\n136\n165\n135\n166\n134\n167\n133\n168\n132\n169\n131\n170\n130\n171\n129\n172\n128\n173\n127\n174\n126\n175\n125\n176\n124\n177\n123\n178\n122\n179\n121\n180\n120\n181\n119\n182\n118\n183\n117\n184\n116\n185\n115\n186\n114\n187\n113\n188\n112\n189\n111\n190\n110\n191\n109\n192\n108\n193\n107\n194\n106\n195\n105\n196\n104\n197\n103\n198\n102\n199\n101\n200\n100\n201\n9..." }, { "input": "10500 5", "output": "3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3\n2\n4\n1\n5\n3..." }, { "input": "90091 322", "output": "161\n162\n160\n163\n159\n164\n158\n165\n157\n166\n156\n167\n155\n168\n154\n169\n153\n170\n152\n171\n151\n172\n150\n173\n149\n174\n148\n175\n147\n176\n146\n177\n145\n178\n144\n179\n143\n180\n142\n181\n141\n182\n140\n183\n139\n184\n138\n185\n137\n186\n136\n187\n135\n188\n134\n189\n133\n190\n132\n191\n131\n192\n130\n193\n129\n194\n128\n195\n127\n196\n126\n197\n125\n198\n124\n199\n123\n200\n122\n201\n121\n202\n120\n203\n119\n204\n118\n205\n117\n206\n116\n207\n115\n208\n114\n209\n113\n210\n112\n211\n111\n212\n1..." }, { "input": "8471 92356", "output": "46178\n46179\n46177\n46180\n46176\n46181\n46175\n46182\n46174\n46183\n46173\n46184\n46172\n46185\n46171\n46186\n46170\n46187\n46169\n46188\n46168\n46189\n46167\n46190\n46166\n46191\n46165\n46192\n46164\n46193\n46163\n46194\n46162\n46195\n46161\n46196\n46160\n46197\n46159\n46198\n46158\n46199\n46157\n46200\n46156\n46201\n46155\n46202\n46154\n46203\n46153\n46204\n46152\n46205\n46151\n46206\n46150\n46207\n46149\n46208\n46148\n46209\n46147\n46210\n46146\n46211\n46145\n46212\n46144\n46213\n46143\n46214\n46142\n..." }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1\n1" }, { "input": "52097 88310", "output": "44155\n44156\n44154\n44157\n44153\n44158\n44152\n44159\n44151\n44160\n44150\n44161\n44149\n44162\n44148\n44163\n44147\n44164\n44146\n44165\n44145\n44166\n44144\n44167\n44143\n44168\n44142\n44169\n44141\n44170\n44140\n44171\n44139\n44172\n44138\n44173\n44137\n44174\n44136\n44175\n44135\n44176\n44134\n44177\n44133\n44178\n44132\n44179\n44131\n44180\n44130\n44181\n44129\n44182\n44128\n44183\n44127\n44184\n44126\n44185\n44125\n44186\n44124\n44187\n44123\n44188\n44122\n44189\n44121\n44190\n44120\n44191\n44119\n..." } ]
1,648,913,288
2,147,483,647
Python 3
OK
TESTS
44
530
0
#---------------------------- # Matheus de Souza Oliveira | # RA: 203407 | #---------------------------- n, m = list(map(int, input().split())) for index in range(0, n): factor = m+index%m isFactorEven = not(bool(factor%2)) if isFactorEven: result = int((m-(index%m))/2) print(result) else: result = int((factor+1)/2) print(result)
Title: After Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on. Input Specification: The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. Output Specification: Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. Demo Input: ['4 3\n', '3 1\n'] Demo Output: ['2\n1\n3\n2\n', '1\n1\n1\n'] Note: none
```python #---------------------------- # Matheus de Souza Oliveira | # RA: 203407 | #---------------------------- n, m = list(map(int, input().split())) for index in range(0, n): factor = m+index%m isFactorEven = not(bool(factor%2)) if isFactorEven: result = int((m-(index%m))/2) print(result) else: result = int((factor+1)/2) print(result) ```
3
304
B
Calendar
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer.
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date).
Print a single integer — the answer to the problem.
[ "1900:01:01\n2038:12:31\n", "1996:03:09\n1991:11:12\n" ]
[ "50768\n", "1579\n" ]
none
1,000
[ { "input": "1900:01:01\n2038:12:31", "output": "50768" }, { "input": "1996:03:09\n1991:11:12", "output": "1579" }, { "input": "1999:12:31\n2000:02:29", "output": "60" }, { "input": "1903:09:27\n1988:06:15", "output": "30943" }, { "input": "1913:11:14\n1901:05:11", "output": "4570" }, { "input": "1915:01:01\n2007:07:01", "output": "33784" }, { "input": "1925:07:15\n2010:06:22", "output": "31023" }, { "input": "1935:10:08\n1923:01:07", "output": "4657" }, { "input": "1986:08:24\n1926:04:13", "output": "22048" }, { "input": "1932:11:18\n2028:09:25", "output": "35010" }, { "input": "1942:06:04\n1982:12:29", "output": "14818" }, { "input": "1993:08:25\n1985:02:16", "output": "3112" }, { "input": "1954:06:30\n1911:05:04", "output": "15763" }, { "input": "2005:08:01\n1963:08:23", "output": "15319" }, { "input": "2015:10:17\n1966:07:12", "output": "17994" }, { "input": "2025:08:10\n2018:09:03", "output": "2533" }, { "input": "2027:07:31\n1945:04:06", "output": "30066" }, { "input": "2037:05:16\n1996:03:11", "output": "15041" }, { "input": "1949:07:09\n1901:10:24", "output": "17425" }, { "input": "2028:04:11\n1931:09:01", "output": "35287" }, { "input": "1900:02:06\n1997:12:07", "output": "35733" }, { "input": "1902:09:06\n1951:03:31", "output": "17738" }, { "input": "1912:03:09\n1954:06:17", "output": "15440" }, { "input": "1963:05:02\n2005:08:02", "output": "15433" }, { "input": "1973:03:18\n1932:11:07", "output": "14741" }, { "input": "1934:01:09\n1935:02:22", "output": "409" }, { "input": "1985:08:24\n1987:05:01", "output": "615" }, { "input": "1995:06:03\n1990:07:22", "output": "1777" }, { "input": "1907:04:04\n1902:10:01", "output": "1646" }, { "input": "1910:01:11\n1987:02:08", "output": "28152" }, { "input": "1996:03:09\n1996:03:09", "output": "0" }, { "input": "1900:03:02\n2038:03:01", "output": "50403" }, { "input": "2000:01:02\n2000:02:02", "output": "31" }, { "input": "1999:04:08\n1999:02:04", "output": "63" }, { "input": "1999:01:01\n1999:01:10", "output": "9" }, { "input": "2012:05:29\n2012:02:29", "output": "90" }, { "input": "1900:01:01\n1900:01:01", "output": "0" }, { "input": "1996:02:01\n1996:01:27", "output": "5" }, { "input": "1901:12:31\n1901:12:31", "output": "0" }, { "input": "2000:02:28\n2000:02:28", "output": "0" } ]
1,541,059,773
2,147,483,647
Python 3
OK
TESTS
40
404
1,126,400
import datetime d1=datetime.datetime.strptime(input(),"%Y:%m:%d") d2=datetime.datetime.strptime(input(),"%Y:%m:%d") print(abs((d2-d1).days))
Title: Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer. Input Specification: The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date). Output Specification: Print a single integer — the answer to the problem. Demo Input: ['1900:01:01\n2038:12:31\n', '1996:03:09\n1991:11:12\n'] Demo Output: ['50768\n', '1579\n'] Note: none
```python import datetime d1=datetime.datetime.strptime(input(),"%Y:%m:%d") d2=datetime.datetime.strptime(input(),"%Y:%m:%d") print(abs((d2-d1).days)) ```
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,694,946,086
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
a,b,c=map(int,input().split()) s=(a+b+c)//3 print(abs(a-s)+abs(s-b)+abs(s-c))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python a,b,c=map(int,input().split()) s=(a+b+c)//3 print(abs(a-s)+abs(s-b)+abs(s-c)) ```
0
31
C
Schedule
PROGRAMMING
1,700
[ "implementation" ]
C. Schedule
2
256
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect. The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=106) — starting and finishing times of lesson of the *i*-th group. It is possible that initially no two lessons intersect (see sample 1).
Output integer *k* — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.
[ "3\n3 10\n20 30\n1 3\n", "4\n3 10\n20 30\n1 3\n1 39\n", "3\n1 5\n2 6\n3 7\n" ]
[ "3\n1 2 3 ", "1\n4 ", "0\n" ]
none
1,500
[ { "input": "3\n3 10\n20 30\n1 3", "output": "3\n1 2 3 " }, { "input": "4\n3 10\n20 30\n1 3\n1 39", "output": "1\n4 " }, { "input": "3\n1 5\n2 6\n3 7", "output": "0" }, { "input": "4\n1 5\n5 7\n6 9\n9 10", "output": "2\n2 3 " }, { "input": "11\n717170 795210\n866429 970764\n163324 322182\n677099 717170\n241684 393937\n50433 114594\n970764 997956\n393937 664883\n235698 241684\n795210 832346\n114594 232438", "output": "1\n3 " }, { "input": "16\n203671 381501\n58867 59732\n817520 962123\n125391 163027\n601766 617692\n381501 444610\n761937 817520\n16 10551\n21096 38291\n718073 761937\n583868 601766\n554859 731755\n678098 718073\n962123 992003\n163027 203671\n87917 96397", "output": "1\n12 " } ]
1,643,679,527
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
204,800
while True: try: n = int(input()) times = [] s = [0] * 5000 sum = 0 for i in range(n): l, r = input().split() l = int(l) r = int(r) times.append((l, r)) for i in range(n): for j in range(i): if times[j][0] < times[i][1] and times[i][0] < times[j][1]: s[i] += 1 s[j] += 1 sum += 1 temp = [] for i in range(n): if s[i] == sum: temp.append(i + 1) print(len(temp)) print(*temp) except EOFError: break
Title: Schedule Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, *n* groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect. The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — amount of groups, which have lessons in the room 31. Then *n* lines follow, each of them contains two integers *l**i* *r**i* (1<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=106) — starting and finishing times of lesson of the *i*-th group. It is possible that initially no two lessons intersect (see sample 1). Output Specification: Output integer *k* — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output *k* numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order. Demo Input: ['3\n3 10\n20 30\n1 3\n', '4\n3 10\n20 30\n1 3\n1 39\n', '3\n1 5\n2 6\n3 7\n'] Demo Output: ['3\n1 2 3 ', '1\n4 ', '0\n'] Note: none
```python while True: try: n = int(input()) times = [] s = [0] * 5000 sum = 0 for i in range(n): l, r = input().split() l = int(l) r = int(r) times.append((l, r)) for i in range(n): for j in range(i): if times[j][0] < times[i][1] and times[i][0] < times[j][1]: s[i] += 1 s[j] += 1 sum += 1 temp = [] for i in range(n): if s[i] == sum: temp.append(i + 1) print(len(temp)) print(*temp) except EOFError: break ```
0
614
B
Gena's Code
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
[ "3\n5 10 1\n", "4\n1 1 10 11\n", "5\n0 3 1 100 1\n" ]
[ "50", "110", "0" ]
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
1,000
[ { "input": "3\n5 10 1", "output": "50" }, { "input": "4\n1 1 10 11", "output": "110" }, { "input": "5\n0 3 1 100 1", "output": "0" }, { "input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100", "output": "1824868942000000000000000000000000000000000000000000000000000" }, { "input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000", "output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "9" }, { "input": "2\n10 50", "output": "500" }, { "input": "3\n500 1 10", "output": "5000" } ]
1,461,235,529
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
139
6,348,800
from sys import stdin def isBad(s): if s[0] != '1': return 1 for i in s[1:]: if i != '0': return 1 return 0 def getBad(a): for i in a: if isBad(i): return i return None def getPowerOfTen(a): res = 0 for i in a: if not isBad(i) and not i == '0': res += len(i) - 1 return res n = int(stdin.readline().strip()) a = stdin.readline().strip().split(' ') b = getBad(a) # print('bad :', b) if b is None: print('1' + '0' * getPowerOfTen(a)) elif b == '0': print('0') else: print(b + '0' * getPowerOfTen(a))
Title: Gena's Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. Input Specification: The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. Output Specification: Print a single number without leading zeroes — the product of the number of tanks presented by each country. Demo Input: ['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n'] Demo Output: ['50', '110', '0'] Note: In sample 1 numbers 10 and 1 are beautiful, number 5 is not not. In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful. In sample 3 number 3 is not beautiful, all others are beautiful.
```python from sys import stdin def isBad(s): if s[0] != '1': return 1 for i in s[1:]: if i != '0': return 1 return 0 def getBad(a): for i in a: if isBad(i): return i return None def getPowerOfTen(a): res = 0 for i in a: if not isBad(i) and not i == '0': res += len(i) - 1 return res n = int(stdin.readline().strip()) a = stdin.readline().strip().split(' ') b = getBad(a) # print('bad :', b) if b is None: print('1' + '0' * getPowerOfTen(a)) elif b == '0': print('0') else: print(b + '0' * getPowerOfTen(a)) ```
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,577,005,173
2,147,483,647
PyPy 3
OK
TESTS
25
312
0
n,m = list(map(int,input().split())) l = list(map(int,input().split())) l.sort() money_earned = 0 for i in range(0,m): if(l[i]<0): money_earned-=l[i] print(money_earned)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python n,m = list(map(int,input().split())) l = list(map(int,input().split())) l.sort() money_earned = 0 for i in range(0,m): if(l[i]<0): money_earned-=l[i] print(money_earned) ```
3.922
15
A
Cottage Village
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Cottage Village
2
64
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000).
Output the amount of possible positions of the new house.
[ "2 2\n0 4\n6 2\n", "2 2\n0 4\n5 2\n", "2 3\n0 4\n5 2\n" ]
[ "4\n", "3\n", "2\n" ]
It is possible for the *x*-coordinate of the new house to have non-integer value.
0
[ { "input": "2 2\n0 4\n6 2", "output": "4" }, { "input": "2 2\n0 4\n5 2", "output": "3" }, { "input": "2 3\n0 4\n5 2", "output": "2" }, { "input": "1 1\n1 1", "output": "2" }, { "input": "1 2\n2 1", "output": "2" }, { "input": "2 1\n2 1\n1 1", "output": "2" }, { "input": "2 2\n0 4\n7 4", "output": "4" }, { "input": "4 1\n-12 1\n-14 1\n4 1\n-11 1", "output": "5" }, { "input": "6 15\n19 1\n2 3\n6 2\n-21 2\n-15 2\n23 1", "output": "2" }, { "input": "10 21\n-61 6\n55 2\n-97 1\n37 1\n-39 1\n26 2\n21 1\n64 3\n-68 1\n-28 6", "output": "6" }, { "input": "26 51\n783 54\n-850 6\n-997 59\n573 31\n-125 20\n472 52\n101 5\n-561 4\n625 35\n911 14\n-47 33\n677 55\n-410 54\n13 53\n173 31\n968 30\n-497 7\n832 42\n271 59\n-638 52\n-301 51\n378 36\n-813 7\n-206 22\n-737 37\n-911 9", "output": "35" }, { "input": "14 101\n121 88\n-452 91\n635 28\n-162 59\n-872 26\n-996 8\n468 86\n742 63\n892 89\n-249 107\n300 51\n-753 17\n-620 31\n-13 34", "output": "16" }, { "input": "3 501\n827 327\n-85 480\n-999 343", "output": "6" }, { "input": "2 999\n-999 471\n530 588", "output": "4" }, { "input": "22 54\n600 43\n806 19\n-269 43\n-384 78\n222 34\n392 10\n318 30\n488 73\n-756 49\n-662 22\n-568 50\n-486 16\n-470 2\n96 66\n864 16\n934 15\n697 43\n-154 30\n775 5\n-876 71\n-33 78\n-991 31", "output": "30" }, { "input": "17 109\n52 7\n216 24\n-553 101\n543 39\n391 92\n-904 67\n95 34\n132 14\n730 103\n952 118\n-389 41\n-324 36\n-74 2\n-147 99\n-740 33\n233 1\n-995 3", "output": "16" }, { "input": "4 512\n-997 354\n-568 216\n-234 221\n603 403", "output": "4" }, { "input": "3 966\n988 5\n15 2\n-992 79", "output": "6" }, { "input": "2 1000\n-995 201\n206 194", "output": "4" }, { "input": "50 21\n-178 1\n49 1\n-98 1\n-220 1\n152 1\n-160 3\n17 2\n77 1\n-24 1\n214 2\n-154 2\n-141 1\n79 1\n206 1\n8 1\n-208 1\n36 1\n231 3\n-2 2\n-130 2\n-14 2\n34 1\n-187 2\n14 1\n-83 2\n-241 1\n149 2\n73 1\n-233 3\n-45 1\n197 1\n145 2\n-127 2\n-229 4\n-85 1\n-66 1\n-76 2\n104 1\n175 1\n70 1\n131 3\n-108 1\n-5 4\n140 1\n33 1\n248 3\n-36 3\n134 1\n-183 1\n56 2", "output": "9" }, { "input": "50 1\n37 1\n-38 1\n7 1\n47 1\n-4 1\n24 1\n-32 1\n-23 1\n-3 1\n-19 1\n5 1\n-50 1\n11 1\n-11 1\n49 1\n-39 1\n0 1\n43 1\n-10 1\n6 1\n19 1\n1 1\n27 1\n29 1\n-47 1\n-40 1\n-46 1\n-26 1\n-42 1\n-37 1\n13 1\n-29 1\n-30 1\n3 1\n44 1\n10 1\n4 1\n-14 1\n-2 1\n34 1\n18 1\n-33 1\n-44 1\n9 1\n-36 1\n-7 1\n25 1\n22 1\n-20 1\n-41 1", "output": "43" }, { "input": "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n684 3\n886 10\n497 4\n380 4\n833 1\n-727 6\n470 11\n584 9\n66 6\n-609 12\n-661 4\n-57 8\n628 7\n635 4\n-924 3\n-982 4\n-201 7\n-9 8\n-560 9\n712 7\n-330 8\n-191 1\n-892 7", "output": "96" }, { "input": "1 1000\n0 1000", "output": "2" } ]
1,690,443,779
2,147,483,647
PyPy 3-64
OK
TESTS
35
154
2,355,200
from collections import deque lst = [w.rstrip() for w in open(0).readlines()] n, t = map(int, lst[0].split()) data = [tuple(map(int, x.split())) for x in lst[1:]] L, R = [], [] for x in data: L.append(x[0] - x[1] / 2) R.append(x[0] + x[1] / 2) L.sort() R.sort() d = deque() for a, b in zip(L, R): if len(d) > 0 and d[-1] == a: d[-1] = b else: d.append(a) d.append(b) d.popleft() d = list(d) r = 2 for a, b in zip(d[::2], d[1::2]): if b-a > t: r += 2 elif b-a == t: r += 1 print(r)
Title: Cottage Village Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? Input Specification: The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). Output Specification: Output the amount of possible positions of the new house. Demo Input: ['2 2\n0 4\n6 2\n', '2 2\n0 4\n5 2\n', '2 3\n0 4\n5 2\n'] Demo Output: ['4\n', '3\n', '2\n'] Note: It is possible for the *x*-coordinate of the new house to have non-integer value.
```python from collections import deque lst = [w.rstrip() for w in open(0).readlines()] n, t = map(int, lst[0].split()) data = [tuple(map(int, x.split())) for x in lst[1:]] L, R = [], [] for x in data: L.append(x[0] - x[1] / 2) R.append(x[0] + x[1] / 2) L.sort() R.sort() d = deque() for a, b in zip(L, R): if len(d) > 0 and d[-1] == a: d[-1] = b else: d.append(a) d.append(b) d.popleft() d = list(d) r = 2 for a, b in zip(d[::2], d[1::2]): if b-a > t: r += 2 elif b-a == t: r += 1 print(r) ```
3.943952
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "output": "130" }, { "input": "900000000 16", "output": "1" }, { "input": "909090909 50", "output": "3" }, { "input": "1001 2", "output": "100" }, { "input": "5 2", "output": "3" }, { "input": "2 1", "output": "1" } ]
1,695,110,998
2,147,483,647
Python 3
OK
TESTS
11
46
0
n,k=map(int,input().split()) a=0#记录操作次数# while a<k: a+=1 if n%10==0: n=n//10 else: n-=1 print(n)
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number. Input Specification: The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Specification: Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number. Demo Input: ['512 4\n', '1000000000 9\n'] Demo Output: ['50\n', '1\n'] Note: The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
```python n,k=map(int,input().split()) a=0#记录操作次数# while a<k: a+=1 if n%10==0: n=n//10 else: n-=1 print(n) ```
3
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "7" }, { "input": "1000000000000 500000000001", "output": "2" }, { "input": "999999999997 499999999999", "output": "999999999997" }, { "input": "999999999999 999999999999", "output": "999999999998" }, { "input": "1000000000000 1", "output": "1" }, { "input": "999999999999 1", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000 1000000000000", "output": "1000000000000" }, { "input": "1000000000000 500000000000", "output": "999999999999" }, { "input": "1000000000000 499999999999", "output": "999999999997" }, { "input": "999999999997 499999999998", "output": "999999999995" }, { "input": "619234238 556154835", "output": "493075432" }, { "input": "38151981 36650624", "output": "35149266" }, { "input": "680402465 442571217", "output": "204739968" }, { "input": "109135284 9408714", "output": "18817427" }, { "input": "603701841 56038951", "output": "112077901" }, { "input": "356764822 321510177", "output": "286255532" }, { "input": "284911189 142190783", "output": "284381565" }, { "input": "91028405 61435545", "output": "31842684" } ]
1,695,345,741
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
138,956,800
n, k = [ int(n) for n in input().split()] odds = [x for x in range(n+1) if x % 2 != 0] evens = [x for x in range(n+1) if x % 2 == 0 and x != 0] combined = odds + evens if k != 0: print(combined[k-1]) else: print(combined[k])
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. Input Specification: The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the number that will stand at the position number *k* after Volodya's manipulations. Demo Input: ['10 3\n', '7 7\n'] Demo Output: ['5', '6'] Note: In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
```python n, k = [ int(n) for n in input().split()] odds = [x for x in range(n+1) if x % 2 != 0] evens = [x for x in range(n+1) if x % 2 == 0 and x != 0] combined = odds + evens if k != 0: print(combined[k-1]) else: print(combined[k]) ```
0
499
A
Watching a movie
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*.
Output a single number — the answer to the problem.
[ "2 3\n5 6\n10 12\n", "1 1\n1 100000\n" ]
[ "6\n", "100000\n" ]
In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
500
[ { "input": "2 3\n5 6\n10 12", "output": "6" }, { "input": "1 1\n1 100000", "output": "100000" }, { "input": "10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53974" }, { "input": "10 3\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "53983" }, { "input": "10 10\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "54038" }, { "input": "10 1000\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n94325 95728", "output": "58728" }, { "input": "12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41870" }, { "input": "12 17\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728", "output": "41872" }, { "input": "18 111\n1449 2156\n3497 4784\n7775 14575\n23857 24593\n29211 30739\n31932 33447\n35902 36426\n36991 38506\n39679 47202\n48772 60016\n60522 61868\n63340 63982\n68417 78537\n79445 86568\n86918 87940\n90081 90310\n90629 94325\n95728 96263", "output": "58967" }, { "input": "1 1\n14575 60522", "output": "45948" }, { "input": "1 10\n14575 60522", "output": "45952" }, { "input": "2 10\n14575 36426\n60522 79445", "output": "40785" }, { "input": "3 1\n14575 36426\n48772 60522\n79445 90081", "output": "44240" }, { "input": "1 100000\n1 100000", "output": "100000" }, { "input": "1 2\n2 100000", "output": "100000" }, { "input": "1 3\n4 100000", "output": "99997" }, { "input": "2 100\n5 6\n7 7", "output": "7" }, { "input": "1 10000\n500 600", "output": "600" }, { "input": "2 3\n1 3\n4 8", "output": "8" }, { "input": "3 1\n1 2\n3 4\n6 7", "output": "6" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 3\n5 6", "output": "3" }, { "input": "1 5\n7 10", "output": "5" }, { "input": "1 100\n5 6", "output": "6" }, { "input": "1 2\n1 1", "output": "1" }, { "input": "1 100000\n100000 100000", "output": "100000" }, { "input": "2 3\n1 1\n5 6", "output": "3" } ]
1,599,204,696
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
204,800
a=list(map(int,input().split())) n=int(a[0]) x=int(a[1]) l=[0]*n r=[0]*n for i in range(0,n): l[i]=int(input()) r[i]=int(input()) j=0 for i in range(0,n): if i==0: j=j+((l[i]-1)%x)+abs(l[i]-r[i])+1 else: j=j+((l[i]-r[i-1])%x)+abs(l[i]-r[i]) print(j)
Title: Watching a movie Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 1. Skip exactly *x* minutes of the movie (*x* is some fixed positive integer). If the player is now at the *t*-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (*t*<=+<=*x*). Initially the movie is turned on in the player on the first minute, and you want to watch exactly *n* best moments of the movie, the *i*-th best moment starts at the *l**i*-th minute and ends at the *r**i*-th minute (more formally, the *i*-th best moment consists of minutes: *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i*). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments? Input Specification: The first line contains two space-separated integers *n*, *x* (1<=≤<=*n*<=≤<=50, 1<=≤<=*x*<=≤<=105) — the number of the best moments of the movie and the value of *x* for the second button. The following *n* lines contain the descriptions of the best moments of the movie, the *i*-th line of the description contains two integers separated by a space *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=105). It is guaranteed that for all integers *i* from 2 to *n* the following condition holds: *r**i*<=-<=1<=&lt;<=*l**i*. Output Specification: Output a single number — the answer to the problem. Demo Input: ['2 3\n5 6\n10 12\n', '1 1\n1 100000\n'] Demo Output: ['6\n', '100000\n'] Note: In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie. In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.
```python a=list(map(int,input().split())) n=int(a[0]) x=int(a[1]) l=[0]*n r=[0]*n for i in range(0,n): l[i]=int(input()) r[i]=int(input()) j=0 for i in range(0,n): if i==0: j=j+((l[i]-1)%x)+abs(l[i]-r[i])+1 else: j=j+((l[i]-r[i-1])%x)+abs(l[i]-r[i]) print(j) ```
-1
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input": "gqrk", "output": "NO" }, { "input": "glxlg", "output": "YES" }, { "input": "czhfc", "output": "YES" }, { "input": "broon", "output": "NO" }, { "input": "rmggmr", "output": "NO" }, { "input": "wvxxzw", "output": "YES" }, { "input": "ukvciu", "output": "NO" }, { "input": "vrnwnrv", "output": "YES" }, { "input": "vlkjkav", "output": "YES" }, { "input": "guayhmg", "output": "NO" }, { "input": "lkvhhvkl", "output": "NO" }, { "input": "ffdsslff", "output": "YES" }, { "input": "galjjtyw", "output": "NO" }, { "input": "uosgwgsou", "output": "YES" }, { "input": "qjwmjmljq", "output": "YES" }, { "input": "ustrvrodf", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "qjfyjjyfjq", "output": "NO" }, { "input": "ysxibbixsq", "output": "YES" }, { "input": "howfslfwmh", "output": "NO" }, { "input": "ekhajrjahke", "output": "YES" }, { "input": "ucnolsloncw", "output": "YES" }, { "input": "jrzsfrrkrtj", "output": "NO" }, { "input": "typayzzyapyt", "output": "NO" }, { "input": "uwdhkzokhdwu", "output": "YES" }, { "input": "xokxpyyuafij", "output": "NO" }, { "input": "eusneioiensue", "output": "YES" }, { "input": "fuxpuajabpxuf", "output": "YES" }, { "input": "guvggtfhlgruy", "output": "NO" }, { "input": "cojhkhxxhkhjoc", "output": "NO" }, { "input": "mhifbmmmmbmihm", "output": "YES" }, { "input": "kxfqqncnebpami", "output": "NO" }, { "input": "scfwrjevejrwfcs", "output": "YES" }, { "input": "thdaonpepdoadht", "output": "YES" }, { "input": "jsfzcbnhsccuqsj", "output": "NO" }, { "input": "nn", "output": "NO" }, { "input": "nm", "output": "YES" }, { "input": "jdj", "output": "YES" }, { "input": "bbcaa", "output": "NO" }, { "input": "abcde", "output": "NO" }, { "input": "abcdf", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "abecd", "output": "NO" }, { "input": "abccacb", "output": "NO" }, { "input": "aabc", "output": "NO" }, { "input": "anpqb", "output": "NO" }, { "input": "c", "output": "YES" }, { "input": "abcdefg", "output": "NO" }, { "input": "aanbb", "output": "NO" }, { "input": "aabbb", "output": "NO" }, { "input": "aaabbab", "output": "NO" }, { "input": "ab", "output": "YES" }, { "input": "aabbc", "output": "NO" }, { "input": "ecabd", "output": "NO" }, { "input": "abcdrty", "output": "NO" }, { "input": "abcdmnp", "output": "NO" }, { "input": "bbbbbb", "output": "NO" }, { "input": "abcxuio", "output": "NO" }, { "input": "abcdabcde", "output": "NO" }, { "input": "abcxpoi", "output": "NO" }, { "input": "aba", "output": "YES" }, { "input": "aacbb", "output": "NO" }, { "input": "abcedca", "output": "NO" }, { "input": "abcdd", "output": "NO" }, { "input": "abbcs", "output": "NO" }, { "input": "aaabccc", "output": "NO" }, { "input": "paxkxbq", "output": "NO" }, { "input": "z", "output": "YES" }, { "input": "b", "output": "YES" }, { "input": "abcdefghi", "output": "NO" }, { "input": "abcqr", "output": "NO" }, { "input": "abcdc", "output": "NO" }, { "input": "abcb", "output": "NO" }, { "input": "aabcd", "output": "NO" }, { "input": "abbba", "output": "YES" }, { "input": "aaabbb", "output": "NO" }, { "input": "bb", "output": "NO" }, { "input": "aaacbbb", "output": "NO" }, { "input": "abbzcca", "output": "NO" }, { "input": "abxab", "output": "NO" }, { "input": "bbb", "output": "YES" }, { "input": "abcrtyu", "output": "NO" }, { "input": "cbacb", "output": "NO" }, { "input": "acbb", "output": "NO" }, { "input": "ww", "output": "NO" }, { "input": "aaaaaa", "output": "NO" }, { "input": "jizzz", "output": "NO" }, { "input": "aaakcba", "output": "NO" }, { "input": "acbak", "output": "NO" }, { "input": "bddeffd", "output": "NO" }, { "input": "aaa", "output": "YES" }, { "input": "afghqwe", "output": "NO" }, { "input": "abcdfga", "output": "NO" } ]
1,637,337,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
s=input() l=len(s) m=0 for i in range(l): if s[i]!=s[l-1-i]: m+=1 continue else: m+=1 if m==1: print('YES') else: print('NO')
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input Specification: The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). Output Specification: Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Demo Input: ['abccaa\n', 'abbcca\n', 'abcda\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python s=input() l=len(s) m=0 for i in range(l): if s[i]!=s[l-1-i]: m+=1 continue else: m+=1 if m==1: print('YES') else: print('NO') ```
0
991
C
Candies
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
[ "68\n" ]
[ "3\n" ]
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
1,250
[ { "input": "68", "output": "3" }, { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "42", "output": "1" }, { "input": "43", "output": "2" }, { "input": "756", "output": "29" }, { "input": "999999972", "output": "39259423" }, { "input": "999999973", "output": "39259424" }, { "input": "1000000000000000000", "output": "39259424579862572" }, { "input": "6", "output": "1" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "5", "output": "1" }, { "input": "66", "output": "2" }, { "input": "67", "output": "3" }, { "input": "1000", "output": "39" }, { "input": "10000", "output": "392" }, { "input": "100500", "output": "3945" }, { "input": "1000000", "output": "39259" }, { "input": "10000000", "output": "392594" }, { "input": "100000000", "output": "3925942" }, { "input": "123456789", "output": "4846842" }, { "input": "543212345", "output": "21326204" }, { "input": "505050505", "output": "19827992" }, { "input": "777777777", "output": "30535108" }, { "input": "888888871", "output": "34897266" }, { "input": "1000000000", "output": "39259424" }, { "input": "999999999999999973", "output": "39259424579862572" }, { "input": "999999999999999998", "output": "39259424579862572" }, { "input": "999999999999999999", "output": "39259424579862573" }, { "input": "100000000000000000", "output": "3925942457986257" }, { "input": "540776028375043656", "output": "21230555700587649" }, { "input": "210364830044445976", "output": "8258802179385535" }, { "input": "297107279239074256", "output": "11664260821414605" }, { "input": "773524766411950187", "output": "30368137227605772" }, { "input": "228684941775227220", "output": "8978039224174797" }, { "input": "878782039723446310", "output": "34500477210660436" }, { "input": "615090701338187389", "output": "24148106998961343" }, { "input": "325990422297859188", "output": "12798196397960353" }, { "input": "255163492355051023", "output": "10017571883647466" }, { "input": "276392003308849171", "output": "10850991008380891" }, { "input": "601", "output": "23" }, { "input": "983", "output": "38" }, { "input": "729", "output": "29" }, { "input": "70", "output": "3" }, { "input": "703", "output": "28" }, { "input": "257", "output": "10" }, { "input": "526", "output": "20" }, { "input": "466", "output": "18" }, { "input": "738", "output": "29" }, { "input": "116", "output": "5" }, { "input": "888888888888888887", "output": "34897266293211176" }, { "input": "888888888888888888", "output": "34897266293211176" }, { "input": "888888888888888889", "output": "34897266293211176" }, { "input": "999999999999999969", "output": "39259424579862571" }, { "input": "999999999999999970", "output": "39259424579862571" }, { "input": "999999999999999971", "output": "39259424579862572" }, { "input": "999999999999999943", "output": "39259424579862571" }, { "input": "999999999999999944", "output": "39259424579862570" }, { "input": "999999999999999945", "output": "39259424579862571" }, { "input": "999999999999999917", "output": "39259424579862570" }, { "input": "999999999999999918", "output": "39259424579862569" }, { "input": "999999999999999919", "output": "39259424579862570" }, { "input": "99999999999999957", "output": "3925942457986255" }, { "input": "99999999999999958", "output": "3925942457986255" }, { "input": "99999999999999959", "output": "3925942457986256" }, { "input": "888888888888888853", "output": "34897266293211174" }, { "input": "888888888888888854", "output": "34897266293211174" }, { "input": "888888888888888855", "output": "34897266293211175" } ]
1,546,188,924
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
0
n=int(input()) def w(k): s=n p=0 while s>0: p+=min(s,k) s=max(0,s-k) s-=s//10 if p>=n/2: return True return False l,r=0,n while l<r: m=(l+r)//2 if w(m): r=m else: l=m+1 print(r)
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on. If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all. Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. Output Specification: Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. Demo Input: ['68\n'] Demo Output: ['3\n'] Note: In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first): $68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$. In total, Vasya would eat $39$ candies, while Petya — $29$.
```python n=int(input()) def w(k): s=n p=0 while s>0: p+=min(s,k) s=max(0,s-k) s-=s//10 if p>=n/2: return True return False l,r=0,n while l<r: m=(l+r)//2 if w(m): r=m else: l=m+1 print(r) ```
0
987
C
Three displays
PROGRAMMING
1,400
[ "brute force", "dp", "implementation" ]
null
null
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i &lt; j &lt; k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i &lt; s_j &lt; s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$.
[ "5\n2 4 5 4 10\n40 30 20 10 40\n", "3\n100 101 100\n2 4 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n" ]
[ "90\n", "-1\n", "33\n" ]
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
1,250
[ { "input": "5\n2 4 5 4 10\n40 30 20 10 40", "output": "90" }, { "input": "3\n100 101 100\n2 4 5", "output": "-1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "output": "33" }, { "input": "3\n1 2 3\n100000000 100000000 100000000", "output": "300000000" }, { "input": "3\n999999998 999999999 1000000000\n100000000 100000000 99999999", "output": "299999999" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754\n23219513 68171337 12183499 5549873 73542337 66661387 79397647 34495917 31413076 50918417", "output": "85904709" }, { "input": "20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n61699500 83254572 59454419 27833657 55743179 99661234 94729965 75591136 62937826 3626886 73906880 3664913 39990362 94385934 33153747 23840219 64514676 14746017 13062847 65187713", "output": "72432912" }, { "input": "3\n1 2 3\n1 1 1", "output": "3" } ]
1,604,770,881
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
10
296
7,270,400
n = int(input()) s = [int(x) for x in input().strip().split()] c = [int(x) for x in input().strip().split()] from functools import lru_cache @lru_cache(None) def helper(i, last, nums): if nums==3: return 0 if i==len(s): return float('inf') ans = helper(i+1, last, nums) if last==None: ans = min(ans, helper(i+1, i, nums+1)+c[i]) else: if s[i]>s[last]: ans = min(ans, helper(i+1, i, nums+1)+c[i]) return ans val = helper(0, None, 0) print(val if val!=float('inf') else -1)
Title: Three displays Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i &lt; j &lt; k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i &lt; s_j &lt; s_k$ should be held. The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay. Input Specification: The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display. Output Specification: If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$. Demo Input: ['5\n2 4 5 4 10\n40 30 20 10 40\n', '3\n100 101 100\n2 4 5\n', '10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n'] Demo Output: ['90\n', '-1\n', '33\n'] Note: In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
```python n = int(input()) s = [int(x) for x in input().strip().split()] c = [int(x) for x in input().strip().split()] from functools import lru_cache @lru_cache(None) def helper(i, last, nums): if nums==3: return 0 if i==len(s): return float('inf') ans = helper(i+1, last, nums) if last==None: ans = min(ans, helper(i+1, i, nums+1)+c[i]) else: if s[i]>s[last]: ans = min(ans, helper(i+1, i, nums+1)+c[i]) return ans val = helper(0, None, 0) print(val if val!=float('inf') else -1) ```
-1
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,584,463,642
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
18
109
0
x=input() n=x.count('n') e=x.count('e') i=x.count('i') t=x.count('t') n1=(n-1)//2 e1=e//3 lim=min(n1,e1,i,t) print(lim)
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python x=input() n=x.count('n') e=x.count('e') i=x.count('i') t=x.count('t') n1=(n-1)//2 e1=e//3 lim=min(n1,e1,i,t) print(lim) ```
0
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, { "input": "7\n3 2 1 6 5 7 4", "output": "8" }, { "input": "8\n2 8 3 7 6 9 1 5", "output": "4" }, { "input": "9\n10 5 9 3 8 7 1 2 4", "output": "6" }, { "input": "10\n7 2 3 8 9 6 5 4 1 10", "output": "11" }, { "input": "1\n1", "output": "2" }, { "input": "2\n1 2", "output": "3" }, { "input": "3\n2 4 1", "output": "3" }, { "input": "4\n4 2 3 1", "output": "5" }, { "input": "5\n3 1 4 2 5", "output": "6" }, { "input": "6\n1 3 6 7 2 4", "output": "5" }, { "input": "7\n1 5 4 7 2 3 6", "output": "8" }, { "input": "8\n12 1 6 5 2 8 3 4", "output": "7" }, { "input": "9\n3 2 7 5 6 4 1 9 10", "output": "8" }, { "input": "10\n1 7 13 6 5 10 3 8 2 4", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n3000", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3000 1", "output": "2" } ]
1,659,519,501
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
1,740,800
n = int(input()) tasks = list(map(int, input().split())) index = -1 for i in range(1, 3001): if not (i in tasks): index = i break if index == -1: tasks.sort() index = tasks[n-1] + 1 print(index)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. Output Specification: Output the required default value for the next test index. Demo Input: ['3\n1 7 2\n'] Demo Output: ['3\n'] Note: none
```python n = int(input()) tasks = list(map(int, input().split())) index = -1 for i in range(1, 3001): if not (i in tasks): index = i break if index == -1: tasks.sort() index = tasks[n-1] + 1 print(index) ```
3.965758
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", "output": "21223442" }, { "input": "91730629", "output": "91230320" }, { "input": "420062703497", "output": "420032203402" }, { "input": "332711047202", "output": "332211042202" }, { "input": "3395184971407775", "output": "3304114021402224" }, { "input": "8464062628894325", "output": "1434032321104324" }, { "input": "164324828731963982", "output": "134324121231033012" }, { "input": "384979173822804784", "output": "314020123122104214" }, { "input": "41312150450968417", "output": "41312140440031412" }, { "input": "2156", "output": "2143" }, { "input": "1932", "output": "1032" }, { "input": "5902", "output": "4002" }, { "input": "5728", "output": "4221" }, { "input": "8537", "output": "1432" }, { "input": "55403857", "output": "44403142" }, { "input": "270739", "output": "220230" }, { "input": "28746918", "output": "21243011" }, { "input": "10279211", "output": "10220211" }, { "input": "40289679", "output": "40210320" }, { "input": "545203238506", "output": "444203231403" }, { "input": "461117063340", "output": "431112033340" }, { "input": "658492686568", "output": "341402313431" }, { "input": "857373361868", "output": "142323331131" }, { "input": "429325660016", "output": "420324330013" }, { "input": "9894448650287940", "output": "9104441340212040" }, { "input": "6354510839296263", "output": "3344410130203233" }, { "input": "6873575462224593", "output": "3123424432224403" }, { "input": "4237951492601449", "output": "4232041402301440" }, { "input": "2680352384836991", "output": "2310342314133001" }, { "input": "606187734191890310", "output": "303112234101100310" }, { "input": "351499943576823355", "output": "341400043423123344" }, { "input": "180593481782177068", "output": "110403411212122031" }, { "input": "999999999999999999", "output": "900000000000000000" }, { "input": "1000000000000000000", "output": "1000000000000000000" }, { "input": "9999", "output": "9000" }, { "input": "99", "output": "90" }, { "input": "9991", "output": "9001" } ]
1,666,180,899
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
n = input() s = 0 for i in n: if 9 - int(i) < int(i): print(9 - int(i) ,end='') else: print(i ,end = '')
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. Output Specification: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Demo Input: ['27\n', '4545\n'] Demo Output: ['22\n', '4444\n'] Note: none
```python n = input() s = 0 for i in n: if 9 - int(i) < int(i): print(9 - int(i) ,end='') else: print(i ,end = '') ```
0
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem.
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95", "output": "2" }, { "input": "51 52", "output": "2" }, { "input": "47 52", "output": "2" }, { "input": "38 98", "output": "2" }, { "input": "30 37", "output": "2" }, { "input": "56 92", "output": "2" }, { "input": "900000000 1000000000", "output": "2" }, { "input": "37622224 162971117", "output": "2" }, { "input": "760632746 850720703", "output": "2" }, { "input": "908580370 968054552", "output": "2" }, { "input": "951594860 953554446", "output": "2" }, { "input": "347877978 913527175", "output": "2" }, { "input": "620769961 988145114", "output": "2" }, { "input": "820844234 892579936", "output": "2" }, { "input": "741254764 741254768", "output": "2" }, { "input": "80270976 80270977", "output": "2" }, { "input": "392602363 392602367", "output": "2" }, { "input": "519002744 519002744", "output": "519002744" }, { "input": "331900277 331900277", "output": "331900277" }, { "input": "419873015 419873018", "output": "2" }, { "input": "349533413 349533413", "output": "349533413" }, { "input": "28829775 28829776", "output": "2" }, { "input": "568814539 568814539", "output": "568814539" }, { "input": "720270740 720270743", "output": "2" }, { "input": "871232720 871232722", "output": "2" }, { "input": "305693653 305693653", "output": "305693653" }, { "input": "634097178 634097179", "output": "2" }, { "input": "450868287 450868290", "output": "2" }, { "input": "252662256 252662260", "output": "2" }, { "input": "575062045 575062049", "output": "2" }, { "input": "273072892 273072894", "output": "2" }, { "input": "770439256 770439256", "output": "770439256" }, { "input": "2 1000000000", "output": "2" }, { "input": "6 8", "output": "2" }, { "input": "2 879190747", "output": "2" }, { "input": "5 5", "output": "5" }, { "input": "999999937 999999937", "output": "999999937" }, { "input": "3 3", "output": "3" }, { "input": "5 100", "output": "2" }, { "input": "2 2", "output": "2" }, { "input": "3 18", "output": "2" }, { "input": "7 7", "output": "7" }, { "input": "39916801 39916801", "output": "39916801" }, { "input": "3 8", "output": "2" }, { "input": "13 13", "output": "13" }, { "input": "4 8", "output": "2" }, { "input": "3 12", "output": "2" }, { "input": "6 12", "output": "2" }, { "input": "999999103 999999103", "output": "999999103" }, { "input": "100000007 100000007", "output": "100000007" }, { "input": "3 99", "output": "2" }, { "input": "999999733 999999733", "output": "999999733" }, { "input": "5 10", "output": "2" }, { "input": "982451653 982451653", "output": "982451653" }, { "input": "999900001 1000000000", "output": "2" }, { "input": "999727999 999727999", "output": "999727999" }, { "input": "2 999999999", "output": "2" }, { "input": "242 244", "output": "2" }, { "input": "3 10", "output": "2" }, { "input": "15 27", "output": "2" }, { "input": "998244353 998244353", "output": "998244353" }, { "input": "5 15", "output": "2" }, { "input": "999999797 999999797", "output": "999999797" }, { "input": "2 3", "output": "2" }, { "input": "999999929 999999929", "output": "999999929" }, { "input": "3 111111", "output": "2" }, { "input": "12 18", "output": "2" }, { "input": "479001599 479001599", "output": "479001599" }, { "input": "10000019 10000019", "output": "10000019" }, { "input": "715827883 715827883", "output": "715827883" }, { "input": "999992977 999992977", "output": "999992977" }, { "input": "11 11", "output": "11" }, { "input": "29 29", "output": "29" }, { "input": "1000003 1000003", "output": "1000003" }, { "input": "6 15", "output": "2" }, { "input": "1200007 1200007", "output": "1200007" }, { "input": "3 1000000000", "output": "2" }, { "input": "990000023 990000023", "output": "990000023" }, { "input": "1717 1717", "output": "1717" }, { "input": "141650963 141650963", "output": "141650963" }, { "input": "1002523 1002523", "output": "1002523" }, { "input": "900000011 900000011", "output": "900000011" }, { "input": "104729 104729", "output": "104729" }, { "input": "4 12", "output": "2" }, { "input": "100003 100003", "output": "100003" }, { "input": "17 17", "output": "17" }, { "input": "10 100", "output": "2" } ]
1,560,206,228
2,147,483,647
Python 3
OK
TESTS
93
124
0
n = input().split() a = int(n[0]) b = int(n[1]) if(a==b): print(a) else: print('2')
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. Input Specification: The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). Output Specification: Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Demo Input: ['19 29\n', '3 6\n'] Demo Output: ['2\n', '3\n'] Note: Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
```python n = input().split() a = int(n[0]) b = int(n[1]) if(a==b): print(a) else: print('2') ```
3
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
1,596,530,873
2,147,483,647
PyPy 3
OK
TESTS
39
140
20,172,800
a,b = [int(x) for x in input().split(" ")] time = 0 while a and b: if a==1 and b==1: break if a<b: a += 1 b -= 2 else: b += 1 a -= 2 time+=1 print(time)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. Input Specification: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. Output Specification: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Demo Input: ['3 5\n', '4 4\n'] Demo Output: ['6\n', '5\n'] Note: In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
```python a,b = [int(x) for x in input().split(" ")] time = 0 while a and b: if a==1 and b==1: break if a<b: a += 1 b -= 2 else: b += 1 a -= 2 time+=1 print(time) ```
3
255
C
Almost Arithmetical Progression
PROGRAMMING
1,500
[ "brute force", "dp" ]
null
null
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: - *a*1<==<=*p*, where *p* is some integer; - *a**i*<==<=*a**i*<=-<=1<=+<=(<=-<=1)*i*<=+<=1·*q* (*i*<=&gt;<=1), where *q* is some integer. Right now Gena has a piece of paper with sequence *b*, consisting of *n* integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression. Sequence *s*1,<=<=*s*2,<=<=...,<=<=*s**k* is a subsequence of sequence *b*1,<=<=*b*2,<=<=...,<=<=*b**n*, if there is such increasing sequence of indexes *i*1,<=*i*2,<=...,<=*i**k* (1<=<=≤<=<=*i*1<=<=&lt;<=<=*i*2<=<=&lt;<=... <=<=&lt;<=<=*i**k*<=<=≤<=<=*n*), that *b**i**j*<=<==<=<=*s**j*. In other words, sequence *s* can be obtained from *b* by crossing out some elements.
The first line contains integer *n* (1<=≤<=*n*<=≤<=4000). The next line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=106).
Print a single integer — the length of the required longest subsequence.
[ "2\n3 5\n", "4\n10 20 10 30\n" ]
[ "2\n", "3\n" ]
In the first test the sequence actually is the suitable subsequence. In the second test the following subsequence fits: 10, 20, 10.
1,500
[ { "input": "2\n3 5", "output": "2" }, { "input": "4\n10 20 10 30", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "2" }, { "input": "6\n2 3 2 2 1 3", "output": "4" }, { "input": "8\n2 2 5 3 4 3 3 2", "output": "3" }, { "input": "2\n468 335", "output": "2" }, { "input": "1\n170", "output": "1" }, { "input": "5\n479 359 963 465 706", "output": "2" }, { "input": "6\n282 828 962 492 996 943", "output": "2" }, { "input": "8\n437 392 605 903 154 293 383 422", "output": "2" }, { "input": "42\n68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 68 100 36 95 4 12 23", "output": "4" }, { "input": "73\n531 626 701 57 708 511 54 441 297 697 411 253 397 652 21 59 851 561 539 461 629 894 275 417 127 505 433 243 963 247 5 368 969 541 408 485 319 117 441 131 265 357 1 659 267 983 643 285 913 782 813 569 99 781 297 636 645 341 6 17 601 129 509 197 226 105 241 737 86 128 762 647 849", "output": "4" }, { "input": "49\n516 161 416 850 361 861 833 233 281 798 225 771 841 111 481 617 463 305 743 945 833 141 70 617 511 522 840 505 753 544 931 213 626 567 137 687 221 942 951 881 617 129 761 225 849 915 96 801 164", "output": "4" } ]
1,605,155,894
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
21
249
5,427,200
#!/usr/bin/env python3 from sys import stdin from bisect import bisect_left def solve(tc): n = int(stdin.readline().strip()) seq = list(map(int, stdin.readline().split())) elems = [] idxcnt = 0 idx = dict() for i in range(n): if seq[i] not in idx: idx[seq[i]] = idxcnt idxcnt += 1 elems.append([]) elems[idx[seq[i]]].append(i) ans = 1 m = len(elems) for i in range(m): for j in range(m): if i == j: continue cur = -1 cnt = 0 leni, lenj = len(elems[i]), len(elems[j]) pi, pj = 0, 0 while True: k = bisect_left(elems[i], cur, pi, leni) if k == leni: break pi = k+1 cur = elems[i][k] cnt += 1 k = bisect_left(elems[j], cur, pj, lenj) if k == lenj: break pj = k+1 cur = elems[j][k] cnt += 1 ans = max(ans, cnt) print(ans) tc = 1 solve(tc)
Title: Almost Arithmetical Progression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: - *a*1<==<=*p*, where *p* is some integer; - *a**i*<==<=*a**i*<=-<=1<=+<=(<=-<=1)*i*<=+<=1·*q* (*i*<=&gt;<=1), where *q* is some integer. Right now Gena has a piece of paper with sequence *b*, consisting of *n* integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression. Sequence *s*1,<=<=*s*2,<=<=...,<=<=*s**k* is a subsequence of sequence *b*1,<=<=*b*2,<=<=...,<=<=*b**n*, if there is such increasing sequence of indexes *i*1,<=*i*2,<=...,<=*i**k* (1<=<=≤<=<=*i*1<=<=&lt;<=<=*i*2<=<=&lt;<=... <=<=&lt;<=<=*i**k*<=<=≤<=<=*n*), that *b**i**j*<=<==<=<=*s**j*. In other words, sequence *s* can be obtained from *b* by crossing out some elements. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=4000). The next line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=106). Output Specification: Print a single integer — the length of the required longest subsequence. Demo Input: ['2\n3 5\n', '4\n10 20 10 30\n'] Demo Output: ['2\n', '3\n'] Note: In the first test the sequence actually is the suitable subsequence. In the second test the following subsequence fits: 10, 20, 10.
```python #!/usr/bin/env python3 from sys import stdin from bisect import bisect_left def solve(tc): n = int(stdin.readline().strip()) seq = list(map(int, stdin.readline().split())) elems = [] idxcnt = 0 idx = dict() for i in range(n): if seq[i] not in idx: idx[seq[i]] = idxcnt idxcnt += 1 elems.append([]) elems[idx[seq[i]]].append(i) ans = 1 m = len(elems) for i in range(m): for j in range(m): if i == j: continue cur = -1 cnt = 0 leni, lenj = len(elems[i]), len(elems[j]) pi, pj = 0, 0 while True: k = bisect_left(elems[i], cur, pi, leni) if k == leni: break pi = k+1 cur = elems[i][k] cnt += 1 k = bisect_left(elems[j], cur, pj, lenj) if k == lenj: break pj = k+1 cur = elems[j][k] cnt += 1 ans = max(ans, cnt) print(ans) tc = 1 solve(tc) ```
0
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,599,243,594
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
248
0
n=int(input()) r=[list(map(int,input().split())) for _ in range(n)] s1,s2=0,0 for i in range(n): s1+=r[i][0] s2+=r[i][1] if s1%2==0 and s2%2==0: print(0) elif s1%2!=s2%2: print(-1) else: print(1)
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 n=int(input()) r=[list(map(int,input().split())) for _ in range(n)] s1,s2=0,0 for i in range(n): s1+=r[i][0] s2+=r[i][1] if s1%2==0 and s2%2==0: print(0) elif s1%2!=s2%2: print(-1) else: print(1) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,604,319,746
2,147,483,647
Python 3
OK
TESTS
40
218
0
line_s = input().strip() line_t = input().strip() if line_s == line_t[-1::-1]: print('YES') else: print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python line_s = input().strip() line_t = input().strip() if line_s == line_t[-1::-1]: print('YES') else: print('NO') ```
3.9455
999
E
Reachability from the Capital
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "greedy" ]
null
null
There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way.
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
[ "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n", "5 4 5\n1 2\n2 3\n3 4\n4 1\n" ]
[ "3\n", "1\n" ]
The first example is illustrated by the following: For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
0
[ { "input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "output": "3" }, { "input": "5 4 5\n1 2\n2 3\n3 4\n4 1", "output": "1" }, { "input": "5000 0 2956", "output": "4999" }, { "input": "2 0 2", "output": "1" }, { "input": "2 1 1\n1 2", "output": "0" }, { "input": "2 1 2\n1 2", "output": "1" }, { "input": "2 2 2\n1 2\n2 1", "output": "0" }, { "input": "5000 2 238\n3212 238\n238 3212", "output": "4998" }, { "input": "5000 2 3810\n3225 1137\n1137 3225", "output": "4998" }, { "input": "100 1 30\n69 81", "output": "98" }, { "input": "500 1 209\n183 107", "output": "498" }, { "input": "1000 1 712\n542 916", "output": "998" }, { "input": "39 40 38\n4 8\n24 28\n16 17\n7 25\n4 29\n34 35\n16 24\n21 10\n23 36\n36 14\n28 16\n34 19\n15 21\n22 38\n22 37\n37 27\n28 33\n3 29\n32 22\n12 30\n9 15\n5 19\n23 27\n19 17\n25 17\n24 11\n39 10\n6 20\n16 6\n3 18\n34 21\n15 38\n11 19\n11 3\n32 4\n15 13\n16 11\n11 7\n33 7\n3 33", "output": "12" }, { "input": "8 8 1\n3 2\n3 4\n4 5\n5 3\n6 4\n6 7\n7 8\n8 6", "output": "1" }, { "input": "7 7 1\n2 3\n4 2\n7 4\n5 7\n4 5\n4 6\n6 4", "output": "1" }, { "input": "2333 1 1\n1 2", "output": "2331" }, { "input": "7 4 2\n1 2\n3 4\n5 6\n7 1", "output": "3" }, { "input": "1 0 1", "output": "0" }, { "input": "9 9 1\n2 3\n3 4\n4 5\n6 2\n7 6\n8 7\n6 8\n5 9\n9 2", "output": "1" }, { "input": "30 30 29\n29 9\n1 3\n15 5\n14 24\n7 18\n17 12\n5 9\n22 7\n26 20\n7 29\n8 2\n10 12\n17 18\n17 24\n8 12\n23 28\n10 15\n18 2\n29 13\n25 29\n9 2\n7 13\n11 5\n19 26\n10 5\n25 5\n20 10\n5 26\n24 23\n22 8", "output": "13" }, { "input": "30 30 28\n16 28\n5 30\n7 17\n6 1\n12 28\n15 28\n14 30\n25 11\n25 10\n25 8\n12 30\n27 5\n30 10\n22 14\n30 13\n20 27\n15 25\n24 20\n20 15\n1 30\n3 10\n3 4\n3 18\n15 14\n18 22\n20 26\n10 3\n15 27\n23 29\n10 24", "output": "9" } ]
1,608,714,662
1,802
PyPy 3
WRONG_ANSWER
TESTS
3
514
11,468,800
import sys import math import random def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() def FACT(n, mod): s = 1 facts = [1] for i in range(1,n+1): s*=i s%=mod facts.append(s) return facts[n] def C(n, k, mod): return (FACT(n,mod) * pow((FACT(k,mod)*FACT(n-k,mod))%mod,mod-2, mod))%mod n,m,s = MI() d = [[] for i in range(n+1)] d1 = [[] for i in range(n+1)] for i in range(m): u,v = MI() d[u].append(v) d1[v].append(u) count = 0 v = [0 for i in range(n+1)] def dfs(i, isD1 = False): global v global d v[i] = 1 if isD1: for x in d1[i]: if v[x] == 0: dfs(x, isD1) else: for x in d[i]: if v[x] == 0: dfs(x,isD1) dfs(s) for i in range(1,n+1): if v[i] == 0: count+=1 dfs(i, True) print(count)
Title: Reachability from the Capital Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way. Input Specification: The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$). Output Specification: Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. Demo Input: ['9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n', '5 4 5\n1 2\n2 3\n3 4\n4 1\n'] Demo Output: ['3\n', '1\n'] Note: The first example is illustrated by the following: For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 5$.
```python import sys import math import random def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() def FACT(n, mod): s = 1 facts = [1] for i in range(1,n+1): s*=i s%=mod facts.append(s) return facts[n] def C(n, k, mod): return (FACT(n,mod) * pow((FACT(k,mod)*FACT(n-k,mod))%mod,mod-2, mod))%mod n,m,s = MI() d = [[] for i in range(n+1)] d1 = [[] for i in range(n+1)] for i in range(m): u,v = MI() d[u].append(v) d1[v].append(u) count = 0 v = [0 for i in range(n+1)] def dfs(i, isD1 = False): global v global d v[i] = 1 if isD1: for x in d1[i]: if v[x] == 0: dfs(x, isD1) else: for x in d[i]: if v[x] == 0: dfs(x,isD1) dfs(s) for i in range(1,n+1): if v[i] == 0: count+=1 dfs(i, True) print(count) ```
0
5
B
Center Alignment
PROGRAMMING
1,200
[ "implementation", "strings" ]
B. Center Alignment
1
64
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck!
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
[ "This is\n\nCodeforces\nBeta\nRound\n5\n", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n" ]
[ "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n" ]
none
0
[ { "input": "This is\n\nCodeforces\nBeta\nRound\n5", "output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************" }, { "input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck", "output": "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************" }, { "input": "0\n2", "output": "***\n*0*\n*2*\n***" }, { "input": "O\no\nd", "output": "***\n*O*\n*o*\n*d*\n***" }, { "input": "0v uO M6Sy", "output": "************\n*0v uO M6Sy*\n************" }, { "input": "fm v\nOL U W", "output": "**********\n* fm v *\n*OL U W*\n**********" }, { "input": "vb\nJ\nyU\nZ", "output": "****\n*vb*\n*J *\n*yU*\n* Z*\n****" }, { "input": "N\nSV\nEh\n6f\nX6\n9e", "output": "****\n*N *\n*SV*\n*Eh*\n*6f*\n*X6*\n*9e*\n****" }, { "input": "Pj\nA\nFA\nP\nVJ\nU\nEb\nW", "output": "****\n*Pj*\n*A *\n*FA*\n* P*\n*VJ*\n*U *\n*Eb*\n* W*\n****" }, { "input": "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA", "output": "****\n*T *\n*7j*\n* S*\n*b *\n*q8*\n*VZ*\n* n*\n*4T*\n*iZ*\n*pA*\n****" }, { "input": "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\nSr\n\n\nV\n\n5\n\nAq\n\n\n\nJ\nR\n\n04\nJ\nv\nhU\n\n\n\nY\nG\n4\n\nG\nb\n\n\n9\n\n6\nd\n\n2\n\n\nE\n7\n\nr\n\n\n\n\nKC\ns\nE\n\nab\n4\nx\n\n\n\n\n\nEe\n4\n\nl\n\np\n\nG\nM\n\n\nn\n\n\nm0\n\nw\n\n\nP\n\n\n\n0", "output": "****\n*8 *\n* *\n* *\n* *\n* y*\n*W *\n* *\n* *\n* *\n*3B*\n* *\n* w*\n*V *\n* *\n* *\n* *\n* L*\n*Sr*\n* *\n* *\n*V *\n* *\n* 5*\n* *\n*Aq*\n* *\n* *\n* *\n*J *\n* R*\n* *\n*04*\n*J *\n* v*\n*hU*\n* *\n* *\n* *\n*Y *\n* G*\n*4 *\n* *\n* G*\n*b *\n* *\n* *\n* 9*\n* *\n*6 *\n* d*\n* *\n*2 *\n* *\n* *\n* E*\n*7 *\n* *\n* r*\n* *\n* *\n* *\n* *\n*KC*\n*s *\n* E*\n* *\n*ab*\n*4 *\n* x*\n* *\n* *\n* *\n* *\n* *\n*Ee*\n*4 *\n* *\n* l*\n* *\n*p *\n* *\n* G*\n*M *\n* *\n*..." }, { "input": "U", "output": "***\n*U*\n***" } ]
1,608,894,784
2,147,483,647
Python 3
OK
TESTS
19
278
5,120,000
import fileinput s = [] left = True for line in fileinput.input(): s.append(line[:-1]) l = len(max(s, key=len)) for i in range(len(s)): free = l - len(s[i]) sp = free//2 if free%2==0: s[i] = '*' + sp*' ' + s[i] + sp*' ' + '*' else: if left: s[i] = '*' + sp*' ' + s[i] + (sp+1)*' ' + '*' else: s[i] = '*' + (sp+1)*' ' + s[i] + sp*' ' + '*' left = not left print('*'*(l+2)) print('\n'.join(s)) print('*'*(l+2))
Title: Center Alignment Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product. You are to implement the alignment in the shortest possible time. Good luck! Input Specification: The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. Output Specification: Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better. Demo Input: ['This is\n\nCodeforces\nBeta\nRound\n5\n', 'welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n'] Demo Output: ['************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n', '****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n'] Note: none
```python import fileinput s = [] left = True for line in fileinput.input(): s.append(line[:-1]) l = len(max(s, key=len)) for i in range(len(s)): free = l - len(s[i]) sp = free//2 if free%2==0: s[i] = '*' + sp*' ' + s[i] + sp*' ' + '*' else: if left: s[i] = '*' + sp*' ' + s[i] + (sp+1)*' ' + '*' else: s[i] = '*' + (sp+1)*' ' + s[i] + sp*' ' + '*' left = not left print('*'*(l+2)) print('\n'.join(s)) print('*'*(l+2)) ```
3.822853
777
C
Alyona and Spreadsheet
PROGRAMMING
1,600
[ "binary search", "data structures", "dp", "greedy", "implementation", "two pointers" ]
null
null
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1. Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive. Alyona is too small to deal with this task and asks you to help!
The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table. Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109). The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona. The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
[ "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n" ]
[ "Yes\nNo\nYes\nYes\nYes\nNo\n" ]
In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3.
1,500
[ { "input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "output": "Yes\nNo\nYes\nYes\nYes\nNo" }, { "input": "1 1\n1\n1\n1 1", "output": "Yes" }, { "input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10", "output": "No\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo" }, { "input": "15 1\n556231456\n573340933\n626155933\n397229387\n10255952\n376567394\n906742013\n269437009\n31298788\n712285290\n620239975\n379221898\n229140718\n95080095\n997123854\n18\n5 15\n1 12\n4 10\n2 15\n12 15\n15 15\n2 2\n15 15\n15 15\n13 13\n10 14\n3 6\n14 15\n3 6\n4 4\n14 15\n12 14\n1 9", "output": "No\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo" }, { "input": "11 1\n501465490\n366941771\n415080944\n385243536\n445132523\n697044413\n894369800\n812743722\n23684788\n466526046\n953916313\n45\n2 4\n8 9\n7 7\n4 9\n2 9\n2 11\n4 4\n5 7\n1 2\n5 10\n4 6\n1 7\n4 4\n1 6\n4 7\n10 11\n1 8\n6 11\n8 8\n8 10\n1 1\n5 10\n9 10\n6 9\n6 11\n1 1\n9 9\n5 11\n1 2\n9 11\n2 6\n3 7\n11 11\n6 7\n11 11\n7 8\n5 8\n11 11\n5 6\n4 5\n2 6\n5 10\n9 9\n1 1\n1 1", "output": "No\nNo\nYes\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes" } ]
1,686,596,592
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
966
23,654,400
import sys input = lambda: sys.stdin.readline().rstrip() N,M = map(int, input().split()) S = [] for _ in range(N): S.append(list(map(int, input().split()))) A = [] for i in range(int(input())): l,r = map(int, input().split()) A.append((l-1,r-1,i)) k = len(A) A.sort() #print(A) ans = [0]*len(A) for j in range(M): pre=0 l=0 for i in range(N): if S[i][j]<S[i-1][j]: pre=i while l<k and A[l][0]<pre: l+=1 while l<k and A[l][1]<=i: ans[A[l][2]]=1 l+=1 #print(l,i-pre+1) for i in range(k): if ans[i]: print('Yes') else: print('No')
Title: Alyona and Spreadsheet Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1. Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive. Alyona is too small to deal with this task and asks you to help! Input Specification: The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table. Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109). The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona. The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Output Specification: Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". Demo Input: ['5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n'] Demo Output: ['Yes\nNo\nYes\nYes\nYes\nNo\n'] Note: In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3.
```python import sys input = lambda: sys.stdin.readline().rstrip() N,M = map(int, input().split()) S = [] for _ in range(N): S.append(list(map(int, input().split()))) A = [] for i in range(int(input())): l,r = map(int, input().split()) A.append((l-1,r-1,i)) k = len(A) A.sort() #print(A) ans = [0]*len(A) for j in range(M): pre=0 l=0 for i in range(N): if S[i][j]<S[i-1][j]: pre=i while l<k and A[l][0]<pre: l+=1 while l<k and A[l][1]<=i: ans[A[l][2]]=1 l+=1 #print(l,i-pre+1) for i in range(k): if ans[i]: print('Yes') else: print('No') ```
0
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,673,434,261
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
l=list(map(int,input().split())) if l[1]==0:print(1) elif l[2]==0 :print(l[0]) else: print(l[1]+1)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python l=list(map(int,input().split())) if l[1]==0:print(1) elif l[2]==0 :print(l[0]) else: print(l[1]+1) ```
0
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\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 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", "output": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
1,686,211,714
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
import math import os from collections import Counter n, m = map(int, input().split()) arr = list(map(int, input().split())) maxN = 0 ans = 0 for i in range(n): a = arr[i] % m b = (arr[i] - a) / m maxN = max(b, maxN) if maxN == b : ans = i+1 print(ans) # for _ in range(int(input())): # grid = [list(map(int, input().split())) for _ in range(3)] # result = [[1] * 3 for _ in range(3)] # n, s, r = map(int, input().split()) # arr = list(map(int, input().split())) # n = input() # n = int(n)
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). Output Specification: Output a single integer, representing the number of the last child. Demo Input: ['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n'] Demo Output: ['4\n', '6\n'] Note: Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
```python import math import os from collections import Counter n, m = map(int, input().split()) arr = list(map(int, input().split())) maxN = 0 ans = 0 for i in range(n): a = arr[i] % m b = (arr[i] - a) / m maxN = max(b, maxN) if maxN == b : ans = i+1 print(ans) # for _ in range(int(input())): # grid = [list(map(int, input().split())) for _ in range(3)] # result = [[1] * 3 for _ in range(3)] # n, s, r = map(int, input().split()) # arr = list(map(int, input().split())) # n = input() # n = int(n) ```
0
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern.
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########" }, { "input": "3 5", "output": "#####\n....#\n#####" }, { "input": "3 6", "output": "######\n.....#\n######" }, { "input": "7 3", "output": "###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "7 4", "output": "####\n...#\n####\n#...\n####\n...#\n####" }, { "input": "49 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 27", "output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................." }, { "input": "11 15", "output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############" }, { "input": "11 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "19 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "23 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "49 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "33 43", "output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................." }, { "input": "33 44", "output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......." }, { "input": "45 45", "output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..." }, { "input": "45 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "45 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###" }, { "input": "45 4", "output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####" }, { "input": "5 4", "output": "####\n...#\n####\n#...\n####" }, { "input": "5 5", "output": "#####\n....#\n#####\n#....\n#####" }, { "input": "5 6", "output": "######\n.....#\n######\n#.....\n######" }, { "input": "7 5", "output": "#####\n....#\n#####\n#....\n#####\n....#\n#####" }, { "input": "7 6", "output": "######\n.....#\n######\n#.....\n######\n.....#\n######" }, { "input": "7 7", "output": "#######\n......#\n#######\n#......\n#######\n......#\n#######" } ]
1,680,323,600
2,147,483,647
Python 3
OK
TESTS
28
46
0
n,m=input().split() n = int(n) m = int(m) arah = 'kanan' for n in range(n): if n%2==0: print('#'*m) else: if arah=='kiri': arah='kanan' print('#','.'*(m-1),sep='') else: arah='kiri' print('.'*(m-1),'#',sep='')
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern. Input Specification: The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number. Output Specification: Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. Demo Input: ['3 3\n', '3 4\n', '5 3\n', '9 9\n'] Demo Output: ['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n'] Note: none
```python n,m=input().split() n = int(n) m = int(m) arah = 'kanan' for n in range(n): if n%2==0: print('#'*m) else: if arah=='kiri': arah='kanan' print('#','.'*(m-1),sep='') else: arah='kiri' print('.'*(m-1),'#',sep='') ```
3
543
A
Writing Code
PROGRAMMING
1,800
[ "dp" ]
null
null
Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes. Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *v*1<=+<=*v*2<=+<=...<=+<=*v**n*<==<=*m*. The programmers follow the plan like that: in the beginning the first programmer writes the first *v*1 lines of the given task, then the second programmer writes *v*2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most *b* bugs in total. Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer *mod*.
The first line contains four integers *n*, *m*, *b*, *mod* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*b*<=≤<=500; 1<=≤<=*mod*<=≤<=109<=+<=7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer. The next line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=500) — the number of bugs per line for each programmer.
Print a single integer — the answer to the problem modulo *mod*.
[ "3 3 3 100\n1 1 1\n", "3 6 5 1000000007\n1 2 3\n", "3 5 6 11\n1 2 1\n" ]
[ "10\n", "0\n", "0\n" ]
none
500
[ { "input": "3 3 3 100\n1 1 1", "output": "10" }, { "input": "3 6 5 1000000007\n1 2 3", "output": "0" }, { "input": "3 5 6 11\n1 2 1", "output": "0" }, { "input": "2 3 3 1000\n1 2", "output": "1" }, { "input": "3 10 10 150691913\n8 7 10", "output": "0" }, { "input": "100 500 500 895583345\n20 39 5 5 41 47 36 33 34 22 21 33 7 4 15 35 16 37 39 46 27 4 12 35 43 26 23 40 16 50 27 7 49 28 17 28 16 22 18 12 25 34 28 24 10 21 38 10 40 50 35 18 23 38 10 42 22 19 24 45 33 34 50 24 29 36 39 11 37 18 10 2 9 38 17 36 49 1 32 6 20 5 37 18 31 44 1 36 24 35 13 35 8 10 26 45 43 28 38 22", "output": "501" }, { "input": "100 100 100 960694994\n1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1", "output": "527886216" }, { "input": "123 432 342 1000000007\n72 20 34 115 65 29 114 41 18 16 122 104 88 37 119 11 108 91 13 110 47 73 80 35 62 12 9 116 55 66 54 113 50 57 8 25 98 105 0 120 93 78 61 17 84 48 42 106 63 103 7 59 90 89 28 49 53 71 51 83 75 67 64 95 107 3 32 85 69 99 33 79 109 56 10 23 87 19 121 94 44 82 102 27 112 52 21 1 5 74 117 111 76 24 4 101 30 36 97 60 92 46 22 68 118 58 38 70 39 26 43 77 6 2 40 100 81 96 14 31 15 45 86", "output": "902925242" }, { "input": "100 500 499 1000000007\n72 20 34 92 65 29 40 41 18 16 86 14 88 37 31 11 39 91 13 43 47 73 80 35 62 12 9 81 55 66 54 2 50 57 8 25 98 58 0 15 93 78 61 17 84 48 42 38 63 68 7 59 90 89 28 49 53 71 51 83 75 67 64 95 70 3 32 85 69 99 33 79 26 56 10 23 87 19 45 94 44 82 22 27 6 52 21 1 5 74 96 77 76 24 4 46 30 36 97 60", "output": "416898599" }, { "input": "1 1 0 1000\n0", "output": "1" }, { "input": "1 4 25 1000\n6", "output": "1" }, { "input": "1 5 1 10\n1", "output": "0" }, { "input": "1 5 5 1000\n1", "output": "1" }, { "input": "1 5 5 1000\n500", "output": "0" }, { "input": "2 500 250 100\n100 200", "output": "0" }, { "input": "2 500 50 10000\n0 50", "output": "2" }, { "input": "100 500 500 1000000007\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": "925584498" }, { "input": "10 9 20 48620\n1 1 1 1 1 1 1 1 2 2", "output": "0" }, { "input": "21 63 40 1009\n4 4 2 2 4 4 3 2 4 2 0 3 3 4 3 4 3 0 4 2 4", "output": "1002" }, { "input": "29 157 50 1\n3 0 0 3 1 1 2 0 4 4 1 2 2 1 0 0 2 0 3 2 2 3 3 1 4 1 1 4 1", "output": "0" }, { "input": "1 1 1 1\n0", "output": "0" }, { "input": "1 1 1 1\n2", "output": "0" } ]
1,680,342,675
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
3,000
14,745,600
n,m,b,mod = map(int, input().split()) a = list(map(int, input().split())) d = [] for i in range(n+1): d.append([]) for j in range(m+1): d[i].append([]) for k in range(b+1): d[i][j].append(0) if i == 0 and j == 0 and k == 0: d[i][j][k] = 1 if i > 0 and j > 0 and k >= a[i-1]: d[i][j][k] = (d[i-1][j][k]%mod + d[i][j-1][k-a[i-1]])%mod elif i > 0: d[i][j][k] = d[i-1][j][k]%mod print(sum(d[-1][-1])%mod)
Title: Writing Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: Programmers working on a large project have just received a task to write exactly *m* lines of code. There are *n* programmers working on a project, the *i*-th of them makes exactly *a**i* bugs in every line of code that he writes. Let's call a sequence of non-negative integers *v*1,<=*v*2,<=...,<=*v**n* a plan, if *v*1<=+<=*v*2<=+<=...<=+<=*v**n*<==<=*m*. The programmers follow the plan like that: in the beginning the first programmer writes the first *v*1 lines of the given task, then the second programmer writes *v*2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most *b* bugs in total. Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer *mod*. Input Specification: The first line contains four integers *n*, *m*, *b*, *mod* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*b*<=≤<=500; 1<=≤<=*mod*<=≤<=109<=+<=7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer. The next line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=500) — the number of bugs per line for each programmer. Output Specification: Print a single integer — the answer to the problem modulo *mod*. Demo Input: ['3 3 3 100\n1 1 1\n', '3 6 5 1000000007\n1 2 3\n', '3 5 6 11\n1 2 1\n'] Demo Output: ['10\n', '0\n', '0\n'] Note: none
```python n,m,b,mod = map(int, input().split()) a = list(map(int, input().split())) d = [] for i in range(n+1): d.append([]) for j in range(m+1): d[i].append([]) for k in range(b+1): d[i][j].append(0) if i == 0 and j == 0 and k == 0: d[i][j][k] = 1 if i > 0 and j > 0 and k >= a[i-1]: d[i][j][k] = (d[i-1][j][k]%mod + d[i][j-1][k-a[i-1]])%mod elif i > 0: d[i][j][k] = d[i-1][j][k]%mod print(sum(d[-1][-1])%mod) ```
0
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,651,160,208
2,147,483,647
Python 3
OK
TESTS
30
92
0
cc,sc=0,0 s=input() for i in range(len(s)): if(ord(s[i])>=65 and ord(s[i])<=90): cc+=1 elif(ord(s[i])>=97 and ord(s[i])<=122): sc+=1 if(sc<cc): print(s.upper()) elif(sc>cc): print(s.lower()) elif(sc==cc): print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it 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 cc,sc=0,0 s=input() for i in range(len(s)): if(ord(s[i])>=65 and ord(s[i])<=90): cc+=1 elif(ord(s[i])>=97 and ord(s[i])<=122): sc+=1 if(sc<cc): print(s.upper()) elif(sc>cc): print(s.lower()) elif(sc==cc): print(s.lower()) ```
3.977
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,664,205,140
2,147,483,647
PyPy 3-64
OK
TESTS
38
62
0
m=list(map(int,input().split())) result_a_win=result_draw=result_b_win=0 for i in range(1,7): if abs(m[0]-i)<abs(m[1]-i): result_a_win += 1 if abs(m[0]-i)==abs(m[1]-i): result_draw += 1 if abs(m[0]-i)>abs(m[1]-i): result_b_win += 1 print(result_a_win,result_draw,result_b_win)
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 m=list(map(int,input().split())) result_a_win=result_draw=result_b_win=0 for i in range(1,7): if abs(m[0]-i)<abs(m[1]-i): result_a_win += 1 if abs(m[0]-i)==abs(m[1]-i): result_draw += 1 if abs(m[0]-i)>abs(m[1]-i): result_b_win += 1 print(result_a_win,result_draw,result_b_win) ```
3