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
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "50\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 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
1,586,460,059
2,147,483,647
Python 3
OK
TESTS
54
124
307,200
from sys import stdin def read(): return stdin.readline().strip() n=int(read()) count=0 k=0 decryptList=[] encryptedList=list((read())) for i in range(len(encryptedList)): if(encryptedList[i]=='B'): count+=1 if(encryptedList[i]=='W' and count!=0): decryptList.append(count) count=0 k+=1 if(count>0): decryptList.append(count) k+=1 print(k) print(*decryptList,sep=" ")
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). Output Specification: The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. Demo Input: ['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n'] Demo Output: ['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 '] Note: The last sample case correspond to the picture in the statement.
```python from sys import stdin def read(): return stdin.readline().strip() n=int(read()) count=0 k=0 decryptList=[] encryptedList=list((read())) for i in range(len(encryptedList)): if(encryptedList[i]=='B'): count+=1 if(encryptedList[i]=='W' and count!=0): decryptList.append(count) count=0 k+=1 if(count>0): decryptList.append(count) k+=1 print(k) print(*decryptList,sep=" ") ```
3
270
A
Fancy Fence
PROGRAMMING
1,100
[ "geometry", "implementation", "math" ]
null
null
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees.
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
[ "3\n30\n60\n90\n" ]
[ "NO\nYES\nYES\n" ]
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
500
[ { "input": "3\n30\n60\n90", "output": "NO\nYES\nYES" }, { "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO" } ]
1,697,442,300
2,147,483,647
Python 3
OK
TESTS
3
62
0
# -*- coding: utf-8 -*- """ Created on Mon Oct 16 15:30:39 2023 @author: 刘婉婷 2300012258 """ t=int(input()) for i in range(t): a=int(input()) n=360//(180-a) if a*n==(n-2)*180: print('YES') else: print('NO')
Title: Fancy Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? Input Specification: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) — the angle the robot can make corners at measured in degrees. Output Specification: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Demo Input: ['3\n30\n60\n90\n'] Demo Output: ['NO\nYES\nYES\n'] Note: In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second test case, the fence is a regular triangle, and in the last test case — a square.
```python # -*- coding: utf-8 -*- """ Created on Mon Oct 16 15:30:39 2023 @author: 刘婉婷 2300012258 """ t=int(input()) for i in range(t): a=int(input()) n=360//(180-a) if a*n==(n-2)*180: print('YES') else: print('NO') ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,668,853,659
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
124
3,584,000
n, m = map(int, input().split()) def isPrime(num): for i in range(2, int(sqrt(num)) + 1): if num % i == 0: return 1 return 0 for i in range(n+1, n+50): checkf = isPrime(i) if checkf == 1: if m == i: print("YES") break
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python n, m = map(int, input().split()) def isPrime(num): for i in range(2, int(sqrt(num)) + 1): if num % i == 0: return 1 return 0 for i in range(n+1, n+50): checkf = isPrime(i) if checkf == 1: if m == i: print("YES") break ```
-1
550
B
Preparing Olympiad
PROGRAMMING
1,400
[ "bitmasks", "brute force" ]
null
null
You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least *l* and at most *r*. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least *x*. Find the number of ways to choose a problemset for the contest.
The first line contains four integers *n*, *l*, *r*, *x* (1<=≤<=*n*<=≤<=15, 1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — the difficulty of each problem.
Print the number of ways to choose a suitable problemset for the contest.
[ "3 5 6 1\n1 2 3\n", "4 40 50 10\n10 20 30 25\n", "5 25 35 10\n10 10 20 10 20\n" ]
[ "2\n", "2\n", "6\n" ]
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems. In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30. In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.
750
[ { "input": "3 5 6 1\n1 2 3", "output": "2" }, { "input": "4 40 50 10\n10 20 30 25", "output": "2" }, { "input": "5 25 35 10\n10 10 20 10 20", "output": "6" }, { "input": "4 15 60 10\n10 20 30 25", "output": "6" }, { "input": "1 10 20 1\n15", "output": "0" }, { "input": "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "output": "914" }, { "input": "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 392011 318488 857649 30681 740872 115749", "output": "31485" }, { "input": "7 1000 2000 1\n10 20 30 40 50 60 70", "output": "0" }, { "input": "4 10 20 1\n4 6 4 6", "output": "9" }, { "input": "4 10 20 1\n5 15 13 7", "output": "4" }, { "input": "2 10 20 5\n5 10", "output": "1" }, { "input": "5 1098816 3969849 167639\n85627 615007 794045 530104 7091", "output": "15" }, { "input": "13 700147 8713522 390093\n996812 94040 954140 545670 369698 423872 365802 784830 700267 960664 949252 84637 257447", "output": "8026" }, { "input": "15 4531977 20754263 137419\n637830 85299 755530 64382 896833 879525 331501 148182 741013 192101 112217 52165 702790 988594 587499", "output": "6759" }, { "input": "15 2572491 5084070 823435\n570344 78552 775918 501843 844935 71141 331498 636557 435494 715447 992666 831188 28969 171046 989614", "output": "15078" }, { "input": "15 4789415 23152928 233992\n502422 273992 449428 947379 700461 681985 857134 243310 478052 77769 936151 642380 464695 281772 964693", "output": "10875" }, { "input": "3 390224 390224 1\n264237 125987 288891", "output": "1" }, { "input": "7 1652707 1652707 1\n492387 684636 235422 332532 924898 499872 192988", "output": "1" }, { "input": "10 501107 501107 1\n843967 30518 196518 619138 204862 690754 274071 550121 173607 359971", "output": "1" }, { "input": "15 6627289 6627289 1\n683844 183950 184972 764255 211665 842336 790234 815301 914823 513046 93547 713159 554415 200951 388028", "output": "1" }, { "input": "15 5083470 5083470 1\n978510 643688 591921 723137 573784 346171 920030 352119 528857 365128 627302 308557 716247 263519 654230", "output": "1" }, { "input": "15 6558665 6558665 1\n572491 435494 916457 775918 823435 78552 501843 331498 71141 844935 636557 992666 570344 831188 715447", "output": "1" }, { "input": "10 159699 10967276 3542\n998862 999751 995306 992648 992661 991407 997503 998809 999740 997669", "output": "942" }, { "input": "5 2815840 8479687 4082\n991137 992161 997887 998891 994990", "output": "14" }, { "input": "15 2898377 6694755 721\n992733 999159 990076 996808 990975 993338 993234 994757 997873 993303 994409 993801 998027 990495 999287", "output": "9819" }, { "input": "6 20 70 1\n10 10 20 20 30 30", "output": "35" }, { "input": "6 20 70 1\n10 10 10 10 10 10", "output": "0" }, { "input": "15 1 1000000000 1\n10 20 30 40 50 60 70 80 90 100 110 120 130 140 150", "output": "32752" }, { "input": "6 30 40 1\n19 20 21 14 15 16", "output": "13" }, { "input": "4 5 234 2\n10 9 12 11", "output": "8" } ]
1,684,594,066
466
PyPy 3
OK
TESTS
30
108
2,969,600
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, l, r, x = map(int, input().split()) c = list(map(int, input().split())) inf = pow(10, 9) + 1 pow2 = [1] for _ in range(n): pow2.append(2 * pow2[-1]) ans = 0 for i in range(1, pow2[n]): u, v, mi, ma = 0, 0, inf, -inf for j in range(n): if i & pow2[j]: u += 1 v += c[j] mi, ma = min(mi, c[j]), max(ma, c[j]) if u >= 2 and l <= v <= r and ma - mi >= x: ans += 1 print(ans)
Title: Preparing Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least *l* and at most *r*. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least *x*. Find the number of ways to choose a problemset for the contest. Input Specification: The first line contains four integers *n*, *l*, *r*, *x* (1<=≤<=*n*<=≤<=15, 1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — the difficulty of each problem. Output Specification: Print the number of ways to choose a suitable problemset for the contest. Demo Input: ['3 5 6 1\n1 2 3\n', '4 40 50 10\n10 20 30 25\n', '5 25 35 10\n10 10 20 10 20\n'] Demo Output: ['2\n', '2\n', '6\n'] Note: In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems. In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30. In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.
```python import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, l, r, x = map(int, input().split()) c = list(map(int, input().split())) inf = pow(10, 9) + 1 pow2 = [1] for _ in range(n): pow2.append(2 * pow2[-1]) ans = 0 for i in range(1, pow2[n]): u, v, mi, ma = 0, 0, inf, -inf for j in range(n): if i & pow2[j]: u += 1 v += c[j] mi, ma = min(mi, c[j]), max(ma, c[j]) if u >= 2 and l <= v <= r and ma - mi >= x: ans += 1 print(ans) ```
3
340
A
The Wall
PROGRAMMING
1,200
[ "math" ]
null
null
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink. After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
[ "2 3 6 18\n" ]
[ "3" ]
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
500
[ { "input": "2 3 6 18", "output": "3" }, { "input": "4 6 20 201", "output": "15" }, { "input": "15 27 100 10000", "output": "74" }, { "input": "105 60 3456 78910", "output": "179" }, { "input": "1 1 1000 100000", "output": "99001" }, { "input": "3 2 5 5", "output": "0" }, { "input": "555 777 1 1000000", "output": "257" }, { "input": "1000 1000 1 32323", "output": "32" }, { "input": "45 125 93451125 100000000", "output": "5821" }, { "input": "101 171 1 1000000000", "output": "57900" }, { "input": "165 255 69696 1000000000", "output": "356482" }, { "input": "555 777 666013 1000000000", "output": "257229" }, { "input": "23 46 123321 900000000", "output": "19562537" }, { "input": "321 123 15 1000000", "output": "75" }, { "input": "819 1000 9532 152901000", "output": "186" }, { "input": "819 1000 10000 1000000", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 2 2 1000003", "output": "500001" }, { "input": "1 1 1 1000000000", "output": "1000000000" }, { "input": "10 15 69 195610342", "output": "6520342" }, { "input": "2 1 1 1000000000", "output": "500000000" }, { "input": "1000 1000 1 20", "output": "0" }, { "input": "1 1 1 2000000000", "output": "2000000000" }, { "input": "1 2 1 2000000000", "output": "1000000000" }, { "input": "2 1 1 2000000000", "output": "1000000000" }, { "input": "2 3 1 1000000000", "output": "166666666" }, { "input": "2 3 1 2000000000", "output": "333333333" }, { "input": "3 7 1 1000000000", "output": "47619047" }, { "input": "1 1 1000000000 2000000000", "output": "1000000001" }, { "input": "2 2 1 2000000000", "output": "1000000000" }, { "input": "1 1 2 2000000000", "output": "1999999999" }, { "input": "3 2 1 2000000000", "output": "333333333" }, { "input": "1 1 2000000000 2000000000", "output": "1" }, { "input": "2 3 7 7", "output": "0" }, { "input": "3 3 3 7", "output": "2" } ]
1,688,458,237
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
import math x,y,a,b=map(int,input().split()) g=math.lcm(x,y) r=(b-a)//g if (a%g+b%g)==0: r+=1 print(r)
Title: The Wall Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink. After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. Input Specification: The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). Output Specification: Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. Demo Input: ['2 3 6 18\n'] Demo Output: ['3'] Note: Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
```python import math x,y,a,b=map(int,input().split()) g=math.lcm(x,y) r=(b-a)//g if (a%g+b%g)==0: r+=1 print(r) ```
0
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work.
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "52870" }, { "input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245", "output": "46995" }, { "input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434", "output": "85540" }, { "input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357", "output": "67147" }, { "input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422", "output": "85876" }, { "input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282", "output": "38570" }, { "input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431", "output": "11134" }, { "input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424", "output": "59043" }, { "input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369", "output": "53608" }, { "input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438", "output": "84067" }, { "input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439", "output": "79844" }, { "input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437", "output": "82686" }, { "input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437", "output": "92356" }, { "input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434", "output": "107490" }, { "input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401", "output": "25258" }, { "input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419", "output": "23992" } ]
1,632,583,005
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
6,963,200
n,p1,p2,p3,t1,t2 = map(int, input().split()) tp = [] # time periods for _ in range(n): tp.append([int(x) for x in input().split()]) res = 0 for i in range(len(tp)-1): res += p1*(tp[i][1] - tp[i][0]) if (tp[i+1][0] - tp[i][1]) <= t1: res += p1*t1 continue else: res += p1*t1 tmp = tp[i+1][0] - tp[i][1] - t1 if tmp <= t2: res += p2*t2 continue else: res += p2*t2 tmp = tmp - t2 res += p3*tmp res += p1*(tp[-1][1] - tp[-1][0]) print(res)
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. Input Specification: The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work. Output Specification: Output the answer to the problem. Demo Input: ['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n'] Demo Output: ['30', '570'] Note: none
```python n,p1,p2,p3,t1,t2 = map(int, input().split()) tp = [] # time periods for _ in range(n): tp.append([int(x) for x in input().split()]) res = 0 for i in range(len(tp)-1): res += p1*(tp[i][1] - tp[i][0]) if (tp[i+1][0] - tp[i][1]) <= t1: res += p1*t1 continue else: res += p1*t1 tmp = tp[i+1][0] - tp[i][1] - t1 if tmp <= t2: res += p2*t2 continue else: res += p2*t2 tmp = tmp - t2 res += p3*tmp res += p1*(tp[-1][1] - tp[-1][0]) print(res) ```
0
38
B
Chess
PROGRAMMING
1,200
[ "brute force", "implementation", "math" ]
B. Chess
2
256
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.
The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.
Print a single number which is the required number of ways.
[ "a1\nb2\n", "a8\nd4\n" ]
[ "44\n", "38\n" ]
none
0
[ { "input": "a1\nb2", "output": "44" }, { "input": "a8\nd4", "output": "38" }, { "input": "a8\nf1", "output": "42" }, { "input": "f8\nh3", "output": "42" }, { "input": "g8\nb7", "output": "42" }, { "input": "h1\ng5", "output": "42" }, { "input": "c6\nb5", "output": "39" }, { "input": "c1\nd2", "output": "42" }, { "input": "g3\nh4", "output": "42" }, { "input": "e3\ng5", "output": "38" }, { "input": "f8\na3", "output": "40" }, { "input": "a2\nh8", "output": "43" }, { "input": "a3\nc5", "output": "40" }, { "input": "g1\ne6", "output": "39" }, { "input": "e1\na7", "output": "41" }, { "input": "b5\nc1", "output": "39" }, { "input": "b2\ne1", "output": "43" }, { "input": "h8\ng2", "output": "43" }, { "input": "a3\nd6", "output": "38" }, { "input": "g6\nb7", "output": "39" }, { "input": "c8\ne6", "output": "40" }, { "input": "e6\nf2", "output": "35" }, { "input": "b6\nd8", "output": "41" }, { "input": "a4\nd1", "output": "42" }, { "input": "b5\nh8", "output": "40" }, { "input": "h6\na1", "output": "42" }, { "input": "c3\na8", "output": "39" }, { "input": "g5\nd2", "output": "38" }, { "input": "b6\ng7", "output": "39" }, { "input": "h6\na8", "output": "43" }, { "input": "a8\nb7", "output": "44" }, { "input": "c8\nb2", "output": "41" }, { "input": "e4\nc1", "output": "37" }, { "input": "f1\nc3", "output": "38" }, { "input": "a3\nc8", "output": "41" }, { "input": "e8\nb6", "output": "40" }, { "input": "a1\nb7", "output": "43" }, { "input": "g2\nb7", "output": "40" }, { "input": "e1\nd6", "output": "38" }, { "input": "e5\nh6", "output": "39" } ]
1,613,134,207
2,147,483,647
PyPy 3
OK
TESTS
40
280
2,457,600
import string def solve(x1, y1, x2, y2): c = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] X = [2, 1, -1, -2, -2, -1, 1, 2] Y = [1, 2, 2, 1, -1, -2, -2, -1] for i in range(8): for j in range(8): if i != x1 and j != y1: f = True for k in range(8): if i == x2 + X[k] and j == y2 + Y[k]: f = False for k in range(8): if i == x1 + X[k] and j == y1 + Y[k]: f = False if f: c[i][j] = 1 c[x2][y2] = 0 # for i in range(8): # print(c[i]) r = 0 for i in range(8): for j in c[i]: if j == 1: r = r + 1 return r for _ in range(1): a = input() b = input() y1 = a[0] x1 = int(a[1]) - 1 y1 = int(string.ascii_lowercase.index(y1)) y2 = b[0] x2 = int(b[1]) - 1 y2 = int(string.ascii_lowercase.index(y2)) # print(x1, y1, x2, y2) print(solve(x1, y1, x2, y2))
Title: Chess Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square. Input Specification: The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide. Output Specification: Print a single number which is the required number of ways. Demo Input: ['a1\nb2\n', 'a8\nd4\n'] Demo Output: ['44\n', '38\n'] Note: none
```python import string def solve(x1, y1, x2, y2): c = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] X = [2, 1, -1, -2, -2, -1, 1, 2] Y = [1, 2, 2, 1, -1, -2, -2, -1] for i in range(8): for j in range(8): if i != x1 and j != y1: f = True for k in range(8): if i == x2 + X[k] and j == y2 + Y[k]: f = False for k in range(8): if i == x1 + X[k] and j == y1 + Y[k]: f = False if f: c[i][j] = 1 c[x2][y2] = 0 # for i in range(8): # print(c[i]) r = 0 for i in range(8): for j in c[i]: if j == 1: r = r + 1 return r for _ in range(1): a = input() b = input() y1 = a[0] x1 = int(a[1]) - 1 y1 = int(string.ascii_lowercase.index(y1)) y2 = b[0] x2 = int(b[1]) - 1 y2 = int(string.ascii_lowercase.index(y2)) # print(x1, y1, x2, y2) print(solve(x1, y1, x2, y2)) ```
3.925422
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,691,769,338
2,147,483,647
PyPy 3-64
OK
TESTS
49
62
1,945,600
s = [] def roll(a): global s if all(i <= 0 for i in a): return s[len(s)-1]+1 else: for i in range(len(a)): if a[i] > m: a[i] = a[i] - m elif a[i] <= 0: continue else: a[i] = a[i] - m s.append(i) return roll(a) n, m = map(int, input().split(" ")) a = list(map(int, input().split(" "))) print(roll(a))
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 s = [] def roll(a): global s if all(i <= 0 for i in a): return s[len(s)-1]+1 else: for i in range(len(a)): if a[i] > m: a[i] = a[i] - m elif a[i] <= 0: continue else: a[i] = a[i] - m s.append(i) return roll(a) n, m = map(int, input().split(" ")) a = list(map(int, input().split(" "))) print(roll(a)) ```
3
888
C
K-Dominant Character
PROGRAMMING
1,400
[ "binary search", "implementation", "two pointers" ]
null
null
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character.
The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000).
Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character.
[ "abacaba\n", "zzzzz\n", "abcde\n" ]
[ "2\n", "1\n", "3\n" ]
none
0
[ { "input": "abacaba", "output": "2" }, { "input": "zzzzz", "output": "1" }, { "input": "abcde", "output": "3" }, { "input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab", "output": "8" }, { "input": "daabcdabbabbacacbaacabacbcaabaacac", "output": "4" }, { "input": "abghim", "output": "4" }, { "input": "gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech", "output": "17" }, { "input": "a", "output": "1" }, { "input": "aaabbb", "output": "4" }, { "input": "ab", "output": "2" }, { "input": "abbb", "output": "2" }, { "input": "ob", "output": "2" }, { "input": "abccba", "output": "3" }, { "input": "saaaaaaaas", "output": "2" }, { "input": "axxx", "output": "2" }, { "input": "abcba", "output": "2" }, { "input": "abb", "output": "2" }, { "input": "abcdea", "output": "4" }, { "input": "axcbb", "output": "3" }, { "input": "tmivvdcbbfrfogjviirrximhttoskopwrcmkcborcxvr", "output": "13" }, { "input": "dlchmmuateksgldkckljrovmeuniobjrelqjpnjljlvhpqrjsfklliqpufplgaelevmlcnodbllquubobecem", "output": "15" }, { "input": "zx", "output": "2" }, { "input": "zxz", "output": "2" }, { "input": "bbhdgaefbhf", "output": "6" }, { "input": "xx", "output": "1" }, { "input": "zxx", "output": "2" }, { "input": "cbcada", "output": "4" }, { "input": "z", "output": "1" }, { "input": "aab", "output": "2" }, { "input": "jficc", "output": "3" }, { "input": "cceeaabfba", "output": "5" }, { "input": "jk", "output": "2" }, { "input": "lzeznbwu", "output": "5" }, { "input": "rr", "output": "1" } ]
1,637,171,590
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
307,200
s = input() minn = 10 ** 18 for i in s: tmp = s.split(i) maxx = max(map(len, tmp)) minn = min(minn, maxx) print(minn + 1) # Wed Nov 17 2021 17:53:11 GMT+0000 (Coordinated Universal Time)
Title: K-Dominant Character Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*. You have to find minimum *k* such that there exists at least one *k*-dominant character. Input Specification: The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). Output Specification: Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. Demo Input: ['abacaba\n', 'zzzzz\n', 'abcde\n'] Demo Output: ['2\n', '1\n', '3\n'] Note: none
```python s = input() minn = 10 ** 18 for i in s: tmp = s.split(i) maxx = max(map(len, tmp)) minn = min(minn, maxx) print(minn + 1) # Wed Nov 17 2021 17:53:11 GMT+0000 (Coordinated Universal Time) ```
0
921
02
Labyrinth-2
PROGRAMMING
3,200
[]
null
null
See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
[]
[]
none
0
[]
1,517,511,726
2,147,483,647
Python 3
PARTIAL
TESTS
0
8,000
220,569,600
def bfs(walls, doors, keys, exits, x, y, a, b, n, m): dist = [[1000000000] * m for i in range(n)] dist[a][b] = 0 queue = [(a, b)] used = set() dx = [1, 0, 0, -1] dy = [0, 1, -1, 0] while queue: (cur_x, cur_y) = queue.pop(0) if (cur_x, cur_y) not in used: used.add((cur_x, cur_y)) for i in range(4): new_x, new_y = cur_x + dx[i], cur_y + dy[i] if 0 <= new_x < n and 0 <= new_y < m: if (new_x, new_y) not in used: if (cur_x, cur_y, new_x, new_y) not in walls: if (new_x, new_y, cur_x, cur_y) not in walls: if (cur_x, cur_y, new_x, new_y) not in doors: if (new_x, new_y, cur_x, cur_y) not in doors: queue.append((new_x, new_y)) dist[new_x][new_y] = dist[cur_x][cur_y] + 1 return dist def restore(dist, x, y, n, m): if dist[x][y] == 0: return "" dx = [1, 0, 0, -1] dy = [0, 1, -1, 0] prt = ["move-down\n", "move-right\n", "move-left\n", "move-up\n"] for i in range(4): new_x, new_y = x + dx[i], y + dy[i] if 0 <= new_x < n and 0 <= new_y < m: if dist[x][y] - 1 == dist[new_x][new_y]: return prt[i] + restore(dist, new_x, new_y, n, m) (g, w, n, m, x, y, c, d, k, e) = map(int, input().split()) walls = set() for i in range(c): (x1, y1, x2, y2) = map(int, input().split()) walls.add((x1, y1, x2, y2)) doors = set() for i in range(d): (x1, y1, x2, y2) = map(int, input().split()) doors.add((x1, y1, x2, y2)) keys = set() for i in range(k): (x1, y1) = map(int, input().split()) keys.add((x1, y1)) exits = set() for i in range(e): (x1, y1) = map(int, input().split()) exits.add((x1, y1)) best_len = 141928123080123 best = "" for (a, b) in exits: dist = bfs(walls, doors, keys, exits, x, y, a, b, n, m) ans = restore(dist, x, y, n, m) if len(ans) < best_len: best = ans best_len = len(ans) print(best)
Title: Labyrinth-2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01). Input Specification: none Output Specification: none Note: none
```python def bfs(walls, doors, keys, exits, x, y, a, b, n, m): dist = [[1000000000] * m for i in range(n)] dist[a][b] = 0 queue = [(a, b)] used = set() dx = [1, 0, 0, -1] dy = [0, 1, -1, 0] while queue: (cur_x, cur_y) = queue.pop(0) if (cur_x, cur_y) not in used: used.add((cur_x, cur_y)) for i in range(4): new_x, new_y = cur_x + dx[i], cur_y + dy[i] if 0 <= new_x < n and 0 <= new_y < m: if (new_x, new_y) not in used: if (cur_x, cur_y, new_x, new_y) not in walls: if (new_x, new_y, cur_x, cur_y) not in walls: if (cur_x, cur_y, new_x, new_y) not in doors: if (new_x, new_y, cur_x, cur_y) not in doors: queue.append((new_x, new_y)) dist[new_x][new_y] = dist[cur_x][cur_y] + 1 return dist def restore(dist, x, y, n, m): if dist[x][y] == 0: return "" dx = [1, 0, 0, -1] dy = [0, 1, -1, 0] prt = ["move-down\n", "move-right\n", "move-left\n", "move-up\n"] for i in range(4): new_x, new_y = x + dx[i], y + dy[i] if 0 <= new_x < n and 0 <= new_y < m: if dist[x][y] - 1 == dist[new_x][new_y]: return prt[i] + restore(dist, new_x, new_y, n, m) (g, w, n, m, x, y, c, d, k, e) = map(int, input().split()) walls = set() for i in range(c): (x1, y1, x2, y2) = map(int, input().split()) walls.add((x1, y1, x2, y2)) doors = set() for i in range(d): (x1, y1, x2, y2) = map(int, input().split()) doors.add((x1, y1, x2, y2)) keys = set() for i in range(k): (x1, y1) = map(int, input().split()) keys.add((x1, y1)) exits = set() for i in range(e): (x1, y1) = map(int, input().split()) exits.add((x1, y1)) best_len = 141928123080123 best = "" for (a, b) in exits: dist = bfs(walls, doors, keys, exits, x, y, a, b, n, m) ans = restore(dist, x, y, n, m) if len(ans) < best_len: best = ans best_len = len(ans) print(best) ```
2
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "output": "21" }, { "input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815", "output": "16" }, { "input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663", "output": "10" }, { "input": "1\n321 88", "output": "0" }, { "input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689", "output": "7" }, { "input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510", "output": "6" }, { "input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888", "output": "5" }, { "input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802", "output": "13" }, { "input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662", "output": "11" }, { "input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786", "output": "38" }, { "input": "3\n175 201\n907 909\n388 360", "output": "2" }, { "input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86", "output": "6" }, { "input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820", "output": "16" }, { "input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901", "output": "31" }, { "input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210", "output": "29" }, { "input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894", "output": "29" }, { "input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823", "output": "13" }, { "input": "5\n175 158\n16 2\n397 381\n668 686\n957 945", "output": "4" }, { "input": "5\n312 284\n490 509\n730 747\n504 497\n782 793", "output": "4" }, { "input": "2\n802 903\n476 348", "output": "1" }, { "input": "4\n325 343\n425 442\n785 798\n275 270", "output": "3" }, { "input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653", "output": "25" }, { "input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124", "output": "34" }, { "input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255", "output": "29" }, { "input": "5\n664 666\n951 941\n739 742\n844 842\n2 2", "output": "4" }, { "input": "3\n939 867\n411 427\n757 708", "output": "2" }, { "input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636", "output": "34" }, { "input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195", "output": "28" }, { "input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488", "output": "22" }, { "input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235", "output": "8" }, { "input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621", "output": "22" }, { "input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461", "output": "22" }, { "input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924", "output": "6" }, { "input": "3\n1 1\n2 1\n2 2", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "5\n1 1\n1 2\n2 2\n3 1\n3 3", "output": "0" }, { "input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3", "output": "0" }, { "input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10", "output": "1" }, { "input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11", "output": "1" }, { "input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11", "output": "3" }, { "input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25", "output": "7" }, { "input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28", "output": "5" }, { "input": "3\n1 2\n2 1\n2 2", "output": "0" }, { "input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "3\n1 1\n2 2\n1 2", "output": "0" }, { "input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4", "output": "1" }, { "input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100", "output": "6" }, { "input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4", "output": "0" }, { "input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3", "output": "0" }, { "input": "4\n3 1\n2 1\n2 2\n1 2", "output": "0" }, { "input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3", "output": "0" }, { "input": "3\n1 2\n1 3\n1 4", "output": "0" }, { "input": "4\n1 1\n2 2\n1 2\n2 1", "output": "0" }, { "input": "4\n1 3\n2 1\n3 2\n3 1", "output": "1" }, { "input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4", "output": "0" }, { "input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700", "output": "2" }, { "input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9", "output": "1" }, { "input": "4\n1 1\n2 2\n3 2\n3 1", "output": "0" }, { "input": "3\n1 2\n3 4\n3 2", "output": "0" }, { "input": "3\n1 1\n1 2\n2 2", "output": "0" }, { "input": "4\n5 5\n5 4\n6 3\n6 4", "output": "0" }, { "input": "3\n1 1\n2 2\n2 1", "output": "0" } ]
1,662,095,471
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
41
92
102,400
x,y,n=[],[],int(input()) from collections import Counter as cnt for pratyush in range(n): a,b=list(map(int,input().split())) x.append(a) y.append(b) c,f,g=cnt(x),0,0 d=cnt(y) for i in c: f+=c[i]-1 if c[i]>1: g+=c[i] for i in d: f+=d[i]-1 if d[i]>1: g+=d[i] print(n-f-1)
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. Output Specification: Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python x,y,n=[],[],int(input()) from collections import Counter as cnt for pratyush in range(n): a,b=list(map(int,input().split())) x.append(a) y.append(b) c,f,g=cnt(x),0,0 d=cnt(y) for i in c: f+=c[i]-1 if c[i]>1: g+=c[i] for i in d: f+=d[i]-1 if d[i]>1: g+=d[i] print(n-f-1) ```
0
383
A
Milking cows
PROGRAMMING
1,600
[ "data structures", "greedy" ]
null
null
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk). Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right.
Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4\n0 0 1 0\n", "5\n1 0 1 0 1\n" ]
[ "1", "3" ]
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
500
[ { "input": "4\n0 0 1 0", "output": "1" }, { "input": "5\n1 0 1 0 1", "output": "3" }, { "input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0", "output": "416" }, { "input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 0", "output": "1446" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "2\n0 1", "output": "0" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 1 1 1", "output": "0" } ]
1,653,932,550
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
n = int(input()) a = [int(x) for x in input().split()] s = 0 res = 0 for i in a: if i == 0: res += s else: s += 1 print(s)
Title: Milking cows Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk). Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. Output Specification: Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['4\n0 0 1 0\n', '5\n1 0 1 0 1\n'] Demo Output: ['1', '3'] Note: In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
```python n = int(input()) a = [int(x) for x in input().split()] s = 0 res = 0 for i in a: if i == 0: res += s else: s += 1 print(s) ```
0
967
A
Mind the Gap
PROGRAMMING
1,100
[ "implementation" ]
null
null
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff.
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
[ "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "3 17\n0 30\n1 0\n12 0\n" ]
[ "6 1\n", "24 50\n", "0 0\n" ]
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. In the third example Arkady can insert the takeoff even between the first landing.
500
[ { "input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50" }, { "input": "3 17\n0 30\n1 0\n12 0", "output": "0 0" }, { "input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7", "output": "23 8" }, { "input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22", "output": "6 47" }, { "input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37", "output": "23 58" }, { "input": "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50", "output": "1 40" }, { "input": "1 1\n0 0", "output": "0 2" }, { "input": "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21", "output": "0 0" }, { "input": "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32", "output": "0 0" }, { "input": "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21", "output": "0 0" }, { "input": "1 5\n1 0", "output": "0 0" }, { "input": "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "output": "25 0" }, { "input": "1 30\n0 29", "output": "1 0" }, { "input": "1 2\n3 0", "output": "0 0" }, { "input": "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "25 0" }, { "input": "1 5\n0 6", "output": "0 0" }, { "input": "2 60\n0 59\n23 59", "output": "2 0" }, { "input": "1 58\n0 1", "output": "1 0" }, { "input": "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "output": "25 0" }, { "input": "2 3\n0 3\n0 30", "output": "0 7" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9", "output": "24 0" }, { "input": "1 60\n2 0", "output": "0 0" }, { "input": "2 60\n0 0\n5 0", "output": "1 1" }, { "input": "1 30\n0 31", "output": "0 0" }, { "input": "2 60\n0 59\n3 1", "output": "2 0" }, { "input": "2 60\n0 59\n5 0", "output": "2 0" }, { "input": "1 59\n0 0", "output": "1 0" }, { "input": "3 25\n0 0\n1 0\n2 0", "output": "0 26" }, { "input": "1 2\n2 3", "output": "0 0" } ]
1,525,304,036
1,736
PyPy 3
WRONG_ANSWER
TESTS
9
124
21,401,600
n, s = [int(i) for i in input().split()] T = [[int(i) for i in input().split()] for _ in range(n)] h, m = T[0] if h*60 + m >= 1 + s + 1: print(0, 0) else: for i in range(1, n): (h1, m1), (h2, m2) = T[i-1], T[i] d = (h2-h1-(m2<m1))*60 + (m2-m1)%60 if d >= 1 + s + 1 + s: h_ = h1+((m1+1+s)>60) m_ = (m1+1+s) % 60 print(h_, m_) break else: h, m = T[n-1] h_ = h+((m+1+s)>60) m_ = (m+1+s) % 60 print(h_, m_)
Title: Mind the Gap Time Limit: None seconds Memory Limit: None megabytes Problem Description: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff. Input Specification: The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. Output Specification: Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. Demo Input: ['6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n', '16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n', '3 17\n0 30\n1 0\n12 0\n'] Demo Output: ['6 1\n', '24 50\n', '0 0\n'] Note: In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. In the third example Arkady can insert the takeoff even between the first landing.
```python n, s = [int(i) for i in input().split()] T = [[int(i) for i in input().split()] for _ in range(n)] h, m = T[0] if h*60 + m >= 1 + s + 1: print(0, 0) else: for i in range(1, n): (h1, m1), (h2, m2) = T[i-1], T[i] d = (h2-h1-(m2<m1))*60 + (m2-m1)%60 if d >= 1 + s + 1 + s: h_ = h1+((m1+1+s)>60) m_ = (m1+1+s) % 60 print(h_, m_) break else: h, m = T[n-1] h_ = h+((m+1+s)>60) m_ = (m+1+s) % 60 print(h_, m_) ```
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "14" }, { "input": "5 5\n3 2 1 0 0", "output": "3" }, { "input": "8 6\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 7\n10 9 8 7 7 7 5 5", "output": "8" }, { "input": "8 4\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "8 3\n10 9 8 7 7 7 5 5", "output": "3" }, { "input": "8 1\n10 9 8 7 7 7 5 5", "output": "1" }, { "input": "8 2\n10 9 8 7 7 7 5 5", "output": "2" }, { "input": "1 1\n100", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 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": "25" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "26" }, { "input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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", "output": "50" }, { "input": "11 5\n100 99 98 97 96 95 94 93 92 91 90", "output": "5" }, { "input": "10 4\n100 81 70 69 64 43 34 29 15 3", "output": "4" }, { "input": "11 6\n87 71 62 52 46 46 43 35 32 25 12", "output": "6" }, { "input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2", "output": "12" }, { "input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2", "output": "3" }, { "input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5", "output": "12" }, { "input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1", "output": "9" }, { "input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0", "output": "29" }, { "input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4", "output": "34" }, { "input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4", "output": "44" }, { "input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3", "output": "13" }, { "input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3", "output": "30" }, { "input": "2 1\n10 10", "output": "2" }, { "input": "2 2\n10 10", "output": "2" }, { "input": "2 2\n10 0", "output": "1" }, { "input": "2 2\n10 1", "output": "2" }, { "input": "2 1\n10 0", "output": "1" }, { "input": "2 1\n10 2", "output": "1" }, { "input": "50 13\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", "output": "0" }, { "input": "50 1\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", "output": "0" }, { "input": "50 50\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", "output": "0" }, { "input": "10 1\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 2\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 3\n5 5 5 3 3 3 0 0 0 0", "output": "3" }, { "input": "10 4\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 5\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 6\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 7\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 8\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 9\n5 5 5 3 3 3 0 0 0 0", "output": "6" }, { "input": "10 10\n5 5 5 3 3 3 0 0 0 0", "output": "6" } ]
1,699,784,108
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
n, k = map(int, input().split()) scores = list(map(int, input().split())) count = 0 for score in scores: if scores[0]==0: count = 0 elif score >= scores[k-1]: count += 1 print(count)
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). Output Specification: Output the number of participants who advance to the next round. Demo Input: ['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n'] Demo Output: ['6\n', '0\n'] Note: In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
```python n, k = map(int, input().split()) scores = list(map(int, input().split())) count = 0 for score in scores: if scores[0]==0: count = 0 elif score >= scores[k-1]: count += 1 print(count) ```
0
569
A
Music
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start.
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105).
Print a single integer — the number of times the song will be restarted.
[ "5 2 2\n", "5 4 7\n", "6 2 3\n" ]
[ "2\n", "1\n", "1\n" ]
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
500
[ { "input": "5 2 2", "output": "2" }, { "input": "5 4 7", "output": "1" }, { "input": "6 2 3", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 1 3", "output": "1" }, { "input": "2 1 10000", "output": "1" }, { "input": "12326 6163 2", "output": "1" }, { "input": "10000 2500 4", "output": "1" }, { "input": "100000 99999 4", "output": "1" }, { "input": "12351 1223 6", "output": "2" }, { "input": "100000 1 10000", "output": "2" }, { "input": "10028 13 10000", "output": "1" }, { "input": "100000 99999 2", "output": "1" }, { "input": "100000 99999 3", "output": "1" }, { "input": "100000 1 2", "output": "17" }, { "input": "100000 1 3", "output": "11" }, { "input": "100000 1 4", "output": "9" }, { "input": "100000 1 5", "output": "8" }, { "input": "100000 3125 2", "output": "5" }, { "input": "12628 1804 7", "output": "1" }, { "input": "100000 45 13", "output": "4" }, { "input": "100000 500 3", "output": "5" }, { "input": "356 2 3", "output": "5" }, { "input": "50 2 2", "output": "5" }, { "input": "65465 12 3", "output": "8" }, { "input": "10033 3 8", "output": "4" }, { "input": "100000 3 2", "output": "16" }, { "input": "64 1 8", "output": "2" }, { "input": "10000 9 2", "output": "11" }, { "input": "25 2 2", "output": "4" }, { "input": "129 2 2", "output": "7" }, { "input": "6562 1 3", "output": "9" }, { "input": "100000 1 10", "output": "5" } ]
1,439,224,827
627
Python 3
WRONG_ANSWER
PRETESTS
2
30
0
t, s, q = map(int, input().split()) ans = 0 downloaded = s listened = 0 while downloaded <= t: listened += q if listened >= downloaded: ans += 1 listened -= downloaded downloaded += q - 1 print(ans)
Title: Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. Input Specification: The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105). Output Specification: Print a single integer — the number of times the song will be restarted. Demo Input: ['5 2 2\n', '5 4 7\n', '6 2 3\n'] Demo Output: ['2\n', '1\n', '1\n'] Note: In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
```python t, s, q = map(int, input().split()) ans = 0 downloaded = s listened = 0 while downloaded <= t: listened += q if listened >= downloaded: ans += 1 listened -= downloaded downloaded += q - 1 print(ans) ```
0
835
C
Star sky
PROGRAMMING
1,600
[ "dp", "implementation" ]
null
null
The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*). Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at moment *t* some star has brightness *x*. Then at moment (*t*<=+<=1) this star will have brightness *x*<=+<=1, if *x*<=+<=1<=≤<=*c*, and 0, otherwise. You want to look at the sky *q* times. In the *i*-th time you will look at the moment *t**i* and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (*x*1*i*, *y*1*i*) and the upper right — (*x*2*i*, *y*2*i*). For each view, you want to know the total brightness of the stars lying in the viewed rectangle. A star lies in a rectangle if it lies on its border or lies strictly inside it.
The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars. The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=100, 0<=≤<=*s**i*<=≤<=*c*<=≤<=10) — the coordinates of *i*-th star and its initial brightness. The next *q* lines contain the views description. The *i*-th from these lines contains five integers *t**i*, *x*1*i*, *y*1*i*, *x*2*i*, *y*2*i* (0<=≤<=*t**i*<=≤<=109, 1<=≤<=*x*1*i*<=&lt;<=*x*2*i*<=≤<=100, 1<=≤<=*y*1*i*<=&lt;<=*y*2*i*<=≤<=100) — the moment of the *i*-th view and the coordinates of the viewed rectangle.
For each view print the total brightness of the viewed stars.
[ "2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n", "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n" ]
[ "3\n0\n3\n", "3\n3\n5\n0\n" ]
Let's consider the first example. At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3. At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0. At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.
1,250
[ { "input": "2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5", "output": "3\n0\n3" }, { "input": "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51", "output": "3\n3\n5\n0" } ]
1,700,384,332
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
409,600
def fun(t, x1, y1, x2, y2, stars, c): sum=0 for i in stars: if x1<=i[0]<=x2 and y1<=i[1]<=y2: if i[2]>0: if t>(c-i[2]): alpha = t-(c-i[2]+1) sum+=(alpha%(c+1)) # print(1, t%(c+1)) else: sum+=(i[2]+t) # print(2, i[2]+t) else: sum+=(t%(c+1)) # print(3, t, c+1) return sum n,q,c = map(lambda x: int(x), input().split()) stars = [] for _ in range(n): a = list(map(lambda x: int(x), input().split())) stars.append(a) for _ in range(q): t, x1, y1, x2, y2 = map(lambda x: int(x), input().split()) print(fun(t, x1, y1, x2, y2, stars, c))
Title: Star sky Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*). Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at moment *t* some star has brightness *x*. Then at moment (*t*<=+<=1) this star will have brightness *x*<=+<=1, if *x*<=+<=1<=≤<=*c*, and 0, otherwise. You want to look at the sky *q* times. In the *i*-th time you will look at the moment *t**i* and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (*x*1*i*, *y*1*i*) and the upper right — (*x*2*i*, *y*2*i*). For each view, you want to know the total brightness of the stars lying in the viewed rectangle. A star lies in a rectangle if it lies on its border or lies strictly inside it. Input Specification: The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars. The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=100, 0<=≤<=*s**i*<=≤<=*c*<=≤<=10) — the coordinates of *i*-th star and its initial brightness. The next *q* lines contain the views description. The *i*-th from these lines contains five integers *t**i*, *x*1*i*, *y*1*i*, *x*2*i*, *y*2*i* (0<=≤<=*t**i*<=≤<=109, 1<=≤<=*x*1*i*<=&lt;<=*x*2*i*<=≤<=100, 1<=≤<=*y*1*i*<=&lt;<=*y*2*i*<=≤<=100) — the moment of the *i*-th view and the coordinates of the viewed rectangle. Output Specification: For each view print the total brightness of the viewed stars. Demo Input: ['2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n', '3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n'] Demo Output: ['3\n0\n3\n', '3\n3\n5\n0\n'] Note: Let's consider the first example. At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3. At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0. At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.
```python def fun(t, x1, y1, x2, y2, stars, c): sum=0 for i in stars: if x1<=i[0]<=x2 and y1<=i[1]<=y2: if i[2]>0: if t>(c-i[2]): alpha = t-(c-i[2]+1) sum+=(alpha%(c+1)) # print(1, t%(c+1)) else: sum+=(i[2]+t) # print(2, i[2]+t) else: sum+=(t%(c+1)) # print(3, t, c+1) return sum n,q,c = map(lambda x: int(x), input().split()) stars = [] for _ in range(n): a = list(map(lambda x: int(x), input().split())) stars.append(a) for _ in range(q): t, x1, y1, x2, y2 = map(lambda x: int(x), input().split()) print(fun(t, x1, y1, x2, y2, stars, c)) ```
0
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*.
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces.
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "output": "6" }, { "input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "5\n1 0\n1 0\n1 0\n0 1\n0 1", "output": "4" } ]
1,658,590,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
c0=0 c1=0 for _ in range(int(input())): l,r=map(int,input().split()) if l==0: c0+=1 elif l==1: c1+=1 print(max(c0,c1))
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. Input Specification: The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. Output Specification: In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Demo Input: ['5\n0 1\n1 0\n0 1\n1 1\n0 1\n'] Demo Output: ['3\n'] Note: none
```python c0=0 c1=0 for _ in range(int(input())): l,r=map(int,input().split()) if l==0: c0+=1 elif l==1: c1+=1 print(max(c0,c1)) ```
0
452
A
Eevee
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
500
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "7\n.laceon", "output": "glaceon" }, { "input": "7\n..lveon", "output": "sylveon" }, { "input": "7\n.l.ceon", "output": "glaceon" }, { "input": "7\n..areon", "output": "flareon" } ]
1,406,989,099
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
input() #not needed. names = { "vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon" } text = input().split('.') text = {item for item in text if item} for name in names: if text < set(name): print(name)
Title: Eevee Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. Input Specification: First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). Output Specification: Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). Demo Input: ['7\nj......\n', '7\n...feon\n', '7\n.l.r.o.\n'] Demo Output: ['jolteon\n', 'leafeon\n', 'flareon\n'] Note: Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
```python input() #not needed. names = { "vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon" } text = input().split('.') text = {item for item in text if item} for name in names: if text < set(name): print(name) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,688,889,074
2,147,483,647
PyPy 3-64
OK
TESTS
71
218
1,945,600
n = int(input()) summ=0 count=0 for i in range(n): s = input().split() summ-=int(s[0]) summ+=int(s[1]) if summ>=count: count=summ print(count)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python n = int(input()) summ=0 count=0 for i in range(n): s = input().split() summ-=int(s[0]) summ+=int(s[1]) if summ>=count: count=summ print(count) ```
3
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\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", "output": "50" }, { "input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "output": "42" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "6\n5 4 3 2 1 2", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "7\n99 100 1 2 3 4 5", "output": "5" }, { "input": "5\n3 3 1 2 3", "output": "3" }, { "input": "1\n100", "output": "1" }, { "input": "1\n5", "output": "1" } ]
1,696,630,974
2,147,483,647
Python 3
OK
TESTS
28
109
13,926,400
n = int(input()) a = list(map(int, input().split())) dp = [0] * n dp[0] = 1 for i in range(1, n): if a[i] >= a[i - 1]: dp[i] = dp[ i -1] + 1 else: dp[i] = 1 print(max(dp))
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. Demo Input: ['6\n2 2 1 3 4 1\n', '3\n2 2 9\n'] Demo Output: ['3', '3'] Note: In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
```python n = int(input()) a = list(map(int, input().split())) dp = [0] * n dp[0] = 1 for i in range(1, n): if a[i] >= a[i - 1]: dp[i] = dp[ i -1] + 1 else: dp[i] = 1 print(max(dp)) ```
3
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,656,237,355
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
4,505,600
p=input() a=0 b=0 c=0 for i in range(p): arr=map(int,raw_input().split(" ")) a=a+arr[0] b=b+arr[1] c=c+arr[2] if(a==0 and b==0 and c==0): print("YES") else: print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python p=input() a=0 b=0 c=0 for i in range(p): arr=map(int,raw_input().split(" ")) a=a+arr[0] b=b+arr[1] c=c+arr[2] if(a==0 and b==0 and c==0): print("YES") else: print("NO") ```
-1
794
B
Cutting Carrot
PROGRAMMING
1,200
[ "geometry", "math" ]
null
null
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area?
The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105).
The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "3 2\n", "2 100000\n" ]
[ "1.154700538379 1.632993161855\n", "70710.678118654752\n" ]
Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
1,000
[ { "input": "3 2", "output": "1.154700538379 1.632993161855" }, { "input": "2 100000", "output": "70710.678118654752" }, { "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8944.271909999159 9486.832980505138 10000.000000000000 10488.088481701515 10954.451150103322 11401.754250991380 11832.159566199232 12247.448713915890 12649.110640673517 13038.404810405297 13416.407864998738 13784.048752090222 14142.135623730950 14491.376746189439 14832.396974191326 15165.750888103101 15491.933384829668 15811.388300841897 16124.515496597099 16431.676725154983 16733.2..." }, { "input": "2 1", "output": "0.707106781187" }, { "input": "1000 1", "output": "0.031622776602 0.044721359550 0.054772255751 0.063245553203 0.070710678119 0.077459666924 0.083666002653 0.089442719100 0.094868329805 0.100000000000 0.104880884817 0.109544511501 0.114017542510 0.118321595662 0.122474487139 0.126491106407 0.130384048104 0.134164078650 0.137840487521 0.141421356237 0.144913767462 0.148323969742 0.151657508881 0.154919333848 0.158113883008 0.161245154966 0.164316767252 0.167332005307 0.170293863659 0.173205080757 0.176068168617 0.178885438200 0.181659021246 0.184390889146 0..." }, { "input": "20 17", "output": "3.801315561750 5.375872022286 6.584071688553 7.602631123499 8.500000000000 9.311283477588 10.057335631269 10.751744044572 11.403946685249 12.020815280171 12.607537428063 13.168143377105 13.705838172108 14.223220451079 14.722431864335 15.205262246999 15.673225577398 16.127616066859 16.569550386175" }, { "input": "999 1", "output": "0.031638599858 0.044743737014 0.054799662435 0.063277199717 0.070746059996 0.077498425829 0.083707867056 0.089487474029 0.094915799575 0.100050037531 0.104933364623 0.109599324870 0.114074594073 0.118380800867 0.122535770349 0.126554399434 0.130449289063 0.134231211043 0.137909459498 0.141492119993 0.144986278734 0.148398187395 0.151733394554 0.154996851658 0.158192999292 0.161325838061 0.164398987305 0.167415734111 0.170379074505 0.173291748303 0.176156268782 0.178974948057 0.181749918935 0.184483153795 0..." }, { "input": "998 99999", "output": "3165.413034717700 4476.570044210349 5482.656203071844 6330.826069435401 7078.078722492680 7753.646760213179 8374.895686665300 8953.140088420697 9496.239104153101 10009.914924893578 10498.487342658843 10965.312406143687 11413.059004696742 11843.891063542002 12259.591967329534 12661.652138870802 13051.332290848021 13429.710132631046 13797.715532900862 14156.157444985360 14505.744837393740 14847.103184390411 15180.787616204127 15507.293520426358 15827.065173588502 16140.502832606510 16447.968609215531 16749.7..." }, { "input": "574 29184", "output": "1218.116624752432 1722.677051277028 2109.839883615525 2436.233249504864 2723.791577469041 2983.764177844748 3222.833656968322 3445.354102554056 3654.349874257297 3852.022989934325 4040.035795197963 4219.679767231051 4391.981950040022 4557.775066957079 4717.745401404559 4872.466499009729 5022.423508175150 5168.031153831084 5309.647268742708 5447.583154938083 5582.111638212139 5713.473414041731 5841.882108059006 5967.528355689497 6090.583123762161 6211.200439444432 6329.519650846576 6445.667313936643 6559.75..." }, { "input": "2 5713", "output": "4039.701040918746" }, { "input": "937 23565", "output": "769.834993893392 1088.711089153444 1333.393322867831 1539.669987786784 1721.403377803760 1885.702921177414 2036.791944396843 2177.422178306887 2309.504981680176 2434.432003204934 2553.253825229922 2666.786645735663 2775.679544129132 2880.458791498282 2981.558110676796 3079.339975573568 3174.110994119182 3266.133267460331 3355.632941582547 3442.806755607520 3527.827132142336 3610.846187821139 3691.998931463184 3771.405842354828 3849.174969466960 3925.403656108988 4000.179968603494 4073.583888793686 4145.688..." }, { "input": "693 39706", "output": "1508.306216302128 2133.067107306117 2612.463000007259 3016.612432604256 3372.675230537060 3694.580605808168 3990.603149268227 4266.134214612233 4524.918648906384 4769.683052505315 5002.485788434792 5224.926000014517 5438.275401978402 5643.565095743912 5841.644856719264 6033.224865208513 6218.905845589392 6399.201321918350 6574.554372775177 6745.350461074120 6911.927407376938 7074.583247583148 7233.582498950279 7389.161211616337 7541.531081510641 7690.882829397851 7837.389000021776 7981.206298536455 8122.47..." }, { "input": "449 88550", "output": "4178.932872810542 5909.903544975429 7238.124057127628 8357.865745621084 9344.377977012855 10236.253207728862 11056.417127089408 11819.807089950858 12536.798618431626 13214.946067032045 13859.952363194553 14476.248114255256 15067.356749640443 15636.135052384012 16184.937421313947 16715.731491242168 17230.181636963718 17729.710634926286 18215.546084421264 18688.755954025709 19150.276213793575 19600.932605874766 20041.458005232581 20472.506415457724 20894.664364052710 21308.460264455309 21714.372171382883 221..." }, { "input": "642 37394", "output": "1475.823459881026 2087.129552632132 2556.201215516026 2951.646919762052 3300.041579082908 3615.014427137354 3904.661853880105 4174.259105264265 4427.470379643078 4666.963557534173 4894.752673229489 5112.402431032051 5321.157158133711 5522.025750238117 5715.839682061424 5903.293839524104 6084.976009853978 6261.388657896397 6432.965320127946 6600.083158165816 6763.072717296425 6922.225614943105 7077.800671741869 7230.028854274709 7379.117299405130 7525.252620551370 7668.603646548077 7809.323707760210 7947.55..." }, { "input": "961 53535", "output": "1726.935483870968 2442.255582633666 2991.139999458060 3453.870967741935 3861.545134691976 4230.110754190240 4569.041820575576 4884.511165267332 5180.806451612903 5461.049501197232 5727.597037150849 5982.279998916119 6226.554436514989 6461.600909707837 6688.392369006905 6907.741935483871 7120.337408627144 7326.766747900998 7527.537256208063 7723.090269383951 7913.812575143900 8100.045409746687 8282.091632275692 8460.221508380480 8634.677419354839 8805.677730973862 8973.419998374179 9138.083641151152 9299.83..." }, { "input": "4 31901", "output": "15950.500000000000 22557.413426632053 27627.076406127377" }, { "input": "4 23850", "output": "11925.000000000000 16864.496731299158 20654.705880258862" }, { "input": "4 72694", "output": "36347.000000000000 51402.420351574886 62954.850702705983" }, { "input": "4 21538", "output": "10769.000000000000 15229.665853195861 18652.455146709240" }, { "input": "4 70383", "output": "35191.500000000000 49768.296580252774 60953.465994560145" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "20 1", "output": "0.223606797750 0.316227766017 0.387298334621 0.447213595500 0.500000000000 0.547722557505 0.591607978310 0.632455532034 0.670820393250 0.707106781187 0.741619848710 0.774596669241 0.806225774830 0.836660026534 0.866025403784 0.894427191000 0.921954445729 0.948683298051 0.974679434481" }, { "input": "775 1", "output": "0.035921060405 0.050800050800 0.062217101684 0.071842120811 0.080321932890 0.087988269013 0.095038192662 0.101600101600 0.107763181216 0.113592366849 0.119136679436 0.124434203368 0.129515225161 0.134404301006 0.139121668728 0.143684241621 0.148106326235 0.152400152400 0.156576272252 0.160643865780 0.164610978351 0.168484707835 0.172271353843 0.175976538026 0.179605302027 0.183162187956 0.186651305051 0.190076385325 0.193440830330 0.196747750735 0.200000000000 0.203200203200 0.206350781829 0.209453975235 0..." }, { "input": "531 1", "output": "0.043396303660 0.061371641193 0.075164602800 0.086792607321 0.097037084957 0.106298800691 0.114815827305 0.122743282386 0.130188910981 0.137231161599 0.143929256529 0.150329205601 0.156467598013 0.162374100149 0.168073161363 0.173585214641 0.178927543753 0.184114923580 0.189160102178 0.194074169913 0.198866846404 0.203546706606 0.208121361089 0.212597601381 0.216981518301 0.221278599182 0.225493808401 0.229631654609 0.233696247231 0.237691344271 0.241620392998 0.245486564773 0.249292785005 0.253041759057 0..." }, { "input": "724 1", "output": "0.037164707312 0.052558833123 0.064371161313 0.074329414625 0.083102811914 0.091034569355 0.098328573097 0.105117666246 0.111494121937 0.117525123681 0.123261389598 0.128742322627 0.133999257852 0.139057601643 0.143938292487 0.148658829249 0.153234013794 0.157676499368 0.161997203441 0.166205623829 0.170310084440 0.174317928887 0.178235674883 0.182069138710 0.185823536562 0.189503567803 0.193113483940 0.196657146194 0.200138073886 0.203559485381 0.206924332929 0.210235332491 0.213494989396 0.216705620524 0..." }, { "input": "917 1", "output": "0.033022909334 0.046701446249 0.057197356781 0.066045818668 0.073841470086 0.080889277691 0.087370405666 0.093402892499 0.099068728003 0.104427608461 0.109524599747 0.114394713561 0.119065792869 0.123560412643 0.127897177895 0.132091637337 0.136156943250 0.140104338748 0.143943524609 0.147682940172 0.151329981692 0.154891174376 0.158372309576 0.161778555382 0.165114546671 0.168384459091 0.171592070342 0.174740811332 0.177833809176 0.180873923568 0.183863777748 0.186805784998 0.189702171441 0.192554995756 0..." }, { "input": "458 100", "output": "4.672693135160 6.608186004551 8.093341918275 9.345386270320 10.448459488214 11.445713905748 12.362783988552 13.216372009102 14.018079405480 14.776353114139 15.497569889795 16.186683836551 16.847634693328 17.483616785299 18.097262694412 18.690772540640 19.266007352363 19.824558013653 20.367797170339 20.896918976429 21.412969991171 21.916873521973 22.409449036367 22.891427811495 23.363465675800 23.826153477212 24.280025754826 24.725567977104 25.163222626003 25.593394344267 26.016454316384 26.432744018204 26...." } ]
1,494,671,435
3,335
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
#include<bits/stdc++.h> using namespace std; int main() { //ios::sync_with_stdio(false); //freopen("out.txt", "w", stdout); double n, h; cin >> n >> h; double s = h / 2; double ans = 0; for(int i=1; i<n; ++ i) { double res = sqrt(i / n) * h; if(i == 1) printf("%.9f", res); else printf(" %.9f", res); } puts("\n"); return 0; }
Title: Cutting Carrot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area? Input Specification: The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). Output Specification: The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Demo Input: ['3 2\n', '2 100000\n'] Demo Output: ['1.154700538379 1.632993161855\n', '70710.678118654752\n'] Note: Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
```python #include<bits/stdc++.h> using namespace std; int main() { //ios::sync_with_stdio(false); //freopen("out.txt", "w", stdout); double n, h; cin >> n >> h; double s = h / 2; double ans = 0; for(int i=1; i<n; ++ i) { double res = sqrt(i / n) * h; if(i == 1) printf("%.9f", res); else printf(" %.9f", res); } puts("\n"); return 0; } ```
-1
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "output": "100" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "199" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb", "output": "99" }, { "input": "abcde\nfghij", "output": "5" }, { "input": "abcde\nabcdf", "output": "5" }, { "input": "abcde\nbbcde", "output": "5" }, { "input": "abcde\neabcd", "output": "5" }, { "input": "abcdefgh\nabdcefgh", "output": "8" }, { "input": "mmmmm\nmnmmm", "output": "5" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa", "output": "34" }, { "input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy", "output": "26" }, { "input": "a\nab", "output": "2" }, { "input": "b\nab", "output": "2" }, { "input": "ab\nb", "output": "2" }, { "input": "ab\nc", "output": "2" }, { "input": "aaaaaa\naaaaaa", "output": "-1" }, { "input": "abacaba\nabacaba", "output": "-1" }, { "input": "aabb\nbbaa", "output": "4" }, { "input": "ab\nba", "output": "2" }, { "input": "abcd\nabc", "output": "4" }, { "input": "abaa\nabaa", "output": "-1" }, { "input": "ab\nab", "output": "-1" }, { "input": "ab\nabcd", "output": "4" }, { "input": "abc\nabcd", "output": "4" }, { "input": "mo\nmomo", "output": "4" }, { "input": "koooooooooooooooo\nloooooooooooooooo", "output": "17" }, { "input": "aaa\naa", "output": "3" }, { "input": "abc\nabc", "output": "-1" }, { "input": "abcd\nabcd", "output": "-1" }, { "input": "abc\ncba", "output": "3" }, { "input": "ahc\nahc", "output": "-1" }, { "input": "abc\nbac", "output": "3" }, { "input": "aa\naaa", "output": "3" }, { "input": "aaa\naaa", "output": "-1" }, { "input": "abc\nacb", "output": "3" }, { "input": "abc\nab", "output": "3" }, { "input": "abb\nabb", "output": "-1" }, { "input": "abc\ncab", "output": "3" }, { "input": "aaaaaa\naaaaa", "output": "6" }, { "input": "aa\naab", "output": "3" }, { "input": "len\nlena", "output": "4" }, { "input": "aaaaa\naa", "output": "5" }, { "input": "aaa\naaaa", "output": "4" }, { "input": "bcd\nabcd", "output": "4" }, { "input": "aaabbc\naaaccc", "output": "6" }, { "input": "abcd\nzycd", "output": "4" }, { "input": "baa\nzaa", "output": "3" }, { "input": "asdf\nadfs", "output": "4" }, { "input": "abcdefgh\nabcdefgh", "output": "-1" }, { "input": "aba\naab", "output": "3" }, { "input": "aba\naba", "output": "-1" }, { "input": "abcccc\naccccc", "output": "6" }, { "input": "acb\nabc", "output": "3" }, { "input": "a\naa", "output": "2" }, { "input": "abababab\nab", "output": "8" }, { "input": "ababab\nab", "output": "6" } ]
1,683,614,135
2,147,483,647
Python 3
OK
TESTS
73
46
204,800
i = input() q = input() if i == q: print(-1) else: print(max(len(i), len(q)))
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input Specification: The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output Specification: If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. Demo Input: ['abcd\ndefgh\n', 'a\na\n'] Demo Output: ['5\n', '-1\n'] Note: In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
```python i = input() q = input() if i == q: print(-1) else: print(max(len(i), len(q))) ```
3
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,680,170,780
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
62
0
def st():return str(input()) def ls():return list(map(int, input().split())) def mx(a):return max(a) def it():return int(input()) def mn(a):return min(a) def yes():return print('YES') def no():return print('NO') def re(a):return range(a) def pr(a):return print(a) def prs(a):return print(str(a)) def mapa():return map(int, input().split()) s = [int(i) for i in input().split(':')] s = (s[0]*60)+s[1] m = [] m.append(0) m.append(70) m.append(140) m.append(210) m.append(280) m.append(350) m.append(601) m.append(671) m.append(741) m.append(811) m.append(881) m.append(951) m.append(1202) m.append(1272) m.append(1342) m.append(1412) v = [] for i in range(len(m)): if m[i] - s > 0: m[i] - s print(str(m[i]//60) + ':' + str(m[i]%60)) break elif s > 1412: print('00:00') 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 def st():return str(input()) def ls():return list(map(int, input().split())) def mx(a):return max(a) def it():return int(input()) def mn(a):return min(a) def yes():return print('YES') def no():return print('NO') def re(a):return range(a) def pr(a):return print(a) def prs(a):return print(str(a)) def mapa():return map(int, input().split()) s = [int(i) for i in input().split(':')] s = (s[0]*60)+s[1] m = [] m.append(0) m.append(70) m.append(140) m.append(210) m.append(280) m.append(350) m.append(601) m.append(671) m.append(741) m.append(811) m.append(881) m.append(951) m.append(1202) m.append(1272) m.append(1342) m.append(1412) v = [] for i in range(len(m)): if m[i] - s > 0: m[i] - s print(str(m[i]//60) + ':' + str(m[i]%60)) break elif s > 1412: print('00:00') break ```
0
192
B
Walking in the Rain
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number *n*. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number *i* (*i*<=&lt;<=*n*<=-<=1), you can reach the tiles number *i*<=+<=1 or the tile number *i*<=+<=2 from it (if you stand on the tile number *n*<=-<=1, you can only reach tile number *n*). We can assume that all the opposition movements occur instantaneously. In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the *i*-th tile is destroyed after *a**i* days of rain (on day *a**i* tile isn't destroyed yet, and on day *a**i*<=+<=1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number *n* is broken, or it is impossible to reach the tile number *n* from the tile number 1 if we can walk on undestroyed tiles. The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number *n* will be possible.
The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the boulevard's length in tiles. The second line contains *n* space-separated integers *a**i* — the number of days after which the *i*-th tile gets destroyed (1<=≤<=*a**i*<=≤<=103).
Print a single number — the sought number of days.
[ "4\n10 3 5 10\n", "5\n10 2 8 3 5\n" ]
[ "5\n", "5\n" ]
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
1,000
[ { "input": "4\n10 3 5 10", "output": "5" }, { "input": "5\n10 2 8 3 5", "output": "5" }, { "input": "10\n10 3 1 6 7 1 3 3 8 1", "output": "1" }, { "input": "10\n26 72 10 52 2 5 61 2 39 64", "output": "5" }, { "input": "100\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 1 5 10 7 6 8 10 2 6 4 4 2 2 10 7 2 7 3 2 6 3 6 4 7 6 2 5 5 8 6 9 5 2 7 5 8 6 5 8 10 6 10 8 5 3 1 10 6 1 7 5 1 8 10 5 1 3 10 7 10 5 7 1 4 3 8 6 3 4 9 6", "output": "2" }, { "input": "100\n10 2 8 7 5 1 5 4 9 2 7 9 3 5 6 2 3 6 10 1 2 7 1 4 8 8 6 1 7 8 8 1 5 8 1 2 7 4 10 7 3 1 2 5 8 1 1 4 9 7 7 4 7 3 8 8 7 1 5 1 6 9 8 8 1 10 4 4 7 7 10 9 5 1 1 3 6 2 6 3 6 4 9 8 2 9 6 2 7 8 10 9 9 6 3 5 3 1 4 8", "output": "1" }, { "input": "100\n21 57 14 6 58 61 37 54 43 22 90 90 90 14 10 97 47 43 19 66 96 58 88 92 22 62 99 97 15 36 58 93 44 42 45 38 41 21 16 30 66 92 39 70 1 73 83 27 63 21 20 84 30 30 30 77 93 30 62 96 33 34 28 59 48 89 68 62 50 16 18 19 42 42 80 58 31 59 40 81 92 26 28 47 26 8 8 74 86 80 88 82 98 27 41 97 11 91 42 67", "output": "8" }, { "input": "100\n37 75 11 81 60 33 17 80 37 77 26 86 31 78 59 23 92 38 8 15 30 91 99 75 79 34 78 80 19 51 48 48 61 74 59 30 26 2 71 74 48 42 42 81 20 55 49 69 60 10 53 2 21 44 10 18 45 64 21 18 5 62 3 34 52 72 16 28 70 31 93 5 21 69 21 90 31 90 91 79 54 94 77 27 97 4 74 9 29 29 81 5 33 81 75 37 61 73 57 75", "output": "15" }, { "input": "100\n190 544 642 723 577 689 757 509 165 193 396 972 742 367 83 294 404 308 683 399 551 770 564 721 465 839 379 68 687 554 821 719 304 533 146 180 596 713 546 743 949 100 458 735 17 525 568 907 957 670 914 374 347 801 227 884 284 444 686 410 127 508 504 273 624 213 873 658 336 79 819 938 3 722 649 368 733 747 577 746 940 308 970 963 145 487 102 559 790 243 609 77 552 565 151 492 726 448 393 837", "output": "180" }, { "input": "100\n606 358 399 589 724 454 741 183 571 244 984 867 828 232 189 821 642 855 220 839 585 203 135 305 970 503 362 658 491 562 706 62 721 465 560 880 833 646 365 23 679 549 317 834 583 947 134 253 250 768 343 996 541 163 355 925 336 874 997 632 498 529 932 487 415 391 766 224 364 790 486 512 183 458 343 751 633 126 688 536 845 380 423 447 904 779 520 843 977 392 406 147 888 520 886 179 176 129 8 750", "output": "129" }, { "input": "5\n3 2 3 4 2", "output": "2" }, { "input": "5\n4 8 9 10 6", "output": "4" }, { "input": "5\n2 21 6 5 9", "output": "2" }, { "input": "5\n34 39 30 37 35", "output": "34" }, { "input": "5\n14 67 15 28 21", "output": "14" }, { "input": "5\n243 238 138 146 140", "output": "140" }, { "input": "5\n46 123 210 119 195", "output": "46" }, { "input": "5\n725 444 477 661 761", "output": "477" }, { "input": "10\n2 2 3 4 4 1 5 3 1 2", "output": "2" }, { "input": "10\n1 10 1 10 1 1 7 8 6 7", "output": "1" }, { "input": "10\n5 17 8 1 10 20 9 18 12 20", "output": "5" }, { "input": "10\n18 11 23 7 9 10 28 29 46 21", "output": "9" }, { "input": "10\n2 17 53 94 95 57 36 47 68 48", "output": "2" }, { "input": "10\n93 231 176 168 177 222 22 137 110 4", "output": "4" }, { "input": "10\n499 173 45 141 425 276 96 290 428 95", "output": "95" }, { "input": "10\n201 186 897 279 703 376 238 93 253 316", "output": "201" }, { "input": "25\n3 2 3 2 2 2 3 4 5 1 1 4 1 2 1 3 5 5 3 5 1 2 4 1 3", "output": "1" }, { "input": "25\n9 9 1 9 10 5 6 4 6 1 5 2 2 1 2 8 4 6 5 7 1 10 5 4 9", "output": "2" }, { "input": "25\n2 17 21 4 13 6 14 18 17 1 16 13 24 4 12 7 8 16 9 25 25 9 11 20 18", "output": "2" }, { "input": "25\n38 30 9 35 33 48 8 4 49 2 39 19 34 35 47 49 33 4 23 5 42 35 49 11 30", "output": "8" }, { "input": "25\n75 34 77 68 60 38 76 89 35 68 28 36 96 63 43 12 9 4 37 75 88 30 11 58 35", "output": "9" }, { "input": "25\n108 3 144 140 239 105 59 126 224 181 147 102 94 201 68 121 167 94 60 130 64 162 45 95 235", "output": "94" }, { "input": "25\n220 93 216 467 134 408 132 220 292 11 363 404 282 253 141 313 310 356 214 256 380 81 42 128 363", "output": "81" }, { "input": "25\n371 884 75 465 891 510 471 52 382 829 514 610 660 642 179 108 41 818 346 106 738 993 706 574 623", "output": "108" }, { "input": "50\n1 2 1 3 2 5 2 2 2 3 4 4 4 3 3 4 1 2 3 1 5 4 1 2 2 1 5 3 2 2 1 5 4 5 2 5 4 1 1 3 5 2 1 4 5 5 1 5 5 5", "output": "1" }, { "input": "50\n2 4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2 3 7 9 10 2 9 9 7 3 8 6 10 6 5 4 8 1 1 5 6 8 9 5 9 5 3", "output": "1" }, { "input": "50\n22 9 5 3 24 21 25 13 17 21 14 8 22 18 2 3 22 9 10 11 25 22 5 10 16 7 15 3 2 13 2 12 9 24 3 14 2 18 3 22 8 2 19 6 16 4 5 20 10 12", "output": "3" }, { "input": "50\n14 4 20 37 50 46 19 20 25 47 10 6 34 12 41 47 9 22 28 41 34 47 40 12 42 9 4 15 15 27 8 38 9 4 17 8 13 47 7 9 38 30 48 50 7 41 34 23 11 16", "output": "9" }, { "input": "50\n69 9 97 15 22 69 27 7 23 84 73 74 60 94 43 98 13 4 63 49 7 31 93 23 6 75 32 63 49 32 99 43 68 48 16 54 20 38 40 65 34 28 21 55 79 50 2 18 22 95", "output": "13" }, { "input": "50\n50 122 117 195 42 178 153 194 7 89 142 40 158 230 213 104 179 56 244 196 85 159 167 19 157 20 230 201 152 98 250 242 10 52 96 242 139 181 90 107 178 52 196 79 23 61 212 47 97 97", "output": "50" }, { "input": "50\n354 268 292 215 187 232 35 38 179 79 108 491 346 384 345 103 14 260 148 322 459 238 220 493 374 237 474 148 21 221 88 377 289 121 201 198 490 117 382 454 359 390 346 456 294 325 130 306 484 83", "output": "38" }, { "input": "50\n94 634 27 328 629 967 728 177 379 908 801 715 787 192 427 48 559 923 841 6 759 335 251 172 193 593 456 780 647 638 750 881 206 129 278 744 91 49 523 248 286 549 593 451 216 753 471 325 870 16", "output": "16" }, { "input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "output": "1" }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "2" }, { "input": "100\n14 7 6 21 12 5 22 23 2 9 8 1 9 2 20 2 24 7 14 24 8 19 15 19 10 24 9 4 21 12 3 21 9 16 9 22 18 4 17 19 19 9 6 1 13 15 23 3 14 3 7 15 17 10 7 24 4 18 21 14 25 20 19 19 14 25 24 21 16 10 2 16 1 21 1 24 13 7 13 20 12 20 2 16 3 6 6 2 19 9 16 4 1 2 7 18 15 14 10 22", "output": "2" }, { "input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "1" }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "5" }, { "input": "100\n26 171 37 63 189 202 180 210 179 131 43 33 227 5 211 130 105 23 229 48 174 48 182 68 174 146 200 166 246 116 106 86 72 206 216 207 70 148 83 149 94 64 142 8 241 211 27 190 58 116 113 96 210 237 73 240 180 110 34 115 167 4 42 30 162 114 74 131 34 206 174 168 216 101 216 149 212 172 180 220 123 201 25 116 42 143 105 40 30 123 174 220 57 238 145 222 105 184 131 162", "output": "26" }, { "input": "100\n182 9 8 332 494 108 117 203 43 473 451 426 119 408 342 84 88 35 383 84 48 69 31 54 347 363 342 69 422 489 194 16 55 171 71 355 116 142 181 246 275 402 155 282 160 179 240 448 49 101 42 499 434 258 21 327 95 376 38 422 68 381 170 372 427 149 38 48 400 224 246 438 62 43 280 40 108 385 351 379 224 311 66 125 300 41 372 358 5 221 223 341 201 261 455 165 74 379 214 10", "output": "9" }, { "input": "100\n836 969 196 706 812 64 743 262 667 27 227 730 50 510 374 915 124 527 778 528 175 151 439 994 835 87 197 91 121 243 534 634 4 410 936 6 979 227 745 734 492 792 209 95 602 446 299 533 376 595 971 879 36 126 528 759 116 499 571 664 787 820 870 838 604 240 334 872 477 415 57 689 870 690 304 122 487 191 253 610 301 348 358 806 828 911 8 320 414 172 268 867 978 205 812 60 845 395 406 155", "output": "121" }, { "input": "250\n5 3 5 1 3 5 3 4 4 3 1 5 2 2 1 1 5 2 3 3 2 5 4 3 2 4 2 3 5 4 1 2 3 5 2 2 5 4 1 3 3 5 4 4 4 4 4 2 4 2 3 5 1 4 3 3 2 3 5 3 3 4 4 2 3 1 3 4 1 4 5 4 1 2 3 4 1 5 3 3 2 3 5 4 2 5 2 2 3 5 4 3 5 4 2 1 4 1 4 1 1 3 5 1 1 2 1 3 4 5 4 3 2 5 1 3 5 1 1 3 3 5 1 4 5 1 2 1 1 5 5 3 5 1 4 1 4 4 4 4 4 1 4 3 4 5 4 1 2 2 5 2 2 4 2 3 5 3 5 5 3 3 2 2 2 1 1 4 4 4 2 1 4 5 3 1 5 4 4 5 5 5 3 3 5 2 1 4 5 4 1 1 1 5 3 5 2 3 3 2 1 3 4 1 4 1 5 3 1 2 5 5 2 1 4 4 2 3 5 2 4 1 3 4 5 5 4 3 2 2 3 2 4 2 5 3 5 5 1 5 3 2 2 4 2 5 5 5 2 5", "output": "1" }, { "input": "1\n987", "output": "987" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 2", "output": "1" }, { "input": "5\n2 5 5 5 5", "output": "2" }, { "input": "1\n500", "output": "500" } ]
1,691,077,252
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
82
124
2,867,200
n=int(input()) l=list(map(int,input().split())) mi=1000000000 if len(l)==1: print(l[0]) else: i=0 j=1 k=2 ans=[] while k<len(l): if l[j]>=l[k]: mi=min(l[i],l[j]) ans.append(mi) i=j j=j+1 k=k+1 else: mi=min(l[i],l[k]) ans.append(mi) i=k k=k+2 j=j+2 #print(ans) print(min(min(ans), l[0], l[n-1]))
Title: Walking in the Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number *n*. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number *i* (*i*<=&lt;<=*n*<=-<=1), you can reach the tiles number *i*<=+<=1 or the tile number *i*<=+<=2 from it (if you stand on the tile number *n*<=-<=1, you can only reach tile number *n*). We can assume that all the opposition movements occur instantaneously. In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the *i*-th tile is destroyed after *a**i* days of rain (on day *a**i* tile isn't destroyed yet, and on day *a**i*<=+<=1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number *n* is broken, or it is impossible to reach the tile number *n* from the tile number 1 if we can walk on undestroyed tiles. The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number *n* will be possible. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=103) — the boulevard's length in tiles. The second line contains *n* space-separated integers *a**i* — the number of days after which the *i*-th tile gets destroyed (1<=≤<=*a**i*<=≤<=103). Output Specification: Print a single number — the sought number of days. Demo Input: ['4\n10 3 5 10\n', '5\n10 2 8 3 5\n'] Demo Output: ['5\n', '5\n'] Note: In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
```python n=int(input()) l=list(map(int,input().split())) mi=1000000000 if len(l)==1: print(l[0]) else: i=0 j=1 k=2 ans=[] while k<len(l): if l[j]>=l[k]: mi=min(l[i],l[j]) ans.append(mi) i=j j=j+1 k=k+1 else: mi=min(l[i],l[k]) ans.append(mi) i=k k=k+2 j=j+2 #print(ans) print(min(min(ans), l[0], l[n-1])) ```
-1
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,680,062,742
2,147,483,647
Python 3
OK
TESTS
35
92
0
m, n = map(int, input().split()) ans = (m * n) // 2 print(ans)
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()) ans = (m * n) // 2 print(ans) ```
3.977
629
A
Far Relative’s Birthday Cake
PROGRAMMING
800
[ "brute force", "combinatorics", "constructive algorithms", "implementation" ]
null
null
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
[ "3\n.CC\nC..\nC.C\n", "4\nCC..\nC..C\n.CC.\n.CC.\n" ]
[ "4\n", "9\n" ]
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
500
[ { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9" }, { "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46" }, { "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84" }, { "input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "output": "80" }, { "input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C", "output": "144" }, { "input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC", "output": "190" }, { "input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..", "output": "228" }, { "input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..", "output": "2103" }, { "input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC", "output": "2071" }, { "input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.", "output": "1160" }, { "input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C", "output": "789" }, { "input": "1\n.", "output": "0" }, { "input": "3\n.CC\nC..\nC.C", "output": "4" }, { "input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C", "output": "529" }, { "input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C", "output": "874" }, { "input": "2\nCC\nCC", "output": "4" }, { "input": "3\nC..\nC..\nC..", "output": "3" } ]
1,616,065,395
2,147,483,647
Python 3
OK
TESTS
48
171
307,200
n = int(input()) cke=[] for i in range(n): a=[] s = input() for j in range(n): a.append(s[j]) cke.append(a) c=0 for i in range(n): for j in range(n): if cke[i][j]=='C': for k in range(j+1,n): if cke[i][k]=='C': c += 1 for k in range(i+1,n): if cke[k][j]=='C': c += 1 print(c)
Title: Far Relative’s Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. Input Specification: In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. Output Specification: Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Demo Input: ['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n'] Demo Output: ['4\n', '9\n'] Note: If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are: 1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
```python n = int(input()) cke=[] for i in range(n): a=[] s = input() for j in range(n): a.append(s[j]) cke.append(a) c=0 for i in range(n): for j in range(n): if cke[i][j]=='C': for k in range(j+1,n): if cke[i][k]=='C': c += 1 for k in range(i+1,n): if cke[k][j]=='C': c += 1 print(c) ```
3
215
A
Bicycle Chain
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
[ "2\n4 5\n3\n12 13 15\n", "4\n1 2 3 4\n5\n10 11 12 13 14\n" ]
[ "2\n", "1\n" ]
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
500
[ { "input": "2\n4 5\n3\n12 13 15", "output": "2" }, { "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "2\n1 2\n1\n1", "output": "1" }, { "input": "1\n1\n2\n1 2", "output": "1" }, { "input": "4\n3 7 11 13\n4\n51 119 187 221", "output": "4" }, { "input": "4\n2 3 4 5\n3\n1 2 3", "output": "2" }, { "input": "10\n6 12 13 20 48 53 74 92 96 97\n10\n1 21 32 36 47 54 69 75 95 97", "output": "1" }, { "input": "10\n5 9 10 14 15 17 19 22 24 26\n10\n2 11 17 19 21 22 24 25 27 28", "output": "1" }, { "input": "10\n24 53 56 126 354 432 442 740 795 856\n10\n273 438 494 619 689 711 894 947 954 958", "output": "1" }, { "input": "10\n3 4 6 7 8 10 14 16 19 20\n10\n3 4 5 7 8 10 15 16 18 20", "output": "1" }, { "input": "10\n1 6 8 14 15 17 25 27 34 39\n10\n1 8 16 17 19 22 32 39 44 50", "output": "1" }, { "input": "10\n5 21 22 23 25 32 35 36 38 39\n10\n3 7 8 9 18 21 23 24 36 38", "output": "4" }, { "input": "50\n5 8 13 16 19 20 21 22 24 27 28 29 30 32 33 34 35 43 45 48 50 51 54 55 58 59 60 61 62 65 70 71 72 76 78 79 80 81 83 84 85 87 89 91 92 94 97 98 99 100\n50\n2 3 5 6 7 10 15 16 17 20 23 28 29 30 31 34 36 37 40 42 45 46 48 54 55 56 58 59 61 62 69 70 71 72 75 76 78 82 84 85 86 87 88 89 90 91 92 97 99 100", "output": "1" }, { "input": "50\n3 5 6 8 9 11 13 19 21 23 24 32 34 35 42 50 51 52 56 58 59 69 70 72 73 75 76 77 78 80 83 88 90 95 96 100 101 102 108 109 113 119 124 135 138 141 142 143 145 150\n50\n5 8 10 11 18 19 23 30 35 43 51 53 55 58 63 68 69 71 77 78 79 82 83 86 88 89 91 92 93 94 96 102 103 105 109 110 113 114 116 123 124 126 127 132 133 135 136 137 142 149", "output": "1" }, { "input": "50\n6 16 24 25 27 33 36 40 51 60 62 65 71 72 75 77 85 87 91 93 98 102 103 106 117 118 120 121 122 123 125 131 134 136 143 148 155 157 160 161 164 166 170 178 184 187 188 192 194 197\n50\n5 9 17 23 27 34 40 44 47 59 62 70 81 82 87 88 89 90 98 101 102 110 113 114 115 116 119 122 124 128 130 137 138 140 144 150 152 155 159 164 166 169 171 175 185 186 187 189 190 193", "output": "1" }, { "input": "50\n14 22 23 31 32 35 48 63 76 79 88 97 101 102 103 104 106 113 114 115 116 126 136 138 145 152 155 156 162 170 172 173 179 180 182 203 208 210 212 222 226 229 231 232 235 237 245 246 247 248\n50\n2 5 6 16 28 44 45 46 54 55 56 63 72 80 87 93 94 96 97 100 101 103 132 135 140 160 164 165 167 168 173 180 182 185 186 192 194 198 199 202 203 211 213 216 217 227 232 233 236 245", "output": "1" }, { "input": "50\n14 19 33 35 38 41 51 54 69 70 71 73 76 80 84 94 102 104 105 106 107 113 121 128 131 168 180 181 187 191 195 201 205 207 210 216 220 238 249 251 263 271 272 275 281 283 285 286 291 294\n50\n2 3 5 20 21 35 38 40 43 48 49 52 55 64 73 77 82 97 109 113 119 121 125 132 137 139 145 146 149 180 182 197 203 229 234 241 244 251 264 271 274 281 284 285 287 291 292 293 294 298", "output": "1" }, { "input": "50\n2 4 5 16 18 19 22 23 25 26 34 44 48 54 67 79 80 84 92 110 116 133 138 154 163 171 174 202 205 218 228 229 234 245 247 249 250 263 270 272 274 275 277 283 289 310 312 334 339 342\n50\n1 5 17 18 25 37 46 47 48 59 67 75 80 83 84 107 115 122 137 141 159 162 175 180 184 204 221 224 240 243 247 248 249 258 259 260 264 266 269 271 274 293 294 306 329 330 334 335 342 350", "output": "1" }, { "input": "50\n6 9 11 21 28 39 42 56 60 63 81 88 91 95 105 110 117 125 149 165 174 176 185 189 193 196 205 231 233 268 278 279 281 286 289 292 298 303 305 306 334 342 350 353 361 371 372 375 376 378\n50\n6 17 20 43 45 52 58 59 82 83 88 102 111 118 121 131 145 173 190 191 200 216 224 225 232 235 243 256 260 271 290 291 321 322 323 329 331 333 334 341 343 348 351 354 356 360 366 379 387 388", "output": "1" }, { "input": "10\n17 239 443 467 661 1069 1823 2333 3767 4201\n20\n51 83 97 457 593 717 997 1329 1401 1459 1471 1983 2371 2539 3207 3251 3329 5469 6637 6999", "output": "8" }, { "input": "20\n179 359 401 467 521 601 919 941 1103 1279 1709 1913 1949 2003 2099 2143 2179 2213 2399 4673\n20\n151 181 191 251 421 967 1109 1181 1249 1447 1471 1553 1619 2327 2551 2791 3049 3727 6071 7813", "output": "3" }, { "input": "20\n79 113 151 709 809 983 1291 1399 1409 1429 2377 2659 2671 2897 3217 3511 3557 3797 3823 4363\n10\n19 101 659 797 1027 1963 2129 2971 3299 9217", "output": "3" }, { "input": "30\n19 47 109 179 307 331 389 401 461 509 547 569 617 853 883 1249 1361 1381 1511 1723 1741 1783 2459 2531 2621 3533 3821 4091 5557 6217\n20\n401 443 563 941 967 997 1535 1567 1655 1747 1787 1945 1999 2251 2305 2543 2735 4415 6245 7555", "output": "8" }, { "input": "30\n3 43 97 179 257 313 353 359 367 389 397 457 547 599 601 647 1013 1021 1063 1433 1481 1531 1669 3181 3373 3559 3769 4157 4549 5197\n50\n13 15 17 19 29 79 113 193 197 199 215 223 271 293 359 485 487 569 601 683 895 919 941 967 1283 1285 1289 1549 1565 1765 1795 1835 1907 1931 1945 1985 1993 2285 2731 2735 2995 3257 4049 4139 5105 5315 7165 7405 7655 8345", "output": "20" }, { "input": "50\n11 17 23 53 59 109 137 149 173 251 353 379 419 421 439 503 593 607 661 773 821 877 941 997 1061 1117 1153 1229 1289 1297 1321 1609 1747 2311 2389 2543 2693 3041 3083 3137 3181 3209 3331 3373 3617 3767 4201 4409 4931 6379\n50\n55 59 67 73 85 89 101 115 211 263 295 353 545 599 607 685 739 745 997 1031 1255 1493 1523 1667 1709 1895 1949 2161 2195 2965 3019 3035 3305 3361 3373 3673 3739 3865 3881 4231 4253 4385 4985 5305 5585 5765 6145 6445 8045 8735", "output": "23" }, { "input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782", "output": "3" }, { "input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428", "output": "4" }, { "input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959", "output": "5" }, { "input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664", "output": "24" }, { "input": "5\n33 78 146 3055 4268\n5\n2211 2584 5226 9402 9782", "output": "3" }, { "input": "5\n35 48 52 86 8001\n10\n332 3430 3554 4704 4860 5096 6215 7583 8228 8428", "output": "4" }, { "input": "10\n97 184 207 228 269 2084 4450 6396 7214 9457\n16\n338 1179 1284 1545 1570 2444 3167 3395 3397 5550 6440 7245 7804 7980 9415 9959", "output": "5" }, { "input": "30\n25 30 41 57 58 62 70 72 76 79 84 85 88 91 98 101 104 109 119 129 136 139 148 151 926 1372 3093 3936 5423 7350\n25\n1600 1920 2624 3648 3712 3968 4480 4608 4864 5056 5376 5440 5632 5824 6272 6464 6656 6934 6976 7616 8256 8704 8896 9472 9664", "output": "24" }, { "input": "47\n66 262 357 457 513 530 538 540 592 691 707 979 1015 1242 1246 1667 1823 1886 1963 2133 2649 2679 2916 2949 3413 3523 3699 3958 4393 4922 5233 5306 5799 6036 6302 6629 7208 7282 7315 7822 7833 7927 8068 8150 8870 8962 9987\n39\n167 199 360 528 1515 1643 1986 1988 2154 2397 2856 3552 3656 3784 3980 4096 4104 4240 4320 4736 4951 5266 5656 5849 5850 6169 6517 6875 7244 7339 7689 7832 8120 8716 9503 9509 9933 9936 9968", "output": "12" }, { "input": "1\n94\n50\n423 446 485 1214 1468 1507 1853 1930 1999 2258 2271 2285 2425 2543 2715 2743 2992 3196 4074 4108 4448 4475 4652 5057 5250 5312 5356 5375 5731 5986 6298 6501 6521 7146 7255 7276 7332 7481 7998 8141 8413 8665 8908 9221 9336 9491 9504 9677 9693 9706", "output": "1" }, { "input": "50\n51 67 75 186 194 355 512 561 720 876 1077 1221 1503 1820 2153 2385 2568 2608 2937 2969 3271 3311 3481 4081 4093 4171 4255 4256 4829 5020 5192 5636 5817 6156 6712 6717 7153 7436 7608 7612 7866 7988 8264 8293 8867 9311 9879 9882 9889 9908\n1\n5394", "output": "1" }, { "input": "50\n26 367 495 585 675 789 855 1185 1312 1606 2037 2241 2587 2612 2628 2807 2873 2924 3774 4067 4376 4668 4902 5001 5082 5100 5104 5209 5345 5515 5661 5777 5902 5907 6155 6323 6675 6791 7503 8159 8207 8254 8740 8848 8855 8933 9069 9164 9171 9586\n5\n1557 6246 7545 8074 8284", "output": "1" }, { "input": "5\n25 58 91 110 2658\n50\n21 372 909 1172 1517 1554 1797 1802 1843 1977 2006 2025 2137 2225 2317 2507 2645 2754 2919 3024 3202 3212 3267 3852 4374 4487 4553 4668 4883 4911 4916 5016 5021 5068 5104 5162 5683 5856 6374 6871 7333 7531 8099 8135 8173 8215 8462 8776 9433 9790", "output": "4" }, { "input": "45\n37 48 56 59 69 70 79 83 85 86 99 114 131 134 135 145 156 250 1739 1947 2116 2315 2449 3104 3666 4008 4406 4723 4829 5345 5836 6262 6296 6870 7065 7110 7130 7510 7595 8092 8442 8574 9032 9091 9355\n50\n343 846 893 1110 1651 1837 2162 2331 2596 3012 3024 3131 3294 3394 3528 3717 3997 4125 4347 4410 4581 4977 5030 5070 5119 5229 5355 5413 5418 5474 5763 5940 6151 6161 6164 6237 6506 6519 6783 7182 7413 7534 8069 8253 8442 8505 9135 9308 9828 9902", "output": "17" }, { "input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\n40\n68 214 957 1649 1940 2078 2134 2716 3492 3686 4462 4559 4656 4756 4850 5044 5490 5529 5592 5626 6014 6111 6693 6790 7178 7275 7566 7663 7702 7857 7954 8342 8511 8730 8957 9021 9215 9377 9445 9991", "output": "28" }, { "input": "39\n10 13 21 25 36 38 47 48 58 64 68 69 73 79 86 972 2012 2215 2267 2503 3717 3945 4197 4800 5266 6169 6612 6824 7023 7322 7582 7766 8381 8626 8879 9079 9088 9838 9968\n50\n432 877 970 1152 1202 1223 1261 1435 1454 1578 1843 1907 2003 2037 2183 2195 2215 2425 3065 3492 3615 3637 3686 3946 4189 4415 4559 4656 4665 4707 4886 4887 5626 5703 5955 6208 6521 6581 6596 6693 6985 7013 7081 7343 7663 8332 8342 8637 9207 9862", "output": "15" }, { "input": "50\n7 144 269 339 395 505 625 688 709 950 1102 1152 1350 1381 1641 1830 1977 1999 2093 2180 2718 3308 3574 4168 4232 4259 4393 4689 4982 5154 5476 5581 5635 5721 6159 6302 6741 7010 7152 7315 7417 7482 8116 8239 8640 9347 9395 9614 9661 9822\n20\n84 162 292 1728 1866 2088 3228 3470 4068 5318 5470 6060 6380 6929 7500 8256 8399 8467 8508 9691", "output": "8" }, { "input": "50\n159 880 1070 1139 1358 1608 1691 1841 2073 2171 2213 2597 2692 2759 2879 2931 3173 3217 3441 4201 4878 5106 5129 5253 5395 5647 5968 6019 6130 6276 6286 6330 6409 6728 7488 7713 7765 7828 7899 8064 8264 8457 8483 8685 8900 8946 8965 9133 9187 9638\n45\n57 159 1070 1139 1391 1608 1691 1841 2171 2213 2692 2759 2931 3173 3217 3441 4201 4878 5106 5129 5253 5647 5968 6130 6276 6286 6409 7488 7694 7713 7765 7828 7899 8003 8064 8081 8244 8264 8685 8900 8946 8965 9133 9638 9673", "output": "38" }, { "input": "3\n3 4 5\n3\n6 20 25", "output": "2" }, { "input": "4\n2 3 5 8\n4\n2 6 8 10", "output": "1" }, { "input": "4\n3 5 7 11\n4\n3 5 7 22", "output": "1" }, { "input": "2\n2 3\n3\n20 30 50", "output": "1" }, { "input": "3\n1 2 3\n4\n2 4 6 49", "output": "1" }, { "input": "2\n4 5\n3\n12 15 20", "output": "1" }, { "input": "3\n2 5 7\n3\n4 5 7", "output": "1" }, { "input": "3\n3 5 8\n3\n6 8 10", "output": "2" }, { "input": "2\n2 3\n4\n4 6 9 33", "output": "1" }, { "input": "2\n2 3\n4\n4 6 21 40", "output": "1" }, { "input": "3\n4 9 10\n3\n8 9 10", "output": "1" }, { "input": "5\n1 5 6 9 51\n5\n5 12 18 27 10000", "output": "1" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n1\n14", "output": "1" } ]
1,587,320,796
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
216
307,200
n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) r=1 c=0 mr=1 for i in range(n): for j in range(m-1,-1,-1): r=b[j]/a[i] if r==int(r): mr=int(r) break for i in a: if mr*i in b: c+=1 print(c)
Title: Bicycle Chain Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. Output Specification: Print the number of "integer" gears with the maximum ratio among all "integer" gears. Demo Input: ['2\n4 5\n3\n12 13 15\n', '4\n1 2 3 4\n5\n10 11 12 13 14\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15.
```python n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) r=1 c=0 mr=1 for i in range(n): for j in range(m-1,-1,-1): r=b[j]/a[i] if r==int(r): mr=int(r) break for i in a: if mr*i in b: c+=1 print(c) ```
0
807
A
Is it rated?
PROGRAMMING
900
[ "implementation", "sortings" ]
null
null
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
[ "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n" ]
[ "rated\n", "unrated\n", "maybe\n" ]
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
500
[ { "input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated" }, { "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n1 1\n1 1", "output": "maybe" }, { "input": "2\n4126 4126\n4126 4126", "output": "maybe" }, { "input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423", "output": "rated" }, { "input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110", "output": "unrated" }, { "input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143", "output": "maybe" }, { "input": "2\n3936 3936\n2967 2967", "output": "maybe" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 1\n1 2", "output": "rated" }, { "input": "2\n2967 2967\n3936 3936", "output": "unrated" }, { "input": "3\n1200 1200\n1200 1200\n1300 1300", "output": "unrated" }, { "input": "3\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "3\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "2\n3 2\n3 2", "output": "rated" }, { "input": "3\n5 5\n4 4\n3 4", "output": "rated" }, { "input": "3\n200 200\n200 200\n300 300", "output": "unrated" }, { "input": "3\n1 1\n2 2\n3 3", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699", "output": "maybe" }, { "input": "2\n10 10\n8 8", "output": "maybe" }, { "input": "3\n1500 1500\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "3\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n100 100\n100 100\n70 70\n80 80", "output": "unrated" }, { "input": "2\n1 2\n2 1", "output": "rated" }, { "input": "3\n5 5\n4 3\n3 3", "output": "rated" }, { "input": "3\n1600 1650\n1500 1550\n1400 1450", "output": "rated" }, { "input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700", "output": "unrated" }, { "input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700", "output": "unrated" }, { "input": "2\n1600 1600\n1400 1400", "output": "maybe" }, { "input": "2\n3 1\n9 8", "output": "rated" }, { "input": "2\n2 1\n1 1", "output": "rated" }, { "input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670", "output": "unrated" }, { "input": "2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n10 11\n5 4", "output": "rated" }, { "input": "2\n15 14\n13 12", "output": "rated" }, { "input": "2\n2 1\n2 2", "output": "rated" }, { "input": "3\n2670 2670\n3670 3670\n4106 4106", "output": "unrated" }, { "input": "3\n4 5\n3 3\n2 2", "output": "rated" }, { "input": "2\n10 9\n10 10", "output": "rated" }, { "input": "3\n1011 1011\n1011 999\n2200 2100", "output": "rated" }, { "input": "2\n3 3\n5 5", "output": "unrated" }, { "input": "2\n1500 1500\n3000 2000", "output": "rated" }, { "input": "2\n5 6\n5 5", "output": "rated" }, { "input": "3\n2000 2000\n1500 1501\n500 500", "output": "rated" }, { "input": "2\n2 3\n2 2", "output": "rated" }, { "input": "2\n3 3\n2 2", "output": "maybe" }, { "input": "2\n1 2\n1 1", "output": "rated" }, { "input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699", "output": "maybe" }, { "input": "2\n15 14\n14 13", "output": "rated" }, { "input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900", "output": "unrated" }, { "input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884", "output": "rated" }, { "input": "2\n100 99\n100 100", "output": "rated" }, { "input": "4\n2 2\n1 1\n1 1\n2 2", "output": "unrated" }, { "input": "3\n100 101\n100 100\n100 100", "output": "rated" }, { "input": "4\n1000 1001\n900 900\n950 950\n890 890", "output": "rated" }, { "input": "2\n2 3\n1 1", "output": "rated" }, { "input": "2\n2 2\n1 1", "output": "maybe" }, { "input": "2\n3 2\n2 2", "output": "rated" }, { "input": "2\n3 2\n3 3", "output": "rated" }, { "input": "2\n1 1\n2 2", "output": "unrated" }, { "input": "3\n3 2\n3 3\n3 3", "output": "rated" }, { "input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "3\n1000 1000\n500 500\n400 300", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000", "output": "unrated" }, { "input": "2\n1 1\n2 3", "output": "rated" }, { "input": "2\n6 2\n6 2", "output": "rated" }, { "input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246", "output": "unrated" }, { "input": "2\n1500 1500\n1600 1600", "output": "unrated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699", "output": "maybe" }, { "input": "2\n20 30\n10 5", "output": "rated" }, { "input": "3\n1 1\n2 2\n1 1", "output": "unrated" }, { "input": "2\n1 2\n3 3", "output": "rated" }, { "input": "5\n5 5\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n2 2\n2 1", "output": "rated" }, { "input": "2\n100 100\n90 89", "output": "rated" }, { "input": "2\n1000 900\n2000 2000", "output": "rated" }, { "input": "2\n50 10\n10 50", "output": "rated" }, { "input": "2\n200 200\n100 100", "output": "maybe" }, { "input": "3\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "3\n1000 1000\n300 300\n100 100", "output": "maybe" }, { "input": "4\n2 2\n2 2\n3 3\n4 4", "output": "unrated" }, { "input": "2\n5 3\n6 3", "output": "rated" }, { "input": "2\n1200 1100\n1200 1000", "output": "rated" }, { "input": "2\n5 5\n4 4", "output": "maybe" }, { "input": "2\n5 5\n3 3", "output": "maybe" }, { "input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100", "output": "unrated" }, { "input": "5\n10 10\n9 9\n8 8\n7 7\n6 6", "output": "maybe" }, { "input": "3\n1000 1000\n300 300\n10 10", "output": "maybe" }, { "input": "5\n6 6\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "2\n3 3\n1 1", "output": "maybe" }, { "input": "4\n2 2\n2 2\n2 2\n3 3", "output": "unrated" }, { "input": "2\n1000 1000\n700 700", "output": "maybe" }, { "input": "2\n4 3\n5 3", "output": "rated" }, { "input": "2\n1000 1000\n1100 1100", "output": "unrated" }, { "input": "4\n5 5\n4 4\n3 3\n2 2", "output": "maybe" }, { "input": "3\n1 1\n2 3\n2 2", "output": "rated" }, { "input": "2\n1 2\n1 3", "output": "rated" }, { "input": "2\n3 3\n1 2", "output": "rated" }, { "input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400", "output": "rated" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "2\n10 10\n1 2", "output": "rated" }, { "input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900", "output": "unrated" }, { "input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699", "output": "unrated" }, { "input": "2\n100 100\n110 110", "output": "unrated" }, { "input": "3\n3 3\n3 3\n4 4", "output": "unrated" }, { "input": "3\n3 3\n3 2\n4 4", "output": "rated" }, { "input": "3\n5 2\n4 4\n3 3", "output": "rated" }, { "input": "4\n4 4\n3 3\n2 2\n1 1", "output": "maybe" }, { "input": "2\n1 1\n3 2", "output": "rated" }, { "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699", "output": "unrated" }, { "input": "3\n3 3\n3 3\n3 4", "output": "rated" }, { "input": "3\n1 2\n2 2\n3 3", "output": "rated" }, { "input": "3\n1 2\n1 2\n1 2", "output": "rated" }, { "input": "2\n2 1\n2 1", "output": "rated" }, { "input": "2\n1 2\n3 4", "output": "rated" }, { "input": "2\n3 2\n2 3", "output": "rated" }, { "input": "3\n1500 1500\n1600 1600\n1600 1600", "output": "unrated" }, { "input": "3\n1 1\n3 3\n4 4", "output": "unrated" }, { "input": "3\n1 1\n2 2\n2 2", "output": "unrated" }, { "input": "2\n10 12\n8 8", "output": "rated" }, { "input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500", "output": "unrated" }, { "input": "2\n1 2\n2 2", "output": "rated" }, { "input": "3\n1500 1400\n1200 1200\n1100 1100", "output": "rated" }, { "input": "2\n10 12\n10 10", "output": "rated" }, { "input": "3\n1500 1500\n1400 1400\n1300 1300", "output": "maybe" }, { "input": "3\n3 3\n4 4\n5 5", "output": "unrated" }, { "input": "3\n2 6\n3 5\n4 4", "output": "rated" }, { "input": "2\n5 6\n4 6", "output": "rated" }, { "input": "4\n10 10\n10 10\n7 7\n8 8", "output": "unrated" }, { "input": "2\n4 4\n3 3", "output": "maybe" } ]
1,591,503,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
108
307,200
n = int(input()) prev = (-1 , -1) maybe = False is_rated = False for i in range(n): a, b = list(map(int, input().split()))\ if a != b: is_rated = True break if a == prev[0] and b == prev[1]: maybe = True prev = (a, b) if is_rated: print('rated') elif maybe: print('maybe') else: print('unrated')
Title: Is it rated? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. Output Specification: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Demo Input: ['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'] Demo Output: ['rated\n', 'unrated\n', 'maybe\n'] Note: In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated. In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure. In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
```python n = int(input()) prev = (-1 , -1) maybe = False is_rated = False for i in range(n): a, b = list(map(int, input().split()))\ if a != b: is_rated = True break if a == prev[0] and b == prev[1]: maybe = True prev = (a, b) if is_rated: print('rated') elif maybe: print('maybe') else: print('unrated') ```
0
44
E
Anfisa the Monkey
PROGRAMMING
1,400
[ "dp" ]
E. Anfisa the Monkey
2
256
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble human speech more. Help Anfisa.
The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols.
Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print "No solution" (without quotes).
[ "3 2 5\nabrakadabra\n", "4 1 2\nabrakadabra\n" ]
[ "ab\nrakad\nabra\n", "No solution\n" ]
none
0
[ { "input": "3 2 5\nabrakadabra", "output": "abra\nkada\nbra" }, { "input": "4 1 2\nabrakadabra", "output": "No solution" }, { "input": "3 1 2\nvgnfpo", "output": "vg\nnf\npo" }, { "input": "5 3 4\nvrrdnhazvexzjfv", "output": "vrr\ndnh\nazv\nexz\njfv" }, { "input": "10 12 15\nctxgddcfdtllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmp", "output": "ctxgddcfdtllm\npuxsjkubuqpld\nznulsilueakbw\nwlzgeyudyrjac\nhmitfdcgyzszo\nejphrubpxzpdt\ngexaqpxgnoxwf\njoikljudnouci\nrussumyhetfwg\naoxfbugfiyjmp" }, { "input": "10 20 30\nbvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpsh", "output": "bvdqvlxiyogiyimdlwdy\nxsummjgqxaxsucfeuegl\neetybsylpnepkqzbutib\ntlgqrbjbwqnvkysxftms\njqkczoploxoqfuwyrufz\nwwsxpcqfuckjainpphpb\nvvtllgkljnnoibsvwnxv\naksxjrffakpoxwkhjjje\nmqatbfkmmlmjhhroetlq\nvfaumctbicqkuxaabpsh" }, { "input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidf", "output": "olahgjusovchbowjxtw\nzvjakrktyjqcgkqmcxk\nnjchzxcvbnkbakwnxdo\nuebomyhjsrfsicmzsgd\nweabbuipbzrhuqfpyny\nbaohzquqbbsqpoaskcc\nszzsmnfleevtasmjuwq\ngcqtvysohvyutqipnvu\nhjumwwyytkeuebbncxs\nnpavwdkoxyycqrhcidf" }, { "input": "30 3 6\nebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqke", "output": "ebd\ngac\nrmh\nfld\nirw\nrcf\nadu\nrng\near\nrfy\njiq\nkmf\nqmg\nzpn\nzcp\nprk\njye\nuup\npzv\nmib\nzzw\nyou\nhxc\nlcg\nqtj\nhjm\nucy\npqn\nhda\nqke" }, { "input": "200 1 200\nlycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqg", "output": "l\ny\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz..." }, { "input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrc", "output": "aro\nnay\njut\njdh\njce\nlge\nxga\nlny\niru\nevj\nelv\ncvz\naih\ngbw\nwrc" }, { "input": "7 3 4\nweoghhroclwslkfcsszplh", "output": "weog\nhhr\nocl\nwsl\nkfc\nssz\nplh" }, { "input": "12 2 5\nozgscnrddhejkhllokmafxcuorxryhvqnkikauclhfbddfoxl", "output": "ozgsc\nnrdd\nhejk\nhllo\nkmaf\nxcuo\nrxry\nhvqn\nkika\nuclh\nfbdd\nfoxl" }, { "input": "3 1 2\nfpos", "output": "fp\no\ns" }, { "input": "5 3 4\nvrrdnhazvexzjfvs", "output": "vrrd\nnha\nzve\nxzj\nfvs" }, { "input": "10 12 15\nllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmpm", "output": "llmpuxsjkubuq\npldznulsilue\nakbwwlzgeyud\nyrjachmitfdc\ngyzszoejphru\nbpxzpdtgexaq\npxgnoxwfjoik\nljudnoucirus\nsumyhetfwgao\nxfbugfiyjmpm" }, { "input": "10 20 30\nvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpshu", "output": "vdqvlxiyogiyimdlwdyx\nsummjgqxaxsucfeuegle\netybsylpnepkqzbutibt\nlgqrbjbwqnvkysxftmsj\nqkczoploxoqfuwyrufzw\nwsxpcqfuckjainpphpbv\nvtllgkljnnoibsvwnxva\nksxjrffakpoxwkhjjjem\nqatbfkmmlmjhhroetlqv\nfaumctbicqkuxaabpshu" }, { "input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidfd", "output": "olahgjusovchbowjxtwz\nvjakrktyjqcgkqmcxkn\njchzxcvbnkbakwnxdou\nebomyhjsrfsicmzsgdw\neabbuipbzrhuqfpynyb\naohzquqbbsqpoaskccs\nzzsmnfleevtasmjuwqg\ncqtvysohvyutqipnvuh\njumwwyytkeuebbncxsn\npavwdkoxyycqrhcidfd" }, { "input": "30 3 6\nhstvoyuksbbsbgatemzmvbhbjdmnzpluefgzlcqgfsmkdydadsonaryzskleebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqkea", "output": "hstvoy\nuksbb\nsbgat\nemzmv\nbhbjd\nmnzpl\nuefgz\nlcqgf\nsmkdy\ndadso\nnaryz\nsklee\nbdgac\nrmhfl\ndirwr\ncfadu\nrngea\nrrfyj\niqkmf\nqmgzp\nnzcpp\nrkjye\nuuppz\nvmibz\nzwyou\nhxclc\ngqtjh\njmucy\npqnhd\naqkea" }, { "input": "200 1 200\nycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqgn", "output": "y\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz\nc..." }, { "input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrcq", "output": "aron\nayj\nutj\ndhj\ncel\ngex\ngal\nnyi\nrue\nvje\nlvc\nvza\nihg\nbww\nrcq" }, { "input": "200 1 10\njtlykeyfekfrzbpzrhvrxagzywzlsktyzoriwiyatoetikfnhyhlrhuogyhjrxdmlqvpfsmqiqkivtodligzerymdtnqahuprhbfefbjwuavmpkurtfzmwediq", "output": "No solution" }, { "input": "15 2 3\ndplkzxpsxodehcj", "output": "No solution" }, { "input": "100 100 200\nximcxraplfjygtrpxrgjhqagrojixizlogaqfvwvqjaiqvcimelxtmtcsqluvcrdzhihgmwhywfgxmzmikdqdytfrlpzqmvhaexrtflwacsuxhkuzbukgvbdcmwpcvxwznupsmmryxwexlevjlonpipuxjgagxtcgqjdczrnmktgcaagmiumnbcxuafmysisahaqnngc", "output": "No solution" }, { "input": "7 2 3\nggzkinj", "output": "No solution" }, { "input": "17 2 4\npgyujupquzenuldnt", "output": "No solution" }, { "input": "100 1 1\nratfdjnvjmaqgcttjtenixeocyxrtuwhpmejhpxjcqhzjsujqolgcccmvnpoomkrforsdtvhgrcpakibozhgqotcrctzozhggrufk", "output": "No solution" }, { "input": "50 2 3\nizlszyucwjarrrgxzbfzyoxapozmunxuygfjynslcjnxitimjjklucjowtkccbnfsuwtyroxirhxzosbyhvnrroaxryhcvvcjvwfcpvnpdaqwzaiuzycyrtvkgkjfbdqnzrmritaonptpvncdifushrquywzykybhjdplbmsrgibpknxkxkqqywmkeljpxrrmufpkubv", "output": "No solution" }, { "input": "15 2 5\nkddainaviqrjsesrhhdnbuisennbgcxseeyxqtmautpoobtpfigcpgagcixmyzsntmgzwmiczsfp", "output": "No solution" }, { "input": "3 1 50\nhcdonseimahtfmtejvxebwctfkjsrcqjrunpcofrapijvwmmbbbrohkskjomeknlwkdxscybxkintcaynwyjfaghwcofpsbwruzqqqkhyndbxbdpgqokjqitznnnrfuaciriqmyuvktpdxewkrycjefkmjwglhoggpgvztvqndbhiajryxqlrqdb", "output": "No solution" }, { "input": "5 1 30\nxmuatgstrlkerxzezenrauupxiskpfugncncatcgtffhuwzojuapgrevnwzfkpyzbzljbzwvfoeuqhinyravsfqrjmgidjoszvkkhxrdstmydvbertvzltpipmcuakzqflldztzdjqlicvadgpicqio", "output": "No solution" }, { "input": "5 2 3\nabacababb", "output": "No solution" }, { "input": "5 6 6\nabacabadabacabaabacabadabacab", "output": "No solution" } ]
1,604,256,244
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
372
204,800
import sys, os from math import sqrt, gcd, ceil, log, floor from bisect import bisect, bisect_left from collections import defaultdict, Counter, deque from heapq import heapify, heappush, heappop input = sys.stdin.readline read = lambda: list(map(int, input().strip().split())) # read_f = lambda file: list(map(int, file.readline().strip().split())) # from time import time # sys.setrecursionlimit(10**6) MOD = 10**9 + 7 def main(): # file1 = open("C:\\Users\\shank\\Desktop\\Comp_Code\\input.txt", "r") # n = int(file1.readline().strip()); # arr = list(map(int, file1.read().strip().split(" "))) # file1.close() k, a, b = read(); s = input().strip() l = len(s); fl = 0 for i in range(a, b+1): if l%i == 0 and l//i <= k: fl = 1 break elif a <= l%i <= b and l//i < k: fl = 1 break if fl: for j in range(0, l, i): print(s[j:j+i]) else: print("No solution") # file = open("output.txt", "w") # file.write(ans+"\n") # file.close() if __name__ == "__main__": main() """ ind 0 1 2 3 1 = 2 3 3 2 2 = 2 2 3 3 """
Title: Anfisa the Monkey Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble human speech more. Help Anfisa. Input Specification: The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols. Output Specification: Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print "No solution" (without quotes). Demo Input: ['3 2 5\nabrakadabra\n', '4 1 2\nabrakadabra\n'] Demo Output: ['ab\nrakad\nabra\n', 'No solution\n'] Note: none
```python import sys, os from math import sqrt, gcd, ceil, log, floor from bisect import bisect, bisect_left from collections import defaultdict, Counter, deque from heapq import heapify, heappush, heappop input = sys.stdin.readline read = lambda: list(map(int, input().strip().split())) # read_f = lambda file: list(map(int, file.readline().strip().split())) # from time import time # sys.setrecursionlimit(10**6) MOD = 10**9 + 7 def main(): # file1 = open("C:\\Users\\shank\\Desktop\\Comp_Code\\input.txt", "r") # n = int(file1.readline().strip()); # arr = list(map(int, file1.read().strip().split(" "))) # file1.close() k, a, b = read(); s = input().strip() l = len(s); fl = 0 for i in range(a, b+1): if l%i == 0 and l//i <= k: fl = 1 break elif a <= l%i <= b and l//i < k: fl = 1 break if fl: for j in range(0, l, i): print(s[j:j+i]) else: print("No solution") # file = open("output.txt", "w") # file.write(ans+"\n") # file.close() if __name__ == "__main__": main() """ ind 0 1 2 3 1 = 2 3 3 2 2 = 2 2 3 3 """ ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,665,042,179
2,147,483,647
Python 3
OK
TESTS
81
124
409,600
from re import X n = int(input()) forces = [0, 0, 0] for i in range(n): [x, y, z] = [int(_) for _ in input().split()] forces[0] += x forces[1] += y forces[2] += z if forces[0] or forces[1] or forces[2]: print('NO') else: print('YES')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python from re import X n = int(input()) forces = [0, 0, 0] for i in range(n): [x, y, z] = [int(_) for _ in input().split()] forces[0] += x forces[1] += y forces[2] += z if forces[0] or forces[1] or forces[2]: print('NO') else: print('YES') ```
3.968237
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,688,398,008
2,147,483,647
Python 3
OK
TESTS
40
46
0
str=input() i,j=0,0 s="hello" while(i<len(str) and j<5): if(str[i]==s[j] ): i=i+1 j=j+1 else: i=i+1 if(j==5): print("YES") else: print("NO") i=i+1 # -*- coding: latin-1 -*-j=j+1
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 str=input() i,j=0,0 s="hello" while(i<len(str) and j<5): if(str[i]==s[j] ): i=i+1 j=j+1 else: i=i+1 if(j==5): print("YES") else: print("NO") i=i+1 # -*- coding: latin-1 -*-j=j+1 ```
3.977
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 0" } ]
1,603,031,369
2,147,483,647
Python 3
OK
TESTS
34
109
0
n, x = list(map(int, input().split(" "))) b = 0 for i in range(n): s = input().split(" ") if s[0] == "+": x += int(s[1]) else: if x < int(s[1]): b+=1 else: x -= int(s[1]) print(x, b)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. Input Specification: The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. Output Specification: Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. Demo Input: ['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n'] Demo Output: ['22 1\n', '3 2\n'] Note: Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
```python n, x = list(map(int, input().split(" "))) b = 0 for i in range(n): s = input().split(" ") if s[0] == "+": x += int(s[1]) else: if x < int(s[1]): b+=1 else: x -= int(s[1]) print(x, b) ```
3
316
A2
Special Task
PROGRAMMING
1,400
[ "math" ]
null
null
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe. And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure: - if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666". After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint. At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): - 1<=≤<=|*s*|<=≤<=5. The input limits for scoring 100 points are (subproblems A1+A2): - 1<=≤<=|*s*|<=≤<=105. Here |*s*| means the length of string *s*.
Print the number of codes that match the given hint.
[ "AJ\n", "1?AA\n" ]
[ "81\n", "100\n" ]
none
70
[ { "input": "AJ", "output": "81" }, { "input": "1?AA", "output": "100" }, { "input": "?", "output": "9" }, { "input": "7", "output": "1" }, { "input": "A", "output": "9" }, { "input": "BBB?", "output": "90" }, { "input": "BC??", "output": "8100" }, { "input": "CC", "output": "9" }, { "input": "CB?", "output": "810" }, { "input": "B??C?", "output": "81000" }, { "input": "BB?C?", "output": "8100" }, { "input": "?BCB?", "output": "8100" }, { "input": "?C", "output": "90" }, { "input": "??C?C", "output": "9000" }, { "input": "???2", "output": "900" }, { "input": "9???", "output": "1000" }, { "input": "GJH2?", "output": "6480" }, { "input": "7I9G4", "output": "90" }, { "input": "JG50?", "output": "810" }, { "input": "CDEFG", "output": "27216" }, { "input": "1023456789??????????????????????????????????????ABCDIFGHIJ", "output": "362880000000000000000000000000000000000000000" } ]
1,682,420,466
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS2
0
0
0
#include <stdio.h> #include <string.h> #include <math.h> #define MAX_LEN 1000 int count_permutations(char *word) { int count[128] = {0}; int n = 0, m = 0; char first_char = word[0]; int i, out; for (i = 0; i < strlen(word); i++) { char c = word[i]; if (c >= 'A' && c <= 'J' && count[c] == 0) { n++; count[c] = 1; } else if (c == '?') { m++; } } if (first_char >= '0' && first_char <= '9') { out = factorial(10) / factorial(10-n); printf("%d", out); for (i = 0; i < m; i++) { printf("0"); } printf("\n"); } else if (first_char == '?') { out = factorial(10) / factorial(10-n) * 9; printf("%d", out); for (i = 0; i < m-1; i++) { printf("0"); } printf("\n"); } else { out = 9 * factorial(9) / factorial(10-n); printf("%d", out); for (i = 0; i < m; i++) { printf("0"); } printf("\n"); } return 0; } int main() { char word[MAX_LEN]; scanf("%s", word); count_permutations(word); return 0; }
Title: Special Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe. And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure: - if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666". After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint. At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night... Input Specification: The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): - 1<=≤<=|*s*|<=≤<=5. The input limits for scoring 100 points are (subproblems A1+A2): - 1<=≤<=|*s*|<=≤<=105. Here |*s*| means the length of string *s*. Output Specification: Print the number of codes that match the given hint. Demo Input: ['AJ\n', '1?AA\n'] Demo Output: ['81\n', '100\n'] Note: none
```python #include <stdio.h> #include <string.h> #include <math.h> #define MAX_LEN 1000 int count_permutations(char *word) { int count[128] = {0}; int n = 0, m = 0; char first_char = word[0]; int i, out; for (i = 0; i < strlen(word); i++) { char c = word[i]; if (c >= 'A' && c <= 'J' && count[c] == 0) { n++; count[c] = 1; } else if (c == '?') { m++; } } if (first_char >= '0' && first_char <= '9') { out = factorial(10) / factorial(10-n); printf("%d", out); for (i = 0; i < m; i++) { printf("0"); } printf("\n"); } else if (first_char == '?') { out = factorial(10) / factorial(10-n) * 9; printf("%d", out); for (i = 0; i < m-1; i++) { printf("0"); } printf("\n"); } else { out = 9 * factorial(9) / factorial(10-n); printf("%d", out); for (i = 0; i < m; i++) { printf("0"); } printf("\n"); } return 0; } int main() { char word[MAX_LEN]; scanf("%s", word); count_permutations(word); return 0; } ```
-1
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n1305" }, { "input": "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\n102\n486\n333\n580\n431\n537\n355\n624\n23\n429\n276\n84\n704\n96\n536\n855\n653\n72\n718\n776\n658\n802\n777\n995\n285\n328\n405\n184\n555\n956\n410\n846\n853\n525\n983\n65\n549\n839\n929\n620\n725\n635\n303\n201\n878\n580\n139\n182\n69\n400\n788\n985\n792\n103\n248\n570\n839\n253\n417", "output": "404305\n251782\n0\n227457\n210832\n284857\n462120\n8535\n20605\n392670\n357082\n39164\n172890\n482574\n-1\n1765\n144024\n484545\n449679\n264039\n5206\n29380\n124228\n105469\n31116\n232909\n197350\n320760\n136555\n178254\n498454\n402504\n83644\n23580\n176457\n57631\n295560\n59704\n127756\n298654\n102263\n4999\n117319\n54589\n166444\n92074\n142407\n62168\n192954\n214\n91213\n37204\n3316\n246114\n4402\n141870\n363894\n211485\n2374\n256075\n299430\n214765\n319957\n300207\n493464\n39733\n52934\n81193\n16510\n15..." }, { "input": "1\n16", "output": "74" }, { "input": "60\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457", "output": "144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875..." }, { "input": "13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73", "output": "-1\n128\n434\n128\n128\n4024\n2521\n2161\n402\n402\n3932\n777\n2447" }, { "input": "1\n16383", "output": "134176770" }, { "input": "16\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100", "output": "5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908" }, { "input": "1\n414234", "output": "85794061921" }, { "input": "1\n414232", "output": "85793233454" }, { "input": "3\n414231\n414231\n414231", "output": "85792819222\n85792819222\n85792819222" }, { "input": "1\n121", "output": "7127" } ]
1,632,040,801
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
77
20,172,800
import math for _ in range(int(input())): n=int(input()) sum=n*(n+1)//2 sum1=0 k=int((math.log(n))//math.log(2))+1 #print(k) print(sum - 2*2**k + 2)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Input Specification: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: Print the requested sum for each of *t* integers *n* given in the input. Demo Input: ['2\n4\n1000000000\n'] Demo Output: ['-4\n499999998352516354\n'] Note: The answer for the first sample is explained in the statement.
```python import math for _ in range(int(input())): n=int(input()) sum=n*(n+1)//2 sum1=0 k=int((math.log(n))//math.log(2))+1 #print(k) print(sum - 2*2**k + 2) ```
0
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" }, { "input": "e1\nf2", "output": "1\nRU" }, { "input": "g4\nd2", "output": "3\nLD\nLD\nL" }, { "input": "a8\nb2", "output": "6\nRD\nD\nD\nD\nD\nD" }, { "input": "d4\nh2", "output": "4\nRD\nRD\nR\nR" }, { "input": "c5\na2", "output": "3\nLD\nLD\nD" }, { "input": "h5\nf8", "output": "3\nLU\nLU\nU" }, { "input": "e6\nb6", "output": "3\nL\nL\nL" }, { "input": "a6\ng4", "output": "6\nRD\nRD\nR\nR\nR\nR" }, { "input": "f7\nc2", "output": "5\nLD\nLD\nLD\nD\nD" }, { "input": "b7\nh8", "output": "6\nRU\nR\nR\nR\nR\nR" }, { "input": "g7\nd6", "output": "3\nLD\nL\nL" }, { "input": "c8\na3", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "h8\nf1", "output": "7\nLD\nLD\nD\nD\nD\nD\nD" }, { "input": "d1\nb7", "output": "6\nLU\nLU\nU\nU\nU\nU" }, { "input": "a7\ne5", "output": "4\nRD\nRD\nR\nR" }, { "input": "d6\nb1", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "f5\ng5", "output": "1\nR" }, { "input": "h4\nd1", "output": "4\nLD\nLD\nLD\nL" }, { "input": "b3\na5", "output": "2\nLU\nU" }, { "input": "d2\nf1", "output": "2\nRD\nR" }, { "input": "f1\nc5", "output": "4\nLU\nLU\nLU\nU" }, { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "c7\ne5", "output": "2\nRD\nRD" }, { "input": "e7\nb1", "output": "6\nLD\nLD\nLD\nD\nD\nD" }, { "input": "g8\na8", "output": "6\nL\nL\nL\nL\nL\nL" }, { "input": "g6\nf2", "output": "4\nLD\nD\nD\nD" }, { "input": "g4\nc4", "output": "4\nL\nL\nL\nL" }, { "input": "g2\na6", "output": "6\nLU\nLU\nLU\nLU\nL\nL" }, { "input": "f8\nf8", "output": "0" }, { "input": "f5\nd2", "output": "3\nLD\nLD\nD" } ]
1,698,522,413
2,147,483,647
PyPy 3-64
OK
TESTS
35
124
0
a = input() b = input() a = [a[0], int(a[1])] b = [b[0], int(b[1])] points = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] b[0] = points.index(b[0]) + 1 a[0] = points.index(a[0]) + 1 print(max(abs(a[0] - b[0]), abs(a[1] - b[1]))) while a[0] != b[0] or a[1] != b[1]: if a[0] < b[0]: print('R', end='') a[0] += 1 elif a[0] > b[0]: print('L', end='') a[0] -= 1 if a[1] < b[1]: print('U', end='') a[1] += 1 elif a[1] > b[1]: print('D', end='') a[1] -= 1 print()
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). Input Specification: The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output Specification: In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Demo Input: ['a8\nh1\n'] Demo Output: ['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n'] Note: none
```python a = input() b = input() a = [a[0], int(a[1])] b = [b[0], int(b[1])] points = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] b[0] = points.index(b[0]) + 1 a[0] = points.index(a[0]) + 1 print(max(abs(a[0] - b[0]), abs(a[1] - b[1]))) while a[0] != b[0] or a[1] != b[1]: if a[0] < b[0]: print('R', end='') a[0] += 1 elif a[0] > b[0]: print('L', end='') a[0] -= 1 if a[1] < b[1]: print('U', end='') a[1] += 1 elif a[1] > b[1]: print('D', end='') a[1] -= 1 print() ```
3.938
629
B
Far Relative’s Problem
PROGRAMMING
1,100
[ "brute force" ]
null
null
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
Print the maximum number of people that may come to Famil Door's party.
[ "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n", "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n" ]
[ "2\n", "4\n" ]
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
1,000
[ { "input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2" }, { "input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4" }, { "input": "1\nF 68 307", "output": "0" }, { "input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244\nF 42 339\nM 253 307\nM 128 192\nF 119 328\nM 135 249\nF 303 358\nF 348 352\nF 8 364\nF 126 303\nM 226 346\nF 110 300\nF 47 303\nF 201 311\nF 287 288\nM 270 352\nM 227 351\nF 8 111\nF 39 229\nM 163 315\nF 269 335\nF 147 351\nF 96 143\nM 97 99\nM 177 295", "output": "22" }, { "input": "2\nF 1 1\nM 1 1", "output": "2" }, { "input": "4\nM 1 2\nM 2 3\nF 3 4\nF 4 5", "output": "2" }, { "input": "1\nF 1 2", "output": "0" }, { "input": "18\nF 3 4\nF 3 4\nF 3 4\nF 3 4\nF 5 6\nF 5 6\nM 3 4\nM 3 4\nM 5 6\nM 5 6\nM 5 6\nM 5 6\nF 7 8\nF 7 8\nF 7 8\nM 7 8\nM 7 8\nM 7 8", "output": "6" }, { "input": "2\nM 1 1\nF 1 1", "output": "2" }, { "input": "3\nM 1 1\nF 1 1\nM 1 1", "output": "2" } ]
1,455,988,088
1,988
PyPy 3
WRONG_ANSWER
PRETESTS
2
233
9,216,000
#!/usr/bin/env python3 # 629B_relative.py - Codeforces.com/problemset/problem/629/B by Sergey 2016 import unittest import sys ############################################################################### # Relative Class (Main Program) ############################################################################### class Relative: """ Relative representation """ def __init__(self, test_inputs=None): """ Default constructor """ it = iter(test_inputs.split("\n")) if test_inputs else None def uinput(): return next(it) if it else sys.stdin.readline().rstrip() # Reading single elements [self.n] = map(int, uinput().split()) # Reading multiple number of lines of the same number of elements each l, s = self.n, 3 inp = (" ".join(uinput() for i in range(l))).split() self.numm = [[(int(inp[i]) if j != 0 else inp[i] == 'M') for i in range(j, l*s, s)] for j in range(s)] self.nums, self.numa, self.numb = self.numm self.dts = [] for i in range(self.n): self.dts.append((self.numa[i], 1, self.nums[i])) self.dts.append((self.numb[i], 0, self.nums[i])) self.sdts = sorted(self.dts) self.ms, self.fs = [0], [0] for i in range(len(self.sdts)): if self.sdts[i][2]: if self.sdts[i][1]: self.ms.append(self.ms[-1] + 1) else: self.ms.append(self.ms[-1] - 1) else: if self.sdts[i][1]: self.fs.append(self.fs[-1] + 1) else: self.fs.append(self.fs[-1] - 1) self.cr = [] for i in range(len(self.ms)): self.cr.append(min(self.ms[i], self.fs[i])*2) def calculate(self): """ Main calcualtion function of the class """ result = max(self.cr) return str(result) ############################################################################### # Unit Tests ############################################################################### class unitTests(unittest.TestCase): def test_single_test(self): """ Relative class testing """ # Constructor test test = "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128" d = Relative(test) self.assertEqual(d.n, 4) self.assertEqual(d.numa, [151, 343, 117, 24]) self.assertEqual(d.nums, [1, 0, 0, 1]) # Sample test self.assertEqual(Relative(test).calculate(), "2") # Sample test test = "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200" self.assertEqual(Relative(test).calculate(), "4") # Sample test test = "" # self.assertEqual(Relative(test).calculate(), "0") # My tests test = "" # self.assertEqual(Relative(test).calculate(), "0") # Time limit test # self.time_limit_test(5000) def time_limit_test(self, nmax): """ Timelimit testing """ import random import timeit # Random inputs test = str(nmax) + " " + str(nmax) + "\n" numnums = [str(i) + " " + str(i+1) for i in range(nmax)] test += "\n".join(numnums) + "\n" nums = [random.randint(1, 10000) for i in range(nmax)] test += " ".join(map(str, nums)) + "\n" # Run the test start = timeit.default_timer() d = Relative(test) calc = timeit.default_timer() d.calculate() stop = timeit.default_timer() print("\nTimelimit Test: " + "{0:.3f}s (init {1:.3f}s calc {2:.3f}s)". format(stop-start, calc-start, stop-calc)) if __name__ == "__main__": # Avoiding recursion limitaions sys.setrecursionlimit(100000) if sys.argv[-1] == "-ut": unittest.main(argv=[" "]) # Print the result string sys.stdout.write(Relative().calculate())
Title: Far Relative’s Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends. Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive. Output Specification: Print the maximum number of people that may come to Famil Door's party. Demo Input: ['4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n', '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
```python #!/usr/bin/env python3 # 629B_relative.py - Codeforces.com/problemset/problem/629/B by Sergey 2016 import unittest import sys ############################################################################### # Relative Class (Main Program) ############################################################################### class Relative: """ Relative representation """ def __init__(self, test_inputs=None): """ Default constructor """ it = iter(test_inputs.split("\n")) if test_inputs else None def uinput(): return next(it) if it else sys.stdin.readline().rstrip() # Reading single elements [self.n] = map(int, uinput().split()) # Reading multiple number of lines of the same number of elements each l, s = self.n, 3 inp = (" ".join(uinput() for i in range(l))).split() self.numm = [[(int(inp[i]) if j != 0 else inp[i] == 'M') for i in range(j, l*s, s)] for j in range(s)] self.nums, self.numa, self.numb = self.numm self.dts = [] for i in range(self.n): self.dts.append((self.numa[i], 1, self.nums[i])) self.dts.append((self.numb[i], 0, self.nums[i])) self.sdts = sorted(self.dts) self.ms, self.fs = [0], [0] for i in range(len(self.sdts)): if self.sdts[i][2]: if self.sdts[i][1]: self.ms.append(self.ms[-1] + 1) else: self.ms.append(self.ms[-1] - 1) else: if self.sdts[i][1]: self.fs.append(self.fs[-1] + 1) else: self.fs.append(self.fs[-1] - 1) self.cr = [] for i in range(len(self.ms)): self.cr.append(min(self.ms[i], self.fs[i])*2) def calculate(self): """ Main calcualtion function of the class """ result = max(self.cr) return str(result) ############################################################################### # Unit Tests ############################################################################### class unitTests(unittest.TestCase): def test_single_test(self): """ Relative class testing """ # Constructor test test = "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128" d = Relative(test) self.assertEqual(d.n, 4) self.assertEqual(d.numa, [151, 343, 117, 24]) self.assertEqual(d.nums, [1, 0, 0, 1]) # Sample test self.assertEqual(Relative(test).calculate(), "2") # Sample test test = "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200" self.assertEqual(Relative(test).calculate(), "4") # Sample test test = "" # self.assertEqual(Relative(test).calculate(), "0") # My tests test = "" # self.assertEqual(Relative(test).calculate(), "0") # Time limit test # self.time_limit_test(5000) def time_limit_test(self, nmax): """ Timelimit testing """ import random import timeit # Random inputs test = str(nmax) + " " + str(nmax) + "\n" numnums = [str(i) + " " + str(i+1) for i in range(nmax)] test += "\n".join(numnums) + "\n" nums = [random.randint(1, 10000) for i in range(nmax)] test += " ".join(map(str, nums)) + "\n" # Run the test start = timeit.default_timer() d = Relative(test) calc = timeit.default_timer() d.calculate() stop = timeit.default_timer() print("\nTimelimit Test: " + "{0:.3f}s (init {1:.3f}s calc {2:.3f}s)". format(stop-start, calc-start, stop-calc)) if __name__ == "__main__": # Avoiding recursion limitaions sys.setrecursionlimit(100000) if sys.argv[-1] == "-ut": unittest.main(argv=[" "]) # Print the result string sys.stdout.write(Relative().calculate()) ```
0
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
1,563,446,395
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
108
0
n = int(input()) was = [0 for i in range(n)] inp = input().split(" ") for i in inp: was = list(map(lambda x: x+1, was)) was[int(i)-1] = 0 print(was.index(max(was)))
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. Input Specification: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. Output Specification: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Demo Input: ['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n'] Demo Output: ['3\n', '2\n'] Note: In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
```python n = int(input()) was = [0 for i in range(n)] inp = input().split(" ") for i in inp: was = list(map(lambda x: x+1, was)) was[int(i)-1] = 0 print(was.index(max(was))) ```
-1
385
A
Bear and Raspberry
PROGRAMMING
1,000
[ "brute force", "greedy", "implementation" ]
null
null
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=&lt;<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Print a single integer — the answer to the problem.
[ "5 1\n5 10 7 3 20\n", "6 2\n100 1 10 40 10 40\n", "3 0\n1 2 3\n" ]
[ "3\n", "97\n", "0\n" ]
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
500
[ { "input": "5 1\n5 10 7 3 20", "output": "3" }, { "input": "6 2\n100 1 10 40 10 40", "output": "97" }, { "input": "3 0\n1 2 3", "output": "0" }, { "input": "2 0\n2 1", "output": "1" }, { "input": "10 5\n10 1 11 2 12 3 13 4 14 5", "output": "4" }, { "input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77", "output": "87" }, { "input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93", "output": "84" }, { "input": "6 100\n10 9 8 7 6 5", "output": "0" }, { "input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46", "output": "78" }, { "input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44", "output": "0" }, { "input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62", "output": "4" }, { "input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71", "output": "0" }, { "input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1", "output": "0" }, { "input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27", "output": "63" }, { "input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22", "output": "38" }, { "input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83", "output": "91" }, { "input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14", "output": "79" }, { "input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24", "output": "91" }, { "input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49", "output": "83" }, { "input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70", "output": "94" }, { "input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42", "output": "43" }, { "input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0", "output": "100" }, { "input": "3 1\n1 2 3", "output": "0" }, { "input": "3 2\n3 3 3", "output": "0" }, { "input": "3 3\n3 2 1", "output": "0" }, { "input": "3 100\n1 2 3", "output": "0" }, { "input": "2 100\n0 0", "output": "0" }, { "input": "2 90\n10 5", "output": "0" }, { "input": "2 5\n5 4", "output": "0" }, { "input": "3 1\n19 20 1", "output": "18" }, { "input": "5 1\n5 10 7 4 20", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "0" } ]
1,621,752,327
2,147,483,647
Python 3
OK
TESTS
32
62
0
n, c = map(int, input().split()) price = list(map(int, input().split())) p = price[0]-price[1]-c for i in range(1,n-1): p = max(price[i]-price[i+1]-c, p) if p<0: print('0') else: print(p)
Title: Bear and Raspberry Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=&lt;<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. Input Specification: The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n'] Demo Output: ['3\n', '97\n', '0\n'] Note: In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
```python n, c = map(int, input().split()) price = list(map(int, input().split())) p = price[0]-price[1]-c for i in range(1,n-1): p = max(price[i]-price[i+1]-c, p) if p<0: print('0') else: print(p) ```
3
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered. Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages. Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen. Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*.
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24 23 22 21 20 19 18 17\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "Karen" }, { "input": "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 1238375 743262 106355 1167830 180315 1233029 816465 752968 782570 1499881 1328457 1867240 13948 1302782\n322597 1868510 1958236 1348157 765908 1023636 874300 537124 631783 414906 886318 1931572 1381013 992451 1305644 1525745 716087 83173 303248 1572710 43084 333341 992413 267806 70390 644521 1014900 497068 178940 1920268", "output": "Karen" }, { "input": "30\n1143673 436496 1214486 1315862 148404 724601 1430740 1433008 1654610 1635673 614673 1713408 1270999 1697 1463796 50027 525482 1659078 688200 842647 518551 877506 1017082 1807856 3280 759698 1208220 470180 829800 1960886\n1312613 1965095 967255 1289012 1950383 582960 856825 49684 808824 319418 1968270 190821 344545 211332 1219388 1773751 1876402 132626 541448 1584672 24276 1053225 1823073 1858232 1209173 1035991 1956373 1237148 1973608 848873", "output": "Karen" }, { "input": "1\n2\n3", "output": "Karen" }, { "input": "1\n1048576\n1020000", "output": "Karen" }, { "input": "3\n9 33 69\n71 74 100", "output": "Karen" }, { "input": "3\n1 2 3\n9 5 6", "output": "Karen" }, { "input": "3\n1 7 8\n9 10 20", "output": "Karen" }, { "input": "3\n1 3 2\n4 5 8", "output": "Karen" }, { "input": "3\n2 1 100\n3 4 9", "output": "Karen" }, { "input": "3\n3 1 100\n2 1000 100000", "output": "Karen" }, { "input": "3\n1 2 5\n3 4 6", "output": "Karen" }, { "input": "3\n3 1 8\n2 4 17", "output": "Karen" }, { "input": "3\n1 5 6\n7 8 3", "output": "Karen" }, { "input": "1\n1\n3", "output": "Karen" }, { "input": "3\n1 3 10\n2 4 20", "output": "Karen" }, { "input": "3\n7 8 10\n15 9 11", "output": "Karen" }, { "input": "3\n5 6 8\n3 100 9", "output": "Karen" }, { "input": "3\n1 2 3\n4 5 8", "output": "Karen" }, { "input": "3\n1 2 19\n3 7 30", "output": "Karen" }, { "input": "3\n1 2 3\n6 7 8", "output": "Karen" }, { "input": "3\n1 4 55\n2 3 9", "output": "Karen" }, { "input": "3\n1 100 200\n5 4 500", "output": "Karen" }, { "input": "1\n6\n7", "output": "Karen" }, { "input": "3\n1 3 5\n2 4 13", "output": "Karen" }, { "input": "3\n3 1 100\n2 1000 10000", "output": "Karen" }, { "input": "3\n1 3 9\n2 4 40", "output": "Karen" }, { "input": "2\n1 199999\n1935807 2000000", "output": "Karen" }, { "input": "3\n1 3 8\n2 4 24", "output": "Karen" }, { "input": "2\n4 1\n7 3", "output": "Karen" }, { "input": "3\n1 2 4\n3 7 8", "output": "Karen" }, { "input": "3\n1 6 10000\n2 3 100000", "output": "Karen" } ]
1,549,357,969
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
78
0
n=int(input()) xi=[] yi=[] for i in range(n): xi=xi+list(map(int,input().split())) for i in range(n): yi=yi+list(map(int,input().split())) c=0 x=set(xi) y=set(yi) for i in range(n): for j in range(n): if(((xi[i]^yi[j])in x)or((xi[i]^yi[j])in y)): c=c+1 if (c%2==0): print("Karen") else: print("Koyomi")
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, denoted by *x*1,<=*x*2,<=...,<=*x**n* and *y*1,<=*y*2,<=...,<=*y**n* respectively. They reveal their sequences, and repeat until all of 2*n* integers become distinct, which is the only final state to be kept and considered. Then they count the number of ordered pairs (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) such that the value *x**i* xor *y**j* equals to one of the 2*n* integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages. Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game. Input Specification: The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (1<=≤<=*y**i*<=≤<=2·106) — the integers finally chosen by Karen. Input guarantees that the given 2*n* integers are pairwise distinct, that is, no pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) exists such that one of the following holds: *x**i*<==<=*y**j*; *i*<=≠<=*j* and *x**i*<==<=*x**j*; *i*<=≠<=*j* and *y**i*<==<=*y**j*. Output Specification: Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization. Demo Input: ['3\n1 2 3\n4 5 6\n', '5\n2 4 6 8 10\n9 7 5 3 1\n'] Demo Output: ['Karen\n', 'Karen\n'] Note: In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
```python n=int(input()) xi=[] yi=[] for i in range(n): xi=xi+list(map(int,input().split())) for i in range(n): yi=yi+list(map(int,input().split())) c=0 x=set(xi) y=set(yi) for i in range(n): for j in range(n): if(((xi[i]^yi[j])in x)or((xi[i]^yi[j])in y)): c=c+1 if (c%2==0): print("Karen") else: print("Koyomi") ```
-1
40
E
Number Table
PROGRAMMING
2,500
[ "combinatorics" ]
E. Number Table
2
216
As it has been found out recently, all the Berland's current economical state can be described using a simple table *n*<=×<=*m* in size. *n* — the number of days in each Berland month, *m* — the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than *max*(*n*,<=*m*). However, there is additional information — the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo *p*.
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The second line contains the integer *k* (0<=≤<=*k*<=&lt;<=*max*(*n*,<=*m*)) — the number of cells in which the data had been preserved. The next *k* lines contain the data on the state of the table in the preserved cells. Each line is of the form "*a* *b* *c*", where *a* (1<=≤<=*a*<=≤<=*n*) — the number of the table row, *b* (1<=≤<=*b*<=≤<=*m*) — the number of the column, *c* — the value containing in the cell (1 or -1). They are numbered starting from 1. It is guaranteed that no two lines with same *a* and *b* values exist. The last line contains an integer *p* (2<=≤<=*p*<=≤<=109<=+<=7).
Print the number of different tables that could conform to the preserved data modulo *p*.
[ "2 2\n0\n100\n", "2 2\n1\n1 1 -1\n100\n" ]
[ "2\n", "1\n" ]
none
2,500
[ { "input": "2 2\n0\n100", "output": "2" }, { "input": "2 2\n1\n1 1 -1\n100", "output": "1" }, { "input": "7 6\n4\n3 2 -1\n7 1 1\n2 1 1\n3 4 -1\n179460773", "output": "0" }, { "input": "6 2\n3\n5 1 -1\n4 2 1\n1 2 -1\n958300150", "output": "4" }, { "input": "6 9\n3\n4 8 1\n2 5 1\n5 1 -1\n589655884", "output": "0" }, { "input": "4 5\n3\n1 3 1\n2 2 1\n4 2 1\n221011618", "output": "0" }, { "input": "4 4\n1\n3 3 -1\n852367357", "output": "256" }, { "input": "3 10\n6\n1 6 -1\n1 3 1\n1 7 -1\n3 2 1\n2 1 1\n2 10 -1\n483723090", "output": "0" }, { "input": "3 7\n0\n115078824", "output": "4096" }, { "input": "6 2\n1\n3 1 1\n865423160", "output": "16" }, { "input": "5 6\n3\n5 6 -1\n2 5 -1\n4 2 -1\n353435294", "output": "0" }, { "input": "4 11\n6\n3 10 1\n2 10 -1\n2 6 -1\n2 3 -1\n4 4 -1\n2 2 1\n841447432", "output": "0" }, { "input": "3 7\n2\n2 2 -1\n1 1 1\n181975928", "output": "1024" }, { "input": "11 11\n0\n669988067", "output": "651673220" }, { "input": "10 6\n3\n5 3 -1\n10 3 -1\n3 4 -1\n158000200", "output": "110944104" }, { "input": "9 10\n6\n5 8 1\n3 8 -1\n3 6 1\n5 2 -1\n6 2 1\n3 5 -1\n646012339", "output": "0" }, { "input": "8 6\n1\n8 6 -1\n945867588", "output": "154252600" }, { "input": "9 9\n2\n9 4 -1\n1 5 1\n474552973", "output": "12113895" }, { "input": "8 5\n3\n1 1 1\n3 2 -1\n1 4 1\n962565112", "output": "0" }, { "input": "1 7\n6\n1 1 -1\n1 2 -1\n1 3 -1\n1 4 -1\n1 5 -1\n1 6 -1\n10", "output": "1" }, { "input": "1 1\n0\n2", "output": "1" }, { "input": "1 1\n0\n1000000000", "output": "1" }, { "input": "1000 1000\n0\n2", "output": "0" }, { "input": "1000 1000\n0\n1000000007", "output": "101469445" }, { "input": "98 93\n33\n55 17 1\n95 35 1\n27 84 1\n55 12 -1\n16 45 -1\n50 15 1\n4 81 -1\n29 3 1\n53 65 -1\n57 11 1\n98 13 -1\n16 81 -1\n46 27 -1\n65 69 1\n38 16 -1\n66 78 -1\n84 11 1\n70 93 1\n10 5 1\n94 89 -1\n63 22 -1\n49 92 1\n19 83 1\n87 16 -1\n64 24 1\n74 72 -1\n8 12 1\n23 83 1\n33 80 -1\n73 84 1\n98 14 -1\n2 61 -1\n84 73 1\n865423160", "output": "0" }, { "input": "91 96\n49\n37 36 -1\n79 89 -1\n25 44 -1\n63 31 1\n60 29 -1\n31 36 1\n33 32 -1\n24 43 1\n19 51 -1\n60 19 1\n89 87 1\n8 81 -1\n36 55 1\n72 74 -1\n90 30 -1\n89 51 -1\n60 59 1\n15 27 -1\n10 20 -1\n21 55 -1\n48 89 -1\n49 19 -1\n59 37 1\n70 25 1\n10 73 1\n63 28 -1\n26 75 -1\n80 4 -1\n91 38 -1\n65 35 1\n20 42 -1\n7 34 -1\n91 3 1\n2 34 1\n82 79 -1\n10 59 1\n72 23 1\n6 33 1\n30 78 -1\n77 34 1\n9 10 1\n37 30 -1\n28 31 1\n45 49 1\n79 68 1\n59 52 1\n61 27 1\n77 31 1\n27 57 1\n353435294", "output": "0" }, { "input": "98 96\n15\n64 87 1\n83 68 -1\n74 80 1\n64 42 1\n20 10 -1\n31 37 1\n36 27 -1\n44 55 1\n98 10 -1\n23 44 -1\n77 17 -1\n40 20 -1\n63 3 1\n37 89 1\n19 90 -1\n962565112", "output": "690616424" }, { "input": "948 994\n32\n176 424 1\n768 12 -1\n126 716 1\n45 522 1\n326 835 -1\n136 578 -1\n471 941 1\n27 278 1\n766 992 -1\n308 911 -1\n226 83 1\n520 908 -1\n132 618 -1\n658 867 1\n484 937 1\n890 43 1\n520 797 -1\n653 401 -1\n93 339 1\n784 846 -1\n428 239 -1\n550 477 1\n10 671 1\n351 796 -1\n754 665 1\n64 71 -1\n189 550 -1\n541 486 1\n841 209 1\n301 288 -1\n919 345 -1\n415 642 -1\n646012339", "output": "300251492" }, { "input": "7 1\n6\n1 1 -1\n2 1 -1\n3 1 -1\n4 1 -1\n5 1 -1\n6 1 -1\n10", "output": "1" }, { "input": "7 1\n6\n1 1 -1\n2 1 -1\n6 1 -1\n4 1 -1\n5 1 -1\n7 1 -1\n10", "output": "1" }, { "input": "7 1\n6\n1 1 1\n2 1 -1\n3 1 1\n4 1 -1\n5 1 1\n6 1 -1\n10", "output": "0" }, { "input": "1 7\n6\n1 1 1\n1 2 -1\n1 3 1\n1 6 -1\n1 5 1\n1 7 -1\n10", "output": "0" }, { "input": "4 4\n3\n1 1 -1\n2 2 1\n3 3 -1\n1000000000", "output": "64" }, { "input": "500 1000\n0\n1000000007", "output": "82701167" }, { "input": "6 2\n3\n5 1 -1\n4 2 1\n1 2 -1\n958300155", "output": "4" }, { "input": "15 5\n13\n10 3 -1\n13 1 1\n8 5 -1\n5 1 1\n14 1 1\n10 5 1\n13 4 -1\n8 3 1\n14 2 1\n11 5 -1\n12 5 -1\n7 2 -1\n8 4 -1\n1000000007", "output": "92960636" }, { "input": "15 5\n12\n3 3 -1\n2 1 1\n6 2 1\n9 2 1\n5 4 -1\n8 5 1\n2 3 1\n14 5 1\n12 2 -1\n7 4 -1\n11 1 -1\n14 4 1\n1000000007", "output": "185921272" }, { "input": "5 3\n4\n1 1 -1\n1 2 1\n1 3 -1\n2 1 1\n1000000007", "output": "0" }, { "input": "3 5\n4\n1 1 -1\n2 1 1\n3 1 -1\n1 2 1\n1000000007", "output": "0" }, { "input": "1000 1\n0\n1000000007", "output": "0" }, { "input": "1000 2\n0\n1000000007", "output": "344211605" }, { "input": "2 1000\n0\n1000000007", "output": "344211605" }, { "input": "999 1\n0\n1000000007", "output": "1" }, { "input": "1 999\n0\n1000000007", "output": "1" }, { "input": "6 2\n5\n2 1 1\n5 2 1\n6 1 1\n5 1 1\n1 1 1\n1000000007", "output": "0" }, { "input": "999 1000\n0\n1000000007", "output": "0" }, { "input": "500 1000\n0\n1000000007", "output": "82701167" }, { "input": "1000 999\n0\n1000000007", "output": "0" }, { "input": "1000 500\n0\n1000000007", "output": "82701167" }, { "input": "1 7\n6\n1 1 -1\n1 2 1\n1 3 -1\n1 5 -1\n1 6 -1\n1 7 -1\n1000", "output": "0" }, { "input": "7 7\n6\n1 1 -1\n2 2 -1\n3 3 -1\n4 4 -1\n5 5 -1\n6 6 -1\n1000000007", "output": "73741817" }, { "input": "7 7\n6\n1 7 -1\n2 6 -1\n3 5 -1\n4 4 -1\n5 3 -1\n6 2 -1\n1000000007", "output": "73741817" }, { "input": "7 7\n6\n1 7 -1\n2 6 -1\n3 5 -1\n4 4 -1\n5 3 -1\n7 2 1\n1000000007", "output": "73741817" }, { "input": "7 7\n6\n1 7 -1\n2 6 -1\n3 5 -1\n4 4 -1\n5 3 -1\n6 2 -1\n1000000007", "output": "73741817" }, { "input": "2 4\n2\n1 1 1\n2 1 -1\n100", "output": "4" }, { "input": "1 5\n1\n1 5 1\n100", "output": "0" }, { "input": "3 1\n1\n1 1 -1\n100", "output": "1" }, { "input": "2 3\n2\n1 1 1\n2 1 1\n1000", "output": "0" } ]
1,689,635,992
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1689635992.7509944")# 1689635992.7510135
Title: Number Table Time Limit: 2 seconds Memory Limit: 216 megabytes Problem Description: As it has been found out recently, all the Berland's current economical state can be described using a simple table *n*<=×<=*m* in size. *n* — the number of days in each Berland month, *m* — the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than *max*(*n*,<=*m*). However, there is additional information — the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo *p*. Input Specification: The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000). The second line contains the integer *k* (0<=≤<=*k*<=&lt;<=*max*(*n*,<=*m*)) — the number of cells in which the data had been preserved. The next *k* lines contain the data on the state of the table in the preserved cells. Each line is of the form "*a* *b* *c*", where *a* (1<=≤<=*a*<=≤<=*n*) — the number of the table row, *b* (1<=≤<=*b*<=≤<=*m*) — the number of the column, *c* — the value containing in the cell (1 or -1). They are numbered starting from 1. It is guaranteed that no two lines with same *a* and *b* values exist. The last line contains an integer *p* (2<=≤<=*p*<=≤<=109<=+<=7). Output Specification: Print the number of different tables that could conform to the preserved data modulo *p*. Demo Input: ['2 2\n0\n100\n', '2 2\n1\n1 1 -1\n100\n'] Demo Output: ['2\n', '1\n'] Note: none
```python print("_RANDOM_GUESS_1689635992.7509944")# 1689635992.7510135 ```
0
300
A
Array
PROGRAMMING
1,100
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
[ "3\n-1 2 0\n", "4\n-1 -2 -3 0\n" ]
[ "1 -1\n1 2\n1 0\n", "1 -1\n2 -3 -2\n1 0\n" ]
none
500
[ { "input": "3\n-1 2 0", "output": "1 -1\n1 2\n1 0" }, { "input": "4\n-1 -2 -3 0", "output": "1 -1\n2 -3 -2\n1 0" }, { "input": "5\n-1 -2 1 2 0", "output": "1 -1\n2 1 2\n2 0 -2" }, { "input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0" }, { "input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0" }, { "input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0" }, { "input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37" }, { "input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61" }, { "input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0" }, { "input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0" }, { "input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20" }, { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0" }, { "input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0" }, { "input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961" }, { "input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673" }, { "input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182" }, { "input": "5\n-1 -2 -3 -4 0", "output": "1 -1\n2 -4 -3\n2 0 -2" }, { "input": "3\n-101 101 0", "output": "1 -101\n1 101\n1 0" }, { "input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000" }, { "input": "4\n0 -1 -2 -3", "output": "1 -1\n2 -3 -2\n1 0" } ]
1,611,474,596
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
102,400
from math import * from collections import * from sys import * t=stdin.readline p=stdout.write def GI(): return map(int, t().strip().split()) def GS(): return map(str, t().strip().split()) def GL(): return list(map(int, t().strip().split())) def SL(): return list(map(str, t().strip().split())) n=int(t()) a=sorted(GL()) l1,l2,l3=[],[],[] while(len(a)>0): x=a.pop() if x<0: l1.append(x) elif x>0: l2.append(x) else: l3.append(x) if len(l2)!=0: print(len(l1),*l1) print(len(l2),*l2) print(len(l3),*l3) else: print(len(l1)-2,*l1[:-2]) print('2',*l1[-2:]) print(len(l3),*l3)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. Output Specification: In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Demo Input: ['3\n-1 2 0\n', '4\n-1 -2 -3 0\n'] Demo Output: ['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n'] Note: none
```python from math import * from collections import * from sys import * t=stdin.readline p=stdout.write def GI(): return map(int, t().strip().split()) def GS(): return map(str, t().strip().split()) def GL(): return list(map(int, t().strip().split())) def SL(): return list(map(str, t().strip().split())) n=int(t()) a=sorted(GL()) l1,l2,l3=[],[],[] while(len(a)>0): x=a.pop() if x<0: l1.append(x) elif x>0: l2.append(x) else: l3.append(x) if len(l2)!=0: print(len(l1),*l1) print(len(l2),*l2) print(len(l3),*l3) else: print(len(l1)-2,*l1[:-2]) print('2',*l1[-2:]) print(len(l3),*l3) ```
0
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,690,953,693
2,147,483,647
PyPy 3-64
OK
TESTS
50
62
1,638,400
M,N = map(int,input().split()) def COLOR(M): Flag = False for _ in range(M): X = list(input().split()) for i in X: if i == 'C' or i == 'M' or i == 'Y': Flag = True return "#Black&White" if Flag==False else "#Color" print(COLOR(M))
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python M,N = map(int,input().split()) def COLOR(M): Flag = False for _ in range(M): X = list(input().split()) for i in X: if i == 'C' or i == 'M' or i == 'Y': Flag = True return "#Black&White" if Flag==False else "#Color" print(COLOR(M)) ```
3
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100", "output": "10" }, { "input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9", "output": "4" }, { "input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54", "output": "12" }, { "input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68", "output": "10" }, { "input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30", "output": "8" }, { "input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14", "output": "7" }, { "input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28", "output": "22" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2", "output": "0" }, { "input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2", "output": "68" }, { "input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8", "output": "5" }, { "input": "1\n0 0", "output": "0" }, { "input": "1\n100 100", "output": "0" }, { "input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73", "output": "42" }, { "input": "3\n1 3\n2 7\n8 9", "output": "2" }, { "input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53", "output": "0" }, { "input": "55\n0 0\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\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54", "output": "0" }, { "input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60", "output": "12" }, { "input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3", "output": "8" } ]
1,694,781,705
2,147,483,647
Python 3
OK
TESTS
27
46
0
N = int(input()) cnt = 0 for i in range(N): X,Y = map(int,input().split()) if((Y-X)>=2): cnt = cnt+1 print(cnt)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. Output Specification: Print a single integer — the number of rooms where George and Alex can move in. Demo Input: ['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n'] Demo Output: ['0\n', '2\n'] Note: none
```python N = int(input()) cnt = 0 for i in range(N): X,Y = map(int,input().split()) if((Y-X)>=2): cnt = cnt+1 print(cnt) ```
3
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "input": "10\n2 6\n3 7\n8 4\n4 10\n6 9\n9 7\n3 10\n1 2\n5 8", "output": "16" }, { "input": "10\n6 9\n9 7\n9 4\n10 9\n9 1\n9 8\n9 2\n9 5\n3 9", "output": "0" }, { "input": "2\n1 2", "output": "0" } ]
1,595,618,693
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
16
1,044
34,508,800
cnt = [0,0] n = int(input()) v = {i:[] for i in range(n)} def dfs(node,pnode,color): global cnt,v cnt[color] += 1 for i in range(len(v[node])): if v[node][i] != pnode: dfs(v[node][i],node,not color) for _ in range(n-1): a,b = map(int,input().split()) v[a-1].append(b-1) v[b-1].append(a-1) dfs(0,0,0) print(cnt[0]*cnt[1] - n + 1)
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . Input Specification: The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. Output Specification: Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. Demo Input: ['3\n1 2\n1 3\n', '5\n1 2\n2 3\n3 4\n4 5\n'] Demo Output: ['0\n', '2\n'] Note: Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
```python cnt = [0,0] n = int(input()) v = {i:[] for i in range(n)} def dfs(node,pnode,color): global cnt,v cnt[color] += 1 for i in range(len(v[node])): if v[node][i] != pnode: dfs(v[node][i],node,not color) for _ in range(n-1): a,b = map(int,input().split()) v[a-1].append(b-1) v[b-1].append(a-1) dfs(0,0,0) print(cnt[0]*cnt[1] - n + 1) ```
-1
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "3\n0 0\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "5\n0 73\n73 189\n189 766\n766 0\n0 0", "output": "766" }, { "input": "5\n0 0\n0 0\n0 0\n0 1\n1 0", "output": "1" }, { "input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0", "output": "1011" }, { "input": "5\n0 1\n1 2\n2 1\n1 2\n2 0", "output": "2" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0", "output": "22" }, { "input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0", "output": "1776" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0", "output": "2" }, { "input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0", "output": "1016" }, { "input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0", "output": "3" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0", "output": "1000" }, { "input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0", "output": "2071" }, { "input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0", "output": "3" }, { "input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0", "output": "1329" }, { "input": "2\n0 863\n863 0", "output": "863" }, { "input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0", "output": "8" }, { "input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0", "output": "11" }, { "input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0", "output": "7" }, { "input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 900\n900 0", "output": "900" }, { "input": "2\n0 1\n1 0", "output": "1" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "2\n0 1000\n1000 0", "output": "1000" }, { "input": "3\n0 802\n175 188\n815 0", "output": "815" }, { "input": "3\n0 910\n910 976\n976 0", "output": "976" }, { "input": "3\n0 2\n2 1\n1 0", "output": "2" } ]
1,690,969,346
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
0
c=0 for i in range (int(input())): a,b=map(int,input().split()) if b-a>0: c+=b-a print(c)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. Input Specification: The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. Output Specification: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Demo Input: ['4\n0 3\n2 5\n4 2\n4 0\n'] Demo Output: ['6\n'] Note: For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
```python c=0 for i in range (int(input())): a,b=map(int,input().split()) if b-a>0: c+=b-a print(c) ```
0
16
B
Burglar and Matches
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
B. Burglar and Matches
0
64
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output the only number — answer to the problem.
[ "7 3\n5 10\n2 5\n3 6\n", "3 3\n1 3\n2 2\n3 1\n" ]
[ "62\n", "7\n" ]
none
0
[ { "input": "7 3\n5 10\n2 5\n3 6", "output": "62" }, { "input": "3 3\n1 3\n2 2\n3 1", "output": "7" }, { "input": "1 1\n1 2", "output": "2" }, { "input": "1 2\n1 9\n1 6", "output": "9" }, { "input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 2\n2 4\n1 4", "output": "8" }, { "input": "2 3\n1 7\n1 2\n1 5", "output": "12" }, { "input": "4 1\n2 2", "output": "4" }, { "input": "4 2\n1 10\n4 4", "output": "22" }, { "input": "4 3\n1 4\n6 4\n1 7", "output": "19" }, { "input": "5 1\n10 5", "output": "25" }, { "input": "5 2\n3 9\n2 2", "output": "31" }, { "input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8", "output": "42" }, { "input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7", "output": "41" }, { "input": "10 1\n9 4", "output": "36" }, { "input": "10 2\n14 3\n1 3", "output": "30" }, { "input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10", "output": "71" }, { "input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4", "output": "70" }, { "input": "10 4\n1 5\n5 2\n1 9\n3 3", "output": "33" }, { "input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4", "output": "716" }, { "input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4", "output": "8218" }, { "input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10", "output": "84715" }, { "input": "100000 3\n2975 2\n35046 4\n61979 9", "output": "703945" }, { "input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9", "output": "8794569" }, { "input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3", "output": "85022733" }, { "input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5", "output": "749254060" }, { "input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3", "output": "1332923354" }, { "input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5", "output": "996523209" }, { "input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6", "output": "630991750" }, { "input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8", "output": "931584598" }, { "input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6", "output": "1447294907" }, { "input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1", "output": "1634907859" }, { "input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10", "output": "1305347138" }, { "input": "200000000 3\n65170000 7\n20790088 1\n74616133 4", "output": "775444620" }, { "input": "200000000 2\n11823018 6\n100000000 9", "output": "970938108" }, { "input": "200000000 1\n100000000 6", "output": "600000000" }, { "input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5", "output": "1152034197" }, { "input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6", "output": "1095537357" }, { "input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5", "output": "83" }, { "input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10", "output": "54980855" }, { "input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6", "output": "939368573" }, { "input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5", "output": "1158946383" }, { "input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3", "output": "1131379312" }, { "input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9", "output": "79" }, { "input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7", "output": "45116295" }, { "input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6", "output": "1489289257" }, { "input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3", "output": "961871671" }, { "input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4", "output": "664376069" } ]
1,601,564,069
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
8
280
2,048,000
n,m=map(int,input().split()) mb=0 boxes=[] for i in range(m): a,b=map(int,input().split()) boxes.append([a,b]) def take_second(elem): return elem[1] boxes=sorted(boxes, key=take_second,reverse=True) i=0 total=0 while mb<n: curr=boxes[i] if(curr[0]>0): curr[0]-=1 mb+=1 total+=curr[1] else: i+=1 print(total)
Title: Burglar and Matches Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. Output Specification: Output the only number — answer to the problem. Demo Input: ['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n'] Demo Output: ['62\n', '7\n'] Note: none
```python n,m=map(int,input().split()) mb=0 boxes=[] for i in range(m): a,b=map(int,input().split()) boxes.append([a,b]) def take_second(elem): return elem[1] boxes=sorted(boxes, key=take_second,reverse=True) i=0 total=0 while mb<n: curr=boxes[i] if(curr[0]>0): curr[0]-=1 mb+=1 total+=curr[1] else: i+=1 print(total) ```
-1
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,690,597,253
2,147,483,647
Python 3
OK
TESTS
34
92
0
number1,number2,number3,number4=input().split() number1,number2,number3,number4=int(number1),int(number2),int(number3),int(number4) count=1 list_=[number1,number2,number3,number4] list_.sort() for i in range(3): if(list_[i]!=list_[i+1]): count+=1 print(4-count)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python number1,number2,number3,number4=input().split() number1,number2,number3,number4=int(number1),int(number2),int(number3),int(number4) count=1 list_=[number1,number2,number3,number4] list_.sort() for i in range(3): if(list_[i]!=list_[i+1]): count+=1 print(4-count) ```
3
895
A
Pizza Separation
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
[ "4\n90 90 90 90\n", "3\n100 100 160\n", "1\n360\n", "4\n170 30 150 10\n" ]
[ "0\n", "40\n", "360\n", "0\n" ]
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
500
[ { "input": "4\n90 90 90 90", "output": "0" }, { "input": "3\n100 100 160", "output": "40" }, { "input": "1\n360", "output": "360" }, { "input": "4\n170 30 150 10", "output": "0" }, { "input": "5\n10 10 10 10 320", "output": "280" }, { "input": "8\n45 45 45 45 45 45 45 45", "output": "0" }, { "input": "3\n120 120 120", "output": "120" }, { "input": "5\n110 90 70 50 40", "output": "40" }, { "input": "2\n170 190", "output": "20" }, { "input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "output": "10" }, { "input": "5\n30 60 180 60 30", "output": "0" }, { "input": "2\n359 1", "output": "358" }, { "input": "5\n100 100 30 100 30", "output": "40" }, { "input": "5\n36 34 35 11 244", "output": "128" }, { "input": "5\n96 94 95 71 4", "output": "18" }, { "input": "2\n85 275", "output": "190" }, { "input": "3\n281 67 12", "output": "202" }, { "input": "5\n211 113 25 9 2", "output": "62" }, { "input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1", "output": "212" }, { "input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "92" }, { "input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0" }, { "input": "3\n1 1 358", "output": "356" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341", "output": "322" }, { "input": "33\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 328", "output": "296" }, { "input": "70\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 291", "output": "222" }, { "input": "130\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231", "output": "102" }, { "input": "200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161", "output": "0" }, { "input": "222\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139", "output": "0" }, { "input": "10\n8 3 11 4 1 10 10 1 8 304", "output": "248" }, { "input": "12\n8 7 7 3 11 2 10 1 10 8 10 283", "output": "206" }, { "input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275", "output": "190" }, { "input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280", "output": "200" }, { "input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275", "output": "190" }, { "input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189", "output": "18" }, { "input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189", "output": "18" }, { "input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168", "output": "0" }, { "input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5", "output": "0" }, { "input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "0" }, { "input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68", "output": "0" }, { "input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0" }, { "input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 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", "output": "0" }, { "input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0" }, { "input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "0" }, { "input": "6\n27 15 28 34 41 215", "output": "70" }, { "input": "7\n41 38 41 31 22 41 146", "output": "14" }, { "input": "8\n24 27 34 23 29 23 30 170", "output": "20" }, { "input": "9\n11 11 20 20 33 32 35 26 172", "output": "6" }, { "input": "10\n36 13 28 13 33 34 23 25 34 121", "output": "0" }, { "input": "11\n19 37 13 41 37 15 32 12 19 35 100", "output": "10" }, { "input": "12\n37 25 34 38 21 24 34 38 11 29 28 41", "output": "2" }, { "input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28", "output": "2" }, { "input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44", "output": "4" }, { "input": "3\n95 91 174", "output": "12" }, { "input": "4\n82 75 78 125", "output": "46" }, { "input": "6\n87 75 88 94 15 1", "output": "4" }, { "input": "10\n27 52 58 64 45 64 1 19 2 28", "output": "12" }, { "input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1", "output": "0" }, { "input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3", "output": "0" }, { "input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1", "output": "0" }, { "input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2", "output": "0" }, { "input": "5\n35 80 45 100 100", "output": "40" }, { "input": "4\n90 179 90 1", "output": "2" }, { "input": "5\n50 50 20 160 80", "output": "0" }, { "input": "5\n30 175 30 5 120", "output": "10" }, { "input": "4\n170 30 10 150", "output": "20" }, { "input": "6\n90 30 90 30 90 30", "output": "60" }, { "input": "4\n70 80 110 100", "output": "20" }, { "input": "7\n35 45 70 100 10 10 90", "output": "0" }, { "input": "6\n50 90 10 90 20 100", "output": "20" }, { "input": "6\n10 155 162 1 26 6", "output": "18" }, { "input": "7\n80 90 80 45 10 10 45", "output": "20" }, { "input": "4\n18 36 162 144", "output": "36" }, { "input": "5\n20 50 50 160 80", "output": "40" }, { "input": "5\n10 30 140 20 160", "output": "0" }, { "input": "6\n90 80 60 50 40 40", "output": "20" }, { "input": "9\n40 20 20 20 20 20 20 40 160", "output": "40" }, { "input": "4\n90 54 90 126", "output": "72" }, { "input": "4\n150 170 30 10", "output": "20" }, { "input": "8\n130 12 13 85 41 67 5 7", "output": "26" }, { "input": "7\n70 170 20 10 30 30 30", "output": "20" }, { "input": "8\n100 100 50 50 15 15 15 15", "output": "40" }, { "input": "4\n100 70 80 110", "output": "20" }, { "input": "5\n160 130 40 20 10", "output": "20" }, { "input": "4\n20 149 151 40", "output": "22" }, { "input": "4\n100 10 100 150", "output": "60" }, { "input": "6\n19 64 105 168 1 3", "output": "16" }, { "input": "8\n10 10 70 70 90 90 10 10", "output": "0" } ]
1,511,757,505
2,147,483,647
Python 3
OK
TESTS
93
498
5,632,000
n=int(input()) from itertools import permutations a=list(map(int,input().split())) b=361 for i in range(n): for j in range(i,n): b=min(b,abs(sum(a[::])-sum(a[i:j])*2)) print(b)
Title: Pizza Separation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. Output Specification: Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. Demo Input: ['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n'] Demo Output: ['0\n', '40\n', '360\n', '0\n'] Note: In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
```python n=int(input()) from itertools import permutations a=list(map(int,input().split())) b=361 for i in range(n): for j in range(i,n): b=min(b,abs(sum(a[::])-sum(a[i:j])*2)) print(b) ```
3
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,661,100,006
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
92
0
a = input() flag=0 x = a[0] for i in range(len(a)-1): # x = a[i] if(x==a[i+1]): flag+=1 else: x = a[i+1] flag+=1 if(flag >= 7): print('YES') else: print('NO')
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python a = input() flag=0 x = a[0] for i in range(len(a)-1): # x = a[i] if(x==a[i+1]): flag+=1 else: x = a[i+1] flag+=1 if(flag >= 7): print('YES') else: print('NO') ```
0
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
1,648,640,432
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a=int(input()) if a==1: print(-1) else: c='' for i in range(a): c+=str(random.randint(1,a))+' ' print(c)
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. Input Specification: A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. Output Specification: If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. Demo Input: ['1\n', '2\n', '4\n'] Demo Output: ['-1\n', '2 1 \n', '2 1 4 3 \n'] Note: none
```python a=int(input()) if a==1: print(-1) else: c='' for i in range(a): c+=str(random.randint(1,a))+' ' print(c) ```
-1
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcdefghijklm" }, { "input": "100 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "100 10", "output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" }, { "input": "3 3", "output": "abc" }, { "input": "6 3", "output": "abcabc" }, { "input": "10 3", "output": "abcabcabca" }, { "input": "50 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab" }, { "input": "90 2", "output": "ababababababababababababababababababababababababababababababababababababababababababababab" }, { "input": "6 2", "output": "ababab" }, { "input": "99 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" }, { "input": "4 2", "output": "abab" }, { "input": "100 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "40 22", "output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr" }, { "input": "13 8", "output": "abcdefghabcde" }, { "input": "16 15", "output": "abcdefghijklmnoa" }, { "input": "17 17", "output": "abcdefghijklmnopq" }, { "input": "19 4", "output": "abcdabcdabcdabcdabc" }, { "input": "100 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv" }, { "input": "100 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" }, { "input": "26 26", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "27 26", "output": "abcdefghijklmnopqrstuvwxyza" }, { "input": "2 2", "output": "ab" }, { "input": "26 25", "output": "abcdefghijklmnopqrstuvwxya" }, { "input": "99 2", "output": "abababababababababababababababababababababababababababababababababababababababababababababababababa" }, { "input": "99 26", "output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" }, { "input": "4 4", "output": "abcd" }, { "input": "5 3", "output": "abcab" }, { "input": "5 4", "output": "abcda" }, { "input": "5 5", "output": "abcde" }, { "input": "24 22", "output": "abcdefghijklmnopqrstuvab" }, { "input": "26 14", "output": "abcdefghijklmnabcdefghijkl" }, { "input": "26 15", "output": "abcdefghijklmnoabcdefghijk" }, { "input": "30 12", "output": "abcdefghijklabcdefghijklabcdef" }, { "input": "35 4", "output": "abcdabcdabcdabcdabcdabcdabcdabcdabc" }, { "input": "79 3", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca" }, { "input": "79 14", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi" }, { "input": "85 13", "output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg" }, { "input": "90 25", "output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno" }, { "input": "90 19", "output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn" }, { "input": "26 24", "output": "abcdefghijklmnopqrstuvwxab" }, { "input": "100 17", "output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno" }, { "input": "26 2", "output": "ababababababababababababab" } ]
1,685,119,950
2,147,483,647
Python 3
OK
TESTS
47
61
1,126,400
import string import random n , k = map(int , input().split()) def generate(n , k): p = '' r = string.ascii_letters[:k] while(True): if len(p) < n: p +=r else: break return p[:n] print(generate(n,k))
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. Input Specification: The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Output Specification: Print any password which satisfies all conditions given by Innokentiy. Demo Input: ['4 3\n', '6 6\n', '5 2\n'] Demo Output: ['java\n', 'python\n', 'phphp\n'] Note: In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters. In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it. Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
```python import string import random n , k = map(int , input().split()) def generate(n , k): p = '' r = string.ascii_letters[:k] while(True): if len(p) < n: p +=r else: break return p[:n] print(generate(n,k)) ```
3
203
A
Two Problems
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for *t* minutes, the minutes are numbered starting from zero. The first problem had the initial cost of *a* points, and every minute its cost reduced by *d**a* points. The second problem had the initial cost of *b* points, and every minute this cost reduced by *d**b* points. Thus, as soon as the zero minute of the contest is over, the first problem will cost *a*<=-<=*d**a* points, and the second problem will cost *b*<=-<=*d**b* points. It is guaranteed that at any moment of the contest each problem has a non-negative cost. Arkady asks you to find out whether Valera could have got exactly *x* points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number *t*<=-<=1. Please note that Valera can't submit a solution exactly *t* minutes after the start of the contest or later.
The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly. It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, *a*<=-<=*i*·*d**a*<=≥<=0 and *b*<=-<=*i*·*d**b*<=≥<=0 for all 0<=≤<=*i*<=≤<=*t*<=-<=1.
If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes).
[ "30 5 20 20 3 5\n", "10 4 100 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
500
[ { "input": "30 5 20 20 3 5", "output": "YES" }, { "input": "10 4 100 5 5 1", "output": "NO" }, { "input": "0 7 30 50 3 4", "output": "YES" }, { "input": "50 10 30 20 1 2", "output": "YES" }, { "input": "40 1 40 5 11 2", "output": "YES" }, { "input": "35 8 20 20 1 2", "output": "YES" }, { "input": "10 2 27 4 11 1", "output": "NO" }, { "input": "64 12 258 141 10 7", "output": "YES" }, { "input": "5 3 11 100 2 4", "output": "NO" }, { "input": "5 4 11 80 2 4", "output": "YES" }, { "input": "28 3 16 20 3 10", "output": "NO" }, { "input": "6 2 11 1 11 1", "output": "NO" }, { "input": "15 5 230 213 32 25", "output": "NO" }, { "input": "223 92 123 118 1 1", "output": "YES" }, { "input": "375 6 133 267 19 36", "output": "NO" }, { "input": "80 5 39 40 1 1", "output": "NO" }, { "input": "543 4 31 69 6 5", "output": "NO" }, { "input": "38 100 99 245 1 1", "output": "YES" }, { "input": "3 1 20 15 17 5", "output": "NO" }, { "input": "360 5 215 4 52 1", "output": "NO" }, { "input": "363 2 280 239 5 231", "output": "NO" }, { "input": "46 7 18 6 3 1", "output": "NO" }, { "input": "5 3 135 12 21 6", "output": "NO" }, { "input": "15 5 230 213 32 25", "output": "NO" }, { "input": "2 5 29 36 5 6", "output": "NO" }, { "input": "59 4 113 45 25 12", "output": "YES" }, { "input": "74 72 104 71 1 1", "output": "YES" }, { "input": "16 24 26 23 1 1", "output": "YES" }, { "input": "11 1 10 1 10 1", "output": "YES" }, { "input": "13 3 11 14 5 1", "output": "YES" }, { "input": "1 2 1 2 1 2", "output": "YES" }, { "input": "145 26 25 150 1 4", "output": "YES" }, { "input": "59 18 50 17 1 1", "output": "YES" }, { "input": "230 125 175 124 1 1", "output": "YES" }, { "input": "142 1 66 76 18 39", "output": "YES" }, { "input": "0 3 5 6 1 2", "output": "YES" }, { "input": "6 46 95 45 1 1", "output": "YES" }, { "input": "16 73 92 72 1 1", "output": "YES" }, { "input": "3 18 272 17 6 1", "output": "YES" }, { "input": "1 21 178 20 1 1", "output": "YES" }, { "input": "0 15 86 84 5 2", "output": "YES" }, { "input": "0 35 208 98 6 2", "output": "YES" }, { "input": "0 11 67 82 6 4", "output": "YES" }, { "input": "30 9 18 83 1 7", "output": "NO" }, { "input": "18 12 11 54 1 3", "output": "NO" }, { "input": "41 77 96 145 1 1", "output": "YES" }, { "input": "27 45 44 169 1 2", "output": "YES" }, { "input": "50 5 30 60 3 3", "output": "NO" }, { "input": "49 2 50 20 2 1", "output": "NO" }, { "input": "49 2 50 20 2 1", "output": "NO" }, { "input": "17 10 10 20 1 2", "output": "YES" } ]
1,683,668,676
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
x, t, a, b, da, db = map(int, input().split()) if x == 0: print("YES") else: ans = False t = 0 for i in range(da): cur_b = b for j in range(db): if a + cur_b == x: ans = True break t += 1 cur_b -= db if t == 5: break a -= da t += 1 if t >= 5: t = 0 if ans: print("YES") else: print("NO")
Title: Two Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for *t* minutes, the minutes are numbered starting from zero. The first problem had the initial cost of *a* points, and every minute its cost reduced by *d**a* points. The second problem had the initial cost of *b* points, and every minute this cost reduced by *d**b* points. Thus, as soon as the zero minute of the contest is over, the first problem will cost *a*<=-<=*d**a* points, and the second problem will cost *b*<=-<=*d**b* points. It is guaranteed that at any moment of the contest each problem has a non-negative cost. Arkady asks you to find out whether Valera could have got exactly *x* points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number *t*<=-<=1. Please note that Valera can't submit a solution exactly *t* minutes after the start of the contest or later. Input Specification: The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly. It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, *a*<=-<=*i*·*d**a*<=≥<=0 and *b*<=-<=*i*·*d**b*<=≥<=0 for all 0<=≤<=*i*<=≤<=*t*<=-<=1. Output Specification: If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes). Demo Input: ['30 5 20 20 3 5\n', '10 4 100 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
```python x, t, a, b, da, db = map(int, input().split()) if x == 0: print("YES") else: ans = False t = 0 for i in range(da): cur_b = b for j in range(db): if a + cur_b == x: ans = True break t += 1 cur_b -= db if t == 5: break a -= da t += 1 if t >= 5: t = 0 if ans: print("YES") else: print("NO") ```
0
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "2", "output": "22" }, { "input": "3", "output": "33" }, { "input": "4", "output": "44" }, { "input": "5", "output": "55" }, { "input": "6", "output": "66" }, { "input": "7", "output": "77" }, { "input": "8", "output": "88" }, { "input": "9", "output": "99" }, { "input": "13", "output": "1331" }, { "input": "14", "output": "1441" }, { "input": "15", "output": "1551" }, { "input": "16", "output": "1661" }, { "input": "17", "output": "1771" }, { "input": "18", "output": "1881" }, { "input": "19", "output": "1991" }, { "input": "20", "output": "2002" }, { "input": "26550", "output": "2655005562" }, { "input": "16137", "output": "1613773161" }, { "input": "91471", "output": "9147117419" }, { "input": "41242", "output": "4124224214" }, { "input": "30866", "output": "3086666803" }, { "input": "4442231232741003009964183199713851566466079882929007253443848371978048610682180431295671905105980116", "output": "44422312327410030099641831997138515664660798829290072534438483719780486106821804312956719051059801166110895015091765921340812860168408791738483443527009292889706646651583179913814699003001472321322444" }, { "input": "7806526084732010742850470902979267046151204705563201965818390803445852115032119297648697933316807252", "output": "78065260847320107428504709029792670461512047055632019658183908034458521150321192976486979333168072522527086133397968467929112305112585443080938185691023655074021516407629792090740582470102374806256087" }, { "input": "2244399823612183124978103773977739948197709395321563148611877999503840818596183803323258317041875913", "output": "22443998236121831249781037739777399481977093953215631486118779995038408185961838033232583170418759133195781407138523233083816958180483059997781168413651235939077918499377793773018794213812163289934422" }, { "input": "123451", "output": "123451154321" } ]
1,636,193,611
2,147,483,647
PyPy 3
OK
TESTS
40
109
22,835,200
s = input() res = ['0'] * (2* len(s)) for i in range(len(s)): res[i] = res[len(res)-1-i] = s[i] print(''.join(res))
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer *n* from the input and tells what is the *n*-th even-length positive palindrome number? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000). Output Specification: Print the *n*-th even-length palindrome number. Demo Input: ['1\n', '10\n'] Demo Output: ['11\n', '1001\n'] Note: The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
```python s = input() res = ['0'] * (2* len(s)) for i in range(len(s)): res[i] = res[len(res)-1-i] = s[i] print(''.join(res)) ```
3
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200", "output": "YES" }, { "input": "2\n100 200", "output": "NO" }, { "input": "2\n200 100", "output": "NO" }, { "input": "3\n100 100 100", "output": "NO" }, { "input": "3\n200 200 200", "output": "NO" }, { "input": "3\n200 100 200", "output": "NO" }, { "input": "4\n100 100 100 100", "output": "YES" }, { "input": "4\n200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "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": "YES" }, { "input": "100\n100 100 200 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": "NO" }, { "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 200 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 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "100\n100 100 100 100 100 100 100 100 200 100 100 200 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 200 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": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "YES" }, { "input": "99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\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", "output": "NO" }, { "input": "99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 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": "YES" }, { "input": "99\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 200 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 200 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": "NO" }, { "input": "100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100", "output": "YES" }, { "input": "100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100", "output": "NO" }, { "input": "100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100", "output": "YES" }, { "input": "99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200", "output": "NO" }, { "input": "99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200", "output": "YES" }, { "input": "56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200", "output": "YES" }, { "input": "32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200", "output": "YES" }, { "input": "48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200", "output": "NO" }, { "input": "60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 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 200 100 100 100", "output": "YES" }, { "input": "24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100", "output": "YES" }, { "input": "40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100", "output": "NO" }, { "input": "5\n200 200 200 200 200", "output": "NO" }, { "input": "9\n100 100 100 200 100 100 200 100 200", "output": "YES" }, { "input": "1\n200", "output": "NO" }, { "input": "7\n200 200 200 100 200 200 200", "output": "NO" }, { "input": "4\n100 100 200 200", "output": "YES" }, { "input": "6\n100 100 100 200 200 200", "output": "NO" }, { "input": "4\n200 100 100 200", "output": "YES" }, { "input": "5\n100 100 100 100 200", "output": "YES" } ]
1,658,899,009
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
77
0
import sys def _input(): return map(int, input().split()) n = int(input()) lst = list(_input()) if lst.count(100)%2==0: print("YES") else: print("NO")
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna. But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. Output Specification: In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). Demo Input: ['3\n100 200 100\n', '4\n100 100 100 200\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
```python import sys def _input(): return map(int, input().split()) n = int(input()) lst = list(_input()) if lst.count(100)%2==0: print("YES") else: print("NO") ```
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,690,865,071
2,147,483,647
Python 3
OK
TESTS
34
92
0
def minimum_horseshoes_to_buy(colors): unique_colors = len(set(colors)) return max(0, 4 - unique_colors) colors = list(map(int, input().split())) output_result = minimum_horseshoes_to_buy(colors) print(output_result)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python def minimum_horseshoes_to_buy(colors): unique_colors = len(set(colors)) return max(0, 4 - unique_colors) colors = list(map(int, input().split())) output_result = minimum_horseshoes_to_buy(colors) print(output_result) ```
3
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "output": "1" }, { "input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77", "output": "6" }, { "input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35", "output": "4" }, { "input": "2\n46 6\n6 46", "output": "2" }, { "input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11", "output": "10" }, { "input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33", "output": "6" }, { "input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73", "output": "0" }, { "input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2", "output": "1" }, { "input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100", "output": "8" }, { "input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "450" }, { "input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3", "output": "0" }, { "input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5", "output": "20" }, { "input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2", "output": "108" }, { "input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2", "output": "312" }, { "input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6", "output": "96" }, { "input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97", "output": "210" }, { "input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78", "output": "73" }, { "input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80", "output": "277" }, { "input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21", "output": "154" }, { "input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17", "output": "418" }, { "input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80", "output": "74" }, { "input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9", "output": "59" }, { "input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67", "output": "100" }, { "input": "4\n8 7\n8 7\n7 8\n7 8", "output": "8" }, { "input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1", "output": "10" }, { "input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1", "output": "72" }, { "input": "4\n1 2\n1 2\n2 1\n2 1", "output": "8" } ]
1,682,385,119
2,147,483,647
Python 3
OK
TESTS
31
92
0
ls = [] counter = 0 for i in range(int(input())): ls_temp = [int(x) for x in input().split()] ls.append(ls_temp) for home in ls : for away in ls : if home[0]==away[1] : counter += 1 print(counter)
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. Output Specification: In a single line print the number of games where the host team is going to play in the guest uniform. Demo Input: ['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n'] Demo Output: ['1\n', '5\n', '0\n'] Note: In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).
```python ls = [] counter = 0 for i in range(int(input())): ls_temp = [int(x) for x in input().split()] ls.append(ls_temp) for home in ls : for away in ls : if home[0]==away[1] : counter += 1 print(counter) ```
3
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" }, { "input": "1000000000000000000 1000000000000000000", "output": "1152921504606846975" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000000000 2", "output": "1152921504606846975" }, { "input": "49194939 22", "output": "67108863" }, { "input": "228104606 17", "output": "268435455" }, { "input": "817034381 7", "output": "1073741823" }, { "input": "700976748 4", "output": "1073741823" }, { "input": "879886415 9", "output": "1073741823" }, { "input": "18007336 10353515", "output": "33554431" }, { "input": "196917003 154783328", "output": "268435455" }, { "input": "785846777 496205300", "output": "1073741823" }, { "input": "964756444 503568330", "output": "1073741823" }, { "input": "848698811 317703059", "output": "1073741823" }, { "input": "676400020444788 1", "output": "676400020444788" }, { "input": "502643198528213 1", "output": "502643198528213" }, { "input": "815936580997298686 684083143940282566", "output": "1152921504606846975" }, { "input": "816762824175382110 752185261508428780", "output": "1152921504606846975" }, { "input": "327942415253132295 222598158321260499", "output": "576460752303423487" }, { "input": "328768654136248423 284493129147496637", "output": "576460752303423487" }, { "input": "329594893019364551 25055600080496801", "output": "576460752303423487" }, { "input": "921874985256864012 297786684518764536", "output": "1152921504606846975" }, { "input": "922701224139980141 573634416190460758", "output": "1152921504606846975" }, { "input": "433880815217730325 45629641110945892", "output": "576460752303423487" }, { "input": "434707058395813749 215729375494216481", "output": "576460752303423487" }, { "input": "435533301573897173 34078453236225189", "output": "576460752303423487" }, { "input": "436359544751980597 199220719961060641", "output": "576460752303423487" }, { "input": "437185783635096725 370972992240105630", "output": "576460752303423487" }, { "input": "438012026813180149 111323110116193830", "output": "576460752303423487" }, { "input": "438838269991263573 295468957052046146", "output": "576460752303423487" }, { "input": "439664513169346997 46560240538186155", "output": "576460752303423487" }, { "input": "440490752052463125 216165966013438147", "output": "576460752303423487" }, { "input": "441316995230546549 401964286420555423", "output": "576460752303423487" }, { "input": "952496582013329437 673506882352402278", "output": "1152921504606846975" }, { "input": "1000000000000000000 1", "output": "1000000000000000000" }, { "input": "2147483647 1", "output": "2147483647" }, { "input": "2147483647 2", "output": "2147483647" }, { "input": "2147483647 31", "output": "2147483647" }, { "input": "8 2", "output": "15" }, { "input": "3 3", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "10 2", "output": "15" }, { "input": "288230376151711743 2", "output": "288230376151711743" }, { "input": "5 2", "output": "7" }, { "input": "576460752303423487 2", "output": "576460752303423487" }, { "input": "36028797018963967 123", "output": "36028797018963967" }, { "input": "1125899906842623 2", "output": "1125899906842623" }, { "input": "576460752303423489 5", "output": "1152921504606846975" }, { "input": "288230376151711743 3", "output": "288230376151711743" }, { "input": "36028797018963967 345", "output": "36028797018963967" }, { "input": "18014398509481984 30", "output": "36028797018963967" }, { "input": "8 8", "output": "15" }, { "input": "8 1", "output": "8" } ]
1,518,550,434
2,147,483,647
PyPy 3
OK
TESTS
58
77
19,968,000
n, k = [int(f) for f in input().split(' ') if f] if k == 1: print(n) else: l = 0 while n > 0: l += 1 n //= 2 print(2 ** l - 1)
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. Input Specification: The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). Output Specification: Output one number — the largest possible xor-sum. Demo Input: ['4 3\n', '6 6\n'] Demo Output: ['7\n', '7\n'] Note: In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
```python n, k = [int(f) for f in input().split(' ') if f] if k == 1: print(n) else: l = 0 while n > 0: l += 1 n //= 2 print(2 ** l - 1) ```
3
275
B
Convex Shape
PROGRAMMING
1,700
[ "constructive algorithms", "implementation" ]
null
null
Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell.
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
[ "3 4\nWWBW\nBWWW\nWWWB\n", "3 1\nB\nB\nW\n" ]
[ "NO\n", "YES\n" ]
none
1,000
[ { "input": "3 4\nWWBW\nBWWW\nWWWB", "output": "NO" }, { "input": "3 1\nB\nB\nW", "output": "YES" }, { "input": "1 1\nB", "output": "YES" }, { "input": "1 2\nBB", "output": "YES" }, { "input": "2 1\nB\nB", "output": "YES" }, { "input": "1 2\nBW", "output": "YES" }, { "input": "2 1\nW\nB", "output": "YES" }, { "input": "5 5\nWBBBW\nWBBBW\nWBBWW\nWBBBW\nWWWWW", "output": "NO" }, { "input": "5 5\nWBBWW\nBBBWW\nBBBWW\nBBBWW\nBBBBB", "output": "YES" }, { "input": "5 5\nWWWBB\nBBBBB\nWWWBB\nWWWBB\nWWWBW", "output": "YES" }, { "input": "5 5\nWBBBW\nWBBWW\nWBBWW\nBBBWW\nBBWWW", "output": "NO" }, { "input": "5 5\nWBBBB\nWBBBB\nWBBBB\nBBBBB\nBBBBB", "output": "YES" }, { "input": "5 5\nWWWWB\nWBBBB\nBBBBB\nBBBBB\nWBBBB", "output": "YES" }, { "input": "5 5\nWWBWW\nWWBWW\nWWBBB\nBBBBB\nWWWWW", "output": "YES" }, { "input": "50 1\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW", "output": "YES" }, { "input": "1 50\nWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBWWWWWW", "output": "YES" }, { "input": "50 2\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWW\nWB\nWB\nWB\nWB\nWB\nWB\nWB\nWB\nWB\nWB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBB\nBW\nBW\nBW\nBW\nBW\nBW\nBW\nWW\nWW\nWW", "output": "NO" }, { "input": "5 5\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW", "output": "YES" }, { "input": "5 5\nWWWWW\nWWWWW\nWWWWW\nWBBBB\nWWWWW", "output": "YES" }, { "input": "5 5\nWWWWW\nWWWBW\nWWWBW\nWWWBB\nWWWWW", "output": "YES" }, { "input": "5 5\nWWWWB\nWWWWB\nWBBBB\nWWWWW\nWWWWW", "output": "YES" }, { "input": "5 5\nWWWWW\nBBBWW\nBBBBW\nWWWWW\nWWWWW", "output": "YES" }, { "input": "5 5\nWWWWW\nBBBBW\nWWWBB\nWWWWW\nWWWWW", "output": "NO" }, { "input": "5 5\nWBWWW\nBBWWW\nWWWWW\nWWWWW\nWWWWW", "output": "YES" }, { "input": "5 5\nWWBBB\nWWBBB\nWWBBB\nWWBBB\nWWBBW", "output": "YES" }, { "input": "5 5\nWWWWB\nWWWBB\nWWWBB\nWWWBB\nWWWBW", "output": "NO" }, { "input": "2 5\nBWWWB\nBBBBB", "output": "NO" } ]
1,658,010,145
2,147,483,647
PyPy 3-64
OK
TESTS
46
280
3,993,600
import bisect import itertools import sys import collections n, m = map(int, input().split()) grid = [list(input()) for _ in range(n)] # print('\n'.join(map(str, grid))) # row check good = True for i in range(n): b = False w = False for j in range(m): if grid[i][j] == 'B' and not b: b = True elif grid[i][j] == 'W' and b and not w: w = True elif grid[i][j] == 'B' and b and w: good = False # print('rowcheck', i, j) break if not good: break # col check if good: for j in range(m): b = False w = False for i in range(n): if grid[i][j] == 'B' and not b and not w: b = True elif grid[i][j] == 'W' and b and not w: w = True elif grid[i][j] == 'B' and b and w: good = False # print('colcheck', i, j) break if not good: break # 2 change check if good: points = [(i, j) for i in range(n) for j in range(m) if grid[i][j] == 'B'] for (i1, j1), (i2, j2) in itertools.combinations(points, 2): if grid[i1][j2] == 'W' and grid[i2][j1] == 'W': # print('2change', i1, j1, i2, j2) good = False break print("YES" if good else "NO")
Title: Convex Shape Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider an *n*<=×<=*m* grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. You're given a painted grid in the input. Tell Lenny if the grid is convex or not. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the size of the grid. Each of the next *n* lines contains *m* characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell. Output Specification: On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes. Demo Input: ['3 4\nWWBW\nBWWW\nWWWB\n', '3 1\nB\nB\nW\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python import bisect import itertools import sys import collections n, m = map(int, input().split()) grid = [list(input()) for _ in range(n)] # print('\n'.join(map(str, grid))) # row check good = True for i in range(n): b = False w = False for j in range(m): if grid[i][j] == 'B' and not b: b = True elif grid[i][j] == 'W' and b and not w: w = True elif grid[i][j] == 'B' and b and w: good = False # print('rowcheck', i, j) break if not good: break # col check if good: for j in range(m): b = False w = False for i in range(n): if grid[i][j] == 'B' and not b and not w: b = True elif grid[i][j] == 'W' and b and not w: w = True elif grid[i][j] == 'B' and b and w: good = False # print('colcheck', i, j) break if not good: break # 2 change check if good: points = [(i, j) for i in range(n) for j in range(m) if grid[i][j] == 'B'] for (i1, j1), (i2, j2) in itertools.combinations(points, 2): if grid[i1][j2] == 'W' and grid[i2][j1] == 'W': # print('2change', i1, j1, i2, j2) good = False break print("YES" if good else "NO") ```
3
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter.
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input": "20 287 3845 5", "output": "YES\n39.646277165210" }, { "input": "48 6428 9807 83", "output": "NO" }, { "input": "72 5272 4552 64", "output": "NO" }, { "input": "100 4117 5106 34", "output": "NO" }, { "input": "20 2961 9852 15", "output": "YES\n180.991437129723" }, { "input": "48 1805 3109 93", "output": "NO" }, { "input": "72 8534 7042 65", "output": "NO" }, { "input": "1 47 80 68", "output": "YES\n1.388102806810" }, { "input": "4 495 8813 1", "output": "YES\n0.706823517575" }, { "input": "5 2797 5925 9", "output": "YES\n9.553973511669" }, { "input": "1 8324 4362 23", "output": "YES\n1.505007106354" }, { "input": "6 1976 8455 3", "output": "YES\n6.674898722265" }, { "input": "7 2644 8080 5", "output": "YES\n12.900417790197" }, { "input": "3 4183 5491 98", "output": "YES\n6.162185601824" }, { "input": "2 8591 320 101", "output": "YES\n9999.259991757254" }, { "input": "10000 10000 10000 10000", "output": "NO" }, { "input": "2 5000 12 3", "output": "YES\n6099.653943875812" }, { "input": "10 1000 100 1", "output": "YES\n3659.792366325487" } ]
1,462,210,801
2,147,483,647
Python 3
OK
TESTS
23
62
5,120,000
d,h,v,e = map(int,input().split(' ')) PI = 3.1415926 S = (d/2)*(d/2)*PI V = h*S V2 = e*S if(V2 >= v): print("NO") exit else: print("YES") print(abs(V/(V2-v)))
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter. Input Specification: The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. Output Specification: If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. Demo Input: ['1 2 3 100\n', '1 1 1 1\n'] Demo Output: ['NO\n', 'YES\n3.659792366325\n'] Note: In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
```python d,h,v,e = map(int,input().split(' ')) PI = 3.1415926 S = (d/2)*(d/2)*PI V = h*S V2 = e*S if(V2 >= v): print("NO") exit else: print("YES") print(abs(V/(V2-v))) ```
3
32
A
Reconnaissance
PROGRAMMING
800
[ "brute force" ]
A. Reconnaissance
2
256
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment. Ways (1,<=2) and (2,<=1) should be regarded as different.
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
[ "5 10\n10 20 50 60 65\n", "5 1\n55 30 29 31 55\n" ]
[ "6\n", "6\n" ]
none
500
[ { "input": "5 10\n10 20 50 60 65", "output": "6" }, { "input": "5 1\n55 30 29 31 55", "output": "6" }, { "input": "6 10\n4 6 4 1 9 3", "output": "30" }, { "input": "7 100\n19 1694 261 162 1 234 513", "output": "8" }, { "input": "8 42\n37 53 74 187 568 22 5 65", "output": "20" }, { "input": "10 4\n11 6 76 49 28 20 57 152 5 32", "output": "4" }, { "input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300", "output": "2404" } ]
1,604,070,410
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
156
0
a1 = int(input()) for i in range(a1): a = input() x = len(a) if x <=10: print(a) else: q = len(a[1:x-1]) s1 = a[:1] + str(q) + a[x-1:x] print(s1)
Title: Reconnaissance Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment. Ways (1,<=2) and (2,<=1) should be regarded as different. Input Specification: The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. Output Specification: Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. Demo Input: ['5 10\n10 20 50 60 65\n', '5 1\n55 30 29 31 55\n'] Demo Output: ['6\n', '6\n'] Note: none
```python a1 = int(input()) for i in range(a1): a = input() x = len(a) if x <=10: print(a) else: q = len(a[1:x-1]) s1 = a[:1] + str(q) + a[x-1:x] print(s1) ```
-1
166
A
Rank List
PROGRAMMING
1,100
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
500
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "output": "1" }, { "input": "3 2\n3 3\n3 3\n3 3", "output": "3" }, { "input": "4 3\n10 3\n6 10\n5 2\n5 2", "output": "2" }, { "input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "output": "3" }, { "input": "3 1\n2 1\n1 1\n1 2", "output": "1" }, { "input": "1 1\n28 28", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10", "output": "1" }, { "input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "50" }, { "input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2", "output": "13" }, { "input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2", "output": "1" }, { "input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6", "output": "1" }, { "input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1", "output": "3" }, { "input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "20" }, { "input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2", "output": "6" }, { "input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "30" }, { "input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1", "output": "13" }, { "input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14", "output": "1" }, { "input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30", "output": "2" }, { "input": "2 1\n50 50\n50 50", "output": "2" }, { "input": "2 2\n50 50\n50 50", "output": "2" }, { "input": "2 1\n50 50\n50 49", "output": "1" }, { "input": "2 2\n50 50\n50 49", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50", "output": "50" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49", "output": "49" }, { "input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "1" }, { "input": "4 3\n1 1\n1 2\n2 1\n2 2", "output": "1" }, { "input": "4 2\n1 2\n1 3\n1 5\n1 2", "output": "2" }, { "input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3", "output": "1" }, { "input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1", "output": "2" }, { "input": "3 1\n1 1\n1 2\n1 3", "output": "1" }, { "input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "4" }, { "input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5", "output": "2" }, { "input": "4 1\n1 1\n1 1\n1 2\n1 3", "output": "2" } ]
1,669,179,464
2,147,483,647
PyPy 3
OK
TESTS
46
186
307,200
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) x = [] for _ in range(n): p, t = map(int, input().split()) x.append(50 * p + 50 - t) x.sort() cnt = defaultdict(lambda : 0) for i in x: cnt[i] += 1 ans = cnt[x[-k]] print(ans)
Title: Rank List Time Limit: None seconds Memory Limit: None megabytes Problem Description: Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces. Output Specification: In the only line print the sought number of teams that got the *k*-th place in the final results' table. Demo Input: ['7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n', '5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n'] Demo Output: ['3\n', '4\n'] Note: The final results' table for the first sample is: - 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place — 5 solved problems, the penalty time equals 3 - 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
```python from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) x = [] for _ in range(n): p, t = map(int, input().split()) x.append(50 * p + 50 - t) x.sort() cnt = defaultdict(lambda : 0) for i in x: cnt[i] += 1 ans = cnt[x[-k]] print(ans) ```
3
386
A
Second-Price Auction
PROGRAMMING
800
[ "implementation" ]
null
null
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
[ "2\n5 7\n", "3\n10 2 8\n", "6\n3 8 2 9 4 14\n" ]
[ "2 5\n", "1 8\n", "6 9\n" ]
none
500
[ { "input": "2\n5 7", "output": "2 5" }, { "input": "3\n10 2 8", "output": "1 8" }, { "input": "6\n3 8 2 9 4 14", "output": "6 9" }, { "input": "4\n4707 7586 4221 5842", "output": "2 5842" }, { "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002" }, { "input": "6\n5083 3289 7708 5362 9031 7458", "output": "5 7708" }, { "input": "7\n9038 6222 3392 1706 3778 1807 2657", "output": "1 6222" }, { "input": "8\n7062 2194 4481 3864 7470 1814 8091 733", "output": "7 7470" }, { "input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408", "output": "3 7906" }, { "input": "2\n3458 1504", "output": "1 1504" }, { "input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991", "output": "39 9752" }, { "input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602", "output": "86 9806" }, { "input": "2\n2 1", "output": "1 1" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "3\n10 20 30", "output": "3 20" }, { "input": "3\n10 30 20", "output": "2 20" }, { "input": "3\n20 10 30", "output": "3 20" }, { "input": "3\n20 30 10", "output": "2 20" }, { "input": "3\n30 10 20", "output": "1 20" }, { "input": "3\n30 20 10", "output": "1 20" }, { "input": "2\n1 10000", "output": "2 1" }, { "input": "2\n10000 999", "output": "1 999" }, { "input": "3\n3 4 1", "output": "2 3" }, { "input": "6\n1 2 24 6 5 7", "output": "3 7" } ]
1,641,466,731
2,147,483,647
PyPy 3-64
OK
TESTS
42
108
0
n = int(input()) arr = list(map(int, input().split())) arr2 = [i for i in arr] arr2.sort() x = arr2[-1] y = arr2[-2] print(arr.index(x)+1, end = " ") print(y)
Title: Second-Price Auction Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. Output Specification: The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. Demo Input: ['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n'] Demo Output: ['2 5\n', '1 8\n', '6 9\n'] Note: none
```python n = int(input()) arr = list(map(int, input().split())) arr2 = [i for i in arr] arr2.sort() x = arr2[-1] y = arr2[-2] print(arr.index(x)+1, end = " ") print(y) ```
3
0
none
none
none
0
[ "none" ]
null
null
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (*x**l*,<=*y**l*) in some small field, the next move should be done in one of the cells of the small field with coordinates (*x**l*,<=*y**l*). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.
First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.
Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.
[ "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n", "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n", "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5\n" ]
[ "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... \n\n", "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\n", "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n" ]
In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
0
[ { "input": "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "output": "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... " }, { "input": "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "output": "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! " }, { "input": "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5", "output": "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! " }, { "input": ".o. .o. ..x\n..x .xx ..o\n... ... ...\n\n... ... xxo\n..x o.o oxo\n.x. .o. xoo\n\n... o.. ...\n..o .xx ..x\n... ... ...\n5 9", "output": "!o! !o! !!x \n!!x !xx !!o \n!!! !!! !!! \n\n!!! !!! xxo \n!!x o!o oxo \n!x! !o! xoo \n\n!!! o!! !!! \n!!o !xx !!x \n!!! !!! !!! " }, { "input": "... .o. ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... .x. ..x\n\n.x. ... ...\n..o ... .o.\n... o.o xx.\n1 5", "output": "... !o! ... \n... !!! ... \n... !!! ... \n\n... ... ... \n... ... ... \n... .x. ..x \n\n.x. ... ... \n..o ... .o. \n... o.o xx. " }, { "input": "ooo oxx xxo\nx.x oox xox\noox xo. xxx\n\nxxo xxx o.o\nxoo xo. oxo\nooo xox ox.\n\nxoo xoo .oo\nxox xox ox.\noxx xox oxo\n1 3", "output": "ooo oxx xxo \nx!x oox xox \noox xo! xxx \n\nxxo xxx o!o \nxoo xo! oxo \nooo xox ox! \n\nxoo xoo !oo \nxox xox ox! \noxx xox oxo " }, { "input": "... ... ...\n..o ... ..o\n... .x. ..x\n\nx.. ... ...\n.x. .ox oo.\n... .xo ..x\n\n... ... .ox\n... ox. ..x\n... ..o .o.\n2 3", "output": "... ... ... \n..o ... ..o \n... .x. ..x \n\nx.. ... !!! \n.x. .ox oo! \n... .xo !!x \n\n... ... .ox \n... ox. ..x \n... ..o .o. " }, { "input": "xox o.x xxo\nxox xox oxo\nxxx .xx xoo\n\nooo oox o.x\n.xx xx. oo.\nooo xox ooo\n\nooo oxo xox\nx.x xox xox\noxo x.o xxo\n1 7", "output": "xox o!x xxo \nxox xox oxo \nxxx !xx xoo \n\nooo oox o!x \n!xx xx! oo! \nooo xox ooo \n\nooo oxo xox \nx!x xox xox \noxo x!o xxo " }, { "input": "ox. x.o ..x\n... ..o .o.\n.o. ... x.o\n\nx.x .oo ...\n..o ox. .xx\n..x o.x .o.\n\n... ... .x.\nox. xx. .o.\n... ... ..o\n9 9", "output": "ox. x.o ..x \n... ..o .o. \n.o. ... x.o \n\nx.x .oo ... \n..o ox. .xx \n..x o.x .o. \n\n... ... !x! \nox. xx. !o! \n... ... !!o " }, { "input": "xx. oxx .xo\nxxx o.o xox\nxoo xoo xoo\n\nooo o.x xox\no.. xoo .xo\noxx .x. xoo\n\nooo oxo oxx\nxxx xox ..o\noo. oxx xx.\n3 8", "output": "xx! oxx !xo \nxxx o!o xox \nxoo xoo xoo \n\nooo o!x xox \no!! xoo !xo \noxx !x! xoo \n\nooo oxo oxx \nxxx xox !!o \noo! oxx xx! " }, { "input": "... xo. o..\noo. ..o xx.\n..x x.. ..o\n\n.ox .xx ...\no.x xox xo.\nxox .xo ..o\n\n..o ... xxo\no.. .o. oxo\n..o x.. ..x\n8 9", "output": "... xo. o.. \noo. ..o xx. \n..x x.. ..o \n\n.ox .xx !!! \no.x xox xo! \nxox .xo !!o \n\n..o ... xxo \no.. .o. oxo \n..o x.. ..x " }, { "input": "oox xoo xxx\nooo xxo oxo\nxxx xoo xxo\n\noxo oxx xoo\nxoo oox xox\nxox oox oox\n\nxxo xoo oxo\noxx xxx xxx\noxo oxo oo.\n1 5", "output": "oox xoo xxx \nooo xxo oxo \nxxx xoo xxo \n\noxo oxx xoo \nxoo oox xox \nxox oox oox \n\nxxo xoo oxo \noxx xxx xxx \noxo oxo oo! " }, { "input": ".oo x.o xoo\n.o. xxx .x.\n..o x.o xxx\n\n..o .oo .xx\n.x. xox o.o\n.xo o.o .x.\n\n.o. xo. xxx\n.xo o.. .xo\n..o ..o xox\n1 8", "output": ".oo x!o xoo \n.o. xxx .x. \n..o x!o xxx \n\n..o .oo .xx \n.x. xox o.o \n.xo o.o .x. \n\n.o. xo. xxx \n.xo o.. .xo \n..o ..o xox " }, { "input": "xxo xoo xxo\nooo ooo xxx\noox oxo oxx\n\noxo oxo xxx\nxoo oxx oxo\nxxx oxx ooo\n\noxx xoo xxo\nxxx oox xox\nxxo o.o oxo\n9 6", "output": "xxo xoo xxo \nooo ooo xxx \noox oxo oxx \n\noxo oxo xxx \nxoo oxx oxo \nxxx oxx ooo \n\noxx xoo xxo \nxxx oox xox \nxxo o!o oxo " }, { "input": "ox. o.x .o.\nxxo xoo .oo\n.xx oox o..\n\nxx. oox oxx\noox oxx xxo\nxo. oxo x.x\n\no.x .x. xx.\n.xo ox. ooo\n.ox xo. ..o\n6 2", "output": "ox. o.x .o. \nxxo xoo .oo \n.xx oox o.. \n\nxx. oox oxx \noox oxx xxo \nxo. oxo x.x \n\no.x !x! xx. \n.xo ox! ooo \n.ox xo! ..o " }, { "input": "oxo xoo ox.\nxxx xoo xxo\nxoo xxx xox\n\nxxx xxx xoo\nooo o.o oxx\nxxo ooo xxx\n\nooo oox ooo\nooo oxo xxx\nxxo xox xxo\n6 1", "output": "oxo xoo ox! \nxxx xoo xxo \nxoo xxx xox \n\nxxx xxx xoo \nooo o!o oxx \nxxo ooo xxx \n\nooo oox ooo \nooo oxo xxx \nxxo xox xxo " }, { "input": ".xo oxx xoo\nooo .xo xxx\noxo oox xoo\n\nx.o xoo xxx\nxo. oxo oxx\nx.x xoo o.o\n\nxoo xox oxx\nooo .x. .xx\nxox x.. xoo\n6 5", "output": ".xo oxx xoo \nooo .xo xxx \noxo oox xoo \n\nx.o xoo xxx \nxo. oxo oxx \nx.x xoo o.o \n\nxoo xox oxx \nooo !x! .xx \nxox x!! xoo " }, { "input": "oxo xox ooo\n.xo xxo oxx\nxxx oxo xxx\n\nxxo oxx .xx\nxo. xoo oxx\noxo oxx xox\n\nxoo ooo oox\nooo ooo xxo\nxxx x.o oxo\n2 2", "output": "oxo xox ooo \n!xo xxo oxx \nxxx oxo xxx \n\nxxo oxx !xx \nxo! xoo oxx \noxo oxx xox \n\nxoo ooo oox \nooo ooo xxo \nxxx x!o oxo " }, { "input": "xox xxx xoo\nxoo xxx oxo\nxoo oox xoo\n\noxo oox xox\noxo xox xox\noox xoo oox\n\no.o xox oox\noox xxo xxo\nxox xxx oxo\n3 4", "output": "xox xxx xoo \nxoo xxx oxo \nxoo oox xoo \n\noxo oox xox \noxo xox xox \noox xoo oox \n\no!o xox oox \noox xxo xxo \nxox xxx oxo " }, { "input": "ooo xxx .x.\nxxo oox ooo\n.o. oox xxx\n\nxox oxx xxo\nxxx oxx oxx\noxx ooo ooo\n\n.oo xoo xo.\nxxo oox ooo\nxox xxx xxo\n5 1", "output": "ooo xxx !x! \nxxo oox ooo \n!o! oox xxx \n\nxox oxx xxo \nxxx oxx oxx \noxx ooo ooo \n\n!oo xoo xo! \nxxo oox ooo \nxox xxx xxo " } ]
1,514,042,652
4,752
Python 3
WRONG_ANSWER
PRETESTS
0
61
5,529,600
field = [input().split() for _ in range(11)] del field[7] del field[3] last_y,last_x = [int(i)-1 for i in input().split()] f_x = last_x % 3 f_y = last_y % 3 for i in range(3): if '.' in field[f_y*3+i][f_x]: for y in range(3): field[f_y*3+y][f_x] = field[f_y*3+y][f_x].replace('.','!') break; else: for y in range(9): for x in range(3): field[y][x] = field[y][x].replace('.','!') print(str([str(s)[2:-2].replace("', '", ' ') for s in field])[2:-2].replace("', '",'\n'))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (*x**l*,<=*y**l*) in some small field, the next move should be done in one of the cells of the small field with coordinates (*x**l*,<=*y**l*). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input Specification: First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Specification: Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Demo Input: ['... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4\n', 'xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4\n', 'o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5\n'] Demo Output: ['... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... \n\n', 'xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\n', 'o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n'] Note: In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
```python field = [input().split() for _ in range(11)] del field[7] del field[3] last_y,last_x = [int(i)-1 for i in input().split()] f_x = last_x % 3 f_y = last_y % 3 for i in range(3): if '.' in field[f_y*3+i][f_x]: for y in range(3): field[f_y*3+y][f_x] = field[f_y*3+y][f_x].replace('.','!') break; else: for y in range(9): for x in range(3): field[y][x] = field[y][x].replace('.','!') print(str([str(s)[2:-2].replace("', '", ' ') for s in field])[2:-2].replace("', '",'\n')) ```
0
922
A
Cloning Toys
PROGRAMMING
1,300
[ "implementation" ]
null
null
Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "6 3\n", "4 2\n", "1000 1001\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
500
[ { "input": "6 3", "output": "Yes" }, { "input": "4 2", "output": "No" }, { "input": "1000 1001", "output": "Yes" }, { "input": "1000000000 999999999", "output": "Yes" }, { "input": "81452244 81452247", "output": "No" }, { "input": "188032448 86524683", "output": "Yes" }, { "input": "365289629 223844571", "output": "No" }, { "input": "247579518 361164458", "output": "No" }, { "input": "424836699 793451637", "output": "No" }, { "input": "602093880 930771525", "output": "No" }, { "input": "779351061 773124120", "output": "Yes" }, { "input": "661640950 836815080", "output": "No" }, { "input": "543930839 974134967", "output": "No" }, { "input": "16155311 406422145", "output": "No" }, { "input": "81601559 445618240", "output": "No" }, { "input": "963891449 582938127", "output": "No" }, { "input": "141148629 351661795", "output": "No" }, { "input": "318405810 783948974", "output": "No" }, { "input": "495662991 921268861", "output": "No" }, { "input": "1 0", "output": "No" }, { "input": "0 1", "output": "Yes" }, { "input": "0 0", "output": "No" }, { "input": "453462237 167520068", "output": "Yes" }, { "input": "630719418 9872663", "output": "Yes" }, { "input": "807976599 442159843", "output": "No" }, { "input": "690266488 579479730", "output": "No" }, { "input": "771581370 589752968", "output": "No" }, { "input": "948838551 727072855", "output": "No" }, { "input": "831128440 790763814", "output": "No" }, { "input": "303352912 928083702", "output": "No" }, { "input": "185642801 65403588", "output": "Yes" }, { "input": "67932690 202723476", "output": "No" }, { "input": "540157163 340043363", "output": "No" }, { "input": "422447052 772330542", "output": "No" }, { "input": "599704233 541054210", "output": "Yes" }, { "input": "481994122 678374097", "output": "No" }, { "input": "48564714 743566477", "output": "No" }, { "input": "225821895 880886365", "output": "No" }, { "input": "403079076 313173543", "output": "Yes" }, { "input": "1000000000 1000000000", "output": "No" }, { "input": "1 1", "output": "No" }, { "input": "1 2", "output": "Yes" }, { "input": "2 1", "output": "No" }, { "input": "2 2", "output": "No" }, { "input": "2 0", "output": "No" }, { "input": "0 2", "output": "No" }, { "input": "1000000000 1", "output": "No" }, { "input": "777777 0", "output": "No" }, { "input": "10 1", "output": "No" }, { "input": "7 0", "output": "No" }, { "input": "3 0", "output": "No" }, { "input": "3 2", "output": "Yes" } ]
1,571,472,484
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
108
0
x,y=input().split() x=int(x) y=int(y) check=abs(x-y) if(check%2==1): print("Yes") else: print("No")
Title: Cloning Toys Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies. Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. Input Specification: The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). Output Specification: Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['6 3\n', '4 2\n', '1000 1001\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n'] Note: In the first example, Imp has to apply the machine twice to original toys and then twice to copies.
```python x,y=input().split() x=int(x) y=int(y) check=abs(x-y) if(check%2==1): print("Yes") else: print("No") ```
0
964
A
Splits
PROGRAMMING
800
[ "math" ]
null
null
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$. For a given $n$, find out the number of different weights of its splits.
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output one integer — the answer to the problem.
[ "7\n", "8\n", "9\n" ]
[ "4\n", "5\n", "5\n" ]
In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
500
[ { "input": "7", "output": "4" }, { "input": "8", "output": "5" }, { "input": "9", "output": "5" }, { "input": "1", "output": "1" }, { "input": "286", "output": "144" }, { "input": "48", "output": "25" }, { "input": "941", "output": "471" }, { "input": "45154", "output": "22578" }, { "input": "60324", "output": "30163" }, { "input": "91840", "output": "45921" }, { "input": "41909", "output": "20955" }, { "input": "58288", "output": "29145" }, { "input": "91641", "output": "45821" }, { "input": "62258", "output": "31130" }, { "input": "79811", "output": "39906" }, { "input": "88740", "output": "44371" }, { "input": "12351", "output": "6176" }, { "input": "1960", "output": "981" }, { "input": "29239", "output": "14620" }, { "input": "85801", "output": "42901" }, { "input": "43255", "output": "21628" }, { "input": "13439", "output": "6720" }, { "input": "35668", "output": "17835" }, { "input": "19122", "output": "9562" }, { "input": "60169", "output": "30085" }, { "input": "50588", "output": "25295" }, { "input": "2467", "output": "1234" }, { "input": "39315", "output": "19658" }, { "input": "29950", "output": "14976" }, { "input": "17286", "output": "8644" }, { "input": "7359066", "output": "3679534" }, { "input": "1016391", "output": "508196" }, { "input": "7928871", "output": "3964436" }, { "input": "3968891", "output": "1984446" }, { "input": "2636452", "output": "1318227" }, { "input": "5076901", "output": "2538451" }, { "input": "9870265", "output": "4935133" }, { "input": "2453786", "output": "1226894" }, { "input": "7263670", "output": "3631836" }, { "input": "1890845", "output": "945423" }, { "input": "574128507", "output": "287064254" }, { "input": "648476655", "output": "324238328" }, { "input": "97349542", "output": "48674772" }, { "input": "716489761", "output": "358244881" }, { "input": "858771038", "output": "429385520" }, { "input": "520778784", "output": "260389393" }, { "input": "439004204", "output": "219502103" }, { "input": "589992198", "output": "294996100" }, { "input": "371106544", "output": "185553273" }, { "input": "894241590", "output": "447120796" }, { "input": "123957268", "output": "61978635" }, { "input": "234149297", "output": "117074649" }, { "input": "789954052", "output": "394977027" }, { "input": "667978920", "output": "333989461" }, { "input": "154647261", "output": "77323631" }, { "input": "751453521", "output": "375726761" }, { "input": "848862308", "output": "424431155" }, { "input": "323926781", "output": "161963391" }, { "input": "576768825", "output": "288384413" }, { "input": "31293802", "output": "15646902" }, { "input": "2", "output": "2" }, { "input": "1000000000", "output": "500000001" }, { "input": "3", "output": "2" } ]
1,540,256,287
2,147,483,647
Python 3
OK
TESTS
63
124
0
q = int(input()) a = q//2 print(a+1)
Title: Splits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$. For a given $n$, find out the number of different weights of its splits. Input Specification: The first line contains one integer $n$ ($1 \leq n \leq 10^9$). Output Specification: Output one integer — the answer to the problem. Demo Input: ['7\n', '8\n', '9\n'] Demo Output: ['4\n', '5\n', '5\n'] Note: In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
```python q = int(input()) a = q//2 print(a+1) ```
3
873
D
Merge Sort
PROGRAMMING
1,800
[ "constructive algorithms", "divide and conquer" ]
null
null
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=&lt;<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions. The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*). The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* — *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted. Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*. Help Ivan to find an array he wants!
The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it.
If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them.
[ "3 3\n", "4 1\n", "5 6\n" ]
[ "2 1 3 ", "1 2 3 4 ", "-1\n" ]
none
0
[ { "input": "3 3", "output": "2 1 3 " }, { "input": "4 1", "output": "1 2 3 4 " }, { "input": "5 6", "output": "-1" }, { "input": "100 100", "output": "-1" }, { "input": "10000 10001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "10000 20001", "output": "-1" }, { "input": "10000 30001", "output": "-1" }, { "input": "20000 10001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "20000 20001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "20000 30001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "30000 10001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "30000 20001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "30000 30001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "40000 10001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "40000 20001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "40000 30001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "50000 10001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "50000 20001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "50000 30001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "60000 10001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "60000 20001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "60000 30001", "output": "2 4 1 6 3 8 5 9 11 7 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 31 33 29 35 32 37 34 38 40 36 42 39 44 41 45 47 43 49 46 51 48 53 50 55 52 57 54 59 56 60 62 58 64 61 66 63 67 69 65 71 68 73 70 74 76 72 78 75 80 77 82 79 84 81 86 83 88 85 89 91 87 93 90 95 92 97 94 99 96 101 98 103 100 104 106 102 108 105 110 107 112 109 114 111 116 113 118 115 119 121 117 123 120 125 122 126 128 124 130 127 132 129 133 135 131 137 134 139 136 141 138 143 140 145 142 147 144 148 150 146 152 149 154 151 155 157..." }, { "input": "70000 10001", "output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..." }, { "input": "70000 20001", "output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..." }, { "input": "70000 30001", "output": "3 1 5 2 7 4 9 6 11 8 13 10 15 12 16 18 14 20 17 22 19 24 21 26 23 28 25 30 27 32 29 33 35 31 37 34 39 36 41 38 43 40 45 42 47 44 49 46 50 52 48 54 51 56 53 58 55 60 57 62 59 64 61 66 63 67 69 65 71 68 73 70 75 72 77 74 79 76 81 78 83 80 84 86 82 88 85 90 87 92 89 94 91 96 93 98 95 100 97 101 103 99 105 102 107 104 109 106 111 108 113 110 115 112 117 114 118 120 116 122 119 124 121 126 123 128 125 130 127 132 129 134 131 135 137 133 139 136 141 138 143 140 145 142 147 144 149 146 151 148 152 154 150 156 153..." }, { "input": "80000 10001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "80000 20001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "80000 30001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27 24 28 30 26 32 29 33 35 31 37 34 38 40 36 42 39 44 41 46 43 47 49 45 51 48 52 54 50 56 53 57 59 55 61 58 62 64 60 66 63 67 69 65 71 68 72 74 70 76 73 77 79 75 81 78 83 80 85 82 86 88 84 90 87 91 93 89 95 92 96 98 94 100 97 101 103 99 105 102 106 108 104 110 107 111 113 109 115 112 116 118 114 120 117 122 119 124 121 125 127 123 129 126 130 132 128 134 131 135 137 133 139 136 140 142 138 144 141 145 147 143 149 146 150 152 148 154 151 155 157..." }, { "input": "90000 10001", "output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..." }, { "input": "90000 20001", "output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..." }, { "input": "90000 30001", "output": "3 1 4 6 2 8 5 9 11 7 13 10 14 16 12 17 19 15 20 22 18 24 21 25 27 23 28 30 26 31 33 29 35 32 36 38 34 39 41 37 42 44 40 46 43 47 49 45 50 52 48 53 55 51 57 54 58 60 56 61 63 59 64 66 62 68 65 69 71 67 72 74 70 75 77 73 79 76 80 82 78 83 85 81 86 88 84 90 87 91 93 89 94 96 92 97 99 95 101 98 102 104 100 105 107 103 108 110 106 112 109 113 115 111 116 118 114 119 121 117 123 120 124 126 122 127 129 125 130 132 128 134 131 135 137 133 138 140 136 141 143 139 145 142 146 148 144 149 151 147 152 154 150 156 153..." }, { "input": "100000 10001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "100000 20001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "100000 30001", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "100000 199999", "output": "2 4 1 5 7 3 8 10 6 11 13 9 14 16 12 17 19 15 20 22 18 23 25 21 26 28 24 29 31 27 32 34 30 35 37 33 38 40 36 41 43 39 44 46 42 47 49 45 50 52 48 53 55 51 56 58 54 59 61 57 62 64 60 65 67 63 68 70 66 71 73 69 74 76 72 77 79 75 80 82 78 83 85 81 86 88 84 89 91 87 92 94 90 96 93 98 95 99 101 97 102 104 100 105 107 103 108 110 106 111 113 109 114 116 112 117 119 115 120 122 118 123 125 121 126 128 124 129 131 127 132 134 130 135 137 133 138 140 136 141 143 139 145 142 147 144 148 150 146 151 153 149 154 156 152..." }, { "input": "10 17", "output": "3 1 4 6 2 8 5 9 7 10 " } ]
1,697,872,053
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
77
3,072,000
from math import log2,ceil def swap(a,i,j): x = a[i] a[i] = a[j] a[j] = x def invert(a,q): swap(a,q-1,q) def invertrec(a,p,r,k,i): q = (p+r)//2 if (r-p>1 and i < k): invert(a,q) i+=2 j = k - i if (j == 0): return if (j == 2): invertrec(a,q,r,k,i) if (j == 4): invertrec(a,p,q,k,i) invertrec(a,q,r,k,i) def maxc(n): return 2*n-1 #if n == 1: return 1 #elif(log2(n)-int(log2(n)) == 0): # return (2*n) -1 #else: # return 1 + maxc(x:=n//2) + maxc(n-x) def solvel(k,n): f = lambda i: 2**(i)-1 l=0 r=n+1 while (r-l>1): m = (l+r)//2 if(k < f(m)): r=m else: l=m return (l,r) n,k = (int(x) for x in input().split()) if (k%2 == 0 or 2*n-1 < k) : print(-1) else: a = list(range(1,n+1)) invertrec(a,0,n,k,1) print(*a)
Title: Merge Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=&lt;<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions. The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*). The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* — *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted. Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*. Help Ivan to find an array he wants! Input Specification: The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it. Output Specification: If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them. Demo Input: ['3 3\n', '4 1\n', '5 6\n'] Demo Output: ['2 1 3 ', '1 2 3 4 ', '-1\n'] Note: none
```python from math import log2,ceil def swap(a,i,j): x = a[i] a[i] = a[j] a[j] = x def invert(a,q): swap(a,q-1,q) def invertrec(a,p,r,k,i): q = (p+r)//2 if (r-p>1 and i < k): invert(a,q) i+=2 j = k - i if (j == 0): return if (j == 2): invertrec(a,q,r,k,i) if (j == 4): invertrec(a,p,q,k,i) invertrec(a,q,r,k,i) def maxc(n): return 2*n-1 #if n == 1: return 1 #elif(log2(n)-int(log2(n)) == 0): # return (2*n) -1 #else: # return 1 + maxc(x:=n//2) + maxc(n-x) def solvel(k,n): f = lambda i: 2**(i)-1 l=0 r=n+1 while (r-l>1): m = (l+r)//2 if(k < f(m)): r=m else: l=m return (l,r) n,k = (int(x) for x in input().split()) if (k%2 == 0 or 2*n-1 < k) : print(-1) else: a = list(range(1,n+1)) invertrec(a,0,n,k,1) print(*a) ```
0
665
C
Simple Strings
PROGRAMMING
1,300
[ "dp", "greedy", "strings" ]
null
null
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters.
[ "aab\n", "caaab\n", "zscoder\n" ]
[ "bab\n", "cabab\n", "zscoder\n" ]
none
0
[ { "input": "aab", "output": "bab" }, { "input": "caaab", "output": "cabab" }, { "input": "zscoder", "output": "zscoder" }, { "input": "u", "output": "u" }, { "input": "h", "output": "h" }, { "input": "dtottttotd", "output": "dtotataotd" }, { "input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr", "output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra" }, { "input": "aazz", "output": "baza" }, { "input": "zz", "output": "za" }, { "input": "gg", "output": "ga" }, { "input": "qasdasd", "output": "qasdasd" }, { "input": "aa", "output": "ba" }, { "input": "ab", "output": "ab" }, { "input": "zza", "output": "zba" }, { "input": "g", "output": "g" }, { "input": "nnop", "output": "naop" }, { "input": "xx", "output": "xa" } ]
1,644,110,906
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define taskname "" using namespace std; using ll=long long; using ldb=long double; using ull=unsigned long long; string a; int n; void nhap(){ cin >> a; n=a.size(); a='?'+a; } void solve(){ for(int i=2; i<=n; i++){ if(a[i]==a[i-1]){ if(a[i-1]=='a'){ if(a[i+1]=='b'){ a[i]='c'; } else{ a[i]='b'; } } else{ if(a[i+1]=='a'){ if(a[i-1]=='b'){ a[i]='c'; } else{ a[i]='b'; } } else{ a[i]='a'; } } } } for(int i=1; i<=n; i++){ cout << a[i]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin >> t; while(t--){ nhap(); solve(); } }
Title: Simple Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! Input Specification: The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. Output Specification: Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters. Demo Input: ['aab\n', 'caaab\n', 'zscoder\n'] Demo Output: ['bab\n', 'cabab\n', 'zscoder\n'] Note: none
```python #include <bits/stdc++.h> #define taskname "" using namespace std; using ll=long long; using ldb=long double; using ull=unsigned long long; string a; int n; void nhap(){ cin >> a; n=a.size(); a='?'+a; } void solve(){ for(int i=2; i<=n; i++){ if(a[i]==a[i-1]){ if(a[i-1]=='a'){ if(a[i+1]=='b'){ a[i]='c'; } else{ a[i]='b'; } } else{ if(a[i+1]=='a'){ if(a[i-1]=='b'){ a[i]='c'; } else{ a[i]='b'; } } else{ a[i]='a'; } } } } for(int i=1; i<=n; i++){ cout << a[i]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin >> t; while(t--){ nhap(); solve(); } } ```
-1
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,699,895,122
2,147,483,647
Python 3
OK
TESTS
59
46
0
n = int(input()) string = input().lower() # Convert the string to lowercase and create a set of unique letters unique_letters = set(string) # Check if the count of unique letters is 26 if len(unique_letters) == 26: print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python n = int(input()) string = input().lower() # Convert the string to lowercase and create a set of unique letters unique_letters = set(string) # Check if the count of unique letters is 26 if len(unique_letters) == 26: print("YES") else: print("NO") ```
3
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,635,434,599
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
28,364,800
i=int(input()) print("8426"[i%4-1] if i>0 else 1)
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python i=int(input()) print("8426"[i%4-1] if i>0 else 1) ```
0
867
A
Between the Offices
PROGRAMMING
800
[ "implementation" ]
null
null
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).
[ "4\nFSSF\n", "2\nSF\n", "10\nFFFFFFFFFF\n", "10\nSSFFSFFSFF\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n" ]
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
500
[ { "input": "4\nFSSF", "output": "NO" }, { "input": "2\nSF", "output": "YES" }, { "input": "10\nFFFFFFFFFF", "output": "NO" }, { "input": "10\nSSFFSFFSFF", "output": "YES" }, { "input": "20\nSFSFFFFSSFFFFSSSSFSS", "output": "NO" }, { "input": "20\nSSFFFFFSFFFFFFFFFFFF", "output": "YES" }, { "input": "20\nSSFSFSFSFSFSFSFSSFSF", "output": "YES" }, { "input": "20\nSSSSFSFSSFSFSSSSSSFS", "output": "NO" }, { "input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF", "output": "NO" }, { "input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF", "output": "YES" }, { "input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF", "output": "NO" }, { "input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS", "output": "NO" }, { "input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS", "output": "NO" }, { "input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS", "output": "NO" }, { "input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS", "output": "NO" }, { "input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS", "output": "NO" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", "output": "NO" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF", "output": "YES" }, { "input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF", "output": "YES" }, { "input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF", "output": "YES" }, { "input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF", "output": "YES" }, { "input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF", "output": "YES" }, { "input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF", "output": "YES" }, { "input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF", "output": "YES" }, { "input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF", "output": "YES" }, { "input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF", "output": "YES" }, { "input": "2\nSS", "output": "NO" } ]
1,639,978,022
2,147,483,647
PyPy 3-64
OK
TESTS
34
124
0
# import sys # sys.stdout = open('DSA/Stacks/output.txt', 'w') # sys.stdin = open('DSA/Stacks/input.txt', 'r') n = int(input()) ll = list(input()) se = 0 sf = 0 for i in range(len(ll)-1): if ll[i]=='S' and ll[i+1]=="F": sf+=1 elif ll[i]=='F' and ll[i+1]=="S": se+=1 if sf>se: print("YES") else: print("NO")
Title: Between the Offices Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane. You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. Input Specification: The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days. The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. Output Specification: Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO". In the second example you just flew from Seattle to San Francisco, so the answer is "YES". In the third example you stayed the whole period in San Francisco, so the answer is "NO". In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.
```python # import sys # sys.stdout = open('DSA/Stacks/output.txt', 'w') # sys.stdin = open('DSA/Stacks/input.txt', 'r') n = int(input()) ll = list(input()) se = 0 sf = 0 for i in range(len(ll)-1): if ll[i]=='S' and ll[i+1]=="F": sf+=1 elif ll[i]=='F' and ll[i+1]=="S": se+=1 if sf>se: print("YES") else: print("NO") ```
3
399
B
Red and Blue Balls
PROGRAMMING
0
[]
null
null
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside. If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue.
Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\nRBR\n", "4\nRBBR\n", "5\nRBBRR\n" ]
[ "2\n", "6\n", "6\n" ]
The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2. The second example is depicted below. The blue arrow denotes a single operation.
1,000
[ { "input": "3\nRBR", "output": "2" }, { "input": "4\nRBBR", "output": "6" }, { "input": "5\nRBBRR", "output": "6" }, { "input": "5\nRBRBR", "output": "10" }, { "input": "10\nRRBRRBBRRR", "output": "100" }, { "input": "10\nBRBRRRRRRR", "output": "5" }, { "input": "10\nBRRRRRRRRR", "output": "1" }, { "input": "20\nBRBRRRRRRRRRRRRRRRRR", "output": "5" }, { "input": "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1073741820" }, { "input": "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1125899906842609" }, { "input": "20\nRRRBRBBBBBRRRRRRRRRR", "output": "1000" }, { "input": "20\nRRBRBBBBBRRRRRRRRRRR", "output": "500" }, { "input": "1\nR", "output": "0" }, { "input": "1\nB", "output": "1" }, { "input": "2\nRR", "output": "0" }, { "input": "2\nBR", "output": "1" }, { "input": "50\nRRRRRRRRRRBBBBBBRRBBRRRBRRBBBRRRRRRRRRRRRRRRRRRRRR", "output": "479001600" }, { "input": "50\nRBRRRRRBRBRRBBBBBBRRRBRRRRRBBBRRBRRRRRBBBRRRRRRRRR", "output": "1929382195842" }, { "input": "48\nRBRBRRRRBRBRRBRRRRRRRBBBRRBRBRRRBBRRRRRRRRRRRRRR", "output": "13235135754" }, { "input": "30\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "0" }, { "input": "50\nRRBBBBBBBBBBBBBBBBRBRRBBBRBBRBBBRRBRBBBBBRBBRBBRBR", "output": "402373705727996" }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1125899906842623" }, { "input": "19\nRRRRRBRRBRRRRBRBBBB", "output": "500000" }, { "input": "32\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBR", "output": "2147483647" }, { "input": "3\nBBB", "output": "7" }, { "input": "3\nBBR", "output": "3" }, { "input": "3\nBRB", "output": "5" }, { "input": "3\nBRR", "output": "1" }, { "input": "3\nRBB", "output": "6" }, { "input": "3\nRBR", "output": "2" }, { "input": "3\nRRB", "output": "4" }, { "input": "3\nRRR", "output": "0" }, { "input": "2\nRB", "output": "2" }, { "input": "2\nBB", "output": "3" } ]
1,566,686,277
2,147,483,647
Python 3
OK
TESTS
34
109
0
def do(): n = int(input()) stack = [s for s in input()][::-1] b = stack.count("B") res = 0 while b > 0: while stack and stack[-1] == "R": stack.pop() stack[-1] = "R" b -= 1 if len(stack) < n: res += (1 << (n - len(stack))) - 1 stack += ["R"] * (n - len(stack)) res += 1 return res print(do())
Title: Red and Blue Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside. If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue. Output Specification: Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\nRBR\n', '4\nRBBR\n', '5\nRBBRR\n'] Demo Output: ['2\n', '6\n', '6\n'] Note: The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2. The second example is depicted below. The blue arrow denotes a single operation.
```python def do(): n = int(input()) stack = [s for s in input()][::-1] b = stack.count("B") res = 0 while b > 0: while stack and stack[-1] == "R": stack.pop() stack[-1] = "R" b -= 1 if len(stack) < n: res += (1 << (n - len(stack))) - 1 stack += ["R"] * (n - len(stack)) res += 1 return res print(do()) ```
3
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1", "output": "YES" }, { "input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1", "output": "NO" }, { "input": "10 3\n8 3 5 4 2 3 2 2 1", "output": "NO" }, { "input": "10 9\n8 3 5 4 2 3 2 2 1", "output": "YES" }, { "input": "3 2\n1 1", "output": "YES" }, { "input": "3 2\n2 1", "output": "NO" }, { "input": "4 2\n2 1 1", "output": "NO" }, { "input": "4 4\n2 2 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "3 3\n1 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 1 1", "output": "YES" }, { "input": "3 3\n2 1", "output": "YES" }, { "input": "4 4\n1 1 1", "output": "YES" }, { "input": "8 8\n1 1 1 1 1 1 1", "output": "YES" }, { "input": "5 5\n1 1 1 1", "output": "YES" } ]
1,662,471,387
2,147,483,647
Python 3
OK
TESTS
34
46
1,740,800
import math import sys # s,n=map(int,input().split()) # t=True # for m in range(int(input())): # n=int(input()) # s=input() n,k=map(int,input().split()) # ar=[a,b] arr=list(map(int,input().split())) ans=0 while(ans<k-1): ans+=arr[ans] if(ans==k-1): print("YES") else: print("NO")
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. Input Specification: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. Output Specification: If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". Demo Input: ['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
```python import math import sys # s,n=map(int,input().split()) # t=True # for m in range(int(input())): # n=int(input()) # s=input() n,k=map(int,input().split()) # ar=[a,b] arr=list(map(int,input().split())) ans=0 while(ans<k-1): ans+=arr[ans] if(ans==k-1): print("YES") else: print("NO") ```
3
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,670,776,470
2,147,483,647
PyPy 3-64
OK
TESTS
33
62
1,331,200
# FAFA and his Company n = int(input()) w = 0 for i in range(1, n+1): if n-i != 0: if (n-i) % i == 0: w = w+1 print(w)
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 # FAFA and his Company n = int(input()) w = 0 for i in range(1, n+1): if n-i != 0: if (n-i) % i == 0: w = w+1 print(w) ```
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,694,064,546
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
input_string=input() for char in input_string: result=char.lower() print(result)
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 input_string=input() for char in input_string: result=char.lower() print(result) ```
0
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894", "output": "894" }, { "input": "6058 8581", "output": "8581" }, { "input": "97259 41764", "output": "125292" }, { "input": "453145 333625", "output": "667250" }, { "input": "2233224 4394826", "output": "4394826" }, { "input": "76770926 13350712", "output": "80104272" }, { "input": "687355301 142098087", "output": "710490435" }, { "input": "1000000000 999999999", "output": "1999999998" }, { "input": "1000000000 1000000000", "output": "2000000000" }, { "input": "999999999 1000000000", "output": "1000000000" }, { "input": "1000000000 1", "output": "1000000001" }, { "input": "1000000000 2", "output": "1000000002" }, { "input": "999999999 1", "output": "1000000000" }, { "input": "100000000 1", "output": "100000001" }, { "input": "999999999 500000000", "output": "1000000000" }, { "input": "999999990 10", "output": "1000000000" }, { "input": "1000000000 999999997", "output": "1999999994" }, { "input": "999999999 2", "output": "1000000000" }, { "input": "999999984 1", "output": "999999985" }, { "input": "999999983 1", "output": "999999984" }, { "input": "666666666 1", "output": "666666667" }, { "input": "1000000000 990000000", "output": "1980000000" }, { "input": "41 48", "output": "48" }, { "input": "123456 2", "output": "123458" }, { "input": "111 111", "output": "222" }, { "input": "878787 1", "output": "878788" }, { "input": "121 1", "output": "122" }, { "input": "114514 114514", "output": "229028" }, { "input": "500000001 1000000000", "output": "1000000000" }, { "input": "999999997 1", "output": "999999998" }, { "input": "100000000 10", "output": "100000010" } ]
1,485,973,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
4,608,000
print ("Hello World");
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Output Specification: Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Demo Input: ['5 3\n', '25 13\n', '26 13\n'] Demo Output: ['6\n', '26\n', '39\n'] Note: none
```python print ("Hello World"); ```
0
909
C
Python Indentation
PROGRAMMING
1,800
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
1,500
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns", "output": "666443222" }, { "input": "4\nf\nf\ns\ns", "output": "3" }, { "input": "2\nf\ns", "output": "1" }, { "input": "1\ns", "output": "1" }, { "input": "3\nf\nf\ns", "output": "1" }, { "input": "2\ns\ns", "output": "1" }, { "input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns", "output": "479461584" }, { "input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns", "output": "392847498" } ]
1,515,051,028
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
124
6,553,600
cmap = dict() def countStmt(a, l): if (len(a)==1): return 1 if (a,l) in cmap: return cmap[(a,l)] s = 0 if a[0]=='s': for i in range(l+1): s+=countStmt(a[1:], i) else: s = countStmt(a[1:], l+1) cmap[(a,l)] = s return s n = int(input()) a = "" for i in range(n): s = input() a += s print(countStmt(a, 0))
Title: Python Indentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program. Input Specification: The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. Output Specification: Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. Demo Input: ['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n'] Demo Output: ['1\n', '2\n'] Note: In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
```python cmap = dict() def countStmt(a, l): if (len(a)==1): return 1 if (a,l) in cmap: return cmap[(a,l)] s = 0 if a[0]=='s': for i in range(l+1): s+=countStmt(a[1:], i) else: s = countStmt(a[1:], l+1) cmap[(a,l)] = s return s n = int(input()) a = "" for i in range(n): s = input() a += s print(countStmt(a, 0)) ```
0
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Print a single line containing a positive integer *m* — the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
1,595,171,881
2,147,483,647
Python 3
OK
TESTS
10
108
6,963,200
t=int(input()) n=[[1 for x in range(t)]for x in range(t)] for x in range(t-1): for y in range(t-1-x): n[x+1][y+x+1]=n[x+1][y+x]+n[x][y+x+1] n[y+x+1][x+1]=n[x+y][x+1]+n[y+x+1][x] print(n[-1][-1])
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=×<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. Input Specification: The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. Output Specification: Print a single line containing a positive integer *m* — the maximum value in the table. Demo Input: ['1\n', '5\n'] Demo Output: ['1', '70'] Note: In the second test the rows of the table look as follows:
```python t=int(input()) n=[[1 for x in range(t)]for x in range(t)] for x in range(t-1): for y in range(t-1-x): n[x+1][y+x+1]=n[x+1][y+x]+n[x][y+x+1] n[y+x+1][x+1]=n[x+y][x+1]+n[y+x+1][x] print(n[-1][-1]) ```
3
496
B
Secret Combination
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display.
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
[ "3\n579\n", "4\n2014\n" ]
[ "024\n", "0142\n" ]
none
1,000
[ { "input": "3\n579", "output": "024" }, { "input": "4\n2014", "output": "0142" }, { "input": "1\n1", "output": "0" }, { "input": "3\n039", "output": "014" }, { "input": "4\n4444", "output": "0000" }, { "input": "5\n46802", "output": "02468" }, { "input": "10\n4447444444", "output": "0000000003" }, { "input": "10\n5810438174", "output": "0147609473" }, { "input": "30\n027027027027027027027027027027", "output": "027027027027027027027027027027" }, { "input": "50\n41012516454101251645410125164541012516454101251645", "output": "01076781720107678172010767817201076781720107678172" }, { "input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304", "output": "001011960020119600201196002011960020119600201996002011960020119620201196" }, { "input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818" }, { "input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544", "output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086" }, { "input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656", "output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006" }, { "input": "1\n0", "output": "0" } ]
1,566,438,550
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
14
2,000
0
def upshift(s): for i in range(n): if s[i] == '9': s[i] = '0' else: s[i] = chr(ord(s[i])+1) return s def lshift(s): k = [s[n-1]] for i in range (0, n-1): k.append(s[i]) s = k return s def copy(s): k = [] for i in s: k.append(i) return k n = int(input()) s = list(str(input())) small = copy(s) for i in range(n): s = lshift(s) for j in range(10): s = upshift(s) if small > s: small = copy(s) for i in small: print(i, end='')
Title: Secret Combination Time Limit: None seconds Memory Limit: None megabytes Problem Description: You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display. Output Specification: Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. Demo Input: ['3\n579\n', '4\n2014\n'] Demo Output: ['024\n', '0142\n'] Note: none
```python def upshift(s): for i in range(n): if s[i] == '9': s[i] = '0' else: s[i] = chr(ord(s[i])+1) return s def lshift(s): k = [s[n-1]] for i in range (0, n-1): k.append(s[i]) s = k return s def copy(s): k = [] for i in s: k.append(i) return k n = int(input()) s = list(str(input())) small = copy(s) for i in range(n): s = lshift(s) for j in range(10): s = upshift(s) if small > s: small = copy(s) for i in small: print(i, end='') ```
0
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty. When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible. You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, { "input": "CACCBAA.BC", "output": "Yes" }, { "input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.", "output": "Yes" }, { "input": "A", "output": "No" }, { "input": "..", "output": "No" }, { "input": "BC", "output": "No" }, { "input": "CAB", "output": "Yes" }, { "input": "A.CB", "output": "No" }, { "input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB", "output": "Yes" }, { "input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.", "output": "No" }, { "input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC", "output": "Yes" }, { "input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.", "output": "No" }, { "input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A", "output": "No" }, { "input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB", "output": "Yes" }, { "input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB", "output": "Yes" }, { "input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB", "output": "Yes" }, { "input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB", "output": "Yes" }, { "input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB", "output": "Yes" }, { "input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C", "output": "Yes" }, { "input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.", "output": "Yes" }, { "input": ".BAB.", "output": "No" }, { "input": "BBBBBBBBB", "output": "No" }, { "input": "..AAC..", "output": "No" }, { "input": ".AAABBBCCC.", "output": "No" }, { "input": "AAABC", "output": "Yes" }, { "input": "BBB", "output": "No" }, { "input": "AAAAABABAAAAA", "output": "No" }, { "input": "AABBCC", "output": "No" }, { "input": ".BA", "output": "No" }, { "input": "CAAAAB", "output": "No" } ]
1,597,597,526
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
16
124
0
s = input().split(".") count = 0 for i in s: if("A" in i and "B" in i and "C" in i): count += 1 print("Yes") break if(count == 0): print("No")
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty. When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible. You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. Input Specification: The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. Output Specification: Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['.BAC.\n', 'AA..CB\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
```python s = input().split(".") count = 0 for i in s: if("A" in i and "B" in i and "C" in i): count += 1 print("Yes") break if(count == 0): print("No") ```
0
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 998320124 820674098", "output": "No" }, { "input": "948253616 -83299062 1031552680", "output": "Yes" }, { "input": "711980199 216568284 928548487", "output": "Yes" }, { "input": "-453961301 271150176 725111473", "output": "No" }, { "input": "0 0 2000000000", "output": "Yes" }, { "input": "0 0 1999999999", "output": "No" }, { "input": "1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 1000000000", "output": "No" }, { "input": "-1 -1 3", "output": "No" }, { "input": "919785634 216774719 129321944", "output": "No" }, { "input": "-467780354 -721273539 1369030008", "output": "No" }, { "input": "-232833910 -880680184 1774549792", "output": "Yes" }, { "input": "45535578 402686155 1011249824", "output": "No" }, { "input": "-203250176 -30379840 233630015", "output": "No" }, { "input": "-814516648 -75830576 890347222", "output": "No" }, { "input": "869184175 -511854751 1381038923", "output": "No" }, { "input": "552884998 -262338193 815223187", "output": "No" }, { "input": "-133874494 857573117 991447611", "output": "Yes" }, { "input": "169406792 786701289 956108082", "output": "No" }, { "input": "30237137 -989203246 1019440385", "output": "Yes" }, { "input": "576608216 -617624133 1194232352", "output": "No" }, { "input": "-662360368 97618995 759979367", "output": "Yes" }, { "input": "-115989290 321714461 437703756", "output": "No" }, { "input": "-1 -3 2", "output": "No" }, { "input": "-2 -2 2", "output": "No" }, { "input": "0 0 1", "output": "No" }, { "input": "0 -1 7", "output": "Yes" }, { "input": "1 2 7", "output": "Yes" }, { "input": "0 5 6", "output": "No" }, { "input": "0 -4 2", "output": "No" }, { "input": "-5 5 2", "output": "No" }, { "input": "-5 -2 7", "output": "Yes" }, { "input": "5 -5 2", "output": "No" } ]
1,657,609,016
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
77
0
a,b,s=map(int,input().split()) if (abs(s-(a+b)))%2==0 and (s>=a and s>=b): print('YES') else: print('NO')
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? Input Specification: You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. Output Specification: If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Demo Input: ['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n'] Demo Output: ['No\n', 'Yes\n', 'No\n', 'Yes\n'] Note: In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a,b,s=map(int,input().split()) if (abs(s-(a+b)))%2==0 and (s>=a and s>=b): print('YES') else: print('NO') ```
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,673,359,209
2,147,483,647
Python 3
OK
TESTS
47
78
0
n,x=[int(x) for x in input().split()] res=0 for k in range(1,n+1): if k*k<=x and x<=k*n and x%k==0: if x==k*k: res+=1 else: res+=2 print(res)
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=[int(x) for x in input().split()] res=0 for k in range(1,n+1): if k*k<=x and x<=k*n and x%k==0: if x==k*k: res+=1 else: res+=2 print(res) ```
3
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Print one integer — the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126", "output": "12" }, { "input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850", "output": "36" }, { "input": "2 6 8\n2 1", "output": "0" }, { "input": "5 15 16\n7 11 5 12 8", "output": "2" }, { "input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574", "output": "4" }, { "input": "5 234613 716125\n642626 494941 234613 234613 234613", "output": "0" }, { "input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547", "output": "0" }, { "input": "5 10 20\n10 10 10 10 1", "output": "1" }, { "input": "5 10 11\n10 10 10 10 1", "output": "2" }, { "input": "3 10 10\n4 3 3", "output": "0" }, { "input": "3 5 5\n5 5 5", "output": "1" }, { "input": "3 4 14\n5 5 5", "output": "0" }, { "input": "2 7 10\n1234 1234", "output": "0" }, { "input": "1 5 6\n10", "output": "0" }, { "input": "3 4 6\n1 2 3", "output": "0" }, { "input": "5 10 12\n13 13 13 13 13", "output": "0" }, { "input": "3 4 5\n5 7 9", "output": "0" }, { "input": "3 10 100\n5 5 5", "output": "0" }, { "input": "5 1 2\n2 2 2 2 2", "output": "0" }, { "input": "5 5 5\n5 5 5 5 5", "output": "2" }, { "input": "2 2 5\n5 5", "output": "0" }, { "input": "3 1 4\n2 2 2", "output": "0" } ]
1,689,849,952
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
93
14,438,400
# -*- coding:utf-8 -*- from typing import List def Juicer(A:List[int], b:int, d:int)->int: # write code here sum = 0 for weight in A: if weight <= b: sum += weight if sum == 0: return 0 elif (sum % d) != 0: ret = sum // d else: ret = (sum // d) - 1 return ret if __name__ == '__main__': n,b,d = map(int, input().split()) L = list(map(int, input().split())) print(Juicer(L, b, d))
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? Input Specification: The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. Output Specification: Print one integer — the number of times Kolya will have to empty the waste section. Demo Input: ['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n'] Demo Output: ['1\n', '0\n', '1\n', '0\n'] Note: In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
```python # -*- coding:utf-8 -*- from typing import List def Juicer(A:List[int], b:int, d:int)->int: # write code here sum = 0 for weight in A: if weight <= b: sum += weight if sum == 0: return 0 elif (sum % d) != 0: ret = sum // d else: ret = (sum // d) - 1 return ret if __name__ == '__main__': n,b,d = map(int, input().split()) L = list(map(int, input().split())) print(Juicer(L, b, d)) ```
0
353
B
Two Heaps
PROGRAMMING
1,900
[ "combinatorics", "constructive algorithms", "greedy", "implementation", "math", "sortings" ]
null
null
Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap. Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
The first line contains integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* space-separated integers *a**i* (10<=≤<=*a**i*<=≤<=99), denoting the numbers on the cubes.
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·*n* numbers *b**i* (1<=≤<=*b**i*<=≤<=2). The numbers mean: the *i*-th cube belongs to the *b**i*-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
[ "1\n10 99\n", "2\n13 24 13 45\n" ]
[ "1\n2 1 \n", "4\n1 2 2 1 \n" ]
In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one. In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
1,500
[ { "input": "1\n10 99", "output": "1\n2 1 " }, { "input": "2\n13 24 13 45", "output": "4\n1 2 2 1 " }, { "input": "5\n21 60 18 21 17 39 58 74 62 34", "output": "25\n1 1 1 2 2 1 2 1 2 2 " }, { "input": "10\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98", "output": "100\n1 2 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 2 2 1 " }, { "input": "20\n80 56 58 61 75 60 25 49 59 15 43 39 21 73 67 13 75 31 18 87 32 44 53 15 53 76 79 94 85 80 27 25 48 78 32 18 20 78 46 37", "output": "400\n1 2 1 2 1 1 1 1 2 1 1 2 2 2 1 2 2 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1 1 " }, { "input": "50\n49 13 81 20 73 62 19 49 65 95 32 84 24 96 51 57 53 83 40 44 26 65 78 80 92 87 87 95 56 46 22 44 69 80 41 61 97 92 58 53 42 78 53 19 47 36 25 77 65 81 14 61 38 99 27 58 67 37 67 80 77 51 32 43 31 48 19 79 31 91 46 97 91 71 27 63 22 84 73 73 89 44 34 84 70 23 45 31 56 73 83 38 68 45 99 33 83 86 87 80", "output": "1936\n1 2 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 1 1 2 1 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 1 2 2 1 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 2 2 2 2 1 2 1 2 2 " }, { "input": "2\n10 10 10 11", "output": "2\n1 2 1 2 " } ]
1,586,335,740
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
248
0
n = int(input()) a = list(enumerate(input().split())) x = [0]*(2*n) a.sort(key=lambda x:x[1]) total = len(set(map(lambda x:x[1],a[::2])))*len(set(map(lambda x:x[1],a[1::2]))) print(total) c=1 for i,e in a: x[i]=1+c%2 c+=1 print(*x)
Title: Two Heaps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has 2·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap. Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible? Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100). The second line contains 2·*n* space-separated integers *a**i* (10<=≤<=*a**i*<=≤<=99), denoting the numbers on the cubes. Output Specification: In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·*n* numbers *b**i* (1<=≤<=*b**i*<=≤<=2). The numbers mean: the *i*-th cube belongs to the *b**i*-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them. Demo Input: ['1\n10 99\n', '2\n13 24 13 45\n'] Demo Output: ['1\n2 1 \n', '4\n1 2 2 1 \n'] Note: In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one. In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
```python n = int(input()) a = list(enumerate(input().split())) x = [0]*(2*n) a.sort(key=lambda x:x[1]) total = len(set(map(lambda x:x[1],a[::2])))*len(set(map(lambda x:x[1],a[1::2]))) print(total) c=1 for i,e in a: x[i]=1+c%2 c+=1 print(*x) ```
0
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 13 4 3 2", "output": "36" }, { "input": "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7", "output": "55" }, { "input": "16\n1 2 3 4 13 14 15 16 9 10 11 12 5 6 7 8", "output": "36" }, { "input": "6\n1000 1 2000 1 3000 1", "output": "11995" }, { "input": "1\n0", "output": "0" }, { "input": "5\n1000000000 1 1000000000 1 1000000000", "output": "4999999996" }, { "input": "5\n1000000000 0 1000000000 0 1000000000", "output": "5000000000" }, { "input": "10\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0", "output": "10000000000" }, { "input": "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "19000000000" }, { "input": "7\n0 1000000000 0 1000000000 0 1000000000 0", "output": "6000000000" }, { "input": "4\n1000000000 -1000000000 1000000000 -1000000000", "output": "7000000000" }, { "input": "20\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "39000000000" }, { "input": "11\n1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000", "output": "11000000000" }, { "input": "5\n1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "9000000000" }, { "input": "22\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "43000000000" } ]
1,447,606,024
724
Python 3
OK
TESTS
76
218
18,022,400
n = int(input()) ans = 0 a = [0] + list(map(int, input().split())) for i in range(n): ans += abs(a[i + 1] - a[i]) print(ans)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). Output Specification: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Demo Input: ['5\n1 2 3 4 5\n', '4\n1 2 2 1\n'] Demo Output: ['5', '3'] Note: In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
```python n = int(input()) ans = 0 a = [0] + list(map(int, input().split())) for i in range(n): ans += abs(a[i + 1] - a[i]) print(ans) ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,691,250,844
2,147,483,647
Python 3
OK
TESTS
33
46
0
def prime(x): if x <= 1: return False for i in range(2, int(x**0.5) + 1): if x % i == 0: return False return True n = int(input()) x = 4 # Start with the smallest possible composite number verif = True while x < n and verif: x += 1 if not prime(x) and not prime(n - x): print(x, n - x) verif = False
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python def prime(x): if x <= 1: return False for i in range(2, int(x**0.5) + 1): if x % i == 0: return False return True n = int(input()) x = 4 # Start with the smallest possible composite number verif = True while x < n and verif: x += 1 if not prime(x) and not prime(n - x): print(x, n - x) verif = False ```
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
1,696,897,798
2,147,483,647
Python 3
OK
TESTS
37
124
204,800
n = input() com = [int(i) for i in input().split()] # print(com) rez = 0 k = 1 while k < len(com): # print(com[:k]) if com[k] > max(com[:k]) or com[k] < min(com[:k]): rez += 1 k += 1 print(rez)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python n = input() com = [int(i) for i in input().split()] # print(com) rez = 0 k = 1 while k < len(com): # print(com[:k]) if com[k] > max(com[:k]) or com[k] < min(com[:k]): rez += 1 k += 1 print(rez) ```
3
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "Still Rozdil" }, { "input": "4\n1000000000 100000000 1000000 1000000", "output": "Still Rozdil" }, { "input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6", "output": "Still Rozdil" }, { "input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7", "output": "8" }, { "input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11", "output": "Still Rozdil" }, { "input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "32" }, { "input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63", "output": "19" }, { "input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622", "output": "68" }, { "input": "5\n5 5 2 3 1", "output": "5" }, { "input": "1\n1000000000", "output": "1" }, { "input": "3\n7 7 4", "output": "3" }, { "input": "3\n2 2 1", "output": "3" }, { "input": "3\n4 4 3", "output": "3" }, { "input": "2\n10000001 10000002", "output": "1" }, { "input": "4\n3 3 2 1", "output": "4" }, { "input": "3\n1 2 3", "output": "1" }, { "input": "2\n1000000000 100000000", "output": "2" }, { "input": "1\n99999999", "output": "1" }, { "input": "3\n5 5 3", "output": "3" }, { "input": "3\n7 7 5", "output": "3" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "4\n10 10 10 1", "output": "4" } ]
1,627,338,486
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
13,824,000
c = int(input()) time = list(map(int, input().split())) match = 0 answer = 0 for x in range(c): if time[x] == min(time): match += 1 if match == 2: answer = 1 break if answer == 1: print("Still Rozdil") elif answer == 0: for x in range(c): if time[x] == min(time): break print(x+1)
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. Output Specification: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Demo Input: ['2\n7 4\n', '7\n7 4 47 100 4 9 12\n'] Demo Output: ['2\n', 'Still Rozdil\n'] Note: In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".
```python c = int(input()) time = list(map(int, input().split())) match = 0 answer = 0 for x in range(c): if time[x] == min(time): match += 1 if match == 2: answer = 1 break if answer == 1: print("Still Rozdil") elif answer == 0: for x in range(c): if time[x] == min(time): break print(x+1) ```
0
408
B
Garland
PROGRAMMING
1,200
[ "implementation" ]
null
null
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
[ "aaabbac\naabbccac\n", "a\nz\n" ]
[ "6\n", "-1" ]
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
1,000
[ { "input": "aaabbac\naabbccac", "output": "6" }, { "input": "a\nz", "output": "-1" }, { "input": "r\nr", "output": "1" }, { "input": "stnsdn\nndnndsn", "output": "4" }, { "input": "yqfqfp\ntttwtqq", "output": "-1" }, { "input": "zzbbrrtrtzr\ntbbtrrrzr", "output": "9" }, { "input": "ivvfisvsvii\npaihjinno", "output": "-1" }, { "input": "zbvwnlgkshqerxptyod\nz", "output": "1" }, { "input": "xlktwjymocqrahnbesf\nfoo", "output": "2" }, { "input": "bbzmzqazmbambnmzaabznmbabzqnaabmabmnnabbmnzaanzzezebzabqaabzqaemeqqammmbazmmz\naznnbbmeebmanbeemzmemqbaeebnqenqzzbanebmnzqqebqmmnmqqzmmeqqqaaezemmazqqmqaqnnqqzbzeeazammmenbbamzbmnaenemenaaaebnmanebqmqnznqbenmqqnnnaeaebqmamennmqqeaaqqbammnzqmnmqnqbbezmemznqmanzmmqzzzzembqnzqbanamezqaqbazenenqqznqaebzaeezbqqbmeeaqnmmbnqbbnmaqqemaeaezaabmbnbzzaae", "output": "77" }, { "input": "lccfdfnfflncddlksndcwnfcllnnaswcdnldafcalssfcdnkkaklwnnacsncfwanwnwfadawcsdcfwflnnlfsfclkfknlaldna\nuaaldlllhedgugugueahddhedbuddaedhaaeugdubaealbgbagedldbl", "output": "-1" }, { "input": "hvewdvwdwudrwarwmddwnazmwauzatrmwptwwevavpmwrtruwnpwantewrnwmepdwvtmnveanunrvrtwpvhhnuhnmpptdttzmmndtvudmzhhannmmnahdpzamuvhzaavnhtnumwrwvttdetvuewaaennddwuvzvaptdzrzhtetwwzmzedrwuvrwznprhdvnavrruvvhzuwpdtmpwmzrwvermrhdamv\nuvzhwtpuputnahwwarduzddhpnwwvettprwavdmnztdnrddmarmvuevtdezndnezvarhmppwwnmvnrtddzhhnzrwuhvpwmezuurundarwdazwptrpeurrnwautddnhdmhtwhwvvtavdzezumetzezpazndhuentmrhamutrtttpevtuutemdnvwnwnmnvmznatneweuaahdavmaddhnrdenwwztrwh", "output": "199" }, { "input": "aaccddff\nabcdf", "output": "-1" } ]
1,659,616,967
2,147,483,647
Python 3
OK
TESTS
21
46
0
x=input() y=input() d1={} d2={} count=0 for i in x: d1[i]=x.count(i) for i in y: d2[i]=y.count(i) for i in d2.keys(): if i in d1.keys(): if d1[i]<d2[i]: count+=d1[i] else: count+=d2[i] else: count=-1 break print(count)
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get. Input Specification: The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make. Output Specification: Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. Demo Input: ['aaabbac\naabbccac\n', 'a\nz\n'] Demo Output: ['6\n', '-1'] Note: In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.
```python x=input() y=input() d1={} d2={} count=0 for i in x: d1[i]=x.count(i) for i in y: d2[i]=y.count(i) for i in d2.keys(): if i in d1.keys(): if d1[i]<d2[i]: count+=d1[i] else: count+=d2[i] else: count=-1 break print(count) ```
3
817
C
Really Big Numbers
PROGRAMMING
1,600
[ "binary search", "brute force", "dp", "math" ]
null
null
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Print one integer — the quantity of really big numbers that are not greater than *n*.
[ "12 1\n", "25 20\n", "10 9\n" ]
[ "3\n", "0\n", "1\n" ]
In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
0
[ { "input": "12 1", "output": "3" }, { "input": "25 20", "output": "0" }, { "input": "10 9", "output": "1" }, { "input": "300 1000", "output": "0" }, { "input": "500 1000", "output": "0" }, { "input": "1000 2000", "output": "0" }, { "input": "10000 1000", "output": "8991" }, { "input": "1000000000000000000 1000000000000000000", "output": "0" }, { "input": "1000000000000000000 100000000000000000", "output": "899999999999999991" }, { "input": "1000000000000000000 10000000000000000", "output": "989999999999999991" }, { "input": "1000000000000000000 1000000000000000", "output": "998999999999999991" }, { "input": "1000000000000000000 100000000000000", "output": "999899999999999991" }, { "input": "1000000000000000000 200000000000000000", "output": "799999999999999991" }, { "input": "10 5", "output": "1" }, { "input": "20 5", "output": "11" }, { "input": "20 9", "output": "11" }, { "input": "100 9", "output": "91" }, { "input": "1 1", "output": "0" }, { "input": "130 118", "output": "1" }, { "input": "190 181", "output": "0" }, { "input": "1999 1971", "output": "10" }, { "input": "100 99", "output": "1" }, { "input": "6909094398 719694282", "output": "6189400069" }, { "input": "260 258", "output": "0" }, { "input": "35 19", "output": "6" }, { "input": "100 87", "output": "1" }, { "input": "91 89", "output": "0" }, { "input": "109 89", "output": "10" }, { "input": "109 91", "output": "10" }, { "input": "20331 11580", "output": "8732" }, { "input": "405487470 255750281", "output": "149737161" }, { "input": "17382 12863", "output": "4493" }, { "input": "19725 14457", "output": "5246" }, { "input": "24848 15384", "output": "9449" }, { "input": "25727 15982", "output": "9728" }, { "input": "109 90", "output": "10" }, { "input": "1000000000000000000 999999999999999999", "output": "1" }, { "input": "1000000000000000000 999999999999999998", "output": "1" }, { "input": "1009 980", "output": "10" }, { "input": "999999999999999999 999999999999999838", "output": "0" }, { "input": "1000000000000000000 99999999999999800", "output": "900000000000000061" }, { "input": "8785369357 3377262261", "output": "5408107058" }, { "input": "110 109", "output": "0" }, { "input": "999 777", "output": "200" }, { "input": "327170000015578 77230000029054", "output": "249939999986479" }, { "input": "12515000022229 1791000022317", "output": "10723999999880" }, { "input": "9999999999999 9999999999882", "output": "10" }, { "input": "213 196", "output": "14" }, { "input": "92 82", "output": "0" }, { "input": "148 136", "output": "0" }, { "input": "8 9", "output": "0" }, { "input": "309 299", "output": "0" }, { "input": "9999 9963", "output": "10" }, { "input": "82 81", "output": "0" }, { "input": "9999999 9999936", "output": "10" }, { "input": "171 155", "output": "2" }, { "input": "999 972", "output": "10" }, { "input": "999999999999 999999999891", "output": "10" }, { "input": "9 9", "output": "0" }, { "input": "6900 6885", "output": "1" }, { "input": "96 57", "output": "27" }, { "input": "5 4", "output": "0" }, { "input": "17386 5814", "output": "11557" }, { "input": "493679757404593 316259583979965", "output": "177420173424564" }, { "input": "18474 9478", "output": "8975" }, { "input": "270091571496186 250931112649966", "output": "19160458846177" }, { "input": "565751690089037 381448507916936", "output": "184303182172038" }, { "input": "19 10", "output": "0" } ]
1,569,078,245
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
21
156
1,228,800
def digisum(n): count = 0 while(n>0): count+=n%10 n = n//10 return count n,s = list(map(int,input().split())) l,r = 1,n flag = 0 while l<r: m = l+(r-l)//2 digi_sum = digisum(m) num = m if num-digi_sum>=s: flag = 1 cur = m r = m else: l = m+1 if r-l==1: digi_sum = digisum(l) num = l if num-digi_sum>=s: flag = 1 cur = l break digi_sum = digisum(r) num = r if num-digi_sum>=s: flag = 1 cur = r break if flag==0: print(0) else: print(n-cur+1)
Title: Really Big Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. Input Specification: The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). Output Specification: Print one integer — the quantity of really big numbers that are not greater than *n*. Demo Input: ['12 1\n', '25 20\n', '10 9\n'] Demo Output: ['3\n', '0\n', '1\n'] Note: In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20). In the third example 10 is the only really big number (10 - 1 ≥ 9).
```python def digisum(n): count = 0 while(n>0): count+=n%10 n = n//10 return count n,s = list(map(int,input().split())) l,r = 1,n flag = 0 while l<r: m = l+(r-l)//2 digi_sum = digisum(m) num = m if num-digi_sum>=s: flag = 1 cur = m r = m else: l = m+1 if r-l==1: digi_sum = digisum(l) num = l if num-digi_sum>=s: flag = 1 cur = l break digi_sum = digisum(r) num = r if num-digi_sum>=s: flag = 1 cur = r break if flag==0: print(0) else: print(n-cur+1) ```
0
596
A
Wilbur and Swimming Pool
PROGRAMMING
1,100
[ "geometry", "implementation" ]
null
null
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices. Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend. Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1.
[ "2\n0 0\n1 1\n", "1\n1 1\n" ]
[ "1\n", "-1\n" ]
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square. In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
500
[ { "input": "2\n0 0\n1 1", "output": "1" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n-188 17", "output": "-1" }, { "input": "1\n71 -740", "output": "-1" }, { "input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174", "output": "570456" }, { "input": "2\n14 153\n566 -13", "output": "91632" }, { "input": "2\n-559 894\n314 127", "output": "669591" }, { "input": "1\n-227 -825", "output": "-1" }, { "input": "2\n-187 583\n25 13", "output": "120840" }, { "input": "2\n-337 451\n32 -395", "output": "312174" }, { "input": "4\n-64 -509\n-64 960\n634 -509\n634 960", "output": "1025362" }, { "input": "2\n-922 -505\n712 -683", "output": "290852" }, { "input": "2\n-1000 -1000\n-1000 0", "output": "-1" }, { "input": "2\n-1000 -1000\n0 -1000", "output": "-1" }, { "input": "4\n-414 -891\n-414 896\n346 -891\n346 896", "output": "1358120" }, { "input": "2\n56 31\n704 -121", "output": "98496" }, { "input": "4\n-152 198\n-152 366\n458 198\n458 366", "output": "102480" }, { "input": "3\n-890 778\n-418 296\n-890 296", "output": "227504" }, { "input": "4\n852 -184\n852 724\n970 -184\n970 724", "output": "107144" }, { "input": "1\n858 -279", "output": "-1" }, { "input": "2\n-823 358\n446 358", "output": "-1" }, { "input": "2\n-739 -724\n-739 443", "output": "-1" }, { "input": "2\n686 664\n686 -590", "output": "-1" }, { "input": "3\n-679 301\n240 -23\n-679 -23", "output": "297756" }, { "input": "2\n-259 -978\n978 -978", "output": "-1" }, { "input": "1\n627 -250", "output": "-1" }, { "input": "3\n-281 598\n679 -990\n-281 -990", "output": "1524480" }, { "input": "2\n-414 -431\n-377 -688", "output": "9509" }, { "input": "3\n-406 566\n428 426\n-406 426", "output": "116760" }, { "input": "3\n-686 695\n-547 308\n-686 308", "output": "53793" }, { "input": "1\n-164 -730", "output": "-1" }, { "input": "2\n980 -230\n980 592", "output": "-1" }, { "input": "4\n-925 306\n-925 602\n398 306\n398 602", "output": "391608" }, { "input": "3\n576 -659\n917 -739\n576 -739", "output": "27280" }, { "input": "1\n720 -200", "output": "-1" }, { "input": "4\n-796 -330\n-796 758\n171 -330\n171 758", "output": "1052096" }, { "input": "2\n541 611\n-26 611", "output": "-1" }, { "input": "3\n-487 838\n134 691\n-487 691", "output": "91287" }, { "input": "2\n-862 -181\n-525 -181", "output": "-1" }, { "input": "1\n-717 916", "output": "-1" }, { "input": "1\n-841 -121", "output": "-1" }, { "input": "4\n259 153\n259 999\n266 153\n266 999", "output": "5922" }, { "input": "2\n295 710\n295 254", "output": "-1" }, { "input": "4\n137 -184\n137 700\n712 -184\n712 700", "output": "508300" }, { "input": "2\n157 994\n377 136", "output": "188760" }, { "input": "1\n193 304", "output": "-1" }, { "input": "4\n5 -952\n5 292\n553 -952\n553 292", "output": "681712" }, { "input": "2\n-748 697\n671 575", "output": "173118" }, { "input": "2\n-457 82\n260 -662", "output": "533448" }, { "input": "2\n-761 907\n967 907", "output": "-1" }, { "input": "3\n-639 51\n-321 -539\n-639 -539", "output": "187620" }, { "input": "2\n-480 51\n89 -763", "output": "463166" }, { "input": "4\n459 -440\n459 -94\n872 -440\n872 -94", "output": "142898" }, { "input": "2\n380 -849\n68 -849", "output": "-1" }, { "input": "2\n-257 715\n102 715", "output": "-1" }, { "input": "2\n247 -457\n434 -921", "output": "86768" }, { "input": "4\n-474 -894\n-474 -833\n-446 -894\n-446 -833", "output": "1708" }, { "input": "3\n-318 831\n450 31\n-318 31", "output": "614400" }, { "input": "3\n-282 584\n696 488\n-282 488", "output": "93888" }, { "input": "3\n258 937\n395 856\n258 856", "output": "11097" }, { "input": "1\n-271 -499", "output": "-1" }, { "input": "2\n-612 208\n326 -559", "output": "719446" }, { "input": "2\n115 730\n562 -546", "output": "570372" }, { "input": "2\n-386 95\n-386 750", "output": "-1" }, { "input": "3\n0 0\n0 1\n1 0", "output": "1" }, { "input": "3\n0 4\n3 4\n3 1", "output": "9" }, { "input": "3\n1 1\n1 2\n2 1", "output": "1" }, { "input": "3\n1 4\n4 4\n4 1", "output": "9" }, { "input": "3\n1 1\n2 1\n1 2", "output": "1" }, { "input": "3\n0 0\n1 0\n1 1", "output": "1" }, { "input": "3\n0 0\n0 5\n5 0", "output": "25" }, { "input": "3\n0 0\n0 1\n1 1", "output": "1" }, { "input": "4\n0 0\n1 0\n1 1\n0 1", "output": "1" }, { "input": "3\n4 4\n1 4\n4 1", "output": "9" }, { "input": "3\n0 0\n2 0\n2 1", "output": "2" }, { "input": "3\n0 0\n2 0\n0 2", "output": "4" }, { "input": "3\n0 0\n0 1\n5 0", "output": "5" }, { "input": "3\n1 1\n1 3\n3 1", "output": "4" }, { "input": "4\n0 0\n1 0\n0 1\n1 1", "output": "1" }, { "input": "2\n1 0\n2 1", "output": "1" }, { "input": "3\n0 0\n1 0\n0 1", "output": "1" }, { "input": "3\n1 0\n0 0\n0 1", "output": "1" }, { "input": "3\n0 0\n0 5\n5 5", "output": "25" }, { "input": "3\n1 0\n5 0\n5 10", "output": "40" }, { "input": "3\n0 0\n1 0\n1 2", "output": "2" }, { "input": "4\n0 1\n0 0\n1 0\n1 1", "output": "1" }, { "input": "3\n0 0\n2 0\n0 1", "output": "2" }, { "input": "3\n-2 -1\n-1 -1\n-1 -2", "output": "1" }, { "input": "2\n1 0\n0 1", "output": "1" }, { "input": "4\n1 1\n3 3\n3 1\n1 3", "output": "4" }, { "input": "3\n2 1\n1 2\n2 2", "output": "1" }, { "input": "3\n0 0\n0 3\n3 0", "output": "9" }, { "input": "2\n0 3\n3 3", "output": "-1" }, { "input": "4\n2 0\n2 8\n5 8\n5 0", "output": "24" }, { "input": "2\n0 999\n100 250", "output": "74900" }, { "input": "3\n1 1\n1 5\n5 1", "output": "16" }, { "input": "3\n0 1\n0 0\n1 1", "output": "1" }, { "input": "3\n0 0\n10 0\n0 10", "output": "100" }, { "input": "2\n0 0\n-1 -1", "output": "1" }, { "input": "3\n1 5\n2 2\n2 5", "output": "3" }, { "input": "3\n0 0\n0 1\n2 0", "output": "2" }, { "input": "3\n0 1\n1 0\n0 0", "output": "1" }, { "input": "3\n0 0\n0 -1\n1 -1", "output": "1" }, { "input": "3\n0 1\n1 0\n1 1", "output": "1" }, { "input": "3\n3 5\n3 2\n7 2", "output": "12" }, { "input": "3\n1 2\n1 3\n2 2", "output": "1" }, { "input": "3\n5 0\n0 0\n0 5", "output": "25" }, { "input": "3\n1 0\n1 3\n5 0", "output": "12" }, { "input": "3\n0 0\n0 2\n2 0", "output": "4" }, { "input": "3\n1 1\n0 0\n1 0", "output": "1" }, { "input": "3\n1 2\n1 3\n2 3", "output": "1" }, { "input": "4\n0 0\n0 1\n1 1\n1 0", "output": "1" }, { "input": "2\n-3 0\n3 3", "output": "18" }, { "input": "3\n1 1\n0 1\n1 0", "output": "1" }, { "input": "3\n0 0\n5 0\n5 5", "output": "25" }, { "input": "3\n79 79\n79 158\n158 79", "output": "6241" }, { "input": "3\n1 0\n1 -1\n0 0", "output": "1" }, { "input": "3\n1 1\n1 2\n2 2", "output": "1" }, { "input": "3\n0 1\n0 0\n1 0", "output": "1" }, { "input": "3\n2 1\n2 4\n6 1", "output": "12" }, { "input": "3\n5 0\n0 0\n5 5", "output": "25" } ]
1,472,735,494
2,147,483,647
Python 3
OK
TESTS
121
93
307,200
if __name__ == '__main__': n = int(input()) lines = list() for i in range(n): line = str(input()).split() line = [int(it) for it in line] lines.append(line) if n == 1 or n == 2 and (lines[0][0] == lines[1][0] or lines[0][1] == lines[1][1]): print(-1) elif n == 2: print(abs((lines[1][0] - lines[0][0]) * (lines[1][1] - lines[0][1]))) else: zones = list() if lines[1][0] == lines[0][0] or lines[1][1] == lines[0][1]: zones.append(abs(lines[1][0] - lines[0][0]) + abs(lines[1][1] - lines[0][1])) if lines[1][0] == lines[2][0] or lines[1][1] == lines[2][1]: zones.append(abs(lines[1][0] - lines[2][0]) + abs(lines[1][1] - lines[2][1])) if lines[0][0] == lines[2][0] or lines[0][1] == lines[2][1]: zones.append(abs(lines[0][0] - lines[2][0]) + abs(lines[0][1] - lines[2][1])) print(zones[0] * zones[1])
Title: Wilbur and Swimming Pool Time Limit: None seconds Memory Limit: None megabytes Problem Description: After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices. Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend. Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes. Output Specification: Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. Demo Input: ['2\n0 0\n1 1\n', '1\n1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square. In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
```python if __name__ == '__main__': n = int(input()) lines = list() for i in range(n): line = str(input()).split() line = [int(it) for it in line] lines.append(line) if n == 1 or n == 2 and (lines[0][0] == lines[1][0] or lines[0][1] == lines[1][1]): print(-1) elif n == 2: print(abs((lines[1][0] - lines[0][0]) * (lines[1][1] - lines[0][1]))) else: zones = list() if lines[1][0] == lines[0][0] or lines[1][1] == lines[0][1]: zones.append(abs(lines[1][0] - lines[0][0]) + abs(lines[1][1] - lines[0][1])) if lines[1][0] == lines[2][0] or lines[1][1] == lines[2][1]: zones.append(abs(lines[1][0] - lines[2][0]) + abs(lines[1][1] - lines[2][1])) if lines[0][0] == lines[2][0] or lines[0][1] == lines[2][1]: zones.append(abs(lines[0][0] - lines[2][0]) + abs(lines[0][1] - lines[2][1])) print(zones[0] * zones[1]) ```
3
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,672,083,371
2,147,483,647
Python 3
OK
TESTS
45
92
0
def gcd(a, b): while a!= 0 and b != 0: if a >b: a %= b else: b %= a return a + b nums = list(map(int, input().split())) a = nums[0] b = nums[1] n = nums[2] turn = 1 while n > 0: turn = 1 - turn if turn == 0: n -= gcd(n, a) else: n -= gcd(n, b) print(turn)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python def gcd(a, b): while a!= 0 and b != 0: if a >b: a %= b else: b %= a return a + b nums = list(map(int, input().split())) a = nums[0] b = nums[1] n = nums[2] turn = 1 while n > 0: turn = 1 - turn if turn == 0: n -= gcd(n, a) else: n -= gcd(n, b) print(turn) ```
3
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Print one integer — the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126", "output": "12" }, { "input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850", "output": "36" }, { "input": "2 6 8\n2 1", "output": "0" }, { "input": "5 15 16\n7 11 5 12 8", "output": "2" }, { "input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574", "output": "4" }, { "input": "5 234613 716125\n642626 494941 234613 234613 234613", "output": "0" }, { "input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547", "output": "0" }, { "input": "5 10 20\n10 10 10 10 1", "output": "1" }, { "input": "5 10 11\n10 10 10 10 1", "output": "2" }, { "input": "3 10 10\n4 3 3", "output": "0" }, { "input": "3 5 5\n5 5 5", "output": "1" }, { "input": "3 4 14\n5 5 5", "output": "0" }, { "input": "2 7 10\n1234 1234", "output": "0" }, { "input": "1 5 6\n10", "output": "0" }, { "input": "3 4 6\n1 2 3", "output": "0" }, { "input": "5 10 12\n13 13 13 13 13", "output": "0" }, { "input": "3 4 5\n5 7 9", "output": "0" }, { "input": "3 10 100\n5 5 5", "output": "0" }, { "input": "5 1 2\n2 2 2 2 2", "output": "0" }, { "input": "5 5 5\n5 5 5 5 5", "output": "2" }, { "input": "2 2 5\n5 5", "output": "0" }, { "input": "3 1 4\n2 2 2", "output": "0" } ]
1,613,646,339
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
78
7,270,400
_, b, d = map(int, input().split()) a = list(map(int, input().split())) total_waste = sum([i for i in a if i < b]) print(total_waste // (d + 1))
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? Input Specification: The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. Output Specification: Print one integer — the number of times Kolya will have to empty the waste section. Demo Input: ['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n'] Demo Output: ['1\n', '0\n', '1\n', '0\n'] Note: In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
```python _, b, d = map(int, input().split()) a = list(map(int, input().split())) total_waste = sum([i for i in a if i < b]) print(total_waste // (d + 1)) ```
0
729
B
Spotlights
PROGRAMMING
1,200
[ "dp", "implementation" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: - there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
1,000
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 1\n1\n0\n0", "output": "2" }, { "input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0", "output": "25" }, { "input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "4" }, { "input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1", "output": "26" }, { "input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "121" }, { "input": "1 2\n0 1", "output": "1" }, { "input": "1 2\n1 0", "output": "1" }, { "input": "1 2\n1 1", "output": "0" }, { "input": "2 1\n1\n0", "output": "1" }, { "input": "2 1\n0\n1", "output": "1" }, { "input": "2 1\n1\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1", "output": "16" } ]
1,497,345,149
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
307,200
""" B. Прожекторы ограничение по времени на тест 1 секунда ограничение по памяти на тест 256 мегабайт ввод стандартный ввод вывод стандартный вывод Театральная сцена представляет собой прямоугольное поле размером n × m. Директор театра выдал вам план сцены, согласно которому на ней будут располагаться актёры. На плане отмечено в каких клетках будут стоять актёры, а в каких нет. Прожектор, установленный на сцену, будет светить в одном из четырёх направлений (если смотреть на план сцены сверху) — влево, вверх, вправо или вниз. Таким образом, под позицией прожектора понимается клетка, в которую он установлен, а также направление, в котором он светит. Перед вами стоит задача поставить на сцену прожектор в хорошую позицию. Позиция называется хорошей, если одновременно выполняются два условия: в соответствующей ей клетке нет актёра; в направлении, в котором светит прожектор, находится хотя бы один актёр. Перед вами стоит задача посчитать количество хороших позиций для установки прожектора. Две позиции установки прожектора считаются различными, если отличаются клетки расположения прожектора, или направление, в котором он светит. Входные данные В первой строке следует два целых положительных числа n и m (1 ≤ n, m ≤ 1000) — количество строк и количество столбцов в плане. В следующих n строках следует по m целых чисел, каждое равно либо 0, либо 1, — описание плана. Если очередное число равно 1, то в соответствующей клетке находится актёр, а если 0, то клетка останется пустой. Гарантируется, что в плане есть хотя бы один актёр. Выходные данные Выведите единственное целое число — количество хороших позиций для установки прожектора. Примеры Входные данные 2 4 0 1 0 0 1 0 1 0 Выходные данные 9 Входные данные 4 4 0 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 Выходные данные 20 Примечание В первом примере хорошими позициями для установки прожектора являются: клетка (1, 1) и направление вправо; клетка (1, 1) и направление вниз; клетка (1, 3) и направление влево; клетка (1, 3) и направление вниз; клетка (1, 4) и направление влево; клетка (2, 2) и направление влево; клетка (2, 2) и направление вверх; клетка (2, 2) и направление вправо; клетка (2, 4) и направление влево. Таким образом, в данном примере всего 9 хороших позиций. """ def count_neighbors(row, col): result = 0 temp_offset = 1 while (row - temp_offset) >= 0: if input_array[row - temp_offset][col] == 1: # North result += 1 break temp_offset += 1 temp_offset = 1 while (col - temp_offset) >= 0: if input_array[row][col - temp_offset] == 1: # West result += 1 break temp_offset += 1 temp_offset = 1 while (row + temp_offset) < len(input_array): if input_array[row + temp_offset][col] == 1: # South result += 1 break temp_offset += 1 temp_offset = 1 while (col + temp_offset) < len(input_array[row]): if input_array[row][col + temp_offset] == 1: # East result += 1 break temp_offset += 1 return result def count_best_positions(): result = 0 for i in range(len(input_array)): for j in range(len(input_array[i])): if input_array[i][j] != 1: result += count_neighbors(i, j) return result input_array = [] with open('./input.txt') as file: count_rows = int(file.readline().split()[0]) for number_row in range(count_rows): input_array.append([int(cell) for cell in file.readline().split()]) with open('./output.txt', 'w') as file: file.write(str(count_best_positions()))
Title: Spotlights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines. A position is good if two conditions hold: - there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects. Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. Input Specification: The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. Output Specification: Print one integer — the number of good positions for placing the spotlight. Demo Input: ['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n'] Demo Output: ['9\n', '20\n'] Note: In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction. Therefore, there are 9 good positions in this example.
```python """ B. Прожекторы ограничение по времени на тест 1 секунда ограничение по памяти на тест 256 мегабайт ввод стандартный ввод вывод стандартный вывод Театральная сцена представляет собой прямоугольное поле размером n × m. Директор театра выдал вам план сцены, согласно которому на ней будут располагаться актёры. На плане отмечено в каких клетках будут стоять актёры, а в каких нет. Прожектор, установленный на сцену, будет светить в одном из четырёх направлений (если смотреть на план сцены сверху) — влево, вверх, вправо или вниз. Таким образом, под позицией прожектора понимается клетка, в которую он установлен, а также направление, в котором он светит. Перед вами стоит задача поставить на сцену прожектор в хорошую позицию. Позиция называется хорошей, если одновременно выполняются два условия: в соответствующей ей клетке нет актёра; в направлении, в котором светит прожектор, находится хотя бы один актёр. Перед вами стоит задача посчитать количество хороших позиций для установки прожектора. Две позиции установки прожектора считаются различными, если отличаются клетки расположения прожектора, или направление, в котором он светит. Входные данные В первой строке следует два целых положительных числа n и m (1 ≤ n, m ≤ 1000) — количество строк и количество столбцов в плане. В следующих n строках следует по m целых чисел, каждое равно либо 0, либо 1, — описание плана. Если очередное число равно 1, то в соответствующей клетке находится актёр, а если 0, то клетка останется пустой. Гарантируется, что в плане есть хотя бы один актёр. Выходные данные Выведите единственное целое число — количество хороших позиций для установки прожектора. Примеры Входные данные 2 4 0 1 0 0 1 0 1 0 Выходные данные 9 Входные данные 4 4 0 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 Выходные данные 20 Примечание В первом примере хорошими позициями для установки прожектора являются: клетка (1, 1) и направление вправо; клетка (1, 1) и направление вниз; клетка (1, 3) и направление влево; клетка (1, 3) и направление вниз; клетка (1, 4) и направление влево; клетка (2, 2) и направление влево; клетка (2, 2) и направление вверх; клетка (2, 2) и направление вправо; клетка (2, 4) и направление влево. Таким образом, в данном примере всего 9 хороших позиций. """ def count_neighbors(row, col): result = 0 temp_offset = 1 while (row - temp_offset) >= 0: if input_array[row - temp_offset][col] == 1: # North result += 1 break temp_offset += 1 temp_offset = 1 while (col - temp_offset) >= 0: if input_array[row][col - temp_offset] == 1: # West result += 1 break temp_offset += 1 temp_offset = 1 while (row + temp_offset) < len(input_array): if input_array[row + temp_offset][col] == 1: # South result += 1 break temp_offset += 1 temp_offset = 1 while (col + temp_offset) < len(input_array[row]): if input_array[row][col + temp_offset] == 1: # East result += 1 break temp_offset += 1 return result def count_best_positions(): result = 0 for i in range(len(input_array)): for j in range(len(input_array[i])): if input_array[i][j] != 1: result += count_neighbors(i, j) return result input_array = [] with open('./input.txt') as file: count_rows = int(file.readline().split()[0]) for number_row in range(count_rows): input_array.append([int(cell) for cell in file.readline().split()]) with open('./output.txt', 'w') as file: file.write(str(count_best_positions())) ```
-1
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "output": "21" }, { "input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815", "output": "16" }, { "input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663", "output": "10" }, { "input": "1\n321 88", "output": "0" }, { "input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689", "output": "7" }, { "input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510", "output": "6" }, { "input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888", "output": "5" }, { "input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802", "output": "13" }, { "input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662", "output": "11" }, { "input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786", "output": "38" }, { "input": "3\n175 201\n907 909\n388 360", "output": "2" }, { "input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86", "output": "6" }, { "input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820", "output": "16" }, { "input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901", "output": "31" }, { "input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210", "output": "29" }, { "input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894", "output": "29" }, { "input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823", "output": "13" }, { "input": "5\n175 158\n16 2\n397 381\n668 686\n957 945", "output": "4" }, { "input": "5\n312 284\n490 509\n730 747\n504 497\n782 793", "output": "4" }, { "input": "2\n802 903\n476 348", "output": "1" }, { "input": "4\n325 343\n425 442\n785 798\n275 270", "output": "3" }, { "input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653", "output": "25" }, { "input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124", "output": "34" }, { "input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255", "output": "29" }, { "input": "5\n664 666\n951 941\n739 742\n844 842\n2 2", "output": "4" }, { "input": "3\n939 867\n411 427\n757 708", "output": "2" }, { "input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636", "output": "34" }, { "input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195", "output": "28" }, { "input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488", "output": "22" }, { "input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235", "output": "8" }, { "input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621", "output": "22" }, { "input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461", "output": "22" }, { "input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924", "output": "6" }, { "input": "3\n1 1\n2 1\n2 2", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "5\n1 1\n1 2\n2 2\n3 1\n3 3", "output": "0" }, { "input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3", "output": "0" }, { "input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10", "output": "1" }, { "input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11", "output": "1" }, { "input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11", "output": "3" }, { "input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25", "output": "7" }, { "input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28", "output": "5" }, { "input": "3\n1 2\n2 1\n2 2", "output": "0" }, { "input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1", "output": "0" }, { "input": "4\n1 1\n1 2\n2 1\n2 2", "output": "0" }, { "input": "3\n1 1\n2 2\n1 2", "output": "0" }, { "input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4", "output": "1" }, { "input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100", "output": "6" }, { "input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4", "output": "0" }, { "input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3", "output": "0" }, { "input": "4\n3 1\n2 1\n2 2\n1 2", "output": "0" }, { "input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3", "output": "0" }, { "input": "3\n1 2\n1 3\n1 4", "output": "0" }, { "input": "4\n1 1\n2 2\n1 2\n2 1", "output": "0" }, { "input": "4\n1 3\n2 1\n3 2\n3 1", "output": "1" }, { "input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4", "output": "0" }, { "input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700", "output": "2" }, { "input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9", "output": "1" }, { "input": "4\n1 1\n2 2\n3 2\n3 1", "output": "0" }, { "input": "3\n1 2\n3 4\n3 2", "output": "0" }, { "input": "3\n1 1\n1 2\n2 2", "output": "0" }, { "input": "4\n5 5\n5 4\n6 3\n6 4", "output": "0" }, { "input": "3\n1 1\n2 2\n2 1", "output": "0" } ]
1,669,473,638
2,147,483,647
PyPy 3
OK
TESTS
76
184
1,536,000
n = int(input()) a = [] for i in range(n): x, y = map(int, input().split()) a.append([x,y,False]) def df(x): x[2]= True for s in a: if not s[2] and (x[0] == s[0] or x[1] == s[1]): df(s) rj = 0 for i in a: if not i[2]: rj += 1 df(i) print(rj-1)
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. Output Specification: Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n = int(input()) a = [] for i in range(n): x, y = map(int, input().split()) a.append([x,y,False]) def df(x): x[2]= True for s in a: if not s[2] and (x[0] == s[0] or x[1] == s[1]): df(s) rj = 0 for i in a: if not i[2]: rj += 1 df(i) print(rj-1) ```
3
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "output": "#Color" }, { "input": "1 6\nC M Y W G B", "output": "#Color" }, { "input": "1 3\nW G B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G C", "output": "#Color" }, { "input": "2 3\nW W W\nB G M", "output": "#Color" }, { "input": "3 3\nC B W\nB Y M\nB B W", "output": "#Color" }, { "input": "1 3\nW C W", "output": "#Color" }, { "input": "3 3\nB W B\nB C W\nB W W", "output": "#Color" }, { "input": "1 2\nW Y", "output": "#Color" }, { "input": "1 1\nG", "output": "#Black&White" }, { "input": "1 3\nB G W", "output": "#Black&White" }, { "input": "2 2\nW W\nB C", "output": "#Color" }, { "input": "1 1\nM", "output": "#Color" }, { "input": "1 2\nW C", "output": "#Color" }, { "input": "2 3\nW W M\nW W M", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB C", "output": "#Color" }, { "input": "2 3\nW W C\nW W W", "output": "#Color" }, { "input": "1 3\nG G G", "output": "#Black&White" }, { "input": "1 1\nC", "output": "#Color" }, { "input": "1 2\nC W", "output": "#Color" }, { "input": "1 3\nW W C", "output": "#Color" }, { "input": "2 2\nW B\nB G", "output": "#Black&White" }, { "input": "2 2\nB B\nY Y", "output": "#Color" }, { "input": "2 2\nG G\nC C", "output": "#Color" }, { "input": "1 2\nB C", "output": "#Color" }, { "input": "1 4\nG G G C", "output": "#Color" }, { "input": "1 1\nB", "output": "#Black&White" }, { "input": "2 1\nY\nB", "output": "#Color" } ]
1,690,114,997
2,147,483,647
Python 3
OK
TESTS
50
31
0
nm = input().split(' ') n = int(nm[0]) m = int(nm[1]) count = 0 for i in range(n): colors = input().split(' ') if ('C' in colors) or ('M' in colors) or ('Y' in colors): count = 1 if count==1: print('#Color') else: print('#Black&White')
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Output Specification: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Demo Input: ['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n'] Demo Output: ['#Color', '#Black&amp;White', '#Black&amp;White'] Note: none
```python nm = input().split(' ') n = int(nm[0]) m = int(nm[1]) count = 0 for i in range(n): colors = input().split(' ') if ('C' in colors) or ('M' in colors) or ('Y' in colors): count = 1 if count==1: print('#Color') else: print('#Black&White') ```
3
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task.
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": ".g.g.d.v.q" }, { "input": "pumesz", "output": ".p.m.s.z" }, { "input": "g", "output": ".g" }, { "input": "zjuotps", "output": ".z.j.t.p.s" }, { "input": "jzbwuehe", "output": ".j.z.b.w.h" }, { "input": "tnkgwuugu", "output": ".t.n.k.g.w.g" }, { "input": "kincenvizh", "output": ".k.n.c.n.v.z.h" }, { "input": "xattxjenual", "output": ".x.t.t.x.j.n.l" }, { "input": "ktajqhpqsvhw", "output": ".k.t.j.q.h.p.q.s.v.h.w" }, { "input": "xnhcigytnqcmy", "output": ".x.n.h.c.g.t.n.q.c.m" }, { "input": "jfmtbejyilxcec", "output": ".j.f.m.t.b.j.l.x.c.c" }, { "input": "D", "output": ".d" }, { "input": "ab", "output": ".b" }, { "input": "Ab", "output": ".b" }, { "input": "aB", "output": ".b" }, { "input": "AB", "output": ".b" }, { "input": "ba", "output": ".b" }, { "input": "bA", "output": ".b" }, { "input": "Ba", "output": ".b" }, { "input": "BA", "output": ".b" }, { "input": "aab", "output": ".b" }, { "input": "baa", "output": ".b" }, { "input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM", "output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m" }, { "input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN", "output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n" }, { "input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ", "output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j" }, { "input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea", "output": ".w.z.t.c.v.v.v.v.z.v" }, { "input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl", "output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l" }, { "input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg", "output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g" }, { "input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ", "output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q" }, { "input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg", "output": ".l.t.g.m.g" }, { "input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy", "output": ".k.z.d.x.f" }, { "input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ", "output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q" }, { "input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY", "output": ".m.r.c.g.p" }, { "input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx", "output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x" }, { "input": "YB", "output": ".b" }, { "input": "fly", "output": ".f.l" }, { "input": "YyyYYYyyYxdwdawdDAWDdaddYYYY", "output": ".x.d.w.d.w.d.d.w.d.d.d.d" } ]
1,694,162,483
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
92
0
s=input() s=s.lower() vowels=['a','e','i','o','u'] res="" for i in s: if i not in vowels: res+='.' res+=i print(res)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string. Help Petya cope with this easy task. Input Specification: The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. Output Specification: Print the resulting string. It is guaranteed that this string is not empty. Demo Input: ['tour\n', 'Codeforces\n', 'aBAcAba\n'] Demo Output: ['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n'] Note: none
```python s=input() s=s.lower() vowels=['a','e','i','o','u'] res="" for i in s: if i not in vowels: res+='.' res+=i print(res) ```
0
304
A
Pythagorean Theorem II
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Print a single integer — the answer to the problem.
[ "5\n", "74\n" ]
[ "1\n", "35\n" ]
none
500
[ { "input": "5", "output": "1" }, { "input": "74", "output": "35" }, { "input": "1000", "output": "881" }, { "input": "586", "output": "472" }, { "input": "2", "output": "0" }, { "input": "362", "output": "258" }, { "input": "778", "output": "653" }, { "input": "194", "output": "120" }, { "input": "906", "output": "786" }, { "input": "659", "output": "535" }, { "input": "75", "output": "37" }, { "input": "787", "output": "664" }, { "input": "851", "output": "730" }, { "input": "563", "output": "446" }, { "input": "979", "output": "862" }, { "input": "395", "output": "291" }, { "input": "755", "output": "634" }, { "input": "171", "output": "103" }, { "input": "883", "output": "759" }, { "input": "400", "output": "294" }, { "input": "817", "output": "693" }, { "input": "177", "output": "107" }, { "input": "593", "output": "476" }, { "input": "305", "output": "214" }, { "input": "721", "output": "595" }, { "input": "785", "output": "664" }, { "input": "497", "output": "383" }, { "input": "913", "output": "791" }, { "input": "625", "output": "507" }, { "input": "334", "output": "236" }, { "input": "10000", "output": "12471" }, { "input": "9999", "output": "12467" } ]
1,663,217,980
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
468
0
num = int(input()) res = 0 for n in range(1,num+1): for m in range(n+1, num+1,2): if (m%n==0) and n!=1: continue c = m**2 + n**2 k = num//c res+=k print(res)
Title: Pythagorean Theorem II Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation: where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides. Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. Input Specification: The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['5\n', '74\n'] Demo Output: ['1\n', '35\n'] Note: none
```python num = int(input()) res = 0 for n in range(1,num+1): for m in range(n+1, num+1,2): if (m%n==0) and n!=1: continue c = m**2 + n**2 k = num//c res+=k print(res) ```
0
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,554,221,111
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
from sys import * rt = stdin.read().split('\n') A = {} B = {} C = {} for s in rt[1:]: if s != '': t = s.split() if t[0] in A: A[t[0]] = A[t[0]]+int(t[1]) else: A[t[0]] = int(t[1]) as = max(A.values()) for i in A: if A[i] == as: C[i] = A[i] A = {} for s in rt[1:]: if s != '': t = s.split() if t[0] in C: if t[0] in A: A[t[0]] = A[t[0]]+int(t[1]) else: A[t[0]] = int(t[1]) if A[t[0]] >= as: print(t[0]) break
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python from sys import * rt = stdin.read().split('\n') A = {} B = {} C = {} for s in rt[1:]: if s != '': t = s.split() if t[0] in A: A[t[0]] = A[t[0]]+int(t[1]) else: A[t[0]] = int(t[1]) as = max(A.values()) for i in A: if A[i] == as: C[i] = A[i] A = {} for s in rt[1:]: if s != '': t = s.split() if t[0] in C: if t[0] in A: A[t[0]] = A[t[0]]+int(t[1]) else: A[t[0]] = int(t[1]) if A[t[0]] >= as: print(t[0]) break ```
-1
946
A
Partition
PROGRAMMING
800
[ "greedy" ]
null
null
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n" ]
[ "3\n", "120\n" ]
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
0
[ { "input": "3\n1 -2 0", "output": "3" }, { "input": "6\n16 23 16 15 42 8", "output": "120" }, { "input": "1\n-1", "output": "1" }, { "input": "100\n-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", "output": "10000" }, { "input": "2\n-1 5", "output": "6" }, { "input": "3\n-2 0 1", "output": "3" }, { "input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3", "output": "94" }, { "input": "4\n1 -1 1 -1", "output": "4" }, { "input": "4\n100 -100 100 -100", "output": "400" }, { "input": "3\n-2 -5 10", "output": "17" }, { "input": "5\n1 -2 3 -4 5", "output": "15" }, { "input": "3\n-100 100 -100", "output": "300" }, { "input": "6\n1 -1 1 -1 1 -1", "output": "6" }, { "input": "6\n2 -2 2 -2 2 -2", "output": "12" }, { "input": "9\n12 93 -2 0 0 0 3 -3 -9", "output": "122" }, { "input": "6\n-1 2 4 -5 -3 55", "output": "70" }, { "input": "6\n-12 8 68 -53 1 -15", "output": "157" }, { "input": "2\n-2 1", "output": "3" }, { "input": "3\n100 -100 100", "output": "300" }, { "input": "5\n100 100 -1 -100 2", "output": "303" }, { "input": "6\n-5 -4 -3 -2 -1 0", "output": "15" }, { "input": "6\n4 4 4 -3 -3 2", "output": "20" }, { "input": "2\n-1 2", "output": "3" }, { "input": "1\n100", "output": "100" }, { "input": "5\n-1 -2 3 1 2", "output": "9" }, { "input": "5\n100 -100 100 -100 100", "output": "500" }, { "input": "5\n1 -1 1 -1 1", "output": "5" }, { "input": "4\n0 0 0 -1", "output": "1" }, { "input": "5\n100 -100 -1 2 100", "output": "303" }, { "input": "2\n75 0", "output": "75" }, { "input": "4\n55 56 -59 -58", "output": "228" }, { "input": "2\n9 71", "output": "80" }, { "input": "2\n9 70", "output": "79" }, { "input": "2\n9 69", "output": "78" }, { "input": "2\n100 -100", "output": "200" }, { "input": "4\n-9 4 -9 5", "output": "27" }, { "input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36", "output": "2348" }, { "input": "7\n-1 2 2 2 -1 2 -1", "output": "11" }, { "input": "6\n-12 8 17 -69 7 -88", "output": "201" }, { "input": "3\n1 -2 5", "output": "8" }, { "input": "6\n-2 3 -4 5 6 -1", "output": "21" }, { "input": "2\n-5 1", "output": "6" }, { "input": "4\n2 2 -2 4", "output": "10" }, { "input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72", "output": "3991" }, { "input": "5\n5 5 -10 -1 1", "output": "22" }, { "input": "3\n-1 2 3", "output": "6" }, { "input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1", "output": "3787" }, { "input": "5\n-1 -2 1 2 3", "output": "9" }, { "input": "4\n2 2 -2 -2", "output": "8" }, { "input": "6\n100 -100 100 -100 100 -100", "output": "600" }, { "input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41", "output": "4362" }, { "input": "2\n-1 1", "output": "2" }, { "input": "3\n1 -2 100", "output": "103" }, { "input": "5\n1 -2 3 1 2", "output": "9" }, { "input": "10\n100 -10 -100 10 10 10 10 10 10 10", "output": "280" }, { "input": "4\n2 0 -2 4", "output": "8" }, { "input": "4\n3 -3 1 -1", "output": "8" }, { "input": "3\n1 -1 1", "output": "3" }, { "input": "4\n2 5 -2 4", "output": "13" }, { "input": "2\n-2 2", "output": "4" }, { "input": "3\n1 -2 1", "output": "4" }, { "input": "5\n-1 -2 1 1 -1", "output": "6" }, { "input": "4\n-2 0 2 4", "output": "8" }, { "input": "8\n-42 7 87 -16 -5 65 -88 1", "output": "311" }, { "input": "3\n1 -3 4", "output": "8" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n-1 2 -1", "output": "4" }, { "input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95", "output": "761" }, { "input": "4\n-1 1 -1 1", "output": "4" }, { "input": "5\n-1 2 1 1 1", "output": "6" }, { "input": "3\n1 1 1", "output": "3" } ]
1,596,454,254
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
6,656,000
a=int(input()) c=list(map(int, input().split())) x=abs(sum(c)) for i in c: if i<0: x+=abs(i) print(x)
Title: Partition Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. Output Specification: Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. Demo Input: ['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n'] Demo Output: ['3\n', '120\n'] Note: In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
```python a=int(input()) c=list(map(int, input().split())) x=abs(sum(c)) for i in c: if i<0: x+=abs(i) print(x) ```
0