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
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,699,451,677
2,147,483,647
Python 3
OK
TESTS
44
31
0
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] name = input() rotations = 0 previous = alph.index('a') for letter in name: afterwards = alph.index(letter) distance = min((previous - afterwards) % 26, (afterwards - previous) % 26) rotations += distance previous = afterwards print(rotations)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] name = input() rotations = 0 previous = alph.index('a') for letter in name: afterwards = alph.index(letter) distance = min((previous - afterwards) % 26, (afterwards - previous) % 26) rotations += distance previous = afterwards print(rotations) ```
3
449
B
Jzzhu and Cities
PROGRAMMING
2,000
[ "graphs", "greedy", "shortest paths" ]
null
null
Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train routes in the country. One can use the *i*-th train route to go from capital of the country to city *s**i* (and vise versa), the length of this route is *y**i*. Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.
The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105). Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109). Each of the next *k* lines contains two integers *s**i* and *y**i* (2<=≤<=*s**i*<=≤<=*n*; 1<=≤<=*y**i*<=≤<=109). It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.
Output a single integer representing the maximum number of the train routes which can be closed.
[ "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n", "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n" ]
[ "2\n", "2\n" ]
none
1,000
[ { "input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2" }, { "input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2" }, { "input": "5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 524444444\n5 529999999\n2 1000000000", "output": "2" }, { "input": "3 2 5\n1 2 2\n2 3 4\n3 5\n3 5\n3 5\n3 6\n3 7", "output": "4" }, { "input": "5 5 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 524524524\n5 3 1000000000\n5 524444444\n5 529999999\n2 1000000000", "output": "2" }, { "input": "2 1 5\n1 2 4\n2 3\n2 5\n2 4\n2 4\n2 5", "output": "4" }, { "input": "3 3 6\n1 2 499999999\n2 3 500000000\n1 3 999999999\n2 499999999\n2 500000000\n2 499999999\n3 999999999\n3 1000000000\n3 1000000000", "output": "6" }, { "input": "2 1 1\n1 2 1\n2 1000000000", "output": "1" }, { "input": "3 2 2\n1 2 4\n2 3 4\n2 2\n3 6", "output": "1" }, { "input": "5 5 2\n1 2 100\n2 3 100\n3 4 100\n4 5 20\n2 5 5\n5 50\n4 1", "output": "1" }, { "input": "3 2 2\n1 2 100\n2 3 1\n2 1\n3 3", "output": "1" } ]
1,667,200,695
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
2
77
2,764,800
from heapq import heapify, heappop, heappush n , m ,k = map(int , input().split()) graph = [[] for i in range(n)] for i in range(0 , m): a , b , d = map(int , input().split()) graph[a-1].append((b-1,d)) graph[b-1].append((a-1,d)) train = [] for i in range(k): a , d = map(int , input().split()) train.append((a-1,d)) def djkestra(source): heap = [] heapify(heap) distance = [100000000] * n distance[source]=0 s = set() heappush(heap , (0 , source)) while len(s) < len(graph): # print(heap) minDistance , popedIndex = heappop(heap) s.add(popedIndex) for curNode , curDist in graph[popedIndex]: # print(curNode , curDist) #relaxation if distance[curNode] > distance[popedIndex] + curDist: distance[curNode] = distance[popedIndex] + curDist heappush(heap , (distance[curNode] , curNode)) return distance dist = djkestra(0) ans = 0 for a , d in train: if dist[a] <= d: ans +=1 print(ans)
Title: Jzzhu and Cities Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jzzhu is the president of country A. There are *n* cities numbered from 1 to *n* in his country. City 1 is the capital of A. Also there are *m* roads connecting the cities. One can go from city *u**i* to *v**i* (and vise versa) using the *i*-th road, the length of this road is *x**i*. Finally, there are *k* train routes in the country. One can use the *i*-th train route to go from capital of the country to city *s**i* (and vise versa), the length of this route is *y**i*. Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change. Input Specification: The first line contains three integers *n*,<=*m*,<=*k* (2<=≤<=*n*<=≤<=105; 1<=≤<=*m*<=≤<=3·105; 1<=≤<=*k*<=≤<=105). Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*; 1<=≤<=*x**i*<=≤<=109). Each of the next *k* lines contains two integers *s**i* and *y**i* (2<=≤<=*s**i*<=≤<=*n*; 1<=≤<=*y**i*<=≤<=109). It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital. Output Specification: Output a single integer representing the maximum number of the train routes which can be closed. Demo Input: ['5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n', '2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n'] Demo Output: ['2\n', '2\n'] Note: none
```python from heapq import heapify, heappop, heappush n , m ,k = map(int , input().split()) graph = [[] for i in range(n)] for i in range(0 , m): a , b , d = map(int , input().split()) graph[a-1].append((b-1,d)) graph[b-1].append((a-1,d)) train = [] for i in range(k): a , d = map(int , input().split()) train.append((a-1,d)) def djkestra(source): heap = [] heapify(heap) distance = [100000000] * n distance[source]=0 s = set() heappush(heap , (0 , source)) while len(s) < len(graph): # print(heap) minDistance , popedIndex = heappop(heap) s.add(popedIndex) for curNode , curDist in graph[popedIndex]: # print(curNode , curDist) #relaxation if distance[curNode] > distance[popedIndex] + curDist: distance[curNode] = distance[popedIndex] + curDist heappush(heap , (distance[curNode] , curNode)) return distance dist = djkestra(0) ans = 0 for a , d in train: if dist[a] <= d: ans +=1 print(ans) ```
-1
358
B
Dima and Text Messages
PROGRAMMING
1,500
[ "brute force", "strings" ]
null
null
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
[ "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n" ]
[ "yes\n", "no\n" ]
Please note that Dima got a good old kick in the pants for the second sample from the statement.
1,000
[ { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes" }, { "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "output": "yes" }, { "input": "4\na\nb\nc\nd\n<3a<3b<3c<3d", "output": "no" }, { "input": "4\na\nb\nc\nd\na<3b<3c<3d<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<3you<3", "output": "yes" }, { "input": "1\na\na", "output": "no" }, { "input": "1\na\n<3a<3b", "output": "yes" }, { "input": "1\naa\n<3a<3", "output": "no" }, { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww", "output": "yes" }, { "input": "3\ni\nlove\nyou\n<3ilove<23you<3", "output": "no" }, { "input": "2\na\ni\n<3ai<3", "output": "no" } ]
1,601,632,430
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
170
2,252,800
import sys, os.path from collections import* from copy import* import math mod=10**9+7 if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") n=int(input()) fake='<3' for i in range(n): s1=input() fake+=s1 fake+='<3' n1=len(fake) text=input() m=len(text) if(n1>m): print("NO") else: c=0 j=0 i=0 while(i<m and j<n1): if(fake[j]==text[i]): c+=1 j+=1 i+=1 if(c==n1): print("YES") else: print("NO")
Title: Dima and Text Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. Output Specification: In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. Demo Input: ['3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n', '7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n'] Demo Output: ['yes\n', 'no\n'] Note: Please note that Dima got a good old kick in the pants for the second sample from the statement.
```python import sys, os.path from collections import* from copy import* import math mod=10**9+7 if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") n=int(input()) fake='<3' for i in range(n): s1=input() fake+=s1 fake+='<3' n1=len(fake) text=input() m=len(text) if(n1>m): print("NO") else: c=0 j=0 i=0 while(i<m and j<n1): if(fake[j]==text[i]): c+=1 j+=1 i+=1 if(c==n1): print("YES") else: print("NO") ```
0
928
A
Login Verification
PROGRAMMING
1,200
[ "*special", "strings" ]
null
null
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types: - transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other. For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not. You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes).
[ "1_wat\n2\n2_wat\nwat_1\n", "000\n3\n00\nooA\noOo\n", "_i_\n3\n__i_\n_1_\nI\n", "La0\n3\n2a0\nLa1\n1a0\n", "abc\n1\naBc\n", "0Lil\n2\nLIL0\n0Ril\n" ]
[ "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
500
[ { "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes" }, { "input": "000\n3\n00\nooA\noOo", "output": "No" }, { "input": "_i_\n3\n__i_\n_1_\nI", "output": "No" }, { "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No" }, { "input": "abc\n1\naBc", "output": "No" }, { "input": "0Lil\n2\nLIL0\n0Ril", "output": "Yes" }, { "input": "iloO\n3\niIl0\noIl0\nIooO", "output": "Yes" }, { "input": "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o", "output": "Yes" }, { "input": "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuoE11u1u1iLOI0oO\nuEOuO0uIOOlO01OlEI0E1Oo0IO1LI0uE0LILO0\nEOo0Il11iIOOOIiuOiIiiLOLEOOII001EE\niOoO0LOulioE0OLIIIulli01OoiuOOOoOlEiI0EiiElIIu0\nlE1LOE1Oil\n1u0EOliIiIOl1u110il0l1O0u", "output": "Yes" }, { "input": "0blo7X\n20\n1oobb6\nXIXIO2X\n2iYI2\n607XXol\n2I6io22\nOl10I\nbXX0Lo\nolOOb7X\n07LlXL\nlXY17\n12iIX2\n7lL70\nbOo11\n17Y6b62\n0O6L7\n1lX2L\n2iYl6lI\n7bXIi1o\niLIY2\n0OIo1X", "output": "Yes" }, { "input": "lkUL\n25\nIIfL\nokl\nfoo\ni0U\noko\niIoU\nUUv\nvli\nv0Uk\n0Of\niill\n1vkl\nUIf\nUfOO\nlvLO\nUUo0\nIOf1\nlovL\nIkk\noIv\nLvfU\n0UI\nkol\n1OO0\n1OOi", "output": "Yes" }, { "input": "L1lo\n3\nOOo1\nL1lo\n0lOl", "output": "No" }, { "input": "LIoooiLO\n5\nLIoooiLO\nl0o01I00\n0OOl0lLO01\nil10i0\noiloi", "output": "No" }, { "input": "1i1lQI\n7\nuLg1uLLigIiOLoggu\nLLLgIuQIQIIloiQuIIoIO0l0o000\n0u1LQu11oIuooIl0OooLg0i0IQu1O1lloI1\nQuQgIQi0LOIliLOuuuioLQou1l\nlLIO00QLi01LogOliOIggII1\no0Ll1uIOQl10IL0IILQ\n1i1lQI", "output": "No" }, { "input": "oIzz1\n20\n1TTl0O\nloF0LT\n1lLzo\noi0Ov\nFlIF1zT\nzoITzx\n0TIFlT\nl1vllil\nOviix1F\nLFvI1lL\nLIl0loz\nixz1v\n1i1vFi\nTIFTol\noIzz1\nIvTl0o\nxv1U0O\niiiioF\n1oiLUlO\nxToxv1", "output": "No" }, { "input": "00L0\n25\n0il\nIlkZ\nL0I\n00L0\nBd0\nZLd\n0d1k\nddk\nIdl\nkBd\nkBOL\nZ1lI\nkBL\nLOko\noZ0i\nZ1lO\nLiOk\niBld\nLO0d\ndIo\nZ10\n1k1i\n0o0L\nIoBd\ni0B0", "output": "No" }, { "input": "Z\n1\nz", "output": "No" }, { "input": "0\n1\no", "output": "No" }, { "input": "0\n1\nO", "output": "No" }, { "input": "o\n1\n0", "output": "No" }, { "input": "o\n1\nO", "output": "No" }, { "input": "o\n1\no", "output": "No" }, { "input": "O\n1\no", "output": "No" }, { "input": "O\n1\n0", "output": "No" }, { "input": "1\n1\nl", "output": "No" }, { "input": "1\n1\nL", "output": "No" }, { "input": "1\n1\ni", "output": "No" }, { "input": "1\n1\nI", "output": "No" }, { "input": "1\n1\no", "output": "Yes" }, { "input": "i\n1\n1", "output": "No" }, { "input": "i\n1\nL", "output": "No" }, { "input": "i\n1\nl", "output": "No" }, { "input": "I\n1\nL", "output": "No" }, { "input": "I\n1\nl", "output": "No" }, { "input": "I\n1\n1", "output": "No" }, { "input": "l\n1\n1", "output": "No" }, { "input": "l\n1\nL", "output": "No" }, { "input": "l\n1\ni", "output": "No" }, { "input": "l\n1\nI", "output": "No" }, { "input": "L\n1\nl", "output": "No" }, { "input": "L\n1\n1", "output": "No" }, { "input": "L\n1\ni", "output": "No" }, { "input": "L\n1\nI", "output": "No" } ]
1,519,487,663
1,163
Python 3
OK
TESTS
73
93
5,632,000
ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c s = st n = int(input()) for i in range(n): ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c if s == st: print("No") exit() print("Yes")
Title: Login Verification Time Limit: None seconds Memory Limit: None megabytes Problem Description: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types: - transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other. For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not. You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones. Input Specification: The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins. The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar. Output Specification: Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes). Demo Input: ['1_wat\n2\n2_wat\nwat_1\n', '000\n3\n00\nooA\noOo\n', '_i_\n3\n__i_\n_1_\nI\n', 'La0\n3\n2a0\nLa1\n1a0\n', 'abc\n1\naBc\n', '0Lil\n2\nLIL0\n0Ril\n'] Demo Output: ['Yes\n', 'No\n', 'No\n', 'No\n', 'No\n', 'Yes\n'] Note: In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
```python ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c s = st n = int(input()) for i in range(n): ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c if s == st: print("No") exit() print("Yes") ```
3
34
C
Page Numbers
PROGRAMMING
1,300
[ "expression parsing", "implementation", "sortings", "strings" ]
C. Page Numbers
2
256
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format *l*1-*r*1,*l*2-*r*2,...,*l**k*-*r**k*, where *r**i*<=+<=1<=&lt;<=*l**i*<=+<=1 for all *i* from 1 to *k*<=-<=1, and *l**i*<=≤<=*r**i*. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element *i* from the new sequence *l**i*<==<=*r**i*, this element should be output as *l**i*, and not as «*l**i*<=-<=*l**i*». For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output the sequence in the required format.
[ "1,2,3,1,1,2,6,6,2\n", "3,2,1\n", "30,20,10\n" ]
[ "1-3,6\n", "1-3\n", "10,20,30\n" ]
none
1,500
[ { "input": "1,2,3,1,1,2,6,6,2", "output": "1-3,6" }, { "input": "3,2,1", "output": "1-3" }, { "input": "30,20,10", "output": "10,20,30" }, { "input": "826,747,849,687,437", "output": "437,687,747,826,849" }, { "input": "999,999,993,969,999", "output": "969,993,999" }, { "input": "4,24,6,1,15", "output": "1,4,6,15,24" }, { "input": "511,32", "output": "32,511" }, { "input": "907,452,355", "output": "355,452,907" }, { "input": "303,872,764,401", "output": "303,401,764,872" }, { "input": "684,698,429,694,956,812,594,170,937,764", "output": "170,429,594,684,694,698,764,812,937,956" }, { "input": "646,840,437,946,640,564,936,917,487,752,844,734,468,969,674,646,728,642,514,695", "output": "437,468,487,514,564,640,642,646,674,695,728,734,752,840,844,917,936,946,969" }, { "input": "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000", "output": "979,981,983-984,987,989,992-993,995-996,998-1000" }, { "input": "93,27,28,4,5,78,59,24,19,134,31,128,118,36,90,32,32,1,44,32,33,13,31,10,12,25,38,50,25,12,4,22,28,53,48,83,4,25,57,31,71,24,8,7,28,86,23,80,101,58", "output": "1,4-5,7-8,10,12-13,19,22-25,27-28,31-33,36,38,44,48,50,53,57-59,71,78,80,83,86,90,93,101,118,128,134" }, { "input": "1000,1000,1000,1000,1000,998,998,1000,1000,1000,1000,999,999,1000,1000,1000,999,1000,997,999,997,1000,999,998,1000,999,1000,1000,1000,999,1000,999,999,1000,1000,999,1000,999,1000,1000,998,1000,1000,1000,998,998,1000,1000,999,1000,1000,1000,1000,1000,1000,1000,998,1000,1000,1000,999,1000,1000,999,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,998,1000,1000,1000,998,1000,1000,998,1000,999,1000,1000,1000,1000", "output": "997-1000" }, { "input": "4,4,21,6,5,3,13,2,6,1,3,4,1,3,1,9,11,1,6,17,4,5,20,4,1,9,5,11,3,4,14,1,3,3,1,4,3,5,27,1,1,2,10,7,11,4,19,7,11,6,11,13,3,1,10,7,2,1,16,1,9,4,29,13,2,12,14,2,21,1,9,8,26,12,12,5,2,14,7,8,8,8,9,4,12,2,6,6,7,16,8,14,2,10,20,15,3,7,4", "output": "1-17,19-21,26-27,29" }, { "input": "713,572,318,890,577,657,646,146,373,783,392,229,455,871,20,593,573,336,26,381,280,916,907,732,820,713,111,840,570,446,184,711,481,399,788,647,492,15,40,530,549,506,719,782,126,20,778,996,712,761,9,74,812,418,488,175,103,585,900,3,604,521,109,513,145,708,990,361,682,827,791,22,596,780,596,385,450,643,158,496,876,975,319,783,654,895,891,361,397,81,682,899,347,623,809,557,435,279,513,438", "output": "3,9,15,20,22,26,40,74,81,103,109,111,126,145-146,158,175,184,229,279-280,318-319,336,347,361,373,381,385,392,397,399,418,435,438,446,450,455,481,488,492,496,506,513,521,530,549,557,570,572-573,577,585,593,596,604,623,643,646-647,654,657,682,708,711-713,719,732,761,778,780,782-783,788,791,809,812,820,827,840,871,876,890-891,895,899-900,907,916,975,990,996" }, { "input": "31,75,86,68,111,27,22,22,26,30,54,163,107,75,160,122,14,23,17,26,27,20,43,58,59,71,21,148,9,32,43,91,133,286,132,70,90,156,84,14,77,93,23,18,13,72,18,131,33,28,72,175,30,86,249,20,14,208,28,57,63,199,6,10,24,30,62,267,43,479,60,28,138,1,45,3,19,47,7,166,116,117,50,140,28,14,95,85,93,43,61,15,2,70,10,51,7,95,9,25", "output": "1-3,6-7,9-10,13-15,17-28,30-33,43,45,47,50-51,54,57-63,68,70-72,75,77,84-86,90-91,93,95,107,111,116-117,122,131-133,138,140,148,156,160,163,166,175,199,208,249,267,286,479" }, { "input": "896,898,967,979,973,709,961,968,806,967,896,967,826,975,936,903,986,856,851,931,852,971,786,837,949,978,686,936,952,909,965,749,908,916,943,973,983,975,939,886,964,928,960,976,907,788,994,773,949,871,947,980,945,985,726,981,887,943,907,990,931,874,840,867,948,951,961,904,888,901,976,967,994,921,828,970,972,722,755,970,860,855,914,869,714,899,969,978,898,862,642,939,904,936,819,934,884,983,955,964", "output": "642,686,709,714,722,726,749,755,773,786,788,806,819,826,828,837,840,851-852,855-856,860,862,867,869,871,874,884,886-888,896,898-899,901,903-904,907-909,914,916,921,928,931,934,936,939,943,945,947-949,951-952,955,960-961,964-965,967-973,975-976,978-981,983,985-986,990,994" }, { "input": "994,927,872,970,815,986,952,996,965,1000,877,986,978,999,950,990,936,997,993,960,921,860,895,869,943,998,983,968,973,953,999,990,995,871,853,979,973,963,953,938,997,989,993,964,960,973,946,975,1000,962,920,746,989,957,904,965,920,979,966,961,1000,993,975,952,846,971,991,979,985,969,984,973,956,1000,952,778,983,974,956,927,995,997,980,997,1000,970,960,970,988,983,947,904,935,972,1000,863,992,996,932,967", "output": "746,778,815,846,853,860,863,869,871-872,877,895,904,920-921,927,932,935-936,938,943,946-947,950,952-953,956-957,960-975,978-980,983-986,988-1000" }, { "input": "48,108,63,21,27,8,49,21,75,8,24,42,149,18,8,28,21,18,25,35,59,70,59,33,40,1,67,34,120,82,4,115,72,87,3,15,15,63,37,12,40,27,83,14,38,20,14,58,93,10,31,3,39,6,197,77,54,16,31,146,9,49,14,8,77,82,5,11,80,116,8,61,50,24,7,103,29,11,3,3,1,12,46,24,21,131,39,29,36,2,107,40,16,99,31,41,29,48,17,17", "output": "1-12,14-18,20-21,24-25,27-29,31,33-42,46,48-50,54,58-59,61,63,67,70,72,75,77,80,82-83,87,93,99,103,107-108,115-116,120,131,146,149,197" }, { "input": "744,359,230,586,944,442", "output": "230,359,442,586,744,944" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "37", "output": "37" }, { "input": "999", "output": "999" }, { "input": "1000", "output": "1000" } ]
1,658,142,001
2,147,483,647
Python 3
OK
TESTS
26
92
0
a = sorted(set(map(int, input().split(",")))) left = right = a[0] for x in a[1:]: if x - right > 1: if left == right: print(left, end=",") else: print(left, right, sep="-", end=",") left = x right = x if left == right: print(left) else: print(left, right, sep="-")
Title: Page Numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format *l*1-*r*1,*l*2-*r*2,...,*l**k*-*r**k*, where *r**i*<=+<=1<=&lt;<=*l**i*<=+<=1 for all *i* from 1 to *k*<=-<=1, and *l**i*<=≤<=*r**i*. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element *i* from the new sequence *l**i*<==<=*r**i*, this element should be output as *l**i*, and not as «*l**i*<=-<=*l**i*». For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6. Input Specification: The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row. Output Specification: Output the sequence in the required format. Demo Input: ['1,2,3,1,1,2,6,6,2\n', '3,2,1\n', '30,20,10\n'] Demo Output: ['1-3,6\n', '1-3\n', '10,20,30\n'] Note: none
```python a = sorted(set(map(int, input().split(",")))) left = right = a[0] for x in a[1:]: if x - right > 1: if left == right: print(left, end=",") else: print(left, right, sep="-", end=",") left = x right = x if left == right: print(left) else: print(left, right, sep="-") ```
3.977
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "1 1 1 1 1 1", "output": "Elephant" }, { "input": "9 9 9 9 9 9", "output": "Elephant" }, { "input": "1 8 9 1 1 1", "output": "Bear" }, { "input": "9 9 9 1 9 9", "output": "Bear" }, { "input": "1 2 3 8 9 7", "output": "Alien" }, { "input": "5 5 5 6 6 6", "output": "Alien" }, { "input": "1 1 2 2 3 4", "output": "Alien" }, { "input": "4 4 4 4 4 2", "output": "Bear" }, { "input": "2 2 3 3 4 4", "output": "Alien" }, { "input": "4 4 4 4 4 5", "output": "Bear" }, { "input": "1 1 2 2 2 2", "output": "Elephant" }, { "input": "1 2 5 5 5 5", "output": "Bear" }, { "input": "4 4 2 2 2 2", "output": "Elephant" }, { "input": "1 1 1 1 1 2", "output": "Bear" }, { "input": "2 2 4 4 4 4", "output": "Elephant" }, { "input": "4 4 4 4 4 3", "output": "Bear" }, { "input": "4 4 5 6 7 8", "output": "Alien" }, { "input": "4 4 4 4 2 2", "output": "Elephant" }, { "input": "1 1 1 1 2 2", "output": "Elephant" }, { "input": "1 1 3 3 3 5", "output": "Alien" }, { "input": "1 2 2 3 3 3", "output": "Alien" }, { "input": "1 2 2 2 2 2", "output": "Bear" }, { "input": "1 3 3 3 4 5", "output": "Alien" }, { "input": "5 1 1 1 1 1", "output": "Bear" } ]
1,488,640,878
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
4,608,000
'''input 4 2 5 4 4 4 ''' l = list(map(int, input().split())) x = sorted([l.count(i) for i in set(l)]) if x == [6] or x == [2, 4]: print("Elephant") elif x == [1, 1, 4]: print("Bear") else: print("Alien")
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. Input Specification: The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. Output Specification: If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). Demo Input: ['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n'] Demo Output: ['Bear', 'Elephant', 'Alien'] Note: If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
```python '''input 4 2 5 4 4 4 ''' l = list(map(int, input().split())) x = sorted([l.count(i) for i in set(l)]) if x == [6] or x == [2, 4]: print("Elephant") elif x == [1, 1, 4]: print("Bear") else: print("Alien") ```
0
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3. You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": "1+2+1+2+2+2+2+1+3+3", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "1", "output": "1" }, { "input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3", "output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "3", "output": "3" }, { "input": "1+1", "output": "1+1" }, { "input": "1+2", "output": "1+2" }, { "input": "1+3", "output": "1+3" }, { "input": "2+1", "output": "1+2" }, { "input": "2+2", "output": "2+2" }, { "input": "2+3", "output": "2+3" }, { "input": "3+1", "output": "1+3" }, { "input": "3+2", "output": "2+3" }, { "input": "3+3", "output": "3+3" } ]
1,699,968,551
2,147,483,647
Python 3
OK
TESTS
21
92
0
s1 = input() nums=[] for i in s1 : if i.isdigit(): nums.append(("+"+i)) nums.sort() x=("".join(nums[0:])) print(x.replace("+","",1))
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3. You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. Input Specification: The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. Output Specification: Print the new sum that Xenia can count. Demo Input: ['3+2+1\n', '1+1+3+1+3\n', '2\n'] Demo Output: ['1+2+3\n', '1+1+1+3+3\n', '2\n'] Note: none
```python s1 = input() nums=[] for i in s1 : if i.isdigit(): nums.append(("+"+i)) nums.sort() x=("".join(nums[0:])) print(x.replace("+","",1)) ```
3
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,634,931,394
2,147,483,647
Python 3
OK
TESTS
73
46
4,608,000
s1 = input() s2 = input() if s1 == s2: print(-1) elif len(s1) > len(s2): print(len(s1)) elif len(s2) > len(s1): print(len(s2)) else: print(len(s1))
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 s1 = input() s2 = input() if s1 == s2: print(-1) elif len(s1) > len(s2): print(len(s1)) elif len(s2) > len(s1): print(len(s2)) else: print(len(s1)) ```
3
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,672,823,236
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
d=['h','e','l','o'] a=list(input()) e=[] for j in a: if j not in e and j in d: e.append(j) if e==d and a.count('l')>=2: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python d=['h','e','l','o'] a=list(input()) e=[] for j in a: if j not in e and j in d: e.append(j) if e==d and a.count('l')>=2: print("YES") else: print("NO") ```
0
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii".
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { "input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa", "output": "0" }, { "input": "3\nxxx", "output": "1" }, { "input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz", "output": "0" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx", "output": "41" }, { "input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc", "output": "49" }, { "input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx", "output": "41" }, { "input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "5\nfcyju", "output": "0" }, { "input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx", "output": "2" } ]
1,677,090,482
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
0
n = int(input()) l = list(input()) count = 0 for x in reversed(range(n)): if x < 2: break if l[x] == "x" and l[x-1] == "x" and l[x-2] == "x": l.remove(l[x]) count = count + 1 print(count)
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". Input Specification: The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. Output Specification: Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Demo Input: ['6\nxxxiii\n', '5\nxxoxx\n', '10\nxxxxxxxxxx\n'] Demo Output: ['1\n', '0\n', '8\n'] Note: In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
```python n = int(input()) l = list(input()) count = 0 for x in reversed(range(n)): if x < 2: break if l[x] == "x" and l[x-1] == "x" and l[x-2] == "x": l.remove(l[x]) count = count + 1 print(count) ```
0
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,663,530,730
2,147,483,647
Python 3
OK
TESTS
23
92
409,600
import string n=int(input()) s=input() if 'L' not in s: print(s.find('R')+1,s.rfind('R')+2) elif 'R' not in s: print(s.rfind('L')+1,s.find('L')) elif 'R' in s and 'L' in s: print(s.find('R')+1,s.find("L"))
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. Output Specification: Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. Demo Input: ['9\n..RRLL...\n', '11\n.RRRLLLLL..\n'] Demo Output: ['3 4\n', '7 5\n'] Note: The first test sample is the one in the picture.
```python import string n=int(input()) s=input() if 'L' not in s: print(s.find('R')+1,s.rfind('R')+2) elif 'R' not in s: print(s.rfind('L')+1,s.find('L')) elif 'R' in s and 'L' in s: print(s.find('R')+1,s.find("L")) ```
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,622,644,484
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
num = int(input()) if num % 2 == 1 or num < 5: print("NO") else: cnt = 0 for i in range(1, num // 4+1): ans = [i, i, num // 2 - i, num // 2 - i] if len(set(ans)) != 1: cnt += 1 print(cnt)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python num = int(input()) if num % 2 == 1 or num < 5: print("NO") else: cnt = 0 for i in range(1, num // 4+1): ans = [i, i, num // 2 - i, num // 2 - i] if len(set(ans)) != 1: cnt += 1 print(cnt) ```
0
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4", "output": "0\nDDDDRRRR" }, { "input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4", "output": "1\nDDRRDRDDRR" }, { "input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2", "output": "0\nRRDRRDRDDDDR" }, { "input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4", "output": "0\nDRRRRRRRDDDDDD" }, { "input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5", "output": "1\nDDDDDRDDDRRRRRRR" }, { "input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3", "output": "1\nDRDDDRRDDDRRDRDRRR" } ]
1,580,587,556
5,396
PyPy 3
WRONG_ANSWER
TESTS
12
155
3,891,200
from math import log2 def hp2(n): if n % 2 != 0: return 0 return round(log2((n & (~(n - 1))))) def hp5(n): if n % 5 != 0: return 0 p = 1 m = 5 while n % m == 0: p += 1 m *= 5 return p - 1 def extract(x): t, f = hp2(x), hp5(x) zeros = min(t, f) # print("extracting", x, (zeros, t - zeros, f - zeros)) return (zeros, t - zeros, f - zeros) inf = float("Inf") def count(x, y): if(memo[x][y] != None): return memo[x][y] tempZ, tempT, tempF = extract(m[x][y]) step = -1 # 0 for up, 1 for left, -1 for start if x == 0 and y == 0: ans = (tempZ, tempT, tempF) else: ans = (inf, inf, inf) if x > 0: temp = count(x - 1, y) z = temp[0] + tempZ netF, netT = temp[2] + tempF, temp[1] + tempT k = min(netF, netT) z += k if z < ans[0]: step = 0 ans = (z, netT - k, netF - k) if y > 0: temp = count(x, y - 1) z = temp[0] + tempZ netF, netT = temp[2] + tempF, temp[1] + tempT k = min(netF, netT) z += k if z < ans[0]: step = 1 ans = (z, netT - k, netF - k) # print(x, y, ans, "from", "left" if step == 0 else "right") memo[x][y] = ans steps[x][y] = step return ans n = int(input()) m = [[0 for i in range(n)] for i in range(n)] memo = [[None for i in range(n)] for i in range(n)] steps = [[-1 for i in range(n)] for i in range(n)] for i in range(n): r = [int(k) for k in input().split()] for j in range(n): m[i][j] = r[j] ans = count(n - 1, n - 1)[0] path = "" x, y = n - 1, n - 1 while not (x == 0 and y == 0): # print(steps[x][y]) if steps[x][y] == 0: path = "D" + path x -= 1 else: path = "R" + path y -= 1 print(ans) print(path)
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. Input Specification: The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). Output Specification: In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n'] Demo Output: ['0\nDDRR\n'] Note: none
```python from math import log2 def hp2(n): if n % 2 != 0: return 0 return round(log2((n & (~(n - 1))))) def hp5(n): if n % 5 != 0: return 0 p = 1 m = 5 while n % m == 0: p += 1 m *= 5 return p - 1 def extract(x): t, f = hp2(x), hp5(x) zeros = min(t, f) # print("extracting", x, (zeros, t - zeros, f - zeros)) return (zeros, t - zeros, f - zeros) inf = float("Inf") def count(x, y): if(memo[x][y] != None): return memo[x][y] tempZ, tempT, tempF = extract(m[x][y]) step = -1 # 0 for up, 1 for left, -1 for start if x == 0 and y == 0: ans = (tempZ, tempT, tempF) else: ans = (inf, inf, inf) if x > 0: temp = count(x - 1, y) z = temp[0] + tempZ netF, netT = temp[2] + tempF, temp[1] + tempT k = min(netF, netT) z += k if z < ans[0]: step = 0 ans = (z, netT - k, netF - k) if y > 0: temp = count(x, y - 1) z = temp[0] + tempZ netF, netT = temp[2] + tempF, temp[1] + tempT k = min(netF, netT) z += k if z < ans[0]: step = 1 ans = (z, netT - k, netF - k) # print(x, y, ans, "from", "left" if step == 0 else "right") memo[x][y] = ans steps[x][y] = step return ans n = int(input()) m = [[0 for i in range(n)] for i in range(n)] memo = [[None for i in range(n)] for i in range(n)] steps = [[-1 for i in range(n)] for i in range(n)] for i in range(n): r = [int(k) for k in input().split()] for j in range(n): m[i][j] = r[j] ans = count(n - 1, n - 1)[0] path = "" x, y = n - 1, n - 1 while not (x == 0 and y == 0): # print(steps[x][y]) if steps[x][y] == 0: path = "D" + path x -= 1 else: path = "R" + path y -= 1 print(ans) print(path) ```
0
611
C
New Year and Domino
PROGRAMMING
1,500
[ "dp", "implementation" ]
null
null
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through *h* from top to bottom. Columns are numbered 1 through *w* from left to right. Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid. Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle?
The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively. The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively. The next line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of queries. Each of the next *q* lines contains four integers *r*1*i*, *c*1*i*, *r*2*i*, *c*2*i* (1<=≤<=*r*1*i*<=≤<=*r*2*i*<=≤<=*h*,<=1<=≤<=*c*1*i*<=≤<=*c*2*i*<=≤<=*w*) — the *i*-th query. Numbers *r*1*i* and *c*1*i* denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers *r*2*i* and *c*2*i* denote the row and the column (respectively) of the bottom right cell of the rectangle.
Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle.
[ "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n", "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8\n" ]
[ "4\n0\n10\n15\n", "53\n89\n120\n23\n0\n2\n" ]
A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways.
1,250
[ { "input": "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8", "output": "4\n0\n10\n15" }, { "input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8", "output": "53\n89\n120\n23\n0\n2" }, { "input": "2 20\n.#..................\n....................\n15\n1 3 1 13\n1 11 2 14\n1 17 1 20\n1 2 2 3\n1 7 1 10\n1 7 2 17\n1 4 1 9\n2 6 2 8\n1 8 2 20\n2 7 2 16\n1 4 2 16\n1 6 1 9\n1 4 2 7\n1 9 1 20\n2 2 2 12", "output": "10\n10\n3\n2\n3\n31\n5\n2\n37\n9\n37\n3\n10\n11\n10" }, { "input": "15 3\n...\n.#.\n.#.\n.#.\n..#\n...\n.#.\n.##\n.#.\n...\n...\n.##\n..#\n.#.\n#.#\n20\n1 1 10 1\n2 1 9 3\n1 2 15 3\n10 2 12 2\n4 1 8 1\n5 2 8 2\n10 1 12 3\n11 1 11 3\n7 2 14 3\n6 2 12 3\n8 1 11 2\n7 1 9 1\n2 1 6 2\n6 3 7 3\n7 1 10 2\n6 1 10 2\n1 1 2 2\n10 1 15 3\n1 1 11 1\n9 1 15 1", "output": "9\n14\n12\n1\n4\n1\n8\n2\n5\n7\n6\n2\n7\n1\n4\n6\n2\n11\n10\n5" }, { "input": "7 19\n.##.#.#.#....#.#...\n.#...##..........#.\n..#.........#..#.#.\n#.#....#....#......\n.#.#.#.#....###...#\n.....##.....#......\n..........#.#..#.#.\n10\n2 2 3 10\n4 10 5 16\n3 3 6 12\n2 12 6 14\n5 1 5 19\n3 11 3 13\n4 10 5 17\n1 13 4 19\n5 3 5 17\n4 15 7 19", "output": "15\n10\n43\n8\n5\n1\n13\n24\n4\n19" }, { "input": "1 1\n.\n1\n1 1 1 1", "output": "0" }, { "input": "1 1\n#\n1\n1 1 1 1", "output": "0" } ]
1,451,570,680
2,147,483,647
Python 3
OK
TESTS
52
2,371
13,516,800
read = lambda: map(int, input().split()) h, w = read() a = [input() for i in range(h)] N = 501 vr = [[0] * N for i in range(N)] hr = [[0] * N for i in range(N)] for i in range(h): for j in range(w): vr[j + 1][i + 1] = vr[j][i + 1] + vr[j + 1][i] - vr[j][i] hr[j + 1][i + 1] = hr[j][i + 1] + hr[j + 1][i] - hr[j][i] if a[i][j] == '#': continue if i != h - 1 and a[i + 1][j] == '.': vr[j + 1][i + 1] += 1 if j != w - 1 and a[i][j + 1] == '.': hr[j + 1][i + 1] += 1 q = int(input()) for i in range(q): r1, c1, r2, c2 = read() p1 = hr[c2 - 1][r2] - hr[c1 - 1][r2] - hr[c2 - 1][r1 - 1] + hr[c1 - 1][r1 - 1] p2 = vr[c2][r2 - 1] - vr[c1 - 1][r2 - 1] - vr[c2][r1 - 1] + vr[c1 - 1][r1 - 1] ans = p1 + p2 print(ans)
Title: New Year and Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through *h* from top to bottom. Columns are numbered 1 through *w* from left to right. Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid. Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle? Input Specification: The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively. The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively. The next line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of queries. Each of the next *q* lines contains four integers *r*1*i*, *c*1*i*, *r*2*i*, *c*2*i* (1<=≤<=*r*1*i*<=≤<=*r*2*i*<=≤<=*h*,<=1<=≤<=*c*1*i*<=≤<=*c*2*i*<=≤<=*w*) — the *i*-th query. Numbers *r*1*i* and *c*1*i* denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers *r*2*i* and *c*2*i* denote the row and the column (respectively) of the bottom right cell of the rectangle. Output Specification: Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle. Demo Input: ['5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n', '7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8\n'] Demo Output: ['4\n0\n10\n15\n', '53\n89\n120\n23\n0\n2\n'] Note: A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways.
```python read = lambda: map(int, input().split()) h, w = read() a = [input() for i in range(h)] N = 501 vr = [[0] * N for i in range(N)] hr = [[0] * N for i in range(N)] for i in range(h): for j in range(w): vr[j + 1][i + 1] = vr[j][i + 1] + vr[j + 1][i] - vr[j][i] hr[j + 1][i + 1] = hr[j][i + 1] + hr[j + 1][i] - hr[j][i] if a[i][j] == '#': continue if i != h - 1 and a[i + 1][j] == '.': vr[j + 1][i + 1] += 1 if j != w - 1 and a[i][j + 1] == '.': hr[j + 1][i + 1] += 1 q = int(input()) for i in range(q): r1, c1, r2, c2 = read() p1 = hr[c2 - 1][r2] - hr[c1 - 1][r2] - hr[c2 - 1][r1 - 1] + hr[c1 - 1][r1 - 1] p2 = vr[c2][r2 - 1] - vr[c1 - 1][r2 - 1] - vr[c2][r1 - 1] + vr[c1 - 1][r1 - 1] ans = p1 + p2 print(ans) ```
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,666,187,439
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
46
1,740,800
n=[int(x) for x in input().split(' ')] c=[int(x) for x in input().split(' ')] respuesta="NO" cont=1 while cont<n[0]: if(cont==n[1]): respuesta="YES" cont+=c[cont-1] print(respuesta)
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 n=[int(x) for x in input().split(' ')] c=[int(x) for x in input().split(' ')] respuesta="NO" cont=1 while cont<n[0]: if(cont==n[1]): respuesta="YES" cont+=c[cont-1] print(respuesta) ```
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,666,422,584
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
def sol(n): if n == 1: return -1 arr = [0]*n for i in range(n): arr[i] = n-i if n%2 != 0: temp = arr[int(n/2)] arr[int(n/2)] = arr[int(n/2)+1] arr[int(n/2)+1] = temp return arr n = int(input()) ans = sol(n) print(ans)
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 def sol(n): if n == 1: return -1 arr = [0]*n for i in range(n): arr[i] = n-i if n%2 != 0: temp = arr[int(n/2)] arr[int(n/2)] = arr[int(n/2)+1] arr[int(n/2)+1] = temp return arr n = int(input()) ans = sol(n) print(ans) ```
0
400
B
Inna and New Matrix of Candies
PROGRAMMING
1,200
[ "brute force", "implementation", "schedules" ]
null
null
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs: - some dwarf in one of the chosen lines is located in the rightmost cell of his row; - some dwarf in the chosen lines is located in the cell with the candy. The point of the game is to transport all the dwarves to the candy cells. Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000). Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
[ "3 4\n*G*S\nG**S\n*G*S\n", "1 3\nS*G\n" ]
[ "2\n", "-1\n" ]
none
1,000
[ { "input": "3 4\n*G*S\nG**S\n*G*S", "output": "2" }, { "input": "1 3\nS*G", "output": "-1" }, { "input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S", "output": "9" }, { "input": "5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****", "output": "4" }, { "input": "4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*", "output": "3" }, { "input": "4 10\n***G****S*\n*****GS***\nG****S****\nG*******S*", "output": "3" }, { "input": "1 2\nSG", "output": "-1" }, { "input": "1 2\nGS", "output": "1" }, { "input": "1 4\nSG**", "output": "-1" } ]
1,651,509,846
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
0
n,m=map(int,input().split()) flag = ans =0 d=dict() for i in range(n): x = input() for j in range(m): if x[j]=='G': gidx=j elif x[j]=='S': sidx=j if sidx-gidx<0: flag=1;break else: if sidx-gidx in d: ans += 1 else: d[x]=1 ans = 1 print(ans if not flag else -1)
Title: Inna and New Matrix of Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs: - some dwarf in one of the chosen lines is located in the rightmost cell of his row; - some dwarf in the chosen lines is located in the cell with the candy. The point of the game is to transport all the dwarves to the candy cells. Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000). Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S". Output Specification: In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. Demo Input: ['3 4\n*G*S\nG**S\n*G*S\n', '1 3\nS*G\n'] Demo Output: ['2\n', '-1\n'] Note: none
```python n,m=map(int,input().split()) flag = ans =0 d=dict() for i in range(n): x = input() for j in range(m): if x[j]=='G': gidx=j elif x[j]=='S': sidx=j if sidx-gidx<0: flag=1;break else: if sidx-gidx in d: ans += 1 else: d[x]=1 ans = 1 print(ans if not flag else -1) ```
0
656
G
You're a Professional
PROGRAMMING
1,900
[ "*special" ]
null
null
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends.
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output an integer — the number of items liked by at least *T* of user's friends.
[ "3 3 2\nYYY\nNNN\nYNY\n", "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n" ]
[ "2\n", "4\n" ]
none
0
[ { "input": "3 3 2\nYYY\nNNN\nYNY", "output": "2" }, { "input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN", "output": "4" }, { "input": "3 5 2\nNYNNY\nYNNNN\nNNYYN", "output": "0" }, { "input": "1 10 1\nYYYNYNNYNN", "output": "5" }, { "input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN", "output": "0" }, { "input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN", "output": "0" }, { "input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY", "output": "10" }, { "input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY", "output": "9" }, { "input": "5 2 3\nNN\nNY\nYY\nNN\nNY", "output": "1" }, { "input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY", "output": "0" }, { "input": "6 1 3\nY\nY\nY\nY\nY\nN", "output": "1" }, { "input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN", "output": "1" }, { "input": "2 4 2\nNYNY\nNYNY", "output": "2" }, { "input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY", "output": "6" }, { "input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN", "output": "0" }, { "input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN", "output": "0" }, { "input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY", "output": "1" }, { "input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY", "output": "6" }, { "input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN", "output": "4" }, { "input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY", "output": "2" }, { "input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN", "output": "2" }, { "input": "3 1 1\nN\nY\nN", "output": "1" }, { "input": "7 1 3\nY\nY\nY\nN\nY\nY\nY", "output": "1" }, { "input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY", "output": "1" }, { "input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN", "output": "0" }, { "input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN", "output": "4" }, { "input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN", "output": "3" }, { "input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY", "output": "5" }, { "input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY", "output": "2" }, { "input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN", "output": "1" }, { "input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN", "output": "3" }, { "input": "1 3 1\nYYN", "output": "2" }, { "input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY", "output": "4" } ]
1,490,896,896
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
5,529,600
def main(): f, i, t = map(int, input().split()) ans = 0 for _ in range(f): likes = input() count = sum(1 for like in likes if like == 'Y') if count >= t: ans += 1 print(ans) main()
Title: You're a Professional Time Limit: None seconds Memory Limit: None megabytes Problem Description: A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends. Input Specification: The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. Output Specification: Output an integer — the number of items liked by at least *T* of user's friends. Demo Input: ['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n'] Demo Output: ['2\n', '4\n'] Note: none
```python def main(): f, i, t = map(int, input().split()) ans = 0 for _ in range(f): likes = input() count = sum(1 for like in likes if like == 'Y') if count >= t: ans += 1 print(ans) main() ```
0
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n500\n500", "output": "0.5" }, { "input": "1000\n1\n1", "output": "500" }, { "input": "1000\n1\n500", "output": "1.996007984" }, { "input": "1000\n500\n1", "output": "998.003992" }, { "input": "1000\n500\n500", "output": "500" }, { "input": "101\n11\n22", "output": "33.66666667" }, { "input": "987\n1\n3", "output": "246.75" }, { "input": "258\n25\n431", "output": "14.14473684" }, { "input": "979\n39\n60", "output": "385.6666667" }, { "input": "538\n479\n416", "output": "287.9351955" }, { "input": "583\n112\n248", "output": "181.3777778" }, { "input": "978\n467\n371", "output": "545.0190931" }, { "input": "980\n322\n193", "output": "612.7378641" }, { "input": "871\n401\n17", "output": "835.576555" }, { "input": "349\n478\n378", "output": "194.885514" }, { "input": "425\n458\n118", "output": "337.9340278" }, { "input": "919\n323\n458", "output": "380.0729834" }, { "input": "188\n59\n126", "output": "59.95675676" }, { "input": "644\n428\n484", "output": "302.2280702" }, { "input": "253\n80\n276", "output": "56.85393258" }, { "input": "745\n152\n417", "output": "199.0158172" }, { "input": "600\n221\n279", "output": "265.2" }, { "input": "690\n499\n430", "output": "370.6243272" }, { "input": "105\n68\n403", "output": "15.15923567" }, { "input": "762\n462\n371", "output": "422.6218487" }, { "input": "903\n460\n362", "output": "505.3284672" }, { "input": "886\n235\n95", "output": "630.9393939" }, { "input": "655\n203\n18", "output": "601.6515837" }, { "input": "718\n29\n375", "output": "51.53960396" }, { "input": "296\n467\n377", "output": "163.7819905" }, { "input": "539\n61\n56", "output": "281.017094" }, { "input": "133\n53\n124", "output": "39.82485876" }, { "input": "998\n224\n65", "output": "773.5363322" }, { "input": "961\n173\n47", "output": "755.6954545" }, { "input": "285\n468\n62", "output": "251.6603774" }, { "input": "496\n326\n429", "output": "214.1668874" }, { "input": "627\n150\n285", "output": "216.2068966" }, { "input": "961\n443\n50", "output": "863.535497" }, { "input": "623\n422\n217", "output": "411.4334898" }, { "input": "678\n295\n29", "output": "617.3148148" } ]
1,616,991,862
2,147,483,647
Python 3
OK
TESTS
45
77
0
s=int(input()) p=int(input()) q=int(input()) print(s*p/(p+q))
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of *q* meters per second. The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse. Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight. Input Specification: The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively. Output Specification: Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['100\n50\n50\n', '199\n60\n40\n'] Demo Output: ['50\n', '119.4\n'] Note: In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
```python s=int(input()) p=int(input()) q=int(input()) print(s*p/(p+q)) ```
3
940
B
Our Tanya is Crying Out Loud
PROGRAMMING
1,400
[ "dp", "greedy" ]
null
null
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
[ "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n" ]
[ "6\n", "8\n", "12\n" ]
In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
1,250
[ { "input": "9\n2\n3\n1", "output": "6" }, { "input": "5\n5\n2\n20", "output": "8" }, { "input": "19\n3\n4\n2", "output": "12" }, { "input": "1845999546\n999435865\n1234234\n2323423", "output": "1044857680578777" }, { "input": "1604353664\n1604353665\n9993432\n1", "output": "16032999235141416" }, { "input": "777888456\n1\n98\n43", "output": "76233068590" }, { "input": "1162261467\n3\n1\n2000000000", "output": "1162261466" }, { "input": "1000000000\n1999999999\n789987\n184569875", "output": "789986999210013" }, { "input": "2000000000\n2\n1\n2000000000", "output": "1999999999" }, { "input": "1999888325\n3\n2\n2000000000", "output": "3333258884" }, { "input": "1897546487\n687\n89798979\n879876541", "output": "110398404423" }, { "input": "20\n1\n20\n1", "output": "380" }, { "input": "16\n5\n17\n3", "output": "54" }, { "input": "19\n19\n19\n1", "output": "1" }, { "input": "18\n2\n3\n16", "output": "40" }, { "input": "1\n11\n8\n9", "output": "0" }, { "input": "9\n10\n1\n20", "output": "8" }, { "input": "19\n10\n19\n2", "output": "173" }, { "input": "16\n9\n14\n2", "output": "100" }, { "input": "15\n2\n5\n2", "output": "21" }, { "input": "14\n7\n13\n1", "output": "14" }, { "input": "43\n3\n45\n3", "output": "189" }, { "input": "99\n1\n98\n1", "output": "9604" }, { "input": "77\n93\n100\n77", "output": "7600" }, { "input": "81\n3\n91\n95", "output": "380" }, { "input": "78\n53\n87\n34", "output": "2209" }, { "input": "80\n3\n15\n1", "output": "108" }, { "input": "97\n24\n4\n24", "output": "40" }, { "input": "100\n100\n1\n100", "output": "99" }, { "input": "87\n4\n17\n7", "output": "106" }, { "input": "65\n2\n3\n6", "output": "36" }, { "input": "1000000\n1435\n3\n999999", "output": "1005804" }, { "input": "783464\n483464\n2\n966928", "output": "1566926" }, { "input": "248035\n11\n3\n20", "output": "202" }, { "input": "524287\n2\n945658\n999756", "output": "34963354" }, { "input": "947352\n78946\n85\n789654", "output": "790589" }, { "input": "1000000\n1\n999899\n60", "output": "999898000101" }, { "input": "753687\n977456\n6547\n456", "output": "4934382242" }, { "input": "1000000\n500000\n1\n999997", "output": "999998" }, { "input": "997458\n843596\n1\n843596", "output": "997457" }, { "input": "821109\n92\n6547\n98787", "output": "394566" }, { "input": "1073741823\n2\n9543\n8923453", "output": "188412866" }, { "input": "1000999777\n1934999345\n2356346\n34534565", "output": "2358701818178496" }, { "input": "2000000000\n1\n2000000000\n98", "output": "3999999998000000000" }, { "input": "1999324353\n978435356\n1\n978435356", "output": "1020888998" }, { "input": "2000000000\n2\n2000000000\n2000000000", "output": "84000000000" }, { "input": "241375690\n17\n2\n1998789654", "output": "482751378" }, { "input": "171507000\n350\n789\n6548687", "output": "14216965" }, { "input": "1100220011\n10001\n2\n1999778654", "output": "1999998674" }, { "input": "1867622656\n43216\n789644\n12315468", "output": "24630936" }, { "input": "1867622656\n43216\n1\n1879865413", "output": "1867622655" }, { "input": "1999999999\n1000000000\n789987\n184569875", "output": "789987183779888" }, { "input": "1987987897\n103546\n7\n98754563", "output": "98946650" }, { "input": "10\n2\n2\n5", "output": "13" }, { "input": "7\n2\n1\n100000", "output": "6" }, { "input": "7\n2\n3\n1", "output": "8" }, { "input": "2000000000\n666666667\n1\n1", "output": "666666668" }, { "input": "1999999997\n666666666\n2\n2", "output": "1333333334" } ]
1,594,024,095
2,147,483,647
Python 3
OK
TESTS
58
109
6,963,200
n = int(input()) k = int(input()) a = int(input()) b = int(input()) res = 0 while n!=1: if k==1 or k>n: res+=a*(n-1) break if n%k!=0: res+=a*(n%k) n = n-n%k else: temp = n//k res+=min(b,a*(n-temp)) n = temp print(res)
Title: Our Tanya is Crying Out Loud Time Limit: None seconds Memory Limit: None megabytes Problem Description: Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109). The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109). The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). Output Specification: Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. Demo Input: ['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n'] Demo Output: ['6\n', '8\n', '12\n'] Note: In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
```python n = int(input()) k = int(input()) a = int(input()) b = int(input()) res = 0 while n!=1: if k==1 or k>n: res+=a*(n-1) break if n%k!=0: res+=a*(n%k) n = n-n%k else: temp = n//k res+=min(b,a*(n-temp)) n = temp print(res) ```
3
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872", "output": "NO" }, { "input": "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326", "output": "YES" }, { "input": "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024", "output": "YES" }, { "input": "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627", "output": "YES" }, { "input": "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563", "output": "YES" }, { "input": "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943", "output": "NO" } ]
1,516,493,982
2,147,483,647
Python 3
OK
TESTS
30
124
5,632,000
n = int(input()) A = set() for _ in range(n): x, d = map(int, input().split()) A.add((x, d)) found = False for x, d in A: if (x + d, -d) in A: found = True if found: print("YES") else: print("NO")
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. Output Specification: If there are two camels, which spitted at each other, output YES. Otherwise, output NO. Demo Input: ['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python n = int(input()) A = set() for _ in range(n): x, d = map(int, input().split()) A.add((x, d)) found = False for x, d in A: if (x + d, -d) in A: found = True if found: print("YES") else: print("NO") ```
3.95851
891
A
Pride
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "math", "number theory" ]
null
null
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1?
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array. The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.
[ "5\n2 2 3 4 6\n", "4\n2 4 6 8\n", "3\n2 6 9\n" ]
[ "5\n", "-1\n", "4\n" ]
In the first sample you can turn all numbers to 1 using the following 5 moves: - [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
500
[ { "input": "5\n2 2 3 4 6", "output": "5" }, { "input": "4\n2 4 6 8", "output": "-1" }, { "input": "3\n2 6 9", "output": "4" }, { "input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21", "output": "15" }, { "input": "12\n10 10 14 14 14 14 14 14 14 14 21 21", "output": "20" }, { "input": "5\n10 10 14 21 21", "output": "6" }, { "input": "9\n10 10 10 10 10 14 14 21 21", "output": "11" }, { "input": "9\n10 10 10 10 10 10 10 10 21", "output": "9" }, { "input": "13\n10 10 10 15 15 15 15 15 15 15 15 21 21", "output": "21" }, { "input": "15\n10 10 10 10 10 10 10 10 10 10 10 10 15 15 21", "output": "17" }, { "input": "4\n1 1 1 1", "output": "0" }, { "input": "1\n3", "output": "-1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n1000000000 1000000000", "output": "-1" }, { "input": "1\n1000000000", "output": "-1" }, { "input": "1\n1", "output": "0" }, { "input": "3\n42 15 35", "output": "4" }, { "input": "3\n6 10 15", "output": "4" }, { "input": "4\n2 1 1 1", "output": "1" }, { "input": "5\n2 1 1 1 2", "output": "2" }, { "input": "3\n30 14 21", "output": "4" }, { "input": "3\n15 6 10", "output": "4" }, { "input": "4\n1 1 1 2", "output": "1" }, { "input": "5\n1 1 1 2 2", "output": "2" }, { "input": "4\n2 6 9 1", "output": "3" }, { "input": "6\n2 3 4 1 1 1", "output": "3" }, { "input": "15\n2 6 6 6 3 3 3 15 5 5 5 7 5 5 5", "output": "15" }, { "input": "5\n2 3 2 6 9", "output": "5" }, { "input": "6\n6 15 10 6 15 10", "output": "7" } ]
1,588,292,609
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
202
2,560,000
def main(): n = int(input()) a = list(map(int, input().split())) if gcd_of_array(a) != 1: print(-1) else: left = 2 right = n while left <= right: mid = (left + right) // 2 if check(a, mid): right = mid - 1 else: left = mid + 1 ans = n + mid - 2 print(ans) def check(a, le): for i in range(len(a) - le): if gcd_of_array(a[i:i+le]) == 1: return True return False def gcd(a, b): if a == 0: return b else: return gcd(b % a, a) def gcd_of_array(a): res = a[0] for i in a: res = gcd(res, i) if res == 1: break return res main()
Title: Pride Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array. The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. Output Specification: Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Demo Input: ['5\n2 2 3 4 6\n', '4\n2 4 6 8\n', '3\n2 6 9\n'] Demo Output: ['5\n', '-1\n', '4\n'] Note: In the first sample you can turn all numbers to 1 using the following 5 moves: - [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
```python def main(): n = int(input()) a = list(map(int, input().split())) if gcd_of_array(a) != 1: print(-1) else: left = 2 right = n while left <= right: mid = (left + right) // 2 if check(a, mid): right = mid - 1 else: left = mid + 1 ans = n + mid - 2 print(ans) def check(a, le): for i in range(len(a) - le): if gcd_of_array(a[i:i+le]) == 1: return True return False def gcd(a, b): if a == 0: return b else: return gcd(b % a, a) def gcd_of_array(a): res = a[0] for i in a: res = gcd(res, i) if res == 1: break return res main() ```
0
868
C
Qualification Rounds
PROGRAMMING
1,500
[ "bitmasks", "brute force", "constructive algorithms", "dp" ]
null
null
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n", "3 2\n1 0\n1 1\n0 1\n" ]
[ "NO\n", "YES\n" ]
In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
1,000
[ { "input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO" }, { "input": "3 2\n1 0\n1 1\n0 1", "output": "YES" }, { "input": "10 2\n1 0\n1 0\n0 0\n1 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1", "output": "YES" }, { "input": "10 3\n1 0 0\n0 1 1\n1 0 0\n0 1 0\n0 0 1\n1 0 1\n0 1 1\n1 0 0\n1 1 0\n0 0 0", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 0 1\n1 1 0 1\n1 0 1 1\n1 1 0 1\n1 0 1 0\n0 0 0 0\n0 0 1 0\n1 0 1 0\n0 0 1 1", "output": "YES" }, { "input": "2 2\n0 0\n1 0", "output": "YES" }, { "input": "3 3\n1 0 1\n1 0 0\n1 1 1", "output": "NO" }, { "input": "4 4\n0 0 0 0\n1 1 0 0\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "4 1\n1\n1\n0\n0", "output": "YES" }, { "input": "1 4\n0 0 0 0", "output": "YES" }, { "input": "3 3\n0 0 1\n0 1 1\n1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n1 0 0", "output": "YES" }, { "input": "1 1\n0", "output": "YES" }, { "input": "2 4\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 0 1\n1 1 1 1", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 1 1 0\n1 1 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 0\n0 0 1 0", "output": "YES" }, { "input": "2 4\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 0 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 1 0\n0 1 1 1\n1 0 0 0", "output": "YES" }, { "input": "1 2\n0 0", "output": "YES" }, { "input": "6 3\n0 1 1\n1 0 1\n1 1 1\n0 1 0\n1 0 1\n1 1 0", "output": "YES" }, { "input": "1 4\n0 0 1 1", "output": "NO" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 1", "output": "YES" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 1", "output": "YES" }, { "input": "3 2\n0 0\n0 0\n0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n1 0 1 1", "output": "NO" }, { "input": "2 4\n0 0 0 1\n1 0 0 0", "output": "YES" }, { "input": "2 4\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "4 4\n1 1 1 1\n0 0 0 1\n0 0 1 1\n1 0 1 1", "output": "NO" }, { "input": "6 3\n1 0 0\n1 1 1\n1 1 1\n0 1 0\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 1 0 0\n1 1 1 1\n1 1 1 1\n1 0 1 1", "output": "YES" }, { "input": "1 3\n0 0 0", "output": "YES" }, { "input": "3 3\n1 0 0\n0 1 0\n0 0 0", "output": "YES" }, { "input": "2 4\n0 1 1 0\n0 0 0 0", "output": "YES" }, { "input": "1 4\n0 0 0 1", "output": "NO" }, { "input": "4 4\n0 0 0 1\n0 0 0 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 1", "output": "YES" }, { "input": "3 2\n0 1\n0 1\n1 0", "output": "YES" }, { "input": "4 3\n1 1 0\n1 1 1\n0 0 1\n0 0 1", "output": "YES" }, { "input": "2 1\n0\n0", "output": "YES" }, { "input": "2 4\n1 1 1 0\n0 0 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n1 1 0 0", "output": "NO" }, { "input": "3 4\n0 1 1 0\n0 1 0 1\n0 0 1 1", "output": "NO" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 0 0 0\n0 1 1 1", "output": "YES" }, { "input": "2 3\n1 1 0\n0 0 1", "output": "YES" }, { "input": "3 3\n0 0 1\n1 1 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 1 1 1\n1 0 1 0\n1 1 0 1\n1 0 1 0", "output": "NO" }, { "input": "3 3\n1 0 0\n0 0 0\n1 0 0", "output": "YES" }, { "input": "3 4\n1 1 0 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 0 1\n0 0 1 0", "output": "YES" }, { "input": "2 4\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "2 3\n0 0 1\n0 1 0", "output": "YES" }, { "input": "2 3\n1 0 0\n0 1 0", "output": "YES" }, { "input": "3 2\n1 0\n0 1\n0 1", "output": "YES" }, { "input": "3 4\n1 1 0 1\n0 0 1 1\n1 0 1 0", "output": "NO" }, { "input": "3 4\n0 0 1 1\n0 1 1 0\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 0 1\n0 0 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 1 1 0\n1 1 0 1\n0 0 1 0", "output": "YES" }, { "input": "8 4\n0 0 0 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n1 0 1 1\n1 1 1 0\n0 1 0 1", "output": "NO" }, { "input": "2 4\n1 1 0 0\n0 0 0 1", "output": "YES" }, { "input": "10 4\n1 0 1 0\n1 0 1 0\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 0 0 1\n0 1 1 1\n0 0 0 1\n1 1 1 1\n1 0 1 0", "output": "YES" }, { "input": "2 4\n0 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "3 3\n1 1 0\n1 0 1\n0 1 1", "output": "NO" }, { "input": "3 3\n1 1 0\n0 0 1\n1 1 1", "output": "YES" }, { "input": "4 4\n1 1 0 0\n1 0 1 0\n0 1 1 0\n0 0 1 1", "output": "YES" }, { "input": "4 4\n1 0 0 0\n1 0 0 1\n1 0 0 1\n0 1 1 1", "output": "YES" }, { "input": "4 3\n1 0 0\n1 0 0\n1 0 0\n0 1 1", "output": "YES" }, { "input": "2 4\n0 0 1 0\n0 1 0 0", "output": "YES" }, { "input": "1 2\n0 1", "output": "NO" }, { "input": "3 4\n1 1 1 0\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n0 1 0 1\n1 0 1 0", "output": "YES" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "YES" }, { "input": "2 4\n0 0 0 0\n0 0 0 0", "output": "YES" }, { "input": "3 4\n0 1 0 1\n0 1 1 0\n1 0 0 1", "output": "YES" }, { "input": "3 4\n0 1 1 0\n1 1 0 0\n0 0 1 1", "output": "YES" }, { "input": "2 4\n1 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "2 3\n0 1 0\n1 0 0", "output": "YES" }, { "input": "4 4\n0 0 1 1\n0 1 1 0\n1 1 0 0\n1 0 0 1", "output": "YES" }, { "input": "10 4\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n0 0 1 1\n1 1 0 0", "output": "YES" }, { "input": "3 3\n1 1 0\n0 1 1\n1 0 1", "output": "NO" }, { "input": "2 3\n0 0 1\n1 1 0", "output": "YES" }, { "input": "4 4\n0 0 0 1\n0 0 1 1\n1 1 0 1\n1 1 1 0", "output": "YES" }, { "input": "3 4\n0 0 1 1\n1 0 1 0\n0 1 0 1", "output": "YES" }, { "input": "5 4\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1\n0 0 1 1", "output": "NO" }, { "input": "3 4\n1 0 0 0\n1 1 0 0\n0 1 1 0", "output": "YES" } ]
1,588,774,649
2,147,483,647
PyPy 3
OK
TESTS
143
888
11,468,800
n,k=map(int,input().split()) a=[] for i in range(n): l=list(map(int,input().split())) a.append(l) a=list(set(tuple(i) for i in a)) for i in range(len(a)): flag=False for j in range(len(a)): cnt=0 for x in range(k): if a[i][x]==1 and a[j][x]!=0: continue else: cnt+=1 if cnt==k: flag=True break if flag: break if flag:print("Yes") else:print("No")
Title: Qualification Rounds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of *n* problems, and they want to select any non-empty subset of it as a problemset. *k* experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems. Determine if Snark and Philip can make an interesting problemset! Input Specification: The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=4) — the number of problems and the number of experienced teams. Each of the next *n* lines contains *k* integers, each equal to 0 or 1. The *j*-th number in the *i*-th line is 1 if *j*-th team knows *i*-th problem and 0 otherwise. Output Specification: Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). Demo Input: ['5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0\n', '3 2\n1 0\n1 1\n0 1\n'] Demo Output: ['NO\n', 'YES\n'] Note: In the first example you can't make any interesting problemset, because the first team knows all problems. In the second example you can choose the first and the third problems.
```python n,k=map(int,input().split()) a=[] for i in range(n): l=list(map(int,input().split())) a.append(l) a=list(set(tuple(i) for i in a)) for i in range(len(a)): flag=False for j in range(len(a)): cnt=0 for x in range(k): if a[i][x]==1 and a[j][x]!=0: continue else: cnt+=1 if cnt==k: flag=True break if flag: break if flag:print("Yes") else:print("No") ```
3
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808", "output": "7" }, { "input": "1\n487 550", "output": "0" }, { "input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676", "output": "0" }, { "input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136", "output": "8" }, { "input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188", "output": "9" }, { "input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191", "output": "5" }, { "input": "4\n1 0\n2 0\n1 1\n1 -1", "output": "0" } ]
1,590,473,275
2,147,483,647
Python 3
OK
TESTS
26
310
307,200
n = int(input()) x= [] y = [] c=0 for k in range(n): a,b = map(int,input().split()) x.append(a) y.append(b) for i in range(n): r1,r2,r3,r4=0,0,0,0 for j in range(n): if x[i]>x[j] and y[i]==y[j]: r1+=1 if x[i]<x[j] and y[i]==y[j]: r2+=1 if x[i]==x[j] and y[i]<y[j]: r3+=1 if x[i]==x[j] and y[i]>y[j]: r4+=1 if r1>0 and r2>0 and r3>0 and r4>0: c = c+1 print(c)
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input Specification: The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Specification: Print the only number — the number of supercentral points of the given set. Demo Input: ['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
```python n = int(input()) x= [] y = [] c=0 for k in range(n): a,b = map(int,input().split()) x.append(a) y.append(b) for i in range(n): r1,r2,r3,r4=0,0,0,0 for j in range(n): if x[i]>x[j] and y[i]==y[j]: r1+=1 if x[i]<x[j] and y[i]==y[j]: r2+=1 if x[i]==x[j] and y[i]<y[j]: r3+=1 if x[i]==x[j] and y[i]>y[j]: r4+=1 if r1>0 and r2>0 and r3>0 and r4>0: c = c+1 print(c) ```
3
853
B
Jury Meeting
PROGRAMMING
1,800
[ "greedy", "sortings", "two pointers" ]
null
null
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to *n* there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires *k* days of work. For all of these *k* days each of the *n* jury members should be present in Metropolis to be able to work on problems. You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day. Gather everybody for *k* days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for *k* days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than *k* days.
The first line of input contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=106). The *i*-th of the following *m* lines contains the description of the *i*-th flight defined by four integers *d**i*, *f**i*, *t**i* and *c**i* (1<=≤<=*d**i*<=≤<=106, 0<=≤<=*f**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=106, exactly one of *f**i* and *t**i* equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost.
Output the only integer that is the minimum cost of gathering all jury members in city 0 for *k* days and then sending them back to their home cities. If it is impossible to gather everybody in Metropolis for *k* days and then send them back to their home cities, output "-1" (without the quotes).
[ "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n", "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n" ]
[ "24500\n", "-1\n" ]
The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more. In the second sample it is impossible to send jury member from city 2 back home from Metropolis.
750
[ { "input": "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500", "output": "24500" }, { "input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000", "output": "-1" }, { "input": "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000", "output": "11011" }, { "input": "2 4 5\n1 1 0 1\n2 2 0 10\n8 0 1 100\n9 0 2 1000", "output": "1111" }, { "input": "1 2 1\n10 1 0 16\n20 0 1 7", "output": "23" }, { "input": "1 2 10\n20 0 1 36\n10 1 0 28", "output": "-1" }, { "input": "1 2 9\n20 0 1 97\n10 1 0 47", "output": "144" }, { "input": "2 4 1\n20 0 1 72\n21 0 2 94\n9 2 0 43\n10 1 0 91", "output": "300" }, { "input": "2 4 10\n20 0 1 7\n9 2 0 32\n10 1 0 27\n21 0 2 19", "output": "-1" }, { "input": "2 4 9\n10 1 0 22\n21 0 2 92\n9 2 0 29\n20 0 1 37", "output": "180" }, { "input": "3 6 1\n10 1 0 62\n8 3 0 83\n20 0 1 28\n22 0 3 61\n21 0 2 61\n9 2 0 75", "output": "370" }, { "input": "3 6 10\n22 0 3 71\n20 0 1 57\n8 3 0 42\n10 1 0 26\n9 2 0 35\n21 0 2 84", "output": "-1" }, { "input": "3 6 9\n10 1 0 93\n20 0 1 26\n8 3 0 51\n22 0 3 90\n21 0 2 78\n9 2 0 65", "output": "403" }, { "input": "4 8 1\n9 2 0 3\n22 0 3 100\n20 0 1 40\n10 1 0 37\n23 0 4 49\n7 4 0 53\n21 0 2 94\n8 3 0 97", "output": "473" }, { "input": "4 8 10\n8 3 0 65\n21 0 2 75\n7 4 0 7\n23 0 4 38\n20 0 1 27\n10 1 0 33\n22 0 3 91\n9 2 0 27", "output": "-1" }, { "input": "4 8 9\n8 3 0 61\n9 2 0 94\n23 0 4 18\n21 0 2 19\n20 0 1 52\n10 1 0 68\n22 0 3 5\n7 4 0 59", "output": "376" }, { "input": "5 10 1\n24 0 5 61\n22 0 3 36\n8 3 0 7\n21 0 2 20\n6 5 0 23\n20 0 1 28\n23 0 4 18\n9 2 0 40\n7 4 0 87\n10 1 0 8", "output": "328" }, { "input": "5 10 10\n24 0 5 64\n23 0 4 17\n20 0 1 91\n9 2 0 35\n21 0 2 4\n22 0 3 51\n6 5 0 69\n7 4 0 46\n8 3 0 92\n10 1 0 36", "output": "-1" }, { "input": "5 10 9\n22 0 3 13\n9 2 0 30\n24 0 5 42\n21 0 2 33\n23 0 4 36\n20 0 1 57\n10 1 0 39\n8 3 0 68\n7 4 0 85\n6 5 0 35", "output": "438" }, { "input": "1 10 1\n278 1 0 4\n208 1 0 4\n102 0 1 9\n499 0 1 7\n159 0 1 8\n218 1 0 6\n655 0 1 5\n532 1 0 6\n318 0 1 6\n304 1 0 7", "output": "9" }, { "input": "2 10 1\n5 0 2 5\n52 2 0 9\n627 0 2 6\n75 0 1 6\n642 0 1 8\n543 0 2 7\n273 1 0 2\n737 2 0 4\n576 0 1 7\n959 0 2 5", "output": "23" }, { "input": "3 10 1\n48 2 0 9\n98 0 2 5\n43 0 1 8\n267 0 1 7\n394 3 0 7\n612 0 3 9\n502 2 0 6\n36 0 2 9\n602 0 1 3\n112 1 0 6", "output": "-1" }, { "input": "4 10 1\n988 0 1 1\n507 1 0 9\n798 1 0 9\n246 0 3 7\n242 1 0 8\n574 4 0 7\n458 0 4 9\n330 0 2 9\n303 2 0 8\n293 0 3 9", "output": "-1" }, { "input": "5 10 1\n132 0 4 7\n803 0 2 8\n280 3 0 5\n175 4 0 6\n196 1 0 7\n801 0 4 6\n320 0 5 7\n221 0 4 6\n446 4 0 8\n699 0 5 9", "output": "-1" }, { "input": "6 10 1\n845 0 4 9\n47 0 4 8\n762 0 2 8\n212 6 0 6\n416 0 5 9\n112 5 0 9\n897 0 6 9\n541 0 4 5\n799 0 6 7\n252 2 0 9", "output": "-1" }, { "input": "7 10 1\n369 6 0 9\n86 7 0 9\n696 0 4 8\n953 6 0 7\n280 4 0 9\n244 0 2 9\n645 6 0 8\n598 7 0 6\n598 0 7 8\n358 0 4 6", "output": "-1" }, { "input": "8 10 1\n196 2 0 9\n67 2 0 9\n372 3 0 6\n886 6 0 6\n943 0 3 8\n430 3 0 6\n548 0 4 9\n522 0 3 8\n1 4 0 3\n279 4 0 8", "output": "-1" }, { "input": "9 10 1\n531 8 0 5\n392 2 0 9\n627 8 0 9\n363 5 0 9\n592 0 5 3\n483 0 6 7\n104 3 0 8\n97 8 0 9\n591 0 7 9\n897 0 6 7", "output": "-1" }, { "input": "10 10 1\n351 0 3 7\n214 0 9 9\n606 0 7 8\n688 0 9 3\n188 3 0 9\n994 0 1 7\n372 5 0 8\n957 0 3 6\n458 8 0 7\n379 0 4 7", "output": "-1" }, { "input": "1 2 1\n5 0 1 91\n1 1 0 87", "output": "178" }, { "input": "2 4 1\n1 1 0 88\n5 2 0 88\n3 0 1 46\n9 0 2 63", "output": "-1" }, { "input": "3 6 1\n19 0 3 80\n11 0 2 32\n8 2 0 31\n4 0 1 45\n1 1 0 63\n15 3 0 76", "output": "-1" }, { "input": "1 0 1", "output": "-1" }, { "input": "5 0 1", "output": "-1" } ]
1,698,876,977
2,147,483,647
Python 3
OK
TESTS
83
389
19,251,200
g = lambda: map(int, input().split()) n, m, k = g() F, T = [], [] e = int(3e11) for i in range(m): d, f, t, c = g() if f: F.append((d, f, c)) else: T.append((-d, t, c)) for p in [F, T]: C = [e] * (n + 1) s = n * e q = [] p.sort() for d, t, c in p: if C[t] > c: s += c - C[t] C[t] = c if s < e: q.append((s, d)) p.clear() p += q s, t = e, (0, 0) for f in F: while f: if t[1] + f[1] + k < 0: s = min(s, f[0] + t[0]) elif T: t = T.pop() continue f = 0 print(s if s < e else -1)
Title: Jury Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to *n* there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires *k* days of work. For all of these *k* days each of the *n* jury members should be present in Metropolis to be able to work on problems. You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day. Gather everybody for *k* days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for *k* days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than *k* days. Input Specification: The first line of input contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=106). The *i*-th of the following *m* lines contains the description of the *i*-th flight defined by four integers *d**i*, *f**i*, *t**i* and *c**i* (1<=≤<=*d**i*<=≤<=106, 0<=≤<=*f**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=*n*, 1<=≤<=*c**i*<=≤<=106, exactly one of *f**i* and *t**i* equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost. Output Specification: Output the only integer that is the minimum cost of gathering all jury members in city 0 for *k* days and then sending them back to their home cities. If it is impossible to gather everybody in Metropolis for *k* days and then send them back to their home cities, output "-1" (without the quotes). Demo Input: ['2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n', '2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n'] Demo Output: ['24500\n', '-1\n'] Note: The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more. In the second sample it is impossible to send jury member from city 2 back home from Metropolis.
```python g = lambda: map(int, input().split()) n, m, k = g() F, T = [], [] e = int(3e11) for i in range(m): d, f, t, c = g() if f: F.append((d, f, c)) else: T.append((-d, t, c)) for p in [F, T]: C = [e] * (n + 1) s = n * e q = [] p.sort() for d, t, c in p: if C[t] > c: s += c - C[t] C[t] = c if s < e: q.append((s, d)) p.clear() p += q s, t = e, (0, 0) for f in F: while f: if t[1] + f[1] + k < 0: s = min(s, f[0] + t[0]) elif T: t = T.pop() continue f = 0 print(s if s < e else -1) ```
3
925
A
Stairs and Elevators
PROGRAMMING
1,600
[ "binary search" ]
null
null
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?"
The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$.
Print $q$ integers, one per line — the answers for the queries.
[ "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n" ]
[ "7\n5\n4\n" ]
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
500
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4" }, { "input": "2 2 0 1 1\n\n1\n1\n1 2 2 2", "output": "3" }, { "input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3", "output": "6\n4\n3\n5\n4" }, { "input": "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\n1 1 3 1\n2 1 7 1\n1 1 9 1\n7 1 4 1\n10 1 7 1\n2 1 7 1\n3 1 2 1\n5 1 2 1\n10 1 5 1\n6 1 9 1", "output": "3\n4\n4\n3\n3\n4\n3\n3\n4\n3" }, { "input": "2 5 1 0 1\n2\n\n1\n1 4 1 5", "output": "1" }, { "input": "2 10 1 1 1\n1\n10\n1\n1 5 1 8", "output": "3" }, { "input": "4 4 1 0 1\n1\n\n1\n1 2 1 4", "output": "2" }, { "input": "2 4 1 1 1\n1\n2\n1\n2 3 2 4", "output": "1" }, { "input": "1000 1000 1 1 10\n1\n2\n1\n1 900 1 1000", "output": "100" }, { "input": "2 4 1 1 1\n1\n4\n1\n1 2 1 3", "output": "1" }, { "input": "5 5 1 1 1\n3\n2\n1\n1 5 1 1", "output": "4" } ]
1,689,345,603
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689345603.107276")# 1689345603.1072981
Title: Stairs and Elevators Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height $n$ and width $m$. We can denote sections with pairs of integers $(i, j)$, where $i$ is the floor, and $j$ is the section number on the floor. The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections $(1, x)$, $(2, x)$, $\ldots$, $(n, x)$ for some $x$ between $1$ and $m$. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to $v$ floors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible. You are to process $q$ queries. Each query is a question "what is the minimum time needed to go from a room in section $(x_1, y_1)$ to a room in section $(x_2, y_2)$?" Input Specification: The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively. The second line contains $c_l$ integers $l_1, \ldots, l_{c_l}$ in increasing order ($1 \leq l_i \leq m$), denoting the positions of the stairs. If $c_l = 0$, the second line is empty. The third line contains $c_e$ integers $e_1, \ldots, e_{c_e}$ in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers $l_i$ and $e_i$ are distinct. The fourth line contains a single integer $q$ ($1 \leq q \leq 10^5$) — the number of queries. The next $q$ lines describe queries. Each of these lines contains four integers $x_1, y_1, x_2, y_2$ ($1 \leq x_1, x_2 \leq n$, $1 \leq y_1, y_2 \leq m$) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. $y_1$ and $y_2$ are not among $l_i$ and $e_i$. Output Specification: Print $q$ integers, one per line — the answers for the queries. Demo Input: ['5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n'] Demo Output: ['7\n5\n4\n'] Note: In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit. In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
```python print("_RANDOM_GUESS_1689345603.107276")# 1689345603.1072981 ```
0
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" }, { "input": "Danil_and_part_time_job", "output": "YES" }, { "input": "Ann_and_books", "output": "YES" }, { "input": "Olya", "output": "YES" }, { "input": "Nikita", "output": "YES" }, { "input": "Slava", "output": "YES" }, { "input": "Vanya", "output": "NO" }, { "input": "I_dont_know_what_to_write_here", "output": "NO" }, { "input": "danil_and_work", "output": "NO" }, { "input": "Ann", "output": "YES" }, { "input": "Batman_Nananananananan_Batman", "output": "NO" }, { "input": "Olya_Nikita_Ann_Slava_Danil", "output": "NO" }, { "input": "its_me_Mario", "output": "NO" }, { "input": "A", "output": "NO" }, { "input": "Wake_up_Neo", "output": "NO" }, { "input": "Hardest_problem_ever", "output": "NO" }, { "input": "Nikita_Nikita", "output": "NO" }, { "input": "____________________________________________________________________________________________________", "output": "NO" }, { "input": "Nikitb", "output": "NO" }, { "input": "Unn", "output": "NO" }, { "input": "oLya_adn_smth", "output": "NO" }, { "input": "FloorISLava", "output": "NO" }, { "input": "ann", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "AAnnnnn", "output": "YES" }, { "input": "AnnAnn", "output": "NO" }, { "input": "Annn", "output": "YES" }, { "input": "Dilzhan", "output": "NO" }, { "input": "Danilaaa", "output": "YES" }, { "input": "AndAnn", "output": "YES" }, { "input": "OlyaAnnAnn", "output": "NO" }, { "input": "DanilDanilOlya", "output": "NO" }, { "input": "DDanil", "output": "YES" }, { "input": "AnnAnnDanil", "output": "NO" }, { "input": "And_Danil", "output": "YES" }, { "input": "abcddddDanil", "output": "YES" }, { "input": "DanilOlyaOlya", "output": "NO" }, { "input": "Nikitaaa", "output": "YES" }, { "input": "aaabbba", "output": "NO" }, { "input": "Ann_Ann_Danil", "output": "NO" }, { "input": "Danil_Danil_Nikita", "output": "NO" }, { "input": "AlexaaaaaaBBBBBOlyaDDDDD", "output": "YES" }, { "input": "IloveDaniland", "output": "YES" }, { "input": "AnAnn", "output": "YES" }, { "input": "Danil_Danil_Olya", "output": "NO" }, { "input": "DanilDanilSlava", "output": "NO" }, { "input": "DanilDanil", "output": "NO" }, { "input": "OlyOlya", "output": "YES" }, { "input": "NikitaNikitb", "output": "YES" }, { "input": "ababaca", "output": "NO" }, { "input": "AnnNikitaNikitaNikitaNikita__good_luck", "output": "NO" } ]
1,593,421,180
2,147,483,647
Python 3
OK
TESTS
55
109
6,656,000
s=input() cnt=s.count("Danil")+s.count("Olya")+s.count("Slava")+s.count("Nikita")+s.count("Ann") print("YES" if cnt == 1 else "NO")
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input Specification: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Output Specification: Print "YES", if problem is from this contest, and "NO" otherwise. Demo Input: ['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n'] Demo Output: ['NO', 'YES', 'NO'] Note: none
```python s=input() cnt=s.count("Danil")+s.count("Olya")+s.count("Slava")+s.count("Nikita")+s.count("Ann") print("YES" if cnt == 1 else "NO") ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "output": "-1" }, { "input": "1000000000000000 1000000000", "output": "-1" }, { "input": "1000000000000000 100", "output": "1953125" }, { "input": "1 2", "output": "-1" }, { "input": "4 3", "output": "4" }, { "input": "4 4", "output": "-1" }, { "input": "9 3", "output": "9" }, { "input": "21 3", "output": "7" }, { "input": "67280421310721 1", "output": "1" }, { "input": "6 3", "output": "3" }, { "input": "3 3", "output": "-1" }, { "input": "16 3", "output": "4" }, { "input": "1 1000", "output": "-1" }, { "input": "16 4", "output": "8" }, { "input": "36 8", "output": "18" }, { "input": "49 4", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "16 1", "output": "1" }, { "input": "16 6", "output": "-1" }, { "input": "16 5", "output": "16" }, { "input": "25 4", "output": "-1" }, { "input": "4010815561 2", "output": "63331" }, { "input": "49 3", "output": "49" }, { "input": "36 6", "output": "9" }, { "input": "36 10", "output": "-1" }, { "input": "25 3", "output": "25" }, { "input": "22876792454961 28", "output": "7625597484987" }, { "input": "1234 2", "output": "2" }, { "input": "179458711 2", "output": "179458711" }, { "input": "900104343024121 100000", "output": "-1" }, { "input": "8 3", "output": "4" }, { "input": "100 6", "output": "20" }, { "input": "15500 26", "output": "-1" }, { "input": "111111 1", "output": "1" }, { "input": "100000000000000 200", "output": "160000000000" }, { "input": "1000000000000 100", "output": "6400000" }, { "input": "100 10", "output": "-1" }, { "input": "1000000000039 2", "output": "1000000000039" }, { "input": "64 5", "output": "16" }, { "input": "999999961946176 33", "output": "63245552" }, { "input": "376219076689 3", "output": "376219076689" }, { "input": "999999961946176 63", "output": "999999961946176" }, { "input": "1048576 12", "output": "2048" }, { "input": "745 21", "output": "-1" }, { "input": "748 6", "output": "22" }, { "input": "999999961946176 50", "output": "161082468097" }, { "input": "10 3", "output": "5" }, { "input": "1099511627776 22", "output": "2097152" }, { "input": "1000000007 100010", "output": "-1" }, { "input": "3 1", "output": "1" }, { "input": "100 8", "output": "50" }, { "input": "100 7", "output": "25" }, { "input": "7 2", "output": "7" }, { "input": "999999961946176 64", "output": "-1" }, { "input": "20 5", "output": "10" }, { "input": "999999999999989 2", "output": "999999999999989" }, { "input": "100000000000000 114", "output": "10240000" }, { "input": "99999640000243 3", "output": "9999991" }, { "input": "999998000001 566", "output": "333332666667" }, { "input": "99999820000081 2", "output": "9999991" }, { "input": "49000042000009 3", "output": "49000042000009" }, { "input": "151491429961 4", "output": "-1" }, { "input": "32416190071 2", "output": "32416190071" }, { "input": "1000 8", "output": "25" }, { "input": "1999967841 15", "output": "1999967841" }, { "input": "26880 26880", "output": "-1" }, { "input": "151491429961 3", "output": "151491429961" }, { "input": "90000000000 300", "output": "100000000" }, { "input": "98765004361 10", "output": "-1" }, { "input": "15 2", "output": "3" }, { "input": "16 2", "output": "2" }, { "input": "1996 2", "output": "2" }, { "input": "1997 2", "output": "1997" }, { "input": "1999 2", "output": "1999" }, { "input": "1998 2", "output": "2" }, { "input": "1998 1", "output": "1" }, { "input": "1998 7", "output": "27" }, { "input": "1998 8", "output": "37" }, { "input": "100000380000361 2", "output": "10000019" }, { "input": "15 1", "output": "1" }, { "input": "100000000000000 226", "output": "-1" }, { "input": "844030857550613 517", "output": "-1" }, { "input": "4567890 14", "output": "430" }, { "input": "123123123 123123123", "output": "-1" }, { "input": "24 4", "output": "4" }, { "input": "999999993568952 17", "output": "31622777" }, { "input": "99999999994190 9", "output": "241656799" }, { "input": "999997874844049 4", "output": "-1" }, { "input": "99999999999931 2", "output": "99999999999931" }, { "input": "2 3", "output": "-1" }, { "input": "67280421310721 2", "output": "67280421310721" } ]
1,628,161,344
2,147,483,647
PyPy 3
OK
TESTS
96
748
23,552,000
import sys import math from collections import Counter # n = int(input()) # a = list(map(int, input().split())) n, k = map(int, input().split()) less = [] more = [] i = 1 count = 0 root = int(math.sqrt(n)) while i <= root : if n % i == 0 : less.append(i) if i * i != n: more.append(n // i) if len(less) >= k : break i += 1 if k > len(less) + len(more) : print(-1) else : if k > len(less) : print(more[-(k - len(less))]) else : print(less[k - 1])
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
```python import sys import math from collections import Counter # n = int(input()) # a = list(map(int, input().split())) n, k = map(int, input().split()) less = [] more = [] i = 1 count = 0 root = int(math.sqrt(n)) while i <= root : if n % i == 0 : less.append(i) if i * i != n: more.append(n // i) if len(less) >= k : break i += 1 if k > len(less) + len(more) : print(-1) else : if k > len(less) : print(more[-(k - len(less))]) else : print(less[k - 1]) ```
3
597
B
Restaurant
PROGRAMMING
1,600
[ "dp", "greedy", "sortings" ]
null
null
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept? No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109).
Print the maximal number of orders that can be accepted.
[ "2\n7 11\n4 7\n", "5\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n" ]
[ "1\n", "3\n", "2\n" ]
none
1,000
[ { "input": "2\n7 11\n4 7", "output": "1" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "3" }, { "input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8", "output": "2" }, { "input": "1\n1 1", "output": "1" }, { "input": "2\n4 6\n4 8", "output": "1" }, { "input": "3\n22 22\n14 21\n9 25", "output": "2" }, { "input": "4\n20 59\n30 62\n29 45\n29 32", "output": "1" }, { "input": "5\n40 124\n40 117\n67 106\n36 121\n38 102", "output": "1" }, { "input": "6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179", "output": "2" }, { "input": "7\n94 113\n54 248\n64 325\n280 306\n62 328\n49 341\n90 324", "output": "2" }, { "input": "8\n116 416\n104 472\n84 476\n100 486\n199 329\n169 444\n171 487\n134 441", "output": "1" }, { "input": "9\n90 667\n366 539\n155 462\n266 458\n323 574\n101 298\n90 135\n641 661\n122 472", "output": "3" }, { "input": "10\n195 443\n229 602\n200 948\n229 876\n228 904\n296 656\n189 818\n611 626\n215 714\n403 937", "output": "2" }, { "input": "1\n28 74", "output": "1" }, { "input": "2\n28 92\n2 59", "output": "1" }, { "input": "3\n5 92\n1 100\n39 91", "output": "1" }, { "input": "4\n4 92\n29 43\n13 73\n10 79", "output": "1" }, { "input": "5\n64 86\n61 61\n46 54\n83 94\n19 46", "output": "3" }, { "input": "6\n80 84\n21 24\n44 80\n14 53\n5 10\n61 74", "output": "4" }, { "input": "7\n32 92\n32 86\n13 25\n45 75\n16 65\n1 99\n17 98", "output": "2" }, { "input": "8\n3 59\n22 94\n26 97\n18 85\n7 84\n1 100\n4 100\n26 93", "output": "1" }, { "input": "9\n11 90\n8 95\n62 95\n43 96\n16 84\n3 70\n23 93\n4 96\n11 86", "output": "1" }, { "input": "10\n30 45\n5 8\n51 83\n37 52\n49 75\n28 92\n94 99\n4 13\n61 83\n36 96", "output": "4" }, { "input": "11\n38 92\n16 85\n32 43\n65 84\n63 100\n21 45\n13 92\n29 58\n56 94\n18 83\n50 81", "output": "2" }, { "input": "12\n66 78\n41 97\n55 69\n55 61\n36 64\n14 97\n96 99\n28 58\n44 93\n2 100\n42 88\n1 2", "output": "4" }, { "input": "13\n50 85\n38 65\n5 51\n50 96\n4 92\n23 94\n2 99\n2 84\n1 98\n2 100\n12 100\n21 97\n7 84", "output": "1" }, { "input": "14\n17 92\n7 96\n49 96\n10 99\n7 98\n12 85\n10 52\n2 99\n23 75\n4 98\n7 100\n2 69\n6 99\n20 87", "output": "1" }, { "input": "15\n1 58\n15 21\n53 55\n59 90\n68 71\n29 51\n52 81\n32 52\n38 44\n57 59\n47 60\n27 32\n49 86\n26 94\n44 45", "output": "6" }, { "input": "16\n4 80\n16 46\n15 16\n60 63\n8 54\n18 49\n67 99\n72 80\n1 8\n19 64\n1 54\n46 94\n2 89\n67 78\n21 47\n5 29", "output": "5" }, { "input": "17\n34 42\n31 84\n8 96\n63 88\n11 99\n80 99\n1 96\n11 12\n27 28\n4 30\n1 79\n16 86\n15 86\n13 80\n3 98\n37 89\n59 88", "output": "4" }, { "input": "18\n11 94\n12 85\n25 90\n7 61\n63 88\n6 87\n49 88\n16 76\n12 78\n61 84\n3 84\n20 91\n1 84\n17 100\n43 80\n8 86\n9 98\n35 97", "output": "2" }, { "input": "19\n24 63\n23 86\n5 89\n10 83\n31 92\n8 96\n21 63\n1 83\n2 100\n5 96\n18 98\n9 77\n11 91\n44 95\n1 98\n22 60\n5 98\n22 91\n1 96", "output": "1" }, { "input": "20\n22 77\n13 50\n55 64\n16 52\n67 96\n49 51\n59 95\n2 25\n69 91\n2 24\n4 46\n50 74\n45 63\n39 55\n31 33\n9 33\n6 72\n14 67\n56 98\n69 94", "output": "5" }, { "input": "1\n1 1000000000", "output": "1" }, { "input": "4\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000", "output": "1" }, { "input": "2\n1000000000 1000000000\n1 1", "output": "2" }, { "input": "4\n1 10000\n2 3\n4 5\n6 7", "output": "3" }, { "input": "3\n1 10\n2 4\n6 8", "output": "2" }, { "input": "2\n1 4\n2 3", "output": "1" }, { "input": "3\n1 100\n2 3\n4 5", "output": "2" }, { "input": "4\n1 10\n2 3\n4 5\n6 7", "output": "3" }, { "input": "3\n1 5\n2 3\n4 4", "output": "2" }, { "input": "3\n1 1000\n1 5\n6 1000", "output": "2" }, { "input": "3\n1 10000\n3 5\n7 8", "output": "2" }, { "input": "4\n1 5\n6 15\n8 10\n11 17", "output": "3" }, { "input": "4\n1 3\n6 800\n7 9\n10 11", "output": "3" }, { "input": "5\n1 10\n2 3\n4 5\n6 7\n8 9", "output": "4" }, { "input": "3\n1 5\n1 3\n4 6", "output": "2" }, { "input": "3\n1 10\n2 3\n4 5", "output": "2" }, { "input": "2\n1 3\n2 4", "output": "1" } ]
1,447,336,455
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
102,400
n = int(input()) order = [[int(__) for __ in input().split()] for _ in range(n)] order.sort(key=lambda x: x[1]) print(order) ans = 0 right = -1 for i in order: if right < i[0]: ans += 1 right = i[1] print(ans)
Title: Restaurant Time Limit: None seconds Memory Limit: None megabytes Problem Description: A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*). Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept? No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). Output Specification: Print the maximal number of orders that can be accepted. Demo Input: ['2\n7 11\n4 7\n', '5\n1 2\n2 3\n3 4\n4 5\n5 6\n', '6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n'] Demo Output: ['1\n', '3\n', '2\n'] Note: none
```python n = int(input()) order = [[int(__) for __ in input().split()] for _ in range(n)] order.sort(key=lambda x: x[1]) print(order) ans = 0 right = -1 for i in order: if right < i[0]: ans += 1 right = i[1] print(ans) ```
0
220
A
Little Elephant and Problem
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
[ "2\n1 2\n", "3\n3 2 1\n", "4\n4 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
500
[ { "input": "2\n1 2", "output": "YES" }, { "input": "3\n3 2 1", "output": "YES" }, { "input": "4\n4 3 2 1", "output": "NO" }, { "input": "3\n1 3 2", "output": "YES" }, { "input": "2\n2 1", "output": "YES" }, { "input": "9\n7 7 8 8 10 10 10 10 1000000000", "output": "YES" }, { "input": "10\n1 2 9 4 5 6 7 8 3 10", "output": "YES" }, { "input": "4\n2 2 2 1", "output": "YES" }, { "input": "10\n1 2 4 4 4 5 5 7 7 10", "output": "YES" }, { "input": "10\n4 5 11 12 13 14 16 16 16 18", "output": "YES" }, { "input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321", "output": "YES" }, { "input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644", "output": "YES" }, { "input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5", "output": "NO" }, { "input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472", "output": "NO" }, { "input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503", "output": "NO" }, { "input": "4\n5 12 12 6", "output": "YES" }, { "input": "5\n1 3 3 3 2", "output": "YES" }, { "input": "4\n2 1 1 1", "output": "YES" }, { "input": "2\n1 1", "output": "YES" }, { "input": "4\n1000000000 1 1000000000 1", "output": "YES" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 1", "output": "YES" }, { "input": "6\n1 2 3 4 5 3", "output": "NO" }, { "input": "9\n3 3 3 2 2 2 1 1 1", "output": "NO" }, { "input": "4\n4 1 2 3", "output": "NO" }, { "input": "6\n3 4 5 6 7 2", "output": "NO" }, { "input": "4\n4 2 1 3", "output": "NO" }, { "input": "4\n3 3 2 2", "output": "NO" }, { "input": "4\n3 2 1 1", "output": "NO" }, { "input": "4\n4 5 1 1", "output": "NO" }, { "input": "6\n1 6 2 4 3 5", "output": "NO" }, { "input": "5\n1 4 5 2 3", "output": "NO" }, { "input": "4\n2 2 1 1", "output": "NO" }, { "input": "5\n1 4 3 2 1", "output": "NO" }, { "input": "5\n1 4 2 2 3", "output": "NO" }, { "input": "6\n1 2 3 1 2 3", "output": "NO" }, { "input": "3\n3 1 2", "output": "NO" }, { "input": "5\n5 1 2 3 4", "output": "NO" }, { "input": "5\n3 3 3 2 2", "output": "NO" }, { "input": "5\n100 5 6 10 7", "output": "NO" }, { "input": "3\n2 3 1", "output": "NO" }, { "input": "5\n4 4 1 1 1", "output": "NO" }, { "input": "5\n1 2 5 3 4", "output": "NO" }, { "input": "4\n3 4 1 2", "output": "NO" }, { "input": "4\n2 4 1 5", "output": "NO" }, { "input": "5\n1 3 3 2 2", "output": "NO" }, { "input": "5\n1 5 4 4 4", "output": "YES" }, { "input": "7\n3 2 1 2 3 5 4", "output": "NO" }, { "input": "5\n1 1 3 2 2", "output": "YES" }, { "input": "9\n1 8 7 7 7 7 7 8 3", "output": "YES" }, { "input": "5\n1 3 2 3 3", "output": "YES" }, { "input": "10\n4 4 4 4 10 4 4 4 4 4", "output": "YES" }, { "input": "8\n3 6 6 6 6 6 4 9", "output": "YES" }, { "input": "4\n4 4 3 3", "output": "NO" }, { "input": "4\n3 2 2 4", "output": "YES" }, { "input": "5\n2 2 1 3 3", "output": "YES" }, { "input": "5\n1 2 7 3 5", "output": "NO" }, { "input": "5\n2 3 4 5 1", "output": "NO" }, { "input": "6\n1 4 3 6 2 5", "output": "NO" }, { "input": "5\n3 3 1 5 4", "output": "NO" }, { "input": "4\n1 2 1 2", "output": "YES" }, { "input": "6\n4 5 3 4 2 6", "output": "NO" }, { "input": "11\n1 2 3 4 5 1 2 3 4 5 1", "output": "NO" }, { "input": "6\n6 1 2 3 4 5", "output": "NO" }, { "input": "5\n4 1 1 1 1", "output": "YES" }, { "input": "9\n1 2 3 5 4 6 7 8 9", "output": "YES" }, { "input": "6\n6 1 2 3 4 2", "output": "NO" }, { "input": "6\n2 2 2 2 3 2", "output": "YES" }, { "input": "3\n2 1 1", "output": "YES" }, { "input": "5\n1 2 1 1 2", "output": "YES" }, { "input": "5\n1 2 2 1 2", "output": "YES" }, { "input": "8\n5 5 5 5 5 5 1 1", "output": "NO" } ]
1,622,488,919
2,147,483,647
Python 3
OK
TESTS
96
264
9,113,600
from sys import stdin from collections import deque,Counter,defaultdict import sys import math import operator import random from fractions import Fraction import functools import bisect import itertools from heapq import * import time n = int(input()) arr = list(map(int,input().split())) c = 0 for i,j in zip(arr,sorted(arr)): if i!=j: c+=1 print('YES' if c == 0 or c == 2 else 'NO')
Title: Little Elephant and Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers. Output Specification: In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. Demo Input: ['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
```python from sys import stdin from collections import deque,Counter,defaultdict import sys import math import operator import random from fractions import Fraction import functools import bisect import itertools from heapq import * import time n = int(input()) arr = list(map(int,input().split())) c = 0 for i,j in zip(arr,sorted(arr)): if i!=j: c+=1 print('YES' if c == 0 or c == 2 else 'NO') ```
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,696,574,190
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
weight = int(input("Enter the weight of the watermelon : ")) if w(1 <=w<= 100): print("Invalid Input") elif weight % 2 != 0: print("NO") else: print("YES")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python weight = int(input("Enter the weight of the watermelon : ")) if w(1 <=w<= 100): print("Invalid Input") elif weight % 2 != 0: print("NO") else: print("YES") ```
-1
198
A
About Bacteria
PROGRAMMING
1,700
[ "implementation", "math" ]
null
null
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria. The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point. For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment.
The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.
Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube.
[ "3 1 3 5\n", "1 4 4 7\n", "2 2 4 100\n" ]
[ "2", "3", "0" ]
none
500
[ { "input": "3 1 3 5", "output": "2" }, { "input": "1 4 4 7", "output": "3" }, { "input": "2 2 4 100", "output": "0" }, { "input": "1 2 3 100", "output": "0" }, { "input": "10 10 10 123456", "output": "6" }, { "input": "847 374 283 485756", "output": "282" }, { "input": "37 1 283475 8347", "output": "283473" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 1 1 1000000", "output": "0" }, { "input": "1 1 1000000 1", "output": "1000000" }, { "input": "1 1 1000000 1000000", "output": "1" }, { "input": "1 1000000 1 1", "output": "1" }, { "input": "1 1000000 1 1000000", "output": "1" }, { "input": "1 1000000 1000000 1", "output": "1000000" }, { "input": "1 1000000 1000000 1000000", "output": "1000000" }, { "input": "1000000 1 1 1", "output": "1" }, { "input": "1000000 1 1 1000000", "output": "1" }, { "input": "1000000 1 1000000 1", "output": "1000000" }, { "input": "1000000 1 1000000 1000000", "output": "1000000" }, { "input": "1000000 1000000 1 1", "output": "1" }, { "input": "1000000 1000000 1 1000000", "output": "1" }, { "input": "1000000 1000000 1000000 1", "output": "1000000" }, { "input": "1000000 1000000 1000000 1000000", "output": "1000000" }, { "input": "1 160 748 108", "output": "748" }, { "input": "1 6099 4415 2783", "output": "4415" }, { "input": "1 1047 230 1199", "output": "229" }, { "input": "1 82435 53193 37909", "output": "53193" }, { "input": "1 96840 99008 63621", "output": "99008" }, { "input": "1 250685 823830 494528", "output": "823829" }, { "input": "1 421986 2348 320240", "output": "2348" }, { "input": "2 8 16 397208", "output": "1" }, { "input": "2 96 676 215286", "output": "665" }, { "input": "2 575 321 606104", "output": "311" }, { "input": "2 8048 37852 278843", "output": "37847" }, { "input": "2 46658 377071 909469", "output": "377067" }, { "input": "3 10 90 567680", "output": "80" }, { "input": "4 4 149 609208", "output": "141" }, { "input": "5 4 3204 986907", "output": "3196" }, { "input": "6 5 5832 885406", "output": "5825" }, { "input": "7 10 141725 219601", "output": "141720" }, { "input": "38 86 441826 91486", "output": "441824" }, { "input": "185 58 579474 889969", "output": "579472" }, { "input": "3901 18 41607 412558", "output": "41606" }, { "input": "9821 62 965712 703044", "output": "965711" }, { "input": "29487 60 3239 483550", "output": "3238" }, { "input": "78993 99 646044 456226", "output": "646043" }, { "input": "193877 3 362586 6779", "output": "362586" }, { "input": "702841 39 622448 218727", "output": "622448" }, { "input": "987899 74 490126 87643", "output": "490126" }, { "input": "1000000 69 296123 144040", "output": "296123" }, { "input": "2 5 501022 406855", "output": "501006" }, { "input": "2 2 420084 748919", "output": "420067" }, { "input": "2 3 822794 574631", "output": "822777" }, { "input": "2 2 968609 433047", "output": "968592" }, { "input": "2 1 371319 775111", "output": "371301" }, { "input": "3 2 942777 573452", "output": "942766" }, { "input": "3 2 312783 882812", "output": "312772" }, { "input": "3 4 715494 741228", "output": "715483" }, { "input": "3 1 410364 566940", "output": "410353" }, { "input": "3 2 780370 425356", "output": "780359" }, { "input": "1 5 71 551204", "output": "0" }, { "input": "1 10 29 409620", "output": "0" }, { "input": "2 1 14 637985", "output": "0" }, { "input": "2 6 73 947345", "output": "56" }, { "input": "3 8 66 951518", "output": "55" }, { "input": "3 3 24 293582", "output": "14" }, { "input": "4 9 10 489244", "output": "2" }, { "input": "4 6 16 831308", "output": "7" }, { "input": "5 6 62 835481", "output": "55" }, { "input": "5 2 68 144841", "output": "61" }, { "input": "1 1 1000000 500000", "output": "500001" }, { "input": "5 2 100 7", "output": "99" }, { "input": "3 1 3 4", "output": "2" }, { "input": "126480 295416 829274 421896", "output": "829273" }, { "input": "999991 5 1000000 999997", "output": "999999" }, { "input": "54772 1 1000000 1000000", "output": "999999" }, { "input": "5 5 2 10", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "100000 100000 10 1000000", "output": "9" }, { "input": "2 2 5 4", "output": "4" }, { "input": "999997 1 100000 1000000", "output": "99999" }, { "input": "5 2 100 38", "output": "98" }, { "input": "1 4 1 5", "output": "0" }, { "input": "1 2149 1000000 1000000", "output": "999535" }, { "input": "99999 99999 10 1000000", "output": "9" }, { "input": "999998 1 1000000 1000000", "output": "999999" }, { "input": "1 1 10 2", "output": "9" }, { "input": "1 1 100 1000", "output": "0" }, { "input": "1 1 1000000 553211", "output": "446790" }, { "input": "1 1 10 1", "output": "10" }, { "input": "3 1 3 1", "output": "3" }, { "input": "888888 2 4 999999", "output": "3" }, { "input": "3 5 10 29", "output": "8" }, { "input": "1 1 100 2", "output": "99" }, { "input": "5 5 2 1", "output": "2" }, { "input": "50000 42 1337 999999", "output": "1336" }, { "input": "2 345678 908765 987654", "output": "908764" }, { "input": "1 7 15 7", "output": "15" }, { "input": "842717 8581 19342 851297", "output": "19342" }, { "input": "5 4 1 4", "output": "1" }, { "input": "2 2 5 94", "output": "0" }, { "input": "2 100000 5 10", "output": "5" }, { "input": "722229 410423 118215 838505", "output": "118215" }, { "input": "3 1 3 13", "output": "1" }, { "input": "900000 1 100 1000000", "output": "99" }, { "input": "2 4 4 36", "output": "1" }, { "input": "999990 1 1000000 1000000", "output": "999999" }, { "input": "100000 100000 1000000 1000000", "output": "999999" }, { "input": "999998 1 5 1000000", "output": "4" }, { "input": "1 1 10 4", "output": "7" }, { "input": "2 3 4 5", "output": "3" }, { "input": "3 1 3 40", "output": "0" }, { "input": "1 10 10 100", "output": "1" }, { "input": "999987 123456 1000000 1", "output": "1000000" } ]
1,593,008,195
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
218
20,172,800
k,b,n,t=map(int,input().split()) temp=1 count=0 while(1): print(temp) if(((t-1)*(k-1))+b>b*temp): temp=temp*k count+=1 else: break; print(max(0,(n-count)-1))
Title: About Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into *k* bacteria. After that some abnormal effects create *b* more bacteria in the test tube. Thus, if at the beginning of some second the test tube had *x* bacteria, then at the end of the second it will have *kx*<=+<=*b* bacteria. The experiment showed that after *n* seconds there were exactly *z* bacteria and the experiment ended at this point. For the second experiment Qwerty is going to sterilize the test tube and put there *t* bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least *z* bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least *z* bacteria in the second experiment. Input Specification: The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. Output Specification: Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. Demo Input: ['3 1 3 5\n', '1 4 4 7\n', '2 2 4 100\n'] Demo Output: ['2', '3', '0'] Note: none
```python k,b,n,t=map(int,input().split()) temp=1 count=0 while(1): print(temp) if(((t-1)*(k-1))+b>b*temp): temp=temp*k count+=1 else: break; print(max(0,(n-count)-1)) ```
0
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,697,816,035
2,147,483,647
Python 3
OK
TESTS
39
46
0
S0l=int(input()) if S0l%2==0: print(S0l//2) else: print(S0l//2-S0l)
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python S0l=int(input()) if S0l%2==0: print(S0l//2) else: print(S0l//2-S0l) ```
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,687,781,491
2,147,483,647
Python 3
OK
TESTS
48
46
0
vals = sorted(map(int, input().split())) dist = max(vals) - min(vals) print(dist)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python vals = sorted(map(int, input().split())) dist = max(vals) - min(vals) print(dist) ```
3
950
B
Intercepted Message
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of *k* files of sizes *l*1,<=*l*2,<=...,<=*l**k* bytes, then the *i*-th file is split to one or more blocks *b**i*,<=1,<=*b**i*,<=2,<=...,<=*b**i*,<=*m**i* (here the total length of the blocks *b**i*,<=1<=+<=*b**i*,<=2<=+<=...<=+<=*b**i*,<=*m**i* is equal to the length of the file *l**i*), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of blocks in the first and in the second messages. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=106) — the length of the blocks that form the first message. The third line contains *m* integers *y*1,<=*y*2,<=...,<=*y**m* (1<=≤<=*y**i*<=≤<=106) — the length of the blocks that form the second message. It is guaranteed that *x*1<=+<=...<=+<=*x**n*<==<=*y*1<=+<=...<=+<=*y**m*. Also, it is guaranteed that *x*1<=+<=...<=+<=*x**n*<=≤<=106.
Print the maximum number of files the intercepted array could consist of.
[ "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n", "3 3\n1 10 100\n1 100 10\n", "1 4\n4\n1 1 1 1\n" ]
[ "3\n", "2\n", "1\n" ]
In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4.
1,000
[ { "input": "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8", "output": "3" }, { "input": "3 3\n1 10 100\n1 100 10", "output": "2" }, { "input": "1 4\n4\n1 1 1 1", "output": "1" }, { "input": "1 1\n1000000\n1000000", "output": "1" }, { "input": "3 5\n2 2 9\n2 1 4 2 4", "output": "2" }, { "input": "5 3\n1 1 4 1 2\n1 4 4", "output": "2" }, { "input": "30 50\n3 3 1 3 1 2 4 3 4 1 3 2 3 3 2 3 2 1 3 4 2 1 1 3 2 2 1 3 1 60\n4 4 1 2 2 2 3 1 3 2 1 2 4 4 2 1 2 3 1 3 4 4 3 3 4 4 4 1 2 1 3 3 1 1 3 3 4 3 2 3 2 4 1 4 2 3 2 2 3 1", "output": "12" }, { "input": "50 50\n5733 740 547 3647 5382 5109 6842 7102 5879 1502 3574 1628 7905 4357 8569 9564 8268 3542 2487 8532 425 7713 2585 925 6458 2697 2844 69 324 9030 495 4428 6724 3524 3304 4874 1303 2098 1136 1048 2464 7316 274 9586 534 2450 2368 8060 7795 70692\n1918 4122 6806 4914 6517 6278 9842 9480 6609 4221 9373 1728 9508 9778 8578 5589 2673 6618 6031 9016 4017 6671 6008 2268 5154 9614 6834 9512 9618 6424 1736 1464 6520 9812 1722 9197 2412 2699 73 968 2906 2715 6573 8675 548 7061 5455 88 5565 2544", "output": "1" }, { "input": "1 2\n2\n1 1", "output": "1" }, { "input": "1 2\n1000000\n999999 1", "output": "1" }, { "input": "2 2\n1 1\n1 1", "output": "2" }, { "input": "2 2\n500000 500000\n1 999999", "output": "1" }, { "input": "2 2\n2 3\n4 1", "output": "1" }, { "input": "2 2\n2 3\n3 2", "output": "1" }, { "input": "2 2\n2 3\n2 3", "output": "2" }, { "input": "2 3\n2 2\n1 1 2", "output": "2" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "2 3\n3 2\n2 1 2", "output": "2" }, { "input": "2 3\n2 3\n2 1 2", "output": "2" }, { "input": "50 30\n2 3 1 2 2 4 3 4 3 2 1 4 2 3 1 3 1 2 2 3 1 1 1 2 3 1 4 3 1 2 1 2 2 1 2 4 4 3 3 2 2 1 1 1 2 2 2 4 3 3\n3 3 3 4 1 4 1 4 4 1 3 4 3 1 2 4 2 1 4 2 3 1 1 2 2 1 2 4 1 41", "output": "12" }, { "input": "50 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\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": "31 31\n5745 258 5486 13779 20931 407 1478 49032 30787 4957 36603 1034 5011 22319 50560 34419 22036 18235 62551 89259 36093 126169 106027 1673 52983 50127 640 30714 54574 20129 45984\n5745 258 5486 13779 20931 407 1478 49032 30787 4957 36603 1034 5011 22319 50560 34419 22036 18235 62551 89259 36093 126169 106027 1673 52983 50127 640 30714 54574 20129 45984", "output": "31" }, { "input": "3 6\n8 4 1\n1 8 1 1 1 1", "output": "2" } ]
1,537,371,204
3,504
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
2,560,000
s = list(map(int, input().split())) n = s[0] m = s[1] x = list(map(int, input().split())) y = list(map(int, input().split())) i = x.pop(0) j = y.pop(0) counter = 0 while True: if i==j: counter+=1 if len(y)==0 or len(x)==0: break i = x.pop(0) j = y.pop(0) elif i>j: if len(y)==0: break j +=y.pop(0) elif i<j: if len(x)==0: break i +=x.pop(0) print(counter)
Title: Intercepted Message Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of *k* files of sizes *l*1,<=*l*2,<=...,<=*l**k* bytes, then the *i*-th file is split to one or more blocks *b**i*,<=1,<=*b**i*,<=2,<=...,<=*b**i*,<=*m**i* (here the total length of the blocks *b**i*,<=1<=+<=*b**i*,<=2<=+<=...<=+<=*b**i*,<=*m**i* is equal to the length of the file *l**i*), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of blocks in the first and in the second messages. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=106) — the length of the blocks that form the first message. The third line contains *m* integers *y*1,<=*y*2,<=...,<=*y**m* (1<=≤<=*y**i*<=≤<=106) — the length of the blocks that form the second message. It is guaranteed that *x*1<=+<=...<=+<=*x**n*<==<=*y*1<=+<=...<=+<=*y**m*. Also, it is guaranteed that *x*1<=+<=...<=+<=*x**n*<=≤<=106. Output Specification: Print the maximum number of files the intercepted array could consist of. Demo Input: ['7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n', '3 3\n1 10 100\n1 100 10\n', '1 4\n4\n1 1 1 1\n'] Demo Output: ['3\n', '2\n', '1\n'] Note: In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4.
```python s = list(map(int, input().split())) n = s[0] m = s[1] x = list(map(int, input().split())) y = list(map(int, input().split())) i = x.pop(0) j = y.pop(0) counter = 0 while True: if i==j: counter+=1 if len(y)==0 or len(x)==0: break i = x.pop(0) j = y.pop(0) elif i>j: if len(y)==0: break j +=y.pop(0) elif i<j: if len(x)==0: break i +=x.pop(0) print(counter) ```
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,494,202,548
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
50
62
0
n,r,o=int(input()),0,0 c,d=map(int,input().split()) for i in range(n-1): a,b=map(int,input().split()) if b!=a:r=1 if a>c:o=1 c,d=a,b print('rated'if r else 'unrated' if o else 'maybe')
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,r,o=int(input()),0,0 c,d=map(int,input().split()) for i in range(n-1): a,b=map(int,input().split()) if b!=a:r=1 if a>c:o=1 c,d=a,b print('rated'if r else 'unrated' if o else 'maybe') ```
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,586,293,890
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
216
307,200
#definim clasa RoundTotals care o sa tina minte numele si punctajul catigatorului unei runde class RoundTotals: def __init__(self, name, points): self.name = name self.points = points #aceasta functie ne ajuta sa citim corect datele de la stdin def value(inputValue): try: #incearca sa transforma nr in integer, daca nu poate arunca o exceptie return int(inputValue) except ValueError: #returneaza stringul return inputValue #citim datele de la stdin def getInput(): #numarul de runde rounds = int(input()) #o lista care va contine toate datele din std in sub forma de obiect ex: [{name:'mike',points:3},..] totals = [] #citim atatea linii de la stdin cate rounds a avut joaca while rounds: #decrimentam rounds rounds -= 1 #functia map primeste 2 agumente, primul: o functie prin care trec toate elementele; al doilea: elementele #str(input()) - transforma input-ul in string #.split() ia fiecare "cuvant" adica string separat de spatiu si il pune intr-o lista, unde fiecare "cuvant" este un element al listei name, points = map(value, str(input()).split()) #adaugam in totals un element cu noul nume si points citite din input totals.append(RoundTotals(name, points)) #returnam lista totals return totals # primeste datele la 2 jucatori si retrueaza pe cel care are cele mai multe puncte def searchWinner(player1, player2): if player1.points > player2.points: return player1 else: return player2 #returneaza castigatorul definitiv def returnWinner(): #definim lista totals care primeste toate datele din input sub forma de array de obiecte totals = getInput() #initializam i cu 0 pentru a parcurge aceasta lista i = 0 #presupunem ca primul castigator introdus in input e winner winner = totals[0] #parcurgem lista totals while i < len(totals)-1: #daca doi castigatori la rand nu au acelasi nume if totals[i].name != totals[i+1].name: #cautam winner dintre ei doi winner = searchWinner(winner, totals[i+1]) else: #daca au acelasi nume adunam punctele lor si stergem din lista jucatorul care se repeta totals[i].points += totals[i+1].points totals.remove(totals[i+1]) #inclimentam i i += 1 #returnam numele castigatroului return winner.name #printam numele castigatorului print(returnWinner())
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 #definim clasa RoundTotals care o sa tina minte numele si punctajul catigatorului unei runde class RoundTotals: def __init__(self, name, points): self.name = name self.points = points #aceasta functie ne ajuta sa citim corect datele de la stdin def value(inputValue): try: #incearca sa transforma nr in integer, daca nu poate arunca o exceptie return int(inputValue) except ValueError: #returneaza stringul return inputValue #citim datele de la stdin def getInput(): #numarul de runde rounds = int(input()) #o lista care va contine toate datele din std in sub forma de obiect ex: [{name:'mike',points:3},..] totals = [] #citim atatea linii de la stdin cate rounds a avut joaca while rounds: #decrimentam rounds rounds -= 1 #functia map primeste 2 agumente, primul: o functie prin care trec toate elementele; al doilea: elementele #str(input()) - transforma input-ul in string #.split() ia fiecare "cuvant" adica string separat de spatiu si il pune intr-o lista, unde fiecare "cuvant" este un element al listei name, points = map(value, str(input()).split()) #adaugam in totals un element cu noul nume si points citite din input totals.append(RoundTotals(name, points)) #returnam lista totals return totals # primeste datele la 2 jucatori si retrueaza pe cel care are cele mai multe puncte def searchWinner(player1, player2): if player1.points > player2.points: return player1 else: return player2 #returneaza castigatorul definitiv def returnWinner(): #definim lista totals care primeste toate datele din input sub forma de array de obiecte totals = getInput() #initializam i cu 0 pentru a parcurge aceasta lista i = 0 #presupunem ca primul castigator introdus in input e winner winner = totals[0] #parcurgem lista totals while i < len(totals)-1: #daca doi castigatori la rand nu au acelasi nume if totals[i].name != totals[i+1].name: #cautam winner dintre ei doi winner = searchWinner(winner, totals[i+1]) else: #daca au acelasi nume adunam punctele lor si stergem din lista jucatorul care se repeta totals[i].points += totals[i+1].points totals.remove(totals[i+1]) #inclimentam i i += 1 #returnam numele castigatroului return winner.name #printam numele castigatorului print(returnWinner()) ```
0
479
C
Exams
PROGRAMMING
1,400
[ "greedy", "sortings" ]
null
null
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
[ "3\n5 2\n3 1\n4 2\n", "3\n6 1\n5 2\n4 3\n" ]
[ "2\n", "6\n" ]
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
1,500
[ { "input": "3\n5 2\n3 1\n4 2", "output": "2" }, { "input": "3\n6 1\n5 2\n4 3", "output": "6" }, { "input": "1\n1000000000 999999999", "output": "999999999" }, { "input": "1\n2 1", "output": "1" }, { "input": "2\n3 2\n3 2", "output": "2" }, { "input": "5\n4 3\n4 2\n4 1\n4 1\n4 1", "output": "3" }, { "input": "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1", "output": "11" }, { "input": "2\n3 1\n3 2", "output": "2" }, { "input": "2\n4 2\n4 1", "output": "2" }, { "input": "2\n5 2\n5 1", "output": "2" }, { "input": "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4", "output": "4" }, { "input": "3\n3 2\n4 1\n100 10", "output": "10" }, { "input": "3\n4 3\n5 2\n10 8", "output": "8" }, { "input": "5\n6 5\n6 4\n6 3\n6 2\n6 1", "output": "5" }, { "input": "3\n5 4\n6 3\n8 7", "output": "7" }, { "input": "4\n7 1\n7 3\n8 2\n9 8", "output": "8" }, { "input": "3\n3 2\n4 1\n10 5", "output": "5" }, { "input": "3\n5 4\n6 3\n11 10", "output": "10" }, { "input": "4\n2 1\n3 2\n4 1\n6 5", "output": "5" } ]
1,697,619,806
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
716,800
import sys n = int(sys.stdin.readline()) t = [] for i in range(n): t.append(list(map(int,sys.stdin.readline().split()))) if i ==0: asd = t[0] if t[i][0] >asd[0] and t[i][1] >asd[1]: asd = t[i] if i ==n-1: memory = t[n-1] if memory[1]>asd[1]: print(asd[0]) else: print(asd[1])
Title: Exams Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=&lt;<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take. Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=&lt;<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly. Output Specification: Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Demo Input: ['3\n5 2\n3 1\n4 2\n', '3\n6 1\n5 2\n4 3\n'] Demo Output: ['2\n', '6\n'] Note: In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
```python import sys n = int(sys.stdin.readline()) t = [] for i in range(n): t.append(list(map(int,sys.stdin.readline().split()))) if i ==0: asd = t[0] if t[i][0] >asd[0] and t[i][1] >asd[1]: asd = t[i] if i ==n-1: memory = t[n-1] if memory[1]>asd[1]: print(asd[0]) else: print(asd[1]) ```
0
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,661,642,803
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
number1 = int(input()) number2 = int(input()) if(number1*number2 != 1): if (number1 >= 1 and number2 >= number1 and number2 <= 16): print(int(((number1*number2) - ((number1-2) * (number2-2)))/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python number1 = int(input()) number2 = int(input()) if(number1*number2 != 1): if (number1 >= 1 and number2 >= number1 and number2 <= 16): print(int(((number1*number2) - ((number1-2) * (number2-2)))/2)) ```
-1
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "12" }, { "input": "1 1\n86399", "output": "1" }, { "input": "6 1200\n86400 86400 86000 86000 86000 86400", "output": "5" }, { "input": "6 1200\n86400 86400 86000 86000 86001 86399", "output": "6" }, { "input": "4 172799\n1 1 86400 0", "output": "4" }, { "input": "4 172799\n0 86400 86399 0", "output": "4" }, { "input": "6 1\n1 1 86400 1 86399 1", "output": "1" }, { "input": "4 1\n86400 86399 86400 86400", "output": "2" }, { "input": "4 1\n86400 86400 0 86400", "output": "3" } ]
1,618,919,497
2,147,483,647
Python 3
OK
TESTS
16
62
0
n, t = map(int, input().split()) daftar_waktu_kerja = list(map(int, input().split())) hari = 1 for waktu_kerja in daftar_waktu_kerja: waktu_kosong = 86400 - waktu_kerja t -= waktu_kosong if t <= 0: print(hari) break hari += 1
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. Output Specification: Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*. Demo Input: ['2 2\n86400 86398\n', '2 86400\n0 86400\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n, t = map(int, input().split()) daftar_waktu_kerja = list(map(int, input().split())) hari = 1 for waktu_kerja in daftar_waktu_kerja: waktu_kosong = 86400 - waktu_kerja t -= waktu_kosong if t <= 0: print(hari) break hari += 1 ```
3
384
A
Coder
PROGRAMMING
800
[ "implementation" ]
null
null
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
[ "2\n" ]
[ "2\nC.\n.C\n" ]
none
500
[ { "input": "2", "output": "2\nC.\n.C" }, { "input": "3", "output": "5\nC.C\n.C.\nC.C" }, { "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C" }, { "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C" }, { "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C" }, { "input": "100", "output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "101", "output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "500", "output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...." }, { "input": "501", "output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..." }, { "input": "755", "output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "888", "output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "998", "output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "999", "output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1000", "output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1", "output": "1\nC" } ]
1,686,143,995
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
62
0
n = int(input()) print(n) a = ['C' if i % 2 == 0 else '.' for i in range(n)] def swap(a): for i in range(n): if a[i] == '.': a[i] = 'C' else: a[i] = '.' return a for i in range(n): print(*a, sep='') a = swap(a)
Title: Coder Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Demo Input: ['2\n'] Demo Output: ['2\nC.\n.C\n'] Note: none
```python n = int(input()) print(n) a = ['C' if i % 2 == 0 else '.' for i in range(n)] def swap(a): for i in range(n): if a[i] == '.': a[i] = 'C' else: a[i] = '.' return a for i in range(n): print(*a, sep='') a = swap(a) ```
0
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,377,950,983
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
218
5,120,000
import sys import math import fractions #f = sys.stdin f = open("input.txt", "r") line_ = map(int, f.readline().split()) line = [] for it in line_: line.append(it) x = int(line[0]) y = int(line[1]) a = int(line[2]) b = int(line[3]) xy = x * y / fractions.gcd(x, y) ans = b // xy - (a - 1) // xy print( int(ans) )
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 sys import math import fractions #f = sys.stdin f = open("input.txt", "r") line_ = map(int, f.readline().split()) line = [] for it in line_: line.append(it) x = int(line[0]) y = int(line[1]) a = int(line[2]) b = int(line[3]) xy = x * y / fractions.gcd(x, y) ans = b // xy - (a - 1) // xy print( int(ans) ) ```
-1
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149", "output": "47" }, { "input": "1 1000000000\n-1000000000", "output": "2" }, { "input": "2 1000000000\n-1000000000 1000000000", "output": "3" }, { "input": "100 2\n1 3 5 6 8 9 12 13 14 17 18 21 22 23 24 25 26 27 29 30 34 35 36 39 41 44 46 48 52 53 55 56 57 59 61 63 64 66 68 69 70 71 72 73 75 76 77 79 80 81 82 87 88 91 92 93 94 95 96 97 99 100 102 103 104 106 109 110 111 112 113 114 115 117 118 119 120 122 124 125 127 128 129 130 131 132 133 134 136 137 139 140 141 142 143 145 146 148 149 150", "output": "6" }, { "input": "100 3\n0 1 3 6 7 8 9 10 13 14 16 17 18 20 21 22 24 26 27 30 33 34 35 36 37 39 42 43 44 45 46 48 53 54 55 56 57 58 61 63 64 65 67 69 70 72 73 76 77 78 79 81 82 83 85 86 87 88 90 92 93 95 96 97 98 99 100 101 104 105 108 109 110 113 114 115 116 118 120 121 123 124 125 128 130 131 132 133 134 135 136 137 139 140 141 142 146 147 148 150", "output": "2" }, { "input": "1 1000000000\n1000000000", "output": "2" }, { "input": "10 2\n-93 -62 -53 -42 -38 11 57 58 87 94", "output": "17" }, { "input": "2 500000000\n-1000000000 1000000000", "output": "4" }, { "input": "100 10\n-489 -476 -445 -432 -430 -421 -420 -418 -412 -411 -404 -383 -356 -300 -295 -293 -287 -276 -265 -263 -258 -251 -249 -246 -220 -219 -205 -186 -166 -157 -143 -137 -136 -130 -103 -86 -80 -69 -67 -55 -43 -41 -40 -26 -19 -9 16 29 41 42 54 76 84 97 98 99 101 115 134 151 157 167 169 185 197 204 208 226 227 232 234 249 259 266 281 282 293 298 300 306 308 313 319 328 331 340 341 344 356 362 366 380 390 399 409 411 419 444 455 498", "output": "23" }, { "input": "1 1000000000\n999999999", "output": "2" }, { "input": "1 1\n-5", "output": "2" }, { "input": "2 1\n-1000000000 1000000000", "output": "4" }, { "input": "1 2\n1", "output": "2" }, { "input": "4 5\n0 20 40 60", "output": "8" }, { "input": "1 1\n-10", "output": "2" }, { "input": "1 1\n-1000000000", "output": "2" }, { "input": "1 1000000000\n0", "output": "2" }, { "input": "1 2\n-10", "output": "2" }, { "input": "1 1\n2", "output": "2" }, { "input": "1 5\n-100", "output": "2" }, { "input": "2 1000000000\n999999999 1000000000", "output": "2" }, { "input": "2 2\n0 5", "output": "4" }, { "input": "1 2\n-5", "output": "2" }, { "input": "1 1\n1", "output": "2" }, { "input": "1 5\n-20", "output": "2" }, { "input": "2 100000000\n-1000000000 1000000000", "output": "4" }, { "input": "1 1000000000\n147483641", "output": "2" }, { "input": "3 3\n1 8 9", "output": "4" }, { "input": "2 1\n1 1000000000", "output": "4" }, { "input": "1 2\n-4", "output": "2" }, { "input": "2 1\n-1000000000 -1", "output": "4" } ]
1,617,882,061
2,147,483,647
PyPy 3
OK
TESTS
45
109
0
n, d = map(int, input().split()) li = list(map(int, input().split())) c = 2 for i in range(1, n): if (li[i] - li[i-1]) == 2*d: c = c + 1 if (li[i] - li[i-1]) > 2*d: c = c + 2 print(c)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. Input Specification: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. Output Specification: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Demo Input: ['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n'] Demo Output: ['6\n', '5\n'] Note: In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
```python n, d = map(int, input().split()) li = list(map(int, input().split())) c = 2 for i in range(1, n): if (li[i] - li[i-1]) == 2*d: c = c + 1 if (li[i] - li[i-1]) > 2*d: c = c + 2 print(c) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10", "output": "0" }, { "input": "8 20", "output": "0" }, { "input": "2 8", "output": "0" }, { "input": "20 11", "output": "0" }, { "input": "57 447", "output": "1" }, { "input": "1 1", "output": "2" }, { "input": "66 296", "output": "1" }, { "input": "75 683", "output": "1" }, { "input": "227 975", "output": "1" }, { "input": "247 499", "output": "1" }, { "input": "266 116", "output": "1" }, { "input": "286 916", "output": "1" }, { "input": "307 341", "output": "1" }, { "input": "451 121", "output": "1" }, { "input": "471 921", "output": "1" }, { "input": "502 346", "output": "1" }, { "input": "535 59", "output": "1" }, { "input": "555 699", "output": "1" }, { "input": "747 351", "output": "1" }, { "input": "790 64", "output": "1" }, { "input": "810 704", "output": "1" }, { "input": "855 225", "output": "1" }, { "input": "902 34", "output": "1" }, { "input": "922 514", "output": "1" }, { "input": "971 131", "output": "1" }, { "input": "991 931", "output": "1" }, { "input": "840 780", "output": "0" }, { "input": "102 595", "output": "0" }, { "input": "139 433", "output": "0" }, { "input": "968 288", "output": "0" }, { "input": "563 354", "output": "0" }, { "input": "994 975", "output": "0" }, { "input": "456 221", "output": "0" }, { "input": "205 210", "output": "0" }, { "input": "1 11", "output": "0" }, { "input": "1000 1000", "output": "0" }, { "input": "3 3", "output": "0" }, { "input": "11 99", "output": "0" }, { "input": "2 2", "output": "1" }, { "input": "11 1", "output": "0" }, { "input": "6 6", "output": "1" }, { "input": "100 452", "output": "0" }, { "input": "420 380", "output": "0" }, { "input": "31 31", "output": "0" }, { "input": "2 6", "output": "0" }, { "input": "112 134", "output": "0" }, { "input": "13 13", "output": "0" }, { "input": "1 571", "output": "0" } ]
1,624,389,835
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
0
from math import sqrt,floor n,m =map(int,input().split()) a=floor(sqrt(n)) b=n-(a*a) if a!=(m-(b*b)): print(0) else: print(1)
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. Input Specification: A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. Output Specification: On a single line print the answer to the problem. Demo Input: ['9 3\n', '14 28\n', '4 20\n'] Demo Output: ['1\n', '1\n', '0\n'] Note: In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
```python from math import sqrt,floor n,m =map(int,input().split()) a=floor(sqrt(n)) b=n-(a*a) if a!=(m-(b*b)): print(0) else: print(1) ```
0
527
D
Clique Problem
PROGRAMMING
1,800
[ "data structures", "dp", "greedy", "implementation", "sortings" ]
null
null
The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different.
Print a single number — the number of vertexes in the maximum clique of the given graph.
[ "4\n2 3\n3 1\n6 1\n0 2\n" ]
[ "3\n" ]
If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
2,000
[ { "input": "4\n2 3\n3 1\n6 1\n0 2", "output": "3" }, { "input": "1\n42 23", "output": "1" }, { "input": "2\n1 5\n2 6", "output": "1" }, { "input": "2\n1 5\n12 6", "output": "2" }, { "input": "1\n0 1", "output": "1" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "2\n4 4\n12 5", "output": "1" }, { "input": "2\n4 4\n12 4", "output": "2" }, { "input": "2\n4 4\n12 3", "output": "2" }, { "input": "3\n0 1\n2 1\n4 1", "output": "3" }, { "input": "3\n0 1\n2 2\n4 1", "output": "2" }, { "input": "2\n0 1\n1000000000 1", "output": "2" }, { "input": "2\n0 1000000000\n1000000000 1000000000", "output": "1" }, { "input": "1\n76438 10", "output": "1" }, { "input": "10\n6 15\n4 5\n1 4\n2 4\n0 6\n9 5\n8 14\n5 4\n7 20\n10 20", "output": "1" }, { "input": "10\n0 3\n30 3\n54 3\n6 3\n36 3\n12 3\n42 3\n24 3\n48 3\n18 3", "output": "10" }, { "input": "10\n48 4\n54 4\n12 4\n6 4\n30 4\n36 4\n24 4\n0 4\n42 4\n18 4", "output": "5" }, { "input": "11\n0 4\n54 4\n48 4\n18 4\n24 4\n42 4\n6 4\n36 4\n12 4\n30 4\n60 4", "output": "6" }, { "input": "12\n66 4\n12 4\n60 4\n24 4\n48 4\n0 4\n36 4\n30 4\n6 4\n54 4\n42 4\n18 4", "output": "6" }, { "input": "1\n0 1000000000", "output": "1" } ]
1,427,322,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
n = int(input()) X = [] W = {} big = -1 for _ in range(n): x,w = list(map(int,input().split())) X.append(x) W[x] = w big = max(big,x) dp = {} X=sorted(X) for i,xi in enumerate(X): m = 1 for j in range(i - 1,-1,-1): xj=X[j] if xi - xj >= W[xi] + W[xj]: m = max(m,1 + dp[xj]) dp[xi] = m print(max(dp))
Title: Clique Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph *G*. It is required to find a subset of vertices *C* of the maximum size such that any two of them are connected by an edge in graph *G*. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph. Consider *n* distinct points on a line. Let the *i*-th point have the coordinate *x**i* and weight *w**i*. Let's form graph *G*, whose vertices are these points and edges connect exactly the pairs of points (*i*,<=*j*), such that the distance between them is not less than the sum of their weights, or more formally: |*x**i*<=-<=*x**j*|<=≥<=*w**i*<=+<=*w**j*. Find the size of the maximum clique in such graph. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of points. Each of the next *n* lines contains two numbers *x**i*, *w**i* (0<=≤<=*x**i*<=≤<=109,<=1<=≤<=*w**i*<=≤<=109) — the coordinate and the weight of a point. All *x**i* are different. Output Specification: Print a single number — the number of vertexes in the maximum clique of the given graph. Demo Input: ['4\n2 3\n3 1\n6 1\n0 2\n'] Demo Output: ['3\n'] Note: If you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars! The picture for the sample test.
```python n = int(input()) X = [] W = {} big = -1 for _ in range(n): x,w = list(map(int,input().split())) X.append(x) W[x] = w big = max(big,x) dp = {} X=sorted(X) for i,xi in enumerate(X): m = 1 for j in range(i - 1,-1,-1): xj=X[j] if xi - xj >= W[xi] + W[xj]: m = max(m,1 + dp[xj]) dp[xi] = m print(max(dp)) ```
0
703
B
Mishka and trip
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of *n* cities, *k* of whose (just imagine!) are capital cities. 1. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of *i*-th city equals to *c**i*. 1. All the cities are consecutively connected by the roads, including 1-st and *n*-th city, forming a cyclic route 1<=—<=2<=—<=...<=—<=*n*<=—<=1. Formally, for every 1<=≤<=*i*<=&lt;<=*n* there is a road between *i*-th and *i*<=+<=1-th city, and another one between 1-st and *n*-th city. 1. Each capital city is connected with each other city directly by the roads. Formally, if city *x* is a capital city, then for every 1<=≤<=*i*<=≤<=*n*,<=<=*i*<=≠<=*x*, there is a road between cities *x* and *i*. 1. There is at most one road between any two cities. 1. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities *i* and *j*, price of passing it equals *c**i*·*c**j*. Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities *a* and *b* (*a*<=&lt;<=*b*), such that there is a road between *a* and *b* you are to find sum of products *c**a*·*c**b*. Will you help her?
The first line of the input contains two integers *n* and *k* (3<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=*n*) — the number of cities in XXX and the number of capital cities among them. The second line of the input contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=10<=000) — beauty values of the cities. The third line of the input contains *k* distinct integers *id*1,<=*id*2,<=...,<=*id**k* (1<=≤<=*id**i*<=≤<=*n*) — indices of capital cities. Indices are given in ascending order.
Print the only integer — summary price of passing each of the roads in XXX.
[ "4 1\n2 3 1 2\n3\n", "5 2\n3 5 2 2 4\n1 4\n" ]
[ "17", "71" ]
This image describes first sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/9dcb0e62694349977e064303a74efd880af5eb03.png" style="max-width: 100.0%;max-height: 100.0%;"/> It is easy to see that summary price is equal to 17. This image describes second sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/c30146637f3647c2fc77818bbbf3c080f94f116e.png" style="max-width: 100.0%;max-height: 100.0%;"/> It is easy to see that summary price is equal to 71.
1,000
[ { "input": "4 1\n2 3 1 2\n3", "output": "17" }, { "input": "5 2\n3 5 2 2 4\n1 4", "output": "71" }, { "input": "3 1\n1 1 1\n1", "output": "3" }, { "input": "3 3\n1 1 1\n1 2 3", "output": "3" }, { "input": "7 7\n6 9 2 7 4 8 7\n1 2 3 4 5 6 7", "output": "775" }, { "input": "5 5\n6 2 4 10 2\n1 2 3 4 5", "output": "208" }, { "input": "5 5\n6 7 8 8 8\n1 2 3 4 5", "output": "546" }, { "input": "9 4\n5 6 7 1 5 4 8 7 1\n1 5 7 9", "output": "647" }, { "input": "7 2\n1 6 8 3 3 5 5\n1 3", "output": "255" }, { "input": "9 4\n182 938 865 240 911 25 373 22 875\n3 6 7 8", "output": "4972597" }, { "input": "10 4\n7931 7116 4954 8578 847 6206 5398 4103 7814 1245\n1 3 5 7", "output": "836854437" }, { "input": "9 7\n341 106 584 605 495 512 66 992 713\n1 4 5 6 7 8 9", "output": "8322420" }, { "input": "8 2\n43 2961 202 2637 1007 4469 9031 9900\n4 7", "output": "246280951" }, { "input": "8 5\n751 782 792 243 111 161 746 331\n1 3 4 6 8", "output": "5635386" }, { "input": "8 4\n733 7990 4777 3024 7627 2283 4959 1698\n1 3 5 7", "output": "382022214" }, { "input": "8 6\n736 620 367 629 539 975 867 937\n1 2 5 6 7 8", "output": "13910835" }, { "input": "6 2\n9436 8718 315 2056 4898 7352\n4 6", "output": "319961666" }, { "input": "6 1\n916 913 649 645 312 968\n6", "output": "5373770" }, { "input": "6 2\n6703 5345 9335 5285 1268 5207\n3 6", "output": "361632002" }, { "input": "51 3\n834 817 726 282 783 437 729 423 444 422 692 522 479 27 744 955 634 885 280 839 851 781 555 286 761 459 245 494 709 464 470 254 862 597 409 276 372 746 135 464 742 400 970 766 388 351 474 104 702 945 835\n12 28 29", "output": "62712861" }, { "input": "52 17\n5281 7307 2542 1181 6890 5104 5081 4658 9629 6973 3504 4423 3184 6012 2538 6778 9611 3163 1907 4489 4923 685 5753 2553 5986 520 192 8643 4805 6469 5311 3074 2045 6836 6993 7126 1415 6149 9093 9635 6004 1983 7263 3171 4378 9436 9813 6464 8656 3819 130 763\n1 5 7 9 11 13 16 19 21 23 35 38 40 42 47 49 51", "output": "20412478312" }, { "input": "76 45\n29 219 740 819 616 699 8 557 969 550 66 259 615 101 560 640 75 632 752 598 820 714 418 858 669 819 456 597 290 956 461 941 359 318 155 378 257 292 699 249 306 676 890 292 25 225 22 520 776 268 397 438 468 239 174 508 265 216 933 857 564 165 59 779 526 826 597 77 704 420 688 1 689 769 323 98\n1 2 3 5 7 8 10 12 14 15 17 18 22 23 25 26 28 30 31 33 34 35 36 37 38 40 43 44 46 47 52 53 55 56 58 60 61 62 63 64 66 69 71 72 73", "output": "508857909" }, { "input": "76 24\n6814 3834 1131 6256 2598 850 7353 1702 5773 1699 35 5103 1368 2258 7891 7455 8546 7316 7428 8864 6536 5750 8455 2624 7326 2197 8239 3806 3016 7126 85 3249 1138 6783 9684 4417 7417 3660 6334 7324 9760 9755 7605 9891 3676 8784 8739 8266 3272 9250 5875 939 4130 6540 7813 6867 9148 781 6190 964 5612 1864 949 7826 9148 6293 4936 870 2042 5838 7141 2030 1241 259 5617 2539\n3 5 9 12 15 18 20 23 25 29 31 33 35 37 39 44 46 48 59 63 65 68 72 76", "output": "43060198680" }, { "input": "50 15\n915 8535 2997 4040 9747 2161 9628 8364 1943 136 1403 7037 9713 7741 7463 4316 1543 994 7320 95 6211 8110 2713 5806 7652 6749 3996 2886 8971 6878 1267 9546 1551 6835 9256 5725 9609 1748 8246 6169 9465 4620 9565 1419 3327 1003 9938 9556 882 6178\n3 8 10 12 15 18 22 24 27 29 33 37 41 43 46", "output": "19733750400" }, { "input": "73 27\n651 944 104 639 369 961 338 573 516 690 889 227 480 160 299 783 270 331 793 796 64 712 649 88 695 550 829 303 965 780 570 374 371 506 954 632 660 987 986 253 144 993 708 710 890 257 303 651 923 107 386 893 301 387 852 596 72 699 63 241 336 855 160 5 981 447 601 601 305 680 448 676 374\n1 3 4 5 6 11 17 18 19 20 27 29 32 33 40 43 46 47 48 53 55 57 61 62 63 67 71", "output": "460505110" }, { "input": "74 27\n8668 693 205 9534 6686 9598 2837 3425 8960 3727 8872 4393 4835 8438 7881 3591 7914 5218 8959 7342 7134 8170 1778 5107 3467 6998 9506 3635 8929 2004 49 701 5059 7285 5236 1540 7643 365 229 2062 7732 3142 7668 8871 2783 7309 529 1695 4255 8084 2708 6936 8300 4015 1142 3705 8564 1031 1685 9262 5077 3674 4788 4981 4693 9896 792 322 5482 584 3852 3484 9410 3889\n1 4 6 12 16 19 21 23 26 29 31 33 36 39 41 43 46 48 51 53 55 58 61 64 67 69 73", "output": "41845373785" }, { "input": "3 1\n1 2 3\n3", "output": "11" } ]
1,689,630,551
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689630551.6644855")# 1689630551.664505
Title: Mishka and trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of *n* cities, *k* of whose (just imagine!) are capital cities. 1. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of *i*-th city equals to *c**i*. 1. All the cities are consecutively connected by the roads, including 1-st and *n*-th city, forming a cyclic route 1<=—<=2<=—<=...<=—<=*n*<=—<=1. Formally, for every 1<=≤<=*i*<=&lt;<=*n* there is a road between *i*-th and *i*<=+<=1-th city, and another one between 1-st and *n*-th city. 1. Each capital city is connected with each other city directly by the roads. Formally, if city *x* is a capital city, then for every 1<=≤<=*i*<=≤<=*n*,<=<=*i*<=≠<=*x*, there is a road between cities *x* and *i*. 1. There is at most one road between any two cities. 1. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities *i* and *j*, price of passing it equals *c**i*·*c**j*. Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities *a* and *b* (*a*<=&lt;<=*b*), such that there is a road between *a* and *b* you are to find sum of products *c**a*·*c**b*. Will you help her? Input Specification: The first line of the input contains two integers *n* and *k* (3<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=*n*) — the number of cities in XXX and the number of capital cities among them. The second line of the input contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=10<=000) — beauty values of the cities. The third line of the input contains *k* distinct integers *id*1,<=*id*2,<=...,<=*id**k* (1<=≤<=*id**i*<=≤<=*n*) — indices of capital cities. Indices are given in ascending order. Output Specification: Print the only integer — summary price of passing each of the roads in XXX. Demo Input: ['4 1\n2 3 1 2\n3\n', '5 2\n3 5 2 2 4\n1 4\n'] Demo Output: ['17', '71'] Note: This image describes first sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/9dcb0e62694349977e064303a74efd880af5eb03.png" style="max-width: 100.0%;max-height: 100.0%;"/> It is easy to see that summary price is equal to 17. This image describes second sample case: <img class="tex-graphics" src="https://espresso.codeforces.com/c30146637f3647c2fc77818bbbf3c080f94f116e.png" style="max-width: 100.0%;max-height: 100.0%;"/> It is easy to see that summary price is equal to 71.
```python print("_RANDOM_GUESS_1689630551.6644855")# 1689630551.664505 ```
0
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,643,810,732
2,147,483,647
Python 3
OK
TESTS
96
46
0
import math n,k = map(int,input().split()) m =(n * (10**k)) / math.gcd(n, (10**k)) print(int(m))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python import math n,k = map(int,input().split()) m =(n * (10**k)) / math.gcd(n, (10**k)) print(int(m)) ```
3
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "input": "4", "output": "Rajesh" }, { "input": "5", "output": "Howard" }, { "input": "10", "output": "Penny" }, { "input": "534", "output": "Rajesh" }, { "input": "5033", "output": "Howard" }, { "input": "10010", "output": "Howard" }, { "input": "500000000", "output": "Penny" }, { "input": "63", "output": "Rajesh" }, { "input": "841", "output": "Leonard" }, { "input": "3667", "output": "Penny" }, { "input": "38614", "output": "Howard" }, { "input": "282798", "output": "Rajesh" }, { "input": "9266286", "output": "Rajesh" }, { "input": "27385966", "output": "Leonard" }, { "input": "121580142", "output": "Penny" }, { "input": "5", "output": "Howard" }, { "input": "300", "output": "Howard" }, { "input": "1745", "output": "Leonard" }, { "input": "8302", "output": "Rajesh" }, { "input": "184518", "output": "Sheldon" }, { "input": "1154414", "output": "Rajesh" }, { "input": "28643950", "output": "Leonard" }, { "input": "159222638", "output": "Howard" }, { "input": "24", "output": "Penny" }, { "input": "505", "output": "Penny" }, { "input": "4425", "output": "Rajesh" }, { "input": "12079", "output": "Sheldon" }, { "input": "469726", "output": "Penny" }, { "input": "3961838", "output": "Penny" }, { "input": "57710446", "output": "Leonard" }, { "input": "80719470", "output": "Howard" }, { "input": "1000000000", "output": "Penny" }, { "input": "999999999", "output": "Penny" }, { "input": "999999998", "output": "Penny" }, { "input": "5", "output": "Howard" } ]
1,517,010,345
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
5,632,000
p=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] a=int(input()) i=1 while True: if a<=(5*i): print(p[int(a/i)-1]) break else: a-=(5*i) i*=2
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python p=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] a=int(input()) i=1 while True: if a<=(5*i): print(p[int(a/i)-1]) break else: a-=(5*i) i*=2 ```
0
637
C
Promocodes with Mistakes
PROGRAMMING
1,400
[ "*special", "brute force", "constructive algorithms", "implementation" ]
null
null
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ. As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly. A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.
The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes. Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".
Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes.
[ "2\n000000\n999999\n", "6\n211111\n212111\n222111\n111111\n112111\n121111\n" ]
[ "2\n", "0\n" ]
In the first sample *k* &lt; 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.
1,500
[ { "input": "2\n000000\n999999", "output": "2" }, { "input": "6\n211111\n212111\n222111\n111111\n112111\n121111", "output": "0" }, { "input": "1\n123456", "output": "6" }, { "input": "2\n000000\n099999", "output": "2" }, { "input": "2\n000000\n009999", "output": "1" }, { "input": "2\n000000\n000999", "output": "1" }, { "input": "2\n000000\n000099", "output": "0" }, { "input": "2\n000000\n000009", "output": "0" }, { "input": "1\n000000", "output": "6" }, { "input": "1\n999999", "output": "6" }, { "input": "10\n946965\n781372\n029568\n336430\n456975\n119377\n179098\n925374\n878716\n461563", "output": "1" }, { "input": "10\n878711\n193771\n965021\n617901\n333641\n307811\n989461\n461561\n956811\n253741", "output": "1" }, { "input": "10\n116174\n914694\n615024\n115634\n717464\n910984\n513744\n111934\n915684\n817874", "output": "0" }, { "input": "10\n153474\n155468\n151419\n151479\n158478\n159465\n150498\n157416\n150429\n159446", "output": "0" }, { "input": "10\n141546\n941544\n141547\n041542\n641545\n841547\n941540\n741544\n941548\n641549", "output": "0" }, { "input": "10\n114453\n114456\n114457\n114450\n114459\n114451\n114458\n114452\n114455\n114454", "output": "0" }, { "input": "5\n145410\n686144\n859775\n922809\n470967", "output": "2" }, { "input": "9\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "20\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832", "output": "2" }, { "input": "50\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "output": "2" }, { "input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "output": "2" }, { "input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "output": "2" }, { "input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "output": "2" }, { "input": "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "output": "2" }, { "input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "output": "1" }, { "input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "output": "1" }, { "input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "output": "1" }, { "input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "output": "1" }, { "input": "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "output": "1" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" }, { "input": "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "output": "2" } ]
1,633,765,739
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
1
31
6,963,200
n = input() promo_code = [] def compare_str(a,b): k = 0 for i in range(6): if a[i] == b[i]: k = k+1 return k for i in range(0,int(n)): x = input() promo_code.append(x) largest_same_num = 0 for i in promo_code: for j in promo_code: if i!=j: a = compare_str(i,j) if a > largest_same_num: largest_same_num = a k = 0 if largest_same_num == 1 or largest_same_num == 0: k = 2 elif largesr_same_num == 2 or largest_same_num == 3: k = 1 print(k)
Title: Promocodes with Mistakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ. As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly. A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits. Input Specification: The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes. Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0". Output Specification: Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes. Demo Input: ['2\n000000\n999999\n', '6\n211111\n212111\n222111\n111111\n112111\n121111\n'] Demo Output: ['2\n', '0\n'] Note: In the first sample *k* &lt; 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.
```python n = input() promo_code = [] def compare_str(a,b): k = 0 for i in range(6): if a[i] == b[i]: k = k+1 return k for i in range(0,int(n)): x = input() promo_code.append(x) largest_same_num = 0 for i in promo_code: for j in promo_code: if i!=j: a = compare_str(i,j) if a > largest_same_num: largest_same_num = a k = 0 if largest_same_num == 1 or largest_same_num == 0: k = 2 elif largesr_same_num == 2 or largest_same_num == 3: k = 1 print(k) ```
-1
527
A
Playing with Paper
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson?
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Print a single integer — the number of ships that Vasya will make.
[ "2 1\n", "10 7\n", "1000000000000 1\n" ]
[ "2\n", "6\n", "1000000000000\n" ]
Pictures to the first and second sample test.
500
[ { "input": "2 1", "output": "2" }, { "input": "10 7", "output": "6" }, { "input": "1000000000000 1", "output": "1000000000000" }, { "input": "3 1", "output": "3" }, { "input": "4 1", "output": "4" }, { "input": "3 2", "output": "3" }, { "input": "4 2", "output": "2" }, { "input": "1000 700", "output": "6" }, { "input": "959986566087 524054155168", "output": "90" }, { "input": "4 3", "output": "4" }, { "input": "7 6", "output": "7" }, { "input": "1000 999", "output": "1000" }, { "input": "1000 998", "output": "500" }, { "input": "1000 997", "output": "336" }, { "input": "42 1", "output": "42" }, { "input": "1000 1", "output": "1000" }, { "input": "8 5", "output": "5" }, { "input": "13 8", "output": "6" }, { "input": "987 610", "output": "15" }, { "input": "442 42", "output": "22" }, { "input": "754 466", "output": "13" }, { "input": "1000000000000 999999999999", "output": "1000000000000" }, { "input": "1000000000000 999999999998", "output": "500000000000" }, { "input": "941 14", "output": "74" }, { "input": "998 2", "output": "499" }, { "input": "1000 42", "output": "32" }, { "input": "1000 17", "output": "66" }, { "input": "5 1", "output": "5" }, { "input": "5 2", "output": "4" }, { "input": "5 3", "output": "4" }, { "input": "5 4", "output": "5" }, { "input": "293 210", "output": "17" }, { "input": "787878787878 424242424242", "output": "8" }, { "input": "956722026041 591286729879", "output": "58" }, { "input": "956722026041 365435296162", "output": "58" }, { "input": "628625247282 464807889701", "output": "102" }, { "input": "695928431619 424778620208", "output": "167" }, { "input": "1000000000000 42", "output": "23809523821" }, { "input": "987654345678 23", "output": "42941493300" }, { "input": "10000000001 2", "output": "5000000002" }, { "input": "1000000000000 2", "output": "500000000000" }, { "input": "1000000000000 3", "output": "333333333336" }, { "input": "100000000000 3", "output": "33333333336" }, { "input": "100000000000 23", "output": "4347826109" }, { "input": "999999999997 7", "output": "142857142861" }, { "input": "8589934592 4294967296", "output": "2" } ]
1,426,612,566
1,866
Python 3
CHALLENGED
CHALLENGES
9
61
0
a_b = input().split() a = int(a_b[0]) b = int(a_b[1]) if a > b: bolshoe = a menshee = b else: bolshoe = b menshee = a vivod = 1 x = 0 i = 0 if bolshoe == menshee: x = 1 elif a == 1 and b != 1: vivod = b x = 1 elif b == 1 and a != 1: vivod = a x = 1 while i > -1: if x == 1: print(vivod) break if bolshoe != menshee: bolshoe = bolshoe - menshee vivod += 1 i += 1 else: i += 1 if bolshoe < menshee: bolshoe, menshee = menshee, bolshoe if bolshoe == menshee: print(vivod) break
Title: Playing with Paper Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? Input Specification: The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Output Specification: Print a single integer — the number of ships that Vasya will make. Demo Input: ['2 1\n', '10 7\n', '1000000000000 1\n'] Demo Output: ['2\n', '6\n', '1000000000000\n'] Note: Pictures to the first and second sample test.
```python a_b = input().split() a = int(a_b[0]) b = int(a_b[1]) if a > b: bolshoe = a menshee = b else: bolshoe = b menshee = a vivod = 1 x = 0 i = 0 if bolshoe == menshee: x = 1 elif a == 1 and b != 1: vivod = b x = 1 elif b == 1 and a != 1: vivod = a x = 1 while i > -1: if x == 1: print(vivod) break if bolshoe != menshee: bolshoe = bolshoe - menshee vivod += 1 i += 1 else: i += 1 if bolshoe < menshee: bolshoe, menshee = menshee, bolshoe if bolshoe == menshee: print(vivod) break ```
-1
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,587,124,617
2,147,483,647
Python 3
OK
TESTS
76
156
0
n = int(input()) if n % 2 != 0 or n < 6: print(0) else: k = n // 2 if n % 4 == 0: print(k//2-1) else: print(k//2)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python n = int(input()) if n % 2 != 0 or n < 6: print(0) else: k = n // 2 if n % 4 == 0: print(k//2-1) else: print(k//2) ```
3
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307", "output": "22258199.5000000000" }, { "input": "2 1000000000\n0 1000000000", "output": "500000000.0000000000" }, { "input": "2 555\n200 300", "output": "255.0000000000" }, { "input": "1 1\n1", "output": "1.0000000000" }, { "input": "1 1\n0", "output": "1.0000000000" }, { "input": "1 1000000000\n0", "output": "1000000000.0000000000" }, { "input": "1 1000000000\n1000000000", "output": "1000000000.0000000000" }, { "input": "1 999999999\n499999999", "output": "500000000.0000000000" }, { "input": "4 700\n0 250 475 700", "output": "125.0000000000" }, { "input": "4 700\n0 225 450 700", "output": "125.0000000000" }, { "input": "5 1000\n0 250 500 750 1000", "output": "125.0000000000" }, { "input": "5 2000\n1001 1001 1001 1001 1001", "output": "1001.0000000000" }, { "input": "1 999\n501", "output": "501.0000000000" }, { "input": "2 1000\n400 600", "output": "400.0000000000" }, { "input": "4 15\n1 3 9 11", "output": "4.0000000000" }, { "input": "1 5\n2", "output": "3.0000000000" } ]
1,696,079,367
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
line1 = input().split() line2 = input().split() n = int(line1[0]) l = int(line1[1]) lanternList = [] for item in line2: lanternList.append(int(item)) lanternList.sort() result = [] if lanternList[0] != 0: result.append(lanternList[0]*1.000000000) for i in range(n-1): result.append(lanternList[i+1]-lanternList[i]*1.000000000) if lanternList[n-1] != l: result.append(l-lanternList[n-1]*1.000000000) final = 000000000 for i in range(1 , len(result)-1): if result[i]/2 >final: final = result[i]/2 /2 if result[0]>final: final = result[0] elif result[len(result)-1]> final: final = result[len(result)-1] print(result) print(f"{final:.9f}")
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? Input Specification: The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. Output Specification: Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. Demo Input: ['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n'] Demo Output: ['2.5000000000\n', '2.0000000000\n'] Note: Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
```python line1 = input().split() line2 = input().split() n = int(line1[0]) l = int(line1[1]) lanternList = [] for item in line2: lanternList.append(int(item)) lanternList.sort() result = [] if lanternList[0] != 0: result.append(lanternList[0]*1.000000000) for i in range(n-1): result.append(lanternList[i+1]-lanternList[i]*1.000000000) if lanternList[n-1] != l: result.append(l-lanternList[n-1]*1.000000000) final = 000000000 for i in range(1 , len(result)-1): if result[i]/2 >final: final = result[i]/2 /2 if result[0]>final: final = result[0] elif result[len(result)-1]> final: final = result[len(result)-1] print(result) print(f"{final:.9f}") ```
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20 1 80", "output": "1 20 40 60 80 100 " }, { "input": "10\n10 8 6 7 5 3 4 2 9 1", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 " }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 " }, { "input": "10\n1 9 7 6 2 4 7 8 1 3", "output": "1 1 2 3 4 6 7 7 8 9 " }, { "input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59", "output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 " }, { "input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12", "output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 " }, { "input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84", "output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 " }, { "input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52", "output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 " }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " }, { "input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6", "output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 " }, { "input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3", "output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 " }, { "input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32", "output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 " }, { "input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41", "output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 " }, { "input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82", "output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 " }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 " }, { "input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 " }, { "input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 " }, { "input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88", "output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 " }, { "input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 " }, { "input": "10\n100 90 80 70 60 50 40 30 20 10", "output": "10 20 30 40 50 60 70 80 90 100 " }, { "input": "1\n10", "output": "10 " } ]
1,698,587,387
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
columnsInBox = int(input()) numOfCubes = input().split() newList = [] for nums in numOfCubes: newList.append(int(nums)) newList.sort() print(newList)
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! Input Specification: The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. Output Specification: Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. Demo Input: ['4\n3 2 1 2\n', '3\n2 3 8\n'] Demo Output: ['1 2 2 3 \n', '2 3 8 \n'] Note: The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns.
```python columnsInBox = int(input()) numOfCubes = input().split() newList = [] for nums in numOfCubes: newList.append(int(nums)) newList.sort() print(newList) ```
0
507
A
Amr and Music
PROGRAMMING
1,000
[ "greedy", "implementation", "sortings" ]
null
null
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
[ "4 10\n4 3 1 2\n", "5 6\n4 3 1 1 2\n", "1 3\n4\n" ]
[ "4\n1 2 3 4", "3\n1 3 4", "0\n" ]
In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
500
[ { "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4" }, { "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5" }, { "input": "1 3\n4", "output": "0" }, { "input": "2 100\n100 100", "output": "1\n1" }, { "input": "3 150\n50 50 50", "output": "3\n1 2 3" }, { "input": "4 0\n100 100 100 100", "output": "0" }, { "input": "100 7567\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": "75\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" }, { "input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50", "output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68" }, { "input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100\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" }, { "input": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93", "output": "25\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" }, { "input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76", "output": "98\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" }, { "input": "5 249\n96 13 7 2 81", "output": "5\n1 2 3 4 5" }, { "input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44", "output": "61\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" }, { "input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80", "output": "99\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" }, { "input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97", "output": "89\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" }, { "input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8", "output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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" }, { "input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12", "output": "27\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" }, { "input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93", "output": "55\n1 2 3 4 5 6 7 8 9 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" }, { "input": "6 41\n6 8 9 8 9 8", "output": "5\n1 2 3 4 6" }, { "input": "9 95\n9 11 12 11 12 11 8 11 10", "output": "9\n1 2 3 4 5 6 7 8 9" }, { "input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52", "output": "89\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" }, { "input": "5 29\n6 3 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "5 49\n16 13 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "6 84\n16 21 25 6 17 16", "output": "5\n1 2 4 5 6" }, { "input": "4 9\n7 4 2 1", "output": "3\n2 3 4" }, { "input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50\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" }, { "input": "100 10000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6", "output": "96\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" }, { "input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3", "output": "47\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" }, { "input": "100 200\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "2 10000\n1 1", "output": "2\n1 2" }, { "input": "1 2\n1", "output": "1\n1" }, { "input": "1 3\n2", "output": "1\n1" }, { "input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71", "output": "34\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34" }, { "input": "2 2\n1 10", "output": "1\n1" }, { "input": "2 5\n1 1", "output": "2\n1 2" }, { "input": "1 4\n3", "output": "1\n1" }, { "input": "4 384\n1 2 3 4", "output": "4\n1 2 3 4" } ]
1,694,784,690
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n,k = map(int,input().split()) a = sorted(list(map(int,input().split()))) c=0 L = [] for i in a: t = sum(L) + i if t <= k: L.append(i) c+= 1 else: break print(c) if L != []: print(*L)
Title: Amr and Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. Input Specification: The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. Output Specification: In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying. Demo Input: ['4 10\n4 3 1 2\n', '5 6\n4 3 1 1 2\n', '1 3\n4\n'] Demo Output: ['4\n1 2 3 4', '3\n1 3 4', '0\n'] Note: In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
```python n,k = map(int,input().split()) a = sorted(list(map(int,input().split()))) c=0 L = [] for i in a: t = sum(L) + i if t <= k: L.append(i) c+= 1 else: break print(c) if L != []: print(*L) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,418,030,814
2,147,483,647
Python 3
OK
TESTS
40
122
0
lines = [] for i in range(2): lines.append(input()) #print(lines) l = len(lines[0]) comp = "" for i in range(l): comp = lines[0][i] + comp if comp == lines[1]: print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python lines = [] for i in range(2): lines.append(input()) #print(lines) l = len(lines[0]) comp = "" for i in range(l): comp = lines[0][i] + comp if comp == lines[1]: print("YES") else: print("NO") ```
3.9695
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,673,525,139
2,147,483,647
Python 3
OK
TESTS
34
46
0
n=int(input()) l=[] Sereja , Dima, i = 0, 0, 0 t=map(int,input().split()) l+=t y=len(l) a=True while(y!=0): if(l[0]>=l[y-1]): x=l[0] l.pop(0) else: x=l[y-1] l.pop(y-1) if(a==True): Sereja+=x a=False else: Dima+=x a=True y-=1 print(Sereja,Dima)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n=int(input()) l=[] Sereja , Dima, i = 0, 0, 0 t=map(int,input().split()) l+=t y=len(l) a=True while(y!=0): if(l[0]>=l[y-1]): x=l[0] l.pop(0) else: x=l[y-1] l.pop(y-1) if(a==True): Sereja+=x a=False else: Dima+=x a=True y-=1 print(Sereja,Dima) ```
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them.
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
1,586,327,859
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
216
0
n=int(input()) s="ROYGBIV" v=n%7 u=n//7 r=n-u*7 s1=s*u #print(s1) if(v>4): s2=s[0:0+r] elif(v<4): s2=s[3:3+r] #print(s2) print(s1+s2)
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python n=int(input()) s="ROYGBIV" v=n%7 u=n//7 r=n-u*7 s1=s*u #print(s1) if(v>4): s2=s[0:0+r] elif(v<4): s2=s[3:3+r] #print(s2) print(s1+s2) ```
-1
582
A
GCD Table
PROGRAMMING
1,700
[ "constructive algorithms", "greedy", "number theory" ]
null
null
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*.
The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*.
In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them.
[ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ]
[ "4 3 6 2", "42 ", "1 1 " ]
none
750
[ { "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 " }, { "input": "1\n42", "output": "42 " }, { "input": "2\n1 1 1 1", "output": "1 1 " }, { "input": "2\n54748096 1 641009859 1", "output": "54748096 641009859 " }, { "input": "3\n1 7 923264237 374288891 7 524125987 1 1 1", "output": "374288891 524125987 923264237 " }, { "input": "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "output": "496813081 561219907 673102149 702209411 " }, { "input": "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "output": "291882089 365329221 412106895 564718673 585325539 " }, { "input": "5\n1 161 1 534447872 161 233427865 1 7 7 73701396 1 401939237 4 1 1 1 1 1 7 115704211 1 4 1 7 1", "output": "73701396 115704211 233427865 401939237 534447872 " }, { "input": "5\n2 11 1 1 2 4 2 1 181951 4 345484316 2 4 4 4 2 1 140772746 1 634524 4 521302304 1 2 11", "output": "181951 634524 140772746 345484316 521302304 " }, { "input": "5\n27 675 1 1 347621274 5 2 13 189 738040275 5 1 189 13 1 959752125 770516962 769220855 5 5 2 675 1 1 27", "output": "347621274 738040275 769220855 770516962 959752125 " }, { "input": "5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2029 165353355 4058 2029 731472761 739767313 2029 2029 2029 585281282", "output": "165353355 527243766 585281282 731472761 739767313 " }, { "input": "5\n537163 537163 537163 537163 537163 537163 1074326 537163 537163 537163 515139317 1074326 537163 537163 537163 539311652 321760637 170817834 537163 537163 537163 537163 537163 537163 392666153", "output": "170817834 321760637 392666153 515139317 539311652 " }, { "input": "4\n1 188110 607844 2 1 1 695147 1 1 1 143380513 1 1 1 1 2", "output": "188110 607844 695147 143380513 " }, { "input": "4\n3 1 96256522 120 360284388 3 3 2 2 2 3 12 12 2 1 198192381", "output": "120 96256522 198192381 360284388 " }, { "input": "4\n67025 13405 1915 1915 1915 1915 5745 676469920 53620 5745 660330300 67025 53620 380098775 533084295 13405", "output": "380098775 533084295 660330300 676469920 " }, { "input": "4\n700521 233507 759364764 467014 468181535 233507 233507 890362191 233507 700521 467014 233507 946637378 233507 233507 233507", "output": "468181535 759364764 890362191 946637378 " }, { "input": "3\n484799 1 1 744137 1 1 909312183 1 1", "output": "484799 744137 909312183 " }, { "input": "3\n1 716963379 1 1 205 1 1 964 1", "output": "205 964 716963379 " }, { "input": "3\n5993 781145599 54740062 5993 5993 267030101 5993 5993 5993", "output": "54740062 267030101 781145599 " }, { "input": "3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339", "output": "55451923 435485671 531222142 " }, { "input": "5\n4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1", "output": "1 2 4 4 4 " }, { "input": "4\n1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3", "output": "1 1 3 3 " }, { "input": "6\n1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6", "output": "1 3 3 6 6 6 " } ]
1,552,100,358
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
409,600
def gcd(a,b): if b==0: return a return gcd(b,a%b) n=int(input()) from collections import Counter l=[int(i) for i in input().split()] g=Counter(l) ans=[] while g: m=max(g) g[m]-=1 for i in ans: g[gcd(m,i)]-=2 ans+=[m] # g+=Counter() print(*ans)
Title: GCD Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*. Output Specification: In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. Demo Input: ['4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n', '1\n42\n', '2\n1 1 1 1\n'] Demo Output: ['4 3 6 2', '42 ', '1 1 '] Note: none
```python def gcd(a,b): if b==0: return a return gcd(b,a%b) n=int(input()) from collections import Counter l=[int(i) for i in input().split()] g=Counter(l) ans=[] while g: m=max(g) g[m]-=1 for i in ans: g[gcd(m,i)]-=2 ans+=[m] # g+=Counter() print(*ans) ```
0
903
C
Boxes Packing
PROGRAMMING
1,200
[ "greedy" ]
null
null
Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes!
The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box.
Print the minimum possible number of visible boxes.
[ "3\n1 2 3\n", "4\n4 2 4 3\n" ]
[ "1\n", "2\n" ]
In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
0
[ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n4 2 4 3", "output": "2" }, { "input": "10\n58 58 58 58 58 58 58 58 58 58", "output": "10" }, { "input": "10\n86 89 89 86 86 89 86 86 89 89", "output": "5" }, { "input": "100\n981 288 186 186 292 876 341 288 981 360 783 907 292 186 341 292 360 876 360 360 981 398 783 288 292 398 876 981 398 907 783 360 288 981 907 186 360 288 186 981 186 288 907 876 288 907 876 360 341 292 907 783 907 783 292 981 907 292 876 398 783 876 398 341 876 186 288 186 981 341 398 360 907 981 341 186 292 981 292 398 876 783 292 186 360 292 288 292 876 398 288 292 341 288 398 360 360 292 981 360", "output": "14" }, { "input": "1\n1", "output": "1" }, { "input": "1\n9", "output": "1" }, { "input": "1\n5", "output": "1" }, { "input": "1\n2", "output": "1" }, { "input": "1\n131", "output": "1" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "11" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1" }, { "input": "8\n1 1 1 1 1 1 1 1", "output": "8" }, { "input": "5\n1 1 1 1 1", "output": "5" } ]
1,605,533,147
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
n = int(input()) arr = list(map(int,input().split())) arr.sort(reverse=True) count =0 for i in range(n): if arr[i]!=-1: selected = arr[i] count+=1 else: continue for i in range(i,n): if(arr[i]<selected): selected = arr[i] arr[i]=-1 print(count)
Title: Boxes Packing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka has got *n* empty boxes. For every *i* (1<=≤<=*i*<=≤<=*n*), *i*-th box is a cube with side length *a**i*. Mishka can put a box *i* into another box *j* if the following conditions are met: - *i*-th box is not put into another box; - *j*-th box doesn't contain any other boxes; - box *i* is smaller than box *j* (*a**i*<=&lt;<=*a**j*). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box. Help Mishka to determine the minimum possible number of visible boxes! Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=5000) — the number of boxes Mishka has got. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the side length of *i*-th box. Output Specification: Print the minimum possible number of visible boxes. Demo Input: ['3\n1 2 3\n', '4\n4 2 4 3\n'] Demo Output: ['1\n', '2\n'] Note: In the first example it is possible to put box 1 into box 2, and 2 into 3. In the second example Mishka can put box 2 into box 3, and box 4 into box 1.
```python n = int(input()) arr = list(map(int,input().split())) arr.sort(reverse=True) count =0 for i in range(n): if arr[i]!=-1: selected = arr[i] count+=1 else: continue for i in range(i,n): if(arr[i]<selected): selected = arr[i] arr[i]=-1 print(count) ```
0
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "input": "1000000000", "output": "1\n999999932" }, { "input": "999999979", "output": "2\n999999899\n999999908" }, { "input": "9", "output": "0" }, { "input": "10", "output": "1\n5" }, { "input": "11", "output": "1\n10" }, { "input": "39", "output": "1\n33" }, { "input": "66", "output": "1\n60" }, { "input": "75", "output": "0" }, { "input": "100", "output": "1\n86" }, { "input": "101", "output": "2\n91\n100" }, { "input": "2014", "output": "2\n1988\n2006" }, { "input": "999999994", "output": "0" } ]
1,602,007,778
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
0
from sys import stdin, stdout n = int(stdin.readline()) ans = [] for x in range(n): running_total = x temp = x while temp != 0: running_total += (temp%10) temp = temp // 10 if running_total == n: ans.append(x) if len(ans) == 0: stdout.write('0') else: end_str = str(len(ans))+'\n' for i in ans: end_str+=str(i)+' ' stdout.write(end_str)
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order. Demo Input: ['21\n', '20\n'] Demo Output: ['1\n15\n', '0\n'] Note: In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
```python from sys import stdin, stdout n = int(stdin.readline()) ans = [] for x in range(n): running_total = x temp = x while temp != 0: running_total += (temp%10) temp = temp // 10 if running_total == n: ans.append(x) if len(ans) == 0: stdout.write('0') else: end_str = str(len(ans))+'\n' for i in ans: end_str+=str(i)+' ' stdout.write(end_str) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,614,015,781
2,147,483,647
Python 3
OK
TESTS
40
62
0
h = 'hello' s = input() i = 0 for c in s: if c == h[i]: i += 1 if i == len(h): break print('YES' if i == len(h) else 'NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python h = 'hello' s = input() i = 0 for c in s: if c == h[i]: i += 1 if i == len(h): break print('YES' if i == len(h) else 'NO') ```
3.969
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,691,876,433
2,147,483,647
Python 3
OK
TESTS
35
92
0
size = input("") sizz = size.split(" ") space = int(sizz[0])*int(sizz[1]) print(int(space/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python size = input("") sizz = size.split(" ") space = int(sizz[0])*int(sizz[1]) print(int(space/2)) ```
3.977
611
A
New Year and Days
PROGRAMMING
900
[ "implementation" ]
null
null
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month. Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
The only line of the input is in one of the following two formats: - "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Print one integer — the number of candies Limak will save in the year 2016.
[ "4 of week\n", "30 of month\n" ]
[ "52\n", "11\n" ]
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday. In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total. In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
500
[ { "input": "4 of week", "output": "52" }, { "input": "30 of month", "output": "11" }, { "input": "17 of month", "output": "12" }, { "input": "31 of month", "output": "7" }, { "input": "6 of week", "output": "53" }, { "input": "1 of week", "output": "52" }, { "input": "2 of week", "output": "52" }, { "input": "3 of week", "output": "52" }, { "input": "5 of week", "output": "53" }, { "input": "7 of week", "output": "52" }, { "input": "1 of month", "output": "12" }, { "input": "2 of month", "output": "12" }, { "input": "3 of month", "output": "12" }, { "input": "4 of month", "output": "12" }, { "input": "5 of month", "output": "12" }, { "input": "6 of month", "output": "12" }, { "input": "7 of month", "output": "12" }, { "input": "8 of month", "output": "12" }, { "input": "9 of month", "output": "12" }, { "input": "10 of month", "output": "12" }, { "input": "11 of month", "output": "12" }, { "input": "12 of month", "output": "12" }, { "input": "13 of month", "output": "12" }, { "input": "14 of month", "output": "12" }, { "input": "15 of month", "output": "12" }, { "input": "16 of month", "output": "12" }, { "input": "18 of month", "output": "12" }, { "input": "19 of month", "output": "12" }, { "input": "20 of month", "output": "12" }, { "input": "21 of month", "output": "12" }, { "input": "22 of month", "output": "12" }, { "input": "23 of month", "output": "12" }, { "input": "24 of month", "output": "12" }, { "input": "25 of month", "output": "12" }, { "input": "26 of month", "output": "12" }, { "input": "27 of month", "output": "12" }, { "input": "28 of month", "output": "12" }, { "input": "29 of month", "output": "12" } ]
1,451,489,662
1,762
Python 3
WRONG_ANSWER
CHALLENGES
0
46
0
help = list(input().split()) if help[2] == 'week': if int(help[0]) == 5 or int(help[0]) == 6 or int(help[0]) == 7: print(366 // 7 + 1) else: print(366 // 7) else: if int(help[0]) <= 29: print(12) elif int(help[0]) == 30: print(11) else: print(7)
Title: New Year and Days Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month. Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him. Input Specification: The only line of the input is in one of the following two formats: - "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. Output Specification: Print one integer — the number of candies Limak will save in the year 2016. Demo Input: ['4 of week\n', '30 of month\n'] Demo Output: ['52\n', '11\n'] Note: Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday. In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total. In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
```python help = list(input().split()) if help[2] == 'week': if int(help[0]) == 5 or int(help[0]) == 6 or int(help[0]) == 7: print(366 // 7 + 1) else: print(366 // 7) else: if int(help[0]) <= 29: print(12) elif int(help[0]) == 30: print(11) else: print(7) ```
0
219
A
k-String
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
[ "2\naazz\n", "3\nabcabcabz\n" ]
[ "azaz\n", "-1\n" ]
none
500
[ { "input": "2\naazz", "output": "azaz" }, { "input": "3\nabcabcabz", "output": "-1" }, { "input": "1\na", "output": "a" }, { "input": "2\nabba", "output": "abab" }, { "input": "2\naaab", "output": "-1" }, { "input": "7\nabacaba", "output": "-1" }, { "input": "5\naaaaa", "output": "aaaaa" }, { "input": "3\naabaaaaabb", "output": "-1" }, { "input": "2\naaab", "output": "-1" }, { "input": "2\nbabac", "output": "-1" }, { "input": "3\nbbbccc", "output": "bcbcbc" }, { "input": "2\naa", "output": "aa" }, { "input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece", "output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece" }, { "input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa", "output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc" }, { "input": "1\naaa", "output": "aaa" }, { "input": "1\naabaab", "output": "aaaabb" }, { "input": "2\naabbbbccccccdddddddd", "output": "abbcccddddabbcccdddd" }, { "input": "3\naaaaaaaaacccdddddd", "output": "aaacddaaacddaaacdd" }, { "input": "3\naaaaaaaaacccbbbbbb", "output": "aaabbcaaabbcaaabbc" }, { "input": "2\naazzzz", "output": "azzazz" }, { "input": "2\naaaa", "output": "aaaa" }, { "input": "2\naaaazz", "output": "aazaaz" }, { "input": "2\naaaabb", "output": "aabaab" }, { "input": "2\naabbbb", "output": "abbabb" }, { "input": "2\naaaazzzz", "output": "aazzaazz" }, { "input": "2\naaazz", "output": "-1" }, { "input": "2\nbbbbaa", "output": "abbabb" }, { "input": "2\naaaaaabbbb", "output": "aaabbaaabb" }, { "input": "2\naaaaaazz", "output": "aaazaaaz" }, { "input": "2\naaaabbbb", "output": "aabbaabb" }, { "input": "2\naabaab", "output": "aabaab" }, { "input": "1\naaaaa", "output": "aaaaa" }, { "input": "2\nbbaaaa", "output": "aabaab" }, { "input": "2\nacaccc", "output": "accacc" } ]
1,693,933,938
2,147,483,647
Python 3
OK
TESTS
42
92
0
alphabet=[0]*27 # print(alphabet) a=int(input()) c=input() # print(a) d=False seta=set() setalfabet=set() for i in range(len(c)): b=int(ord(c[i])-ord('a')) alphabet[b]+=1 setalfabet.add(c[i]) value=0 lista=[] for i in range(27): if alphabet[i]%a!=0: d=True break if(alphabet[i]!=0): alphabet[i]=int(alphabet[i]/a) # Convert the set to a string without commas and brackets set_string =''.join(map(str,setalfabet)) # print(set_string) setlist = list(seta) # print(setlist) if d : print(-1) else: stringa="" for i in setalfabet: for j in range(alphabet[int(ord(i)-ord('a'))]): stringa+=i mainstring="" for i in range(a): mainstring+=stringa print(mainstring)
Title: k-String Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. Input Specification: The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. Output Specification: Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes). Demo Input: ['2\naazz\n', '3\nabcabcabz\n'] Demo Output: ['azaz\n', '-1\n'] Note: none
```python alphabet=[0]*27 # print(alphabet) a=int(input()) c=input() # print(a) d=False seta=set() setalfabet=set() for i in range(len(c)): b=int(ord(c[i])-ord('a')) alphabet[b]+=1 setalfabet.add(c[i]) value=0 lista=[] for i in range(27): if alphabet[i]%a!=0: d=True break if(alphabet[i]!=0): alphabet[i]=int(alphabet[i]/a) # Convert the set to a string without commas and brackets set_string =''.join(map(str,setalfabet)) # print(set_string) setlist = list(seta) # print(setlist) if d : print(-1) else: stringa="" for i in setalfabet: for j in range(alphabet[int(ord(i)-ord('a'))]): stringa+=i mainstring="" for i in range(a): mainstring+=stringa print(mainstring) ```
3
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,695,044,303
2,147,483,647
Python 3
OK
TESTS
85
92
0
s=input() a=[] for i in s: if i not in a: a.append(i) if len(a)%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python s=input() a=[] for i in s: if i not in a: a.append(i) if len(a)%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, { "input": "20\n44444444444444444444", "output": "YES" }, { "input": "2\n44", "output": "YES" }, { "input": "10\n4745474547", "output": "NO" }, { "input": "14\n77770004444444", "output": "NO" }, { "input": "10\n4747777744", "output": "YES" }, { "input": "10\n1234567890", "output": "NO" }, { "input": "50\n44444444444444444444444444444444444444444444444444", "output": "YES" }, { "input": "50\n44444444444444444444444444444444444444444444444447", "output": "NO" }, { "input": "50\n74444444444444444444444444444444444444444444444444", "output": "NO" }, { "input": "50\n07777777777777777777777777777777777777777777777770", "output": "NO" }, { "input": "50\n77777777777777777777777777777777777777777777777777", "output": "YES" }, { "input": "50\n44747747774474747747747447777447774747447477444474", "output": "YES" }, { "input": "48\n447474444777444474747747744774447444747474774474", "output": "YES" }, { "input": "32\n74474474777444474444747774474774", "output": "YES" }, { "input": "40\n4747777444447747777447447747447474774777", "output": "YES" }, { "input": "10\n4477477444", "output": "YES" }, { "input": "18\n447747474447744747", "output": "YES" }, { "input": "26\n44747744444774744774474447", "output": "YES" }, { "input": "50\n44707747774474747747747447777447774747447477444474", "output": "NO" }, { "input": "40\n4747777444447737777447447747447474774777", "output": "NO" }, { "input": "36\n764477744747444444447747747474744444", "output": "NO" }, { "input": "22\n4477407474777477744447", "output": "NO" }, { "input": "32\n74274474777444474444747774474774", "output": "NO" }, { "input": "16\n4744447974444747", "output": "NO" }, { "input": "2\n11", "output": "NO" }, { "input": "2\n22", "output": "NO" }, { "input": "2\n33", "output": "NO" }, { "input": "2\n74", "output": "NO" }, { "input": "2\n55", "output": "NO" }, { "input": "2\n66", "output": "NO" }, { "input": "2\n77", "output": "YES" }, { "input": "2\n88", "output": "NO" }, { "input": "2\n99", "output": "NO" }, { "input": "4\n4004", "output": "NO" }, { "input": "14\n00077774444444", "output": "NO" }, { "input": "6\n004444", "output": "NO" }, { "input": "4\n0044", "output": "NO" }, { "input": "14\n77771114444444", "output": "NO" }, { "input": "14\n44444447777000", "output": "NO" }, { "input": "6\n004774", "output": "NO" } ]
1,591,878,055
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
11
404
2,048,000
# cook your dish here l = int(input()) n = int(input()) val = n count = 0 a = [] while n>0: x = n%10 if x==4 or x==7: a.append(x) n = n //10 else: count = count + 1 n = n//10 s = sum(a) sa = 0 for i in range(l//2): sa = sa + a[i] if sa==(s//2) and count==0: print("YES") else: print("NO")
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. Input Specification: The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. Output Specification: On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['2\n47\n', '4\n4738\n', '4\n4774\n'] Demo Output: ['NO\n', 'NO\n', 'YES\n'] Note: In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
```python # cook your dish here l = int(input()) n = int(input()) val = n count = 0 a = [] while n>0: x = n%10 if x==4 or x==7: a.append(x) n = n //10 else: count = count + 1 n = n//10 s = sum(a) sa = 0 for i in range(l//2): sa = sa + a[i] if sa==(s//2) and count==0: print("YES") else: print("NO") ```
-1
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 21 73839", "output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99991 623 36438", "output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99999 334 94854", "output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99252 9827 84849", "output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99313 9833 10561", "output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "94885 55815 11417", "output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99492 58525 53481", "output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99858 28531 79193", "output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "99136 47208 42607", "output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "63270 19953 5555", "output": "-1" }, { "input": "10240 128 100000", "output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "12 11 3", "output": "12100" }, { "input": "14 12 99998", "output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "1 11 3", "output": "1100" }, { "input": "3 40 1", "output": "-1" }, { "input": "150 100 10", "output": "1500000000000" }, { "input": "5 10 1", "output": "50" }, { "input": "1 15 10", "output": "15000000000" }, { "input": "3 13 2", "output": "390" } ]
1,589,646,579
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
29,081,600
def check(a, b): for i in range(10): if int(str(a) + str(i)) % b == 0: return int(str(a) + str(i)) return -1 a, b, n = [int(x) for x in input().split()] def q(a, b, n): for _ in range(n): z = check(a, b) if z != -1: a = z else: return -1 return a print(q(a, b, n))
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. Input Specification: The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). Output Specification: In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. Demo Input: ['5 4 5\n', '12 11 1\n', '260 150 10\n'] Demo Output: ['524848\n', '121\n', '-1\n'] Note: none
```python def check(a, b): for i in range(10): if int(str(a) + str(i)) % b == 0: return int(str(a) + str(i)) return -1 a, b, n = [int(x) for x in input().split()] def q(a, b, n): for _ in range(n): z = check(a, b) if z != -1: a = z else: return -1 return a print(q(a, b, n)) ```
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,597,008,183
2,147,483,647
PyPy 3
OK
TESTS
40
312
20,172,800
from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x], x) for x in range(n*2)]) group = {} for x,ind in a: if x in group: group[x].append(ind) else: group[x] = [ind] g2 = [] for x in group: g2.append([len(group[x]), group[x]]) g2.sort() left = 0 right = 0 board = [0 for x in range(n*2)] ind = 0 for x,l in g2: if x == 1: ind += 1 if left <= right: left += 1 board[l[0]] = '1' else: right += 1 board[l[0]] = '2' else: break if right > left: turn = True else: turn = False for x,l in g2[ind:]: left += 1 right += 1 if x%2 == 1: last = l.pop() if turn: board[last] = '1' else: board[last] = '2' turn = not turn for n in l[::2]: board[n] = '1' for n in l[1::2]: board[n] = '2' print(left*right) print(' '.join(board))
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 from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x], x) for x in range(n*2)]) group = {} for x,ind in a: if x in group: group[x].append(ind) else: group[x] = [ind] g2 = [] for x in group: g2.append([len(group[x]), group[x]]) g2.sort() left = 0 right = 0 board = [0 for x in range(n*2)] ind = 0 for x,l in g2: if x == 1: ind += 1 if left <= right: left += 1 board[l[0]] = '1' else: right += 1 board[l[0]] = '2' else: break if right > left: turn = True else: turn = False for x,l in g2[ind:]: left += 1 right += 1 if x%2 == 1: last = l.pop() if turn: board[last] = '1' else: board[last] = '2' turn = not turn for n in l[::2]: board[n] = '1' for n in l[1::2]: board[n] = '2' print(left*right) print(' '.join(board)) ```
3
7
A
Kalevitch and Chess
PROGRAMMING
1,100
[ "brute force", "constructive algorithms" ]
A. Kalevitch and Chess
2
64
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
[ "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n" ]
[ "3\n", "1\n" ]
none
0
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1" }, { "input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "0" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW", "output": "14" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "14" }, { "input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW", "output": "9" }, { "input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB", "output": "9" }, { "input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB", "output": "8" }, { "input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB", "output": "7" }, { "input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW", "output": "9" }, { "input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "11" }, { "input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB", "output": "10" }, { "input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW", "output": "6" }, { "input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB", "output": "9" }, { "input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB", "output": "8" }, { "input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW", "output": "6" }, { "input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB", "output": "11" }, { "input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW", "output": "9" }, { "input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB", "output": "12" }, { "input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB", "output": "7" }, { "input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB", "output": "6" }, { "input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB", "output": "7" } ]
1,645,028,254
2,147,483,647
Python 3
OK
TESTS
30
92
0
#**************************************** #** Solution by BAZOOKA ** #** Sponsored by RED BULL** #** Team Galaxy ** #** I love ❤Kateryna Gret❤ ** #****************************************/ t = [input().count('B') for i in range(8)] print(t.count(8) + min(t)%8) #**************************************** #** Solution by BAZOOKA ** #** Sponsored by RED BULL** #** Team Galaxy ** #** I love ❤Kateryna Gret❤ ** #****************************************/
Title: Kalevitch and Chess Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. Input Specification: The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). Output Specification: Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. Demo Input: ['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n'] Demo Output: ['3\n', '1\n'] Note: none
```python #**************************************** #** Solution by BAZOOKA ** #** Sponsored by RED BULL** #** Team Galaxy ** #** I love ❤Kateryna Gret❤ ** #****************************************/ t = [input().count('B') for i in range(8)] print(t.count(8) + min(t)%8) #**************************************** #** Solution by BAZOOKA ** #** Sponsored by RED BULL** #** Team Galaxy ** #** I love ❤Kateryna Gret❤ ** #****************************************/ ```
3.977
771
A
Bear and Friendship Condition
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
250
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { "input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8", "output": "YES" }, { "input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11", "output": "NO" }, { "input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69", "output": "NO" }, { "input": "3 1\n1 2", "output": "YES" }, { "input": "3 2\n3 2\n1 3", "output": "NO" }, { "input": "3 3\n2 3\n1 2\n1 3", "output": "YES" }, { "input": "4 2\n4 1\n2 1", "output": "NO" }, { "input": "4 3\n3 1\n2 1\n3 2", "output": "YES" }, { "input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2", "output": "NO" }, { "input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6", "output": "NO" }, { "input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8", "output": "NO" }, { "input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3", "output": "NO" }, { "input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762", "output": "YES" }, { "input": "150000 0", "output": "YES" }, { "input": "4 4\n1 2\n2 3\n3 4\n1 4", "output": "NO" }, { "input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7", "output": "NO" }, { "input": "5 4\n1 2\n2 5\n3 4\n4 5", "output": "NO" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "NO" }, { "input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3", "output": "NO" }, { "input": "3 2\n1 2\n1 3", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n2 4\n3 4", "output": "NO" }, { "input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n3 4", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n2 4", "output": "NO" }, { "input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1", "output": "NO" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "NO" }, { "input": "150000 3\n150000 149999\n149998 149999\n149998 150000", "output": "YES" }, { "input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10", "output": "NO" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "output": "NO" }, { "input": "5 4\n1 2\n1 3\n1 4\n1 5", "output": "NO" }, { "input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4", "output": "NO" }, { "input": "4 4\n1 2\n1 3\n4 2\n4 3", "output": "NO" }, { "input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4", "output": "NO" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "output": "NO" }, { "input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6", "output": "NO" }, { "input": "1000 4\n100 132\n100 164\n196 132\n196 164", "output": "NO" } ]
1,619,366,422
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
8,499,200
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members n,m=map(int,input().split()) g=[[] for i in range(n)] uf=UnionFind(n) for _ in range(m): u,v=map(int,input().split()) g[u-1].append(v-1) g[v-1].append(u-1) uf.union(u-1,v-1) for r in uf.roots(): s=uf.size(r) for i in uf.members(r): if len(g[i])!=s-1: print("NO") exit() print("YES")
Title: Bear and Friendship Condition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. Input Specification: The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. Output Specification: If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). Demo Input: ['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n'] Note: The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
```python from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members n,m=map(int,input().split()) g=[[] for i in range(n)] uf=UnionFind(n) for _ in range(m): u,v=map(int,input().split()) g[u-1].append(v-1) g[v-1].append(u-1) uf.union(u-1,v-1) for r in uf.roots(): s=uf.size(r) for i in uf.members(r): if len(g[i])!=s-1: print("NO") exit() print("YES") ```
0
535
C
Tavas and Karafs
PROGRAMMING
1,900
[ "binary search", "greedy", "math" ]
null
null
Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=×<=*B*. For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero. Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=≤<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*.
The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105). Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query.
For each query, print its answer in a single line.
[ "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n", "1 5 2\n1 5 10\n2 7 4\n" ]
[ "4\n-1\n8\n-1\n", "1\n2\n" ]
none
1,500
[ { "input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8", "output": "4\n-1\n8\n-1" }, { "input": "1 5 2\n1 5 10\n2 7 4", "output": "1\n2" }, { "input": "1 1 4\n1 1000000 1000000\n1 1 1000000\n1 1000000 1\n1 1 1", "output": "1000000\n1\n1413\n1" }, { "input": "1000000 1000000 1\n1000000 1000000 1000000", "output": "-1" }, { "input": "999999 1000000 1\n1 1000000 1000000", "output": "1" }, { "input": "1 1000000 1\n1 1000000 1000000", "output": "1" }, { "input": "1 5000 1\n1 1000000 1000000", "output": "200" }, { "input": "1 1 1\n1 1000000 1000000", "output": "1000000" }, { "input": "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 777\n7 477777 444444", "output": "-1\n-1\n-1\n7" } ]
1,689,415,386
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689415386.8781166")# 1689415386.8781364
Title: Tavas and Karafs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karafs is some kind of vegetable in shape of an 1<=×<=*h* rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the *i*-th Karafs is *s**i*<==<=*A*<=+<=(*i*<=-<=1)<=×<=*B*. For a given *m*, let's define an *m*-bite operation as decreasing the height of at most *m* distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero. Now SaDDas asks you *n* queries. In each query he gives you numbers *l*, *t* and *m* and you should find the largest number *r* such that *l*<=≤<=*r* and sequence *s**l*,<=*s**l*<=+<=1,<=...,<=*s**r* can be eaten by performing *m*-bite no more than *t* times or print -1 if there is no such number *r*. Input Specification: The first line of input contains three integers *A*, *B* and *n* (1<=≤<=*A*,<=*B*<=≤<=106, 1<=≤<=*n*<=≤<=105). Next *n* lines contain information about queries. *i*-th line contains integers *l*,<=*t*,<=*m* (1<=≤<=*l*,<=*t*,<=*m*<=≤<=106) for *i*-th query. Output Specification: For each query, print its answer in a single line. Demo Input: ['2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n', '1 5 2\n1 5 10\n2 7 4\n'] Demo Output: ['4\n-1\n8\n-1\n', '1\n2\n'] Note: none
```python print("_RANDOM_GUESS_1689415386.8781166")# 1689415386.8781364 ```
0
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,617,823,584
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
import math a, b, n = map(int,input().split()) x = a while n >= 0: n -= math.gcd(x, n) if x == a: x = b else: x = a print(x)
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 import math a, b, n = map(int,input().split()) x = a while n >= 0: n -= math.gcd(x, n) if x == a: x = b else: x = a print(x) ```
0
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "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 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
1,693,920,622
2,147,483,647
Python 3
OK
TESTS
31
92
0
x = int(input()) y = (input()) z = y.split(' ') s = 0 for j in z: s += int(j) # for i in y: # s += int(i) print (s/x)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. Output Specification: Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. Demo Input: ['3\n50 50 100\n', '4\n0 25 50 75\n'] Demo Output: ['66.666666666667\n', '37.500000000000\n'] Note: Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
```python x = int(input()) y = (input()) z = y.split(' ') s = 0 for j in z: s += int(j) # for i in y: # s += int(i) print (s/x) ```
3
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,697,775,651
2,147,483,647
Python 3
OK
TESTS
25
46
204,800
n=int(input()) a=d=0 s=input() for i in range(n): if s[i]=='A': a+=1 else: d+=1 if a==d: print('Friendship') elif a>d: print('Anton') else: print('Danik')
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python n=int(input()) a=d=0 s=input() for i in range(n): if s[i]=='A': a+=1 else: d+=1 if a==d: print('Friendship') elif a>d: print('Anton') else: print('Danik') ```
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,481,601,417
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
12
122
0
n = int(input()) given = [int(i) for i in input().split()] given = [k%2 for k in given] total = 0 for k in range(1,n-1): if (given[k] != given[k-1]) and (given[k] != given[k+1]): print(k+1) elif (given[0] != given[1]) and (given[0] != given[2]): print(1) elif (given[-1] != given[-2]) and (given[-1] != given[-3]): print(n)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n = int(input()) given = [int(i) for i in input().split()] given = [k%2 for k in given] total = 0 for k in range(1,n-1): if (given[k] != given[k-1]) and (given[k] != given[k+1]): print(k+1) elif (given[0] != given[1]) and (given[0] != given[2]): print(1) elif (given[-1] != given[-2]) and (given[-1] != given[-3]): print(n) ```
0
675
A
Infinite Sequence
PROGRAMMING
1,100
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
500
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
1,496,498,745
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
l=list(map(int,input().split(" "))) a=l[0] b=l[1] c=l[2] d=b-a if d==0 or d%c==0: print("YES") else: print("NO")
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. Input Specification: The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output Specification: If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). Demo Input: ['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
```python l=list(map(int,input().split(" "))) a=l[0] b=l[1] c=l[2] d=b-a if d==0 or d%c==0: print("YES") else: print("NO") ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,678,022,039
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
a="localization" g="internationalization" d="pneumonoultramicroscopicsilicovolcanoconiosis" y=a.replace("ocalizatio","10") #print(y) b=g.replace("nternationalizatio","18") #print(b) c=d.replace("neumonoultramicroscopicsilicovolcanoconiosi","43") #print(c) print("word\n",y,"\n",b,"\n",c)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python a="localization" g="internationalization" d="pneumonoultramicroscopicsilicovolcanoconiosis" y=a.replace("ocalizatio","10") #print(y) b=g.replace("nternationalizatio","18") #print(b) c=d.replace("neumonoultramicroscopicsilicovolcanoconiosi","43") #print(c) print("word\n",y,"\n",b,"\n",c) ```
0
265
B
Roadside Trees (Simplified Edition)
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions: - Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=&gt;<=*h**i*<=+<=1. Compute the minimal time (in seconds) required to eat all nuts.
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Print a single integer — the minimal time required to eat all nuts in seconds.
[ "2\n1\n2\n", "5\n2\n1\n2\n1\n1\n" ]
[ "5\n", "14\n" ]
none
1,000
[ { "input": "2\n1\n2", "output": "5" }, { "input": "5\n2\n1\n2\n1\n1", "output": "14" }, { "input": "1\n1", "output": "2" } ]
1,598,219,745
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
248
6,963,200
t = input() n = int(t) treeList = [] time = 0 for i in range(n): s = input() temp = int(s) treeList.append(temp) time = treeList[0] + 1 for i in range(1, n): if treeList[i - 1] > treeList[i]: time = time + 1 + treeList[i] + 1 else: time = time + 1 + (treeList[i] - treeList[i-1]) + 1 print(time)
Title: Roadside Trees (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions: - Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=&gt;<=*h**i*<=+<=1. Compute the minimal time (in seconds) required to eat all nuts. Input Specification: The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. Output Specification: Print a single integer — the minimal time required to eat all nuts in seconds. Demo Input: ['2\n1\n2\n', '5\n2\n1\n2\n1\n1\n'] Demo Output: ['5\n', '14\n'] Note: none
```python t = input() n = int(t) treeList = [] time = 0 for i in range(n): s = input() temp = int(s) treeList.append(temp) time = treeList[0] + 1 for i in range(1, n): if treeList[i - 1] > treeList[i]: time = time + 1 + treeList[i] + 1 else: time = time + 1 + (treeList[i] - treeList[i-1]) + 1 print(time) ```
0
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1000000000 -1000000000\n1000000000 1000000000", "output": "Yes" }, { "input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5", "output": "Yes" }, { "input": "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000", "output": "No" }, { "input": "2\n-1000000000 1000000000\n-1000000000 -1000000000", "output": "Yes" }, { "input": "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2", "output": "No" }, { "input": "2\n1 0\n-1 0", "output": "Yes" }, { "input": "4\n-1 1\n-1 2\n-1 3\n-1 4", "output": "Yes" }, { "input": "2\n-1 0\n1 0", "output": "Yes" }, { "input": "2\n1 2\n-1 2", "output": "Yes" }, { "input": "2\n8 0\n7 0", "output": "Yes" }, { "input": "6\n-1 0\n-2 0\n-1 -1\n-1 5\n1 0\n1 1", "output": "No" }, { "input": "4\n1 0\n2 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-2 0\n-1 0\n1 0\n2 0", "output": "No" }, { "input": "2\n1 1\n-1 1", "output": "Yes" }, { "input": "4\n-1 0\n-2 0\n1 0\n2 0", "output": "No" }, { "input": "2\n4 3\n-4 -2", "output": "Yes" }, { "input": "4\n1 0\n2 0\n-1 1\n-1 2", "output": "No" }, { "input": "5\n1 1\n2 1\n3 1\n-1 1\n-2 1", "output": "No" }, { "input": "2\n1 1\n-1 -1", "output": "Yes" }, { "input": "4\n1 2\n1 0\n1 -2\n-1 2", "output": "Yes" }, { "input": "5\n-2 3\n-3 3\n4 2\n3 2\n1 2", "output": "No" }, { "input": "3\n2 0\n3 0\n4 0", "output": "Yes" }, { "input": "5\n-3 1\n-2 1\n-1 1\n1 1\n2 1", "output": "No" }, { "input": "4\n-3 0\n1 0\n2 0\n3 0", "output": "Yes" }, { "input": "2\n1 0\n-1 1", "output": "Yes" }, { "input": "3\n-1 0\n1 0\n2 0", "output": "Yes" }, { "input": "5\n1 0\n3 0\n-1 0\n-6 0\n-4 1", "output": "No" }, { "input": "5\n-1 2\n-2 2\n-3 1\n1 2\n2 3", "output": "No" }, { "input": "3\n1 0\n-1 0\n-2 0", "output": "Yes" }, { "input": "4\n1 0\n2 0\n3 1\n4 1", "output": "Yes" }, { "input": "4\n1 0\n1 2\n1 3\n-1 5", "output": "Yes" }, { "input": "4\n2 2\n2 5\n-2 3\n-2 0", "output": "No" }, { "input": "4\n1 1\n-1 1\n-1 0\n-1 -1", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-3 -3\n-3 -4", "output": "No" }, { "input": "4\n-1 0\n-2 0\n-3 0\n-4 0", "output": "Yes" }, { "input": "2\n-1 1\n1 1", "output": "Yes" }, { "input": "5\n1 1\n2 2\n3 3\n-4 -4\n-5 -5", "output": "No" }, { "input": "5\n2 0\n3 0\n4 0\n5 0\n6 0", "output": "Yes" }, { "input": "2\n-1 2\n1 2", "output": "Yes" }, { "input": "4\n1 1\n2 1\n-3 0\n-4 0", "output": "No" }, { "input": "4\n-1 0\n-2 0\n3 0\n4 0", "output": "No" }, { "input": "3\n3 0\n2 0\n1 0", "output": "Yes" }, { "input": "4\n-2 0\n-3 0\n1 -1\n3 1", "output": "No" }, { "input": "3\n-1 -1\n1 1\n2 2", "output": "Yes" }, { "input": "4\n-2 0\n-1 0\n2 0\n1 0", "output": "No" }, { "input": "2\n-3 5\n3 5", "output": "Yes" }, { "input": "2\n-1 5\n1 5", "output": "Yes" }, { "input": "4\n2 0\n3 0\n-2 0\n-3 0", "output": "No" }, { "input": "3\n-1 1\n1 1\n1 -1", "output": "Yes" }, { "input": "2\n1 0\n2 0", "output": "Yes" }, { "input": "4\n-1 1\n-2 1\n2 -1\n3 -1", "output": "No" }, { "input": "5\n1 0\n2 0\n3 0\n-1 0\n-2 0", "output": "No" }, { "input": "4\n-3 0\n-4 0\n-5 0\n-6 0", "output": "Yes" }, { "input": "6\n-3 0\n-2 0\n-1 0\n1 0\n2 0\n3 0", "output": "No" }, { "input": "4\n5 0\n5 1\n6 0\n6 1", "output": "Yes" } ]
1,560,308,230
2,147,483,647
Python 3
OK
TESTS
71
311
0
n = int(input()) p , nn = 0 ,0 for i in range(n): x,y = map(int,input().split()) if x > 0: p += 1 else: nn += 1 if p > 1 and nn > 1: print('NO') elif p <= 1 or nn <= 1: print('YES')
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. Output Specification: Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower). Demo Input: ['3\n1 1\n-1 -1\n2 -1\n', '4\n1 1\n2 2\n-1 1\n-2 2\n', '3\n1 2\n2 1\n4 60\n'] Demo Output: ['Yes', 'No', 'Yes'] Note: In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
```python n = int(input()) p , nn = 0 ,0 for i in range(n): x,y = map(int,input().split()) if x > 0: p += 1 else: nn += 1 if p > 1 and nn > 1: print('NO') elif p <= 1 or nn <= 1: print('YES') ```
3
343
C
Read Time
PROGRAMMING
1,900
[ "binary search", "greedy", "two pointers" ]
null
null
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the *i*-th reading head is above the track number *h**i*. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered *h*1, *h*2, ..., *h**n* have been read at the beginning of the operation. Mike needs to read the data on *m* distinct tracks with numbers *p*1, *p*2, ..., *p**m*. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
The first line of the input contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers *h**i* in ascending order (1<=≤<=*h**i*<=≤<=1010, *h**i*<=&lt;<=*h**i*<=+<=1) — the initial positions of the heads. The third line contains *m* distinct integers *p**i* in ascending order (1<=≤<=*p**i*<=≤<=1010, *p**i*<=&lt;<=*p**i*<=+<=1) - the numbers of tracks to read. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
[ "3 4\n2 5 6\n1 3 6 8\n", "3 3\n1 2 3\n1 2 3\n", "1 2\n165\n142 200\n" ]
[ "2\n", "0\n", "81\n" ]
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way: 1. during the first second move the 1-st head to the left and let it stay there; 1. move the second head to the left twice; 1. move the third head to the right twice (note that the 6-th track has already been read at the beginning). One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
1,500
[ { "input": "3 4\n2 5 6\n1 3 6 8", "output": "2" }, { "input": "3 3\n1 2 3\n1 2 3", "output": "0" }, { "input": "1 2\n165\n142 200", "output": "81" }, { "input": "1 2\n5000000000\n1 10000000000", "output": "14999999998" }, { "input": "2 4\n3 12\n1 7 8 14", "output": "8" }, { "input": "3 3\n1 2 3\n2 3 4", "output": "1" }, { "input": "2 1\n1 10\n9", "output": "1" }, { "input": "3 19\n7 10 13\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19", "output": "6" }, { "input": "3 3\n2 3 4\n1 3 5", "output": "1" }, { "input": "10 11\n1 909090909 1818181817 2727272725 3636363633 4545454541 5454545449 6363636357 7272727265 8181818173\n454545455 1363636363 2272727271 3181818179 4090909087 4999999995 5909090903 6818181811 7727272719 8636363627 9545454535", "output": "1363636362" }, { "input": "3 10\n4999999999 5000000000 5000000001\n1 1000 100000 1000000 4999999999 5000000000 5000000001 6000000000 8000000000 10000000000", "output": "4999999999" }, { "input": "2 4\n4500000000 5500000000\n5 499999999 5000000001 9999999995", "output": "5499999993" }, { "input": "10 10\n331462447 1369967506 1504296131 2061390288 2309640071 3006707770 4530801731 4544099460 7357049371 9704808257\n754193799 3820869903 4594383880 5685752675 6303322854 6384906441 7863448848 8542634752 9573124462 9665646063", "output": "1840806981" }, { "input": "1 1\n10000000000\n1", "output": "9999999999" }, { "input": "1 1\n1\n10000000000", "output": "9999999999" }, { "input": "10 10\n9999999991 9999999992 9999999993 9999999994 9999999995 9999999996 9999999997 9999999998 9999999999 10000000000\n1 2 3 4 5 6 7 8 9 10", "output": "9999999990" }, { "input": "3 12\n477702277 4717363935 8947981095\n477702276 477702304 477702312 477702317 4717363895 4717363896 4717363920 4717363936 8947981094 8947981111 8947981112 8947981135", "output": "42" }, { "input": "10 10\n389151626 1885767612 2609703695 3054567325 4421751790 5636236054 6336088034 7961001379 8631992167 9836923433\n389144165 389158510 1885760728 1885775073 2609696234 2609710579 3054559864 3054574209 4421744329 4421758674", "output": "21229" }, { "input": "1 1\n10000000000\n1", "output": "9999999999" } ]
1,668,674,701
2,147,483,647
PyPy 3-64
OK
TESTS
61
233
20,172,800
# Read Time import sys input = sys.stdin.buffer.readline n, m = map(int, input().split()) h = list(map(int, input().split())) p = list(map(int, input().split())) # minimmum time for h_i to cover all p_s...p_e def min_t(h_i, p_s, p_e): return min(abs(h[h_i]-p[p_s]),abs(h[h_i]-p[p_e])) + (p[p_e]-p[p_s]) # if all the heads can read all the tracks in <= mx_t time # we use greedy :) def check(mx_t): h_i = 0 p_i = 0 while p_i < m and h_i < n: p_j = p_i while p_j+1 < m and min_t(h_i, p_i, p_j+1) <= mx_t: p_j += 1 if min_t(h_i, p_i, p_j) <= mx_t: p_i = p_j+1 h_i += 1 return p_i == m l = 0 r = 10**11 while l != r: mt = (l+r)//2 if check(mt): r = mt else: l = mt+1 print(l)
Title: Read Time Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the *i*-th reading head is above the track number *h**i*. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered *h*1, *h*2, ..., *h**n* have been read at the beginning of the operation. Mike needs to read the data on *m* distinct tracks with numbers *p*1, *p*2, ..., *p**m*. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read. Input Specification: The first line of the input contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers *h**i* in ascending order (1<=≤<=*h**i*<=≤<=1010, *h**i*<=&lt;<=*h**i*<=+<=1) — the initial positions of the heads. The third line contains *m* distinct integers *p**i* in ascending order (1<=≤<=*p**i*<=≤<=1010, *p**i*<=&lt;<=*p**i*<=+<=1) - the numbers of tracks to read. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. Output Specification: Print a single number — the minimum time required, in seconds, to read all the needed tracks. Demo Input: ['3 4\n2 5 6\n1 3 6 8\n', '3 3\n1 2 3\n1 2 3\n', '1 2\n165\n142 200\n'] Demo Output: ['2\n', '0\n', '81\n'] Note: The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way: 1. during the first second move the 1-st head to the left and let it stay there; 1. move the second head to the left twice; 1. move the third head to the right twice (note that the 6-th track has already been read at the beginning). One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
```python # Read Time import sys input = sys.stdin.buffer.readline n, m = map(int, input().split()) h = list(map(int, input().split())) p = list(map(int, input().split())) # minimmum time for h_i to cover all p_s...p_e def min_t(h_i, p_s, p_e): return min(abs(h[h_i]-p[p_s]),abs(h[h_i]-p[p_e])) + (p[p_e]-p[p_s]) # if all the heads can read all the tracks in <= mx_t time # we use greedy :) def check(mx_t): h_i = 0 p_i = 0 while p_i < m and h_i < n: p_j = p_i while p_j+1 < m and min_t(h_i, p_i, p_j+1) <= mx_t: p_j += 1 if min_t(h_i, p_i, p_j) <= mx_t: p_i = p_j+1 h_i += 1 return p_i == m l = 0 r = 10**11 while l != r: mt = (l+r)//2 if check(mt): r = mt else: l = mt+1 print(l) ```
3
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }, { "input": "4\n5 4 5 4", "output": "-1" }, { "input": "7\n3 4 5 5 5 1 2", "output": "2" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "5\n5 4 1 2 3", "output": "-1" }, { "input": "4\n6 1 2 7", "output": "-1" }, { "input": "5\n4 5 6 2 3", "output": "2" }, { "input": "2\n1 1", "output": "0" }, { "input": "4\n1 2 2 1", "output": "1" }, { "input": "9\n4 5 6 7 1 2 3 4 10", "output": "-1" }, { "input": "7\n2 3 4 1 2 3 4", "output": "-1" }, { "input": "6\n1 2 1 2 1 2", "output": "-1" }, { "input": "3\n3 2 1", "output": "-1" }, { "input": "4\n1 4 4 1", "output": "1" }, { "input": "5\n1 2 1 1 1", "output": "3" }, { "input": "5\n4 6 7 3 5", "output": "-1" }, { "input": "4\n2 3 1 4", "output": "-1" }, { "input": "5\n5 4 3 2 1", "output": "-1" }, { "input": "4\n2 4 1 4", "output": "-1" }, { "input": "6\n4 5 6 1 2 7", "output": "-1" }, { "input": "6\n1 2 3 1 1 1", "output": "3" }, { "input": "5\n1 3 3 3 1", "output": "1" }, { "input": "6\n5 6 7 5 5 5", "output": "3" }, { "input": "5\n3 4 2 1 2", "output": "-1" }, { "input": "3\n3 4 2", "output": "1" }, { "input": "6\n1 1 2 2 1 1", "output": "2" }, { "input": "4\n2 3 4 2", "output": "1" }, { "input": "5\n3 5 7 7 3", "output": "1" }, { "input": "4\n1 1 4 1", "output": "1" }, { "input": "7\n1 5 6 1 1 1 1", "output": "4" }, { "input": "5\n7 8 6 7 8", "output": "-1" }, { "input": "4\n2 4 1 3", "output": "-1" } ]
1,624,363,083
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) l=list(map(int,input().split())) z=l.index(max(l)) l1=l[:z+1] x=l.index(min(l)) l2=l[x:] if l==sorted(l): print(0) elif l1==sorted(l) and l2==sorted(l): if min(l1)>=max(l2): print(len(l2)) else: print(-1) elif l2==l: if l[-1]=l[0] print(1) else: print(-1)
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. Demo Input: ['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n'] Demo Output: ['1\n', '-1\n', '0\n'] Note: none
```python n=int(input()) l=list(map(int,input().split())) z=l.index(max(l)) l1=l[:z+1] x=l.index(min(l)) l2=l[x:] if l==sorted(l): print(0) elif l1==sorted(l) and l2==sorted(l): if min(l1)>=max(l2): print(len(l2)) else: print(-1) elif l2==l: if l[-1]=l[0] print(1) else: print(-1) ```
-1
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "100000", "output": "50000\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "7", "output": "3\n2 2 3" }, { "input": "4", "output": "2\n2 2" }, { "input": "8", "output": "4\n2 2 2 2" }, { "input": "9", "output": "4\n2 2 2 3" }, { "input": "99995", "output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "99996", "output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "10", "output": "5\n2 2 2 2 2" }, { "input": "11", "output": "5\n2 2 2 2 3" }, { "input": "99997", "output": "49998\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "99998", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "12", "output": "6\n2 2 2 2 2 2" }, { "input": "13", "output": "6\n2 2 2 2 2 3" }, { "input": "99993", "output": "49996\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "99994", "output": "49997\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "14", "output": "7\n2 2 2 2 2 2 2" }, { "input": "15", "output": "7\n2 2 2 2 2 2 3" }, { "input": "53", "output": "26\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 3" }, { "input": "57", "output": "28\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3" }, { "input": "61", "output": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3" }, { "input": "774", "output": "387\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "202", "output": "101\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2" }, { "input": "530", "output": "265\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "7166", "output": "3583\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "9294", "output": "4647\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "2422", "output": "1211\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "15326", "output": "7663\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "11454", "output": "5727\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "14878", "output": "7439\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2..." }, { "input": "90672", "output": "45336\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "99544", "output": "49772\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "90472", "output": "45236\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..." }, { "input": "23", "output": "11\n2 2 2 2 2 2 2 2 2 2 3" }, { "input": "93", "output": "46\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3" }, { "input": "19", "output": "9\n2 2 2 2 2 2 2 2 3" }, { "input": "11110", "output": "5555\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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,628,254,013
2,147,483,647
Python 3
OK
TESTS
41
109
7,475,200
n=int(input()) if n%2==0: k=[2]*(n//2) print(n//2) print(*k) else: k=[2]*(n//2) k[len(k)-1]=3 print(n//2) print(*k)
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. Input Specification: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). Output Specification: The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. Demo Input: ['5\n', '6\n'] Demo Output: ['2\n2 3\n', '3\n2 2 2\n'] Note: none
```python n=int(input()) if n%2==0: k=[2]*(n//2) print(n//2) print(*k) else: k=[2]*(n//2) k[len(k)-1]=3 print(n//2) print(*k) ```
3
678
D
Iterated Linear Function
PROGRAMMING
1,700
[ "math", "number theory" ]
null
null
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7.
The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement. Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7.
[ "3 4 1 1\n", "3 4 2 1\n", "3 4 3 1\n" ]
[ "7\n", "25\n", "79\n" ]
none
0
[ { "input": "3 4 1 1", "output": "7" }, { "input": "3 4 2 1", "output": "25" }, { "input": "3 4 3 1", "output": "79" }, { "input": "1 1 1 1", "output": "2" }, { "input": "3 10 723 6", "output": "443623217" }, { "input": "14 81 51 82", "output": "908370438" }, { "input": "826504481 101791432 76 486624528", "output": "621999403" }, { "input": "475965351 844435993 96338 972382431", "output": "83709654" }, { "input": "528774798 650132512 6406119 36569714", "output": "505858307" }, { "input": "632656975 851906850 1 310973933", "output": "230360736" }, { "input": "1 1 352875518515340737 1", "output": "45212126" }, { "input": "978837295 606974665 846646545585165081 745145208", "output": "154788991" }, { "input": "277677243 142088706 8846851 253942280", "output": "221036825" }, { "input": "1 192783664 1000000000000000000 596438713", "output": "42838179" }, { "input": "1 1000000000 1000000000000000000 1", "output": "999999665" }, { "input": "1 1000000000 1000000000000000000 1000000000", "output": "999999657" }, { "input": "1 100000000 10000000000000 1000000000", "output": "48993" }, { "input": "1 1171281 1000000000000000000 100", "output": "57392869" }, { "input": "1 1000000000 100000000000000000 1000000000", "output": "899999965" }, { "input": "1 100000000 100000000000000000 10000", "output": "490010000" }, { "input": "1 100000456 10000000000000000 54165", "output": "129054389" }, { "input": "1 1000000000 10000000000000 1", "output": "490001" }, { "input": "1 100000000 10000000000000000 10000", "output": "49010000" }, { "input": "1 1000000000 10000000000 12", "output": "502" }, { "input": "1 999999999 999999999999999999 12345678", "output": "12345294" }, { "input": "1 1000000 1000000000000000000 100000", "output": "49100000" }, { "input": "1 1000000000 1000000000000 12", "output": "49012" }, { "input": "1 10000 1000000000000000000 5", "output": "490005" }, { "input": "1 10000 1000000000000000000 10000", "output": "500000" }, { "input": "1 1000000000 10000000000000 12", "output": "490012" }, { "input": "1 1000000000 1000000000000000 12", "output": "49000012" }, { "input": "1 1000000000 1000000000000000000 12", "output": "999999676" }, { "input": "1 10000000 100000000000000000 100000", "output": "49100000" }, { "input": "114514 114514 114514 114514", "output": "623380685" }, { "input": "2 1 1000000006 1", "output": "1" }, { "input": "1 1234 10 9", "output": "12349" } ]
1,590,082,179
2,147,483,647
PyPy 3
OK
TESTS
36
140
0
import sys,math def power(x, y, p): res = 1; x = x % p; while (y > 0): if (y & 1): res = (res * x) % p; y = y >> 1; x = (x * x) % p; return res; def modInverse(b,m): g = math.gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def modDivide(a,b,m): a = a % m inv = modInverse(b,m) if(inv == -1): print("Division not defined") else: return (inv*a) % m #using sum of GP series A,B,n,X=map(int,sys.stdin.readline().split()) m=10**9+7 if A==1: print(((n%m)*B+X)%m) else: temp=power(A,n,m) s=(temp*(X%m))%m s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m print(s%m)
Title: Iterated Linear Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. Input Specification: The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement. Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Specification: Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7. Demo Input: ['3 4 1 1\n', '3 4 2 1\n', '3 4 3 1\n'] Demo Output: ['7\n', '25\n', '79\n'] Note: none
```python import sys,math def power(x, y, p): res = 1; x = x % p; while (y > 0): if (y & 1): res = (res * x) % p; y = y >> 1; x = (x * x) % p; return res; def modInverse(b,m): g = math.gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def modDivide(a,b,m): a = a % m inv = modInverse(b,m) if(inv == -1): print("Division not defined") else: return (inv*a) % m #using sum of GP series A,B,n,X=map(int,sys.stdin.readline().split()) m=10**9+7 if A==1: print(((n%m)*B+X)%m) else: temp=power(A,n,m) s=(temp*(X%m))%m s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m print(s%m) ```
3
424
A
Squats
PROGRAMMING
900
[ "implementation" ]
null
null
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
[ "4\nxxXx\n", "2\nXX\n", "6\nxXXxXx\n" ]
[ "1\nXxXx\n", "1\nxX\n", "0\nxXXxXx\n" ]
none
500
[ { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "2\nXX", "output": "1\nxX" }, { "input": "6\nxXXxXx", "output": "0\nxXXxXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "22\nXXxXXxxXxXxXXXXXXXXXxx", "output": "4\nxxxxxxxXxXxXXXXXXXXXxx" }, { "input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx", "output": "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx" }, { "input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX", "output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX" }, { "input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX", "output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX" }, { "input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX", "output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX" }, { "input": "198\nxXxxXxxXxxXXxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx", "output": "5\nxxxxxxxxxxxxxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx" }, { "input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, { "input": "200\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "198\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "output": "99\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, { "input": "2\nxx", "output": "1\nXx" }, { "input": "2\nXx", "output": "0\nXx" }, { "input": "2\nxX", "output": "0\nxX" }, { "input": "4\nXXXX", "output": "2\nxxXX" }, { "input": "4\nxxxx", "output": "2\nXXxx" }, { "input": "4\nxxXX", "output": "0\nxxXX" }, { "input": "4\nXXxx", "output": "0\nXXxx" }, { "input": "4\nxXxx", "output": "1\nXXxx" }, { "input": "4\nXxxx", "output": "1\nXXxx" }, { "input": "4\nxxxX", "output": "1\nXxxX" }, { "input": "4\nxxXx", "output": "1\nXxXx" }, { "input": "4\nXXXx", "output": "1\nxXXx" }, { "input": "4\nxXXX", "output": "1\nxxXX" }, { "input": "4\nXxXX", "output": "1\nxxXX" }, { "input": "4\nXXxX", "output": "1\nxXxX" }, { "input": "4\nXxXx", "output": "0\nXxXx" }, { "input": "6\nxXXxXX", "output": "1\nxxXxXX" } ]
1,421,146,541
2,147,483,647
Python 3
OK
TESTS
32
46
0
def main(): input() s = input() ta = t = (s.count('x') - s.count('X')) // 2 res = [] if t > 0: for c in s: if t and c == 'x': c = 'X' t -= 1 res.append(c) else: for c in s: if t and c == 'X': c = 'x' t += 1 res.append(c) print(abs(ta)) print(''.join(res)) if __name__ == '__main__': main()
Title: Squats Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. Output Specification: In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Demo Input: ['4\nxxXx\n', '2\nXX\n', '6\nxXXxXx\n'] Demo Output: ['1\nXxXx\n', '1\nxX\n', '0\nxXXxXx\n'] Note: none
```python def main(): input() s = input() ta = t = (s.count('x') - s.count('X')) // 2 res = [] if t > 0: for c in s: if t and c == 'x': c = 'X' t -= 1 res.append(c) else: for c in s: if t and c == 'X': c = 'x' t += 1 res.append(c) print(abs(ta)) print(''.join(res)) if __name__ == '__main__': main() ```
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,688,881,865
2,147,483,647
Python 3
OK
TESTS
35
46
0
n,k=map(int,input().split()) l=list(map(int,input().split())) c=0 for i in range(len(l)): a=5-l[i] if a>=k: c+=1 print(c//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n,k=map(int,input().split()) l=list(map(int,input().split())) c=0 for i in range(len(l)): a=5-l[i] if a>=k: c+=1 print(c//3) ```
3
265
B
Roadside Trees (Simplified Edition)
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions: - Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=&gt;<=*h**i*<=+<=1. Compute the minimal time (in seconds) required to eat all nuts.
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Print a single integer — the minimal time required to eat all nuts in seconds.
[ "2\n1\n2\n", "5\n2\n1\n2\n1\n1\n" ]
[ "5\n", "14\n" ]
none
1,000
[ { "input": "2\n1\n2", "output": "5" }, { "input": "5\n2\n1\n2\n1\n1", "output": "14" }, { "input": "1\n1", "output": "2" } ]
1,605,195,598
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
n = int(input()) s = list(map(int,input().rsplit())) a=n+sum(s) for i in range (n-1): if s[i]>s[i-1]: a=a+(s[i]-s[i-1]) print(a)
Title: Roadside Trees (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions: - Walk up or down one unit on a tree. - Eat a nut on the top of the current tree. - Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height *h* of the tree *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), she jumps to height *h* of the tree *i*<=+<=1. This action can't be performed if *h*<=&gt;<=*h**i*<=+<=1. Compute the minimal time (in seconds) required to eat all nuts. Input Specification: The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. Output Specification: Print a single integer — the minimal time required to eat all nuts in seconds. Demo Input: ['2\n1\n2\n', '5\n2\n1\n2\n1\n1\n'] Demo Output: ['5\n', '14\n'] Note: none
```python n = int(input()) s = list(map(int,input().rsplit())) a=n+sum(s) for i in range (n-1): if s[i]>s[i-1]: a=a+(s[i]-s[i-1]) print(a) ```
0
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "output": "NO" }, { "input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555", "output": "NO" }, { "input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333", "output": "NO" }, { "input": "5 5\n88888\n44444\n66666\n55555\n88888", "output": "YES" }, { "input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222", "output": "YES" }, { "input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888", "output": "YES" }, { "input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111", "output": "NO" }, { "input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0", "output": "YES" } ]
1,558,991,338
2,147,483,647
Python 3
OK
TESTS
35
248
0
i = input().split(" ") n = int(i[0]) m = int(i[1]) flag = [input() for x in range(n)] previous = "" result = True for row in flag: if not row == row[0]*m: result = False if row == previous: result = False previous = row if result: print("YES") else: print("NO")
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. Input Specification: The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output Specification: Output YES, if the flag meets the new ISO standard, and NO otherwise. Demo Input: ['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python i = input().split(" ") n = int(i[0]) m = int(i[1]) flag = [input() for x in range(n)] previous = "" result = True for row in flag: if not row == row[0]*m: result = False if row == previous: result = False previous = row if result: print("YES") else: print("NO") ```
3.938
67
A
Partial Teacher
PROGRAMMING
1,800
[ "dp", "graphs", "greedy", "implementation" ]
A. Partial Teacher
1
256
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one. It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
[ "5\nLRLR\n", "5\n=RRR\n" ]
[ "2 1 2 1 2\n", "1 1 2 3 4\n" ]
none
500
[ { "input": "5\nLRLR", "output": "2 1 2 1 2" }, { "input": "5\n=RRR", "output": "1 1 2 3 4" }, { "input": "6\nRLRL=", "output": "1 2 1 2 1 1" }, { "input": "3\nR=", "output": "1 2 2" }, { "input": "7\nRR==RR", "output": "1 2 3 3 3 4 5" }, { "input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==", "output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2 2 1 2 1 2 3 3 3" }, { "input": "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L=R=RLRR==LRRL=LRL=RLRLRR=R=LR=LLR===LRL=RRL====R==LRLR===LLLLL=LLLRLRLLLLLL==RLL=RL==LR=RRLRLL=R=R=R=RLRLRLLRRL==L==LRR=L=R=R===RLR=R=L=LR=LRLRR=RRL=L=RRLR=RRL=RRRL=RLRRRLLLRR=RRRLRLLLR==RR=RL===R=RL=RLL====RRRR=LR=LL=RL==RRLR====R=L=R==L=R=R=RLR=RR=R=LRRRRLLL", "output": "4 3 2 2 1 2 2 3 3 4 5 6 6 2 2 1 2 3 3 4 1 4 3 2 1 2 2 1 2 1 1 2 3 1 2 3 4 2 1 2 3 2 1 1 1 1 1 5 4 4 3 3 3 3 3 2 1 2 1 1 2 3 3 3 1 1 1 4 3 2 2 2 1 1 2 2 3 1 2 3 3 3 1 2 3 2 2 1 2 1 1 2 1 2 1 2 3 3 4 4 1 3 3 2 1 2 2 2 2 1 2 1 1 2 3 1 1 1 1 1 2 2 2 1 2 1 9 9 9 9 8 7 6 5 4 4 3 2 1 2 1 7 6 5 4 3 2 1 1 1 3 2 1 1 3 2 2 2 1 2 2 3 4 1 3 2 1 1 2 2 3 3 4 4 5 1 2 1 3 2 1 2 4 3 3 3 2 2 2 1 2 3 3 1 1 2 2 3 3 3 3 4 1 2 2 3 3 2 2 1 2 2 1 2 1 2 3 3 4 5 2 2 1 1 2 3 1 2 2 3 4 1 1 2 3 4 1 1 2 1 2 3 4 3 2 1 2 3 3 4 5 6 1 4 3 2..." }, { "input": "24\nR=R==RL=RL=RLL=LLL=LLRL", "output": "1 2 2 3 3 3 4 1 1 2 1 1 8 7 6 6 5 4 3 3 2 1 2 1" }, { "input": "438\nLR=RLLLRL=R==LLR=RRLRRR==RLRLRLLRRRRRLRL=RRRRLRR==RR=RR=LLRR=L=LLRRRLLR==RL=L=LLR=L=R==LLR=L=RR==LRL=LLL=RRR=R=LRLLRLLLR==LRRLLL=L==LLR=RL=LLLLR=RR=LR=RL==LRLRR=RRRRRLRLRR==RR=LLLRLR====LRRLL==LR==LL=LLRR=LRL=RRRRLR=RLLR=R=LLLRRRRR===R==LRLLRLR=LLL=L=L=R=RLLR=R=RR=RL=LLRRLLRR=LRRRR==LR==L==R=L=L=R===LLL=LL==L=L=LLLLL==RRRR==R=RLL=RLR=RRRR=R=L=RRRLLRRLRRRLLRLLRRRL=LR=R=LRLRL=R=RLRRLRRL==R=RRR=RLLR=RR=LL=RLR=R==R===RRLR=LLLR=L===LR=L=R", "output": "2 1 2 2 4 3 2 1 2 1 1 3 3 3 2 1 2 2 3 4 1 2 3 4 4 4 5 1 2 1 3 2 1 2 3 4 5 6 1 2 1 1 2 3 4 5 1 2 3 3 3 4 5 5 6 7 7 2 1 2 4 4 3 3 2 1 2 3 4 2 1 2 2 2 5 4 4 3 3 2 1 2 2 1 1 3 3 3 2 1 2 2 1 1 2 3 3 3 1 5 4 4 3 2 1 1 2 3 4 4 5 5 1 3 2 1 4 3 2 1 2 2 2 1 2 7 6 5 4 4 3 3 3 2 1 2 2 6 5 5 4 3 2 1 2 2 3 4 4 1 2 2 3 2 2 2 1 2 1 2 3 3 4 5 6 7 8 1 2 1 2 3 3 3 4 5 5 3 2 1 2 1 2 2 2 2 2 1 2 4 3 2 2 2 1 5 5 5 4 3 3 2 1 2 3 3 1 2 1 1 2 3 4 5 1 2 2 3 2 1 2 2 4 4 3 2 1 2 3 4 5 6 6 6 6 7 7 7 1 3 2 1 2 1 6 6 5 4 3 3 2 2 1 1 2 2..." }, { "input": "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RRLLR=L==LRR=RRLRLLRR=LL==RLRLLRRRL=RRL=R====L=RLRR=RR=RRRL=R=RL=LLR=LR=L=RR=RR====LRRLRRLLR==R==L==RRLLRLR=RLLLLR==L=L=L=RR==L=LRRRL=R==RRL=LRR=RRRRRL===RLRLR=RLRLRLRLRR=RL=LL=RLLRR=LL=RLL=L=LRLLLLLR==RRL=R=L===LRLLL=RRRLR=LR====RR=L===LLLL=R=LLLRRRLL=LL==RLRL=LRLRL=RR=RLR==LLR=LR=RLLRLRRLL==L=LL==L==RLRLRLL=L=RLLR==LLRRLRRL==L=R=RLLRLLLL====L=====", "output": "1 3 3 3 2 1 1 1 2 3 2 1 2 3 1 3 3 2 2 1 4 3 2 2 1 2 3 4 4 5 5 5 5 5 1 1 2 1 1 1 1 1 1 1 2 3 3 3 4 5 6 7 7 1 2 4 4 3 2 1 2 12 12 11 10 9 8 7 7 7 7 6 5 5 4 3 2 2 1 2 2 3 1 3 2 2 2 2 1 1 1 2 2 1 3 2 2 1 1 2 2 2 3 4 2 1 3 3 2 2 2 1 2 3 3 4 5 1 3 2 1 2 3 3 2 1 1 1 2 1 3 2 1 2 3 4 1 1 2 3 1 1 2 2 2 2 2 1 1 2 1 2 3 3 4 5 5 6 7 8 1 1 2 2 4 3 3 2 1 2 2 1 2 2 1 1 2 3 3 4 5 5 5 5 5 1 2 3 1 2 3 2 1 2 2 2 3 3 3 1 1 1 2 3 2 1 2 1 2 2 5 4 3 2 1 4 4 4 3 3 2 2 1 1 2 3 3 3 2 2 1 2 3 4 1 1 2 2 2 3 4 2 2 1 2 3 3 4 5 6 7 8 1 1..." }, { "input": "100\n=L=L=L=R=LR=RRRLRL=LRL=RRLLLLRL=R==R=LLLRR===RR=LR==LRLR===RRLRLLRLLR=LRLRR=L=LRRLLLRR==LLRLLLL==RL", "output": "4 4 3 3 2 2 1 1 2 2 1 2 2 3 4 5 1 3 2 2 1 2 1 1 2 5 4 3 2 1 2 1 1 2 2 2 4 4 3 2 1 2 3 3 3 3 4 5 5 1 2 2 2 1 2 1 2 2 2 2 3 4 1 3 2 1 3 2 1 2 2 1 2 1 2 3 3 2 2 1 2 4 3 2 1 2 3 3 3 2 1 5 4 3 2 1 1 1 2 1" }, { "input": "484\nLLRRRL==RRLRRLR=LRR=RL=LLLRL===RLRRRLRR=RRRL=LLLLRL==RL==R==LLLRL=RLLRLRLLLLLLLRRLL=LLR=LLR==RLL==LLLR=RL==LL=LRRL=LLRRRLR====R=R=LRRRLLL==RLRRLR=LL==LLRLR===RR=LR==RL==L==R====LRL=LR=R=R=R=LL=L=RLR=RL==R==LRLRL==L==LL=LR=L=RRRR=R==RRLRRRLR==R=LL===R===RLRRR===LRRLLRRRRR=L==LLRRRRLRRRLL===L==LR==LR==RRLRRLRLLLL=RRL=L=LLLRLRRLLL=LRRRRLLLR=L=LL=LRLL=R==L=LRR=R=LLLRR=LRRRLR=R=RLLRR=LRL===LL==LR===L=L=L=RLL=LRRL=LL==RL==RRL====RR=L=R==L==RRL=LLRLR=RLLLL==R==RRL=====LR=RRR=LRLRRR=RLR", "output": "3 2 1 2 3 4 1 1 1 2 3 1 2 3 1 2 2 1 2 3 3 5 4 4 3 2 1 2 1 1 1 1 2 1 2 3 4 1 2 3 3 4 5 6 5 5 4 3 2 1 2 1 1 1 2 1 1 1 4 4 4 3 2 1 2 1 1 3 2 1 2 1 8 7 6 5 4 3 2 1 2 5 4 3 3 2 1 3 3 2 1 2 2 2 6 5 4 4 4 3 2 1 2 2 5 4 4 4 3 2 2 1 2 4 3 3 2 1 2 3 4 1 2 2 2 2 2 3 3 4 4 1 2 3 4 3 2 1 1 1 2 1 2 3 1 5 5 4 3 3 3 2 1 2 1 2 2 2 2 3 4 4 1 2 2 2 3 2 2 2 1 1 1 2 2 2 2 2 1 3 2 2 1 2 2 3 3 4 4 5 5 3 2 2 1 1 2 1 2 2 3 1 1 1 2 2 2 1 2 1 6 5 5 5 4 4 4 3 2 2 1 2 2 1 1 2 3 4 5 5 6 6 6 7 8 1 2 3 4 1 2 2 2 3 3 2 1 1 1 1 2 2 2 2 3 1..." }, { "input": "338\n==R===L=RLRLR===RR=RRL==R=R=RLRLLRLRRRLR=LR=RR=RLLRR=RRRLLRLL=RRRRRLRLLLL=RLLRLLLRL===RRR=RRLLR=LLLL===RLL==LRLLLLRLLLLR=====RLRLRLRL=L==RRLL=RLL===LL=R=RRL=LL=L==RRLLR=LLRLL=LL=LL==RRLR=L=RLLL=LRLLLRRLR=RL=RR=R=L==RLRLL=LRRLLLLLL=RRL==RLL==R===LR===LRLRLR==LR=RR==RR=RRRRRLRRRLRLLRRRLL=LR=RRR=RL=R=LRRLR==RRR=LLL===RR=RL==RRLLL=RL=L=RLL", "output": "1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 2 2 3 4 4 5 6 1 1 1 2 2 3 3 4 1 3 2 1 2 1 2 3 4 1 2 2 1 2 2 3 4 4 5 2 1 2 3 3 4 5 6 2 1 3 2 1 1 2 3 4 5 6 1 5 4 3 2 1 1 3 2 1 4 3 2 1 2 1 1 1 1 2 3 4 4 5 6 2 1 5 5 4 3 2 1 1 1 1 4 3 2 2 2 1 5 4 3 2 1 5 4 3 2 1 2 2 2 2 2 2 3 1 2 1 2 1 3 2 2 1 1 1 2 3 2 1 1 5 4 3 3 3 3 2 1 1 2 2 3 5 4 4 3 2 2 1 1 1 2 3 2 1 3 3 2 1 7 6 5 5 4 3 3 2 1 1 1 2 3 1 2 2 1 1 5 4 3 2 2 1 4 3 2 1 2 3 1 2 2 3 1 1 2 3 3 4 4 1 1 1 2 1 4 3 2 2 1 2 7 6 5 4 3 2 1 1 2 3 1 1 1 3 2 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1 2 1..." }, { "input": "198\nLLRRR=RRRRLRRLRR=R===R=RL==R=RLLLR=R=L=LR=R====RRL=RRR=LL=R=RR=RRRLRRLRRR==L=LRLLL====LR=RL==L===LRR=L=L==R==R==L=LLL===R=LLL=R=L=LLLLRLL=RL=LRRLR=RL==RR=R==RLR==R=R==RLRL=LL=RRR=R===LLLRRRRL=RLRLL", "output": "3 2 1 2 3 4 4 5 6 7 8 1 2 3 1 2 3 3 4 4 4 4 5 5 6 1 1 1 2 2 4 3 2 1 2 2 3 3 2 2 1 2 2 3 3 3 3 3 4 5 1 1 2 3 4 4 2 1 1 2 2 3 4 4 5 6 7 1 2 3 1 2 3 4 4 4 2 2 1 5 4 3 2 2 2 2 2 1 2 2 4 3 3 3 2 2 2 2 1 2 3 3 2 2 1 1 1 2 2 2 5 5 5 4 4 3 2 1 1 1 1 4 4 3 2 1 1 6 6 5 5 4 3 2 1 3 2 1 1 3 2 2 1 2 3 1 2 2 3 1 1 1 2 3 3 4 4 4 5 1 2 2 2 3 3 4 4 4 5 1 4 3 3 2 1 1 2 3 4 4 5 5 5 5 3 2 1 2 3 4 5 1 1 2 1 3 2 1" }, { "input": "426\nR==LRRRL=R==LLRRRLRLLLR=====R=RRRLLR==LL=L=RR=L=L==LRRR=LL=RR=LRRRLRLLR=R==RL=RRL===RRRL=RLRRRRRLRLLR=LR==LL=R=RRRLRLLLRL=L=RL=R==L==RRLLRRR=RRR==RL=====R=R==RLR=R==L==RL=RRR=RLL=L=LL=RLLR===R=RL==LR=LRLLLR==L==LR=RLLLRRRRL=RRRL=RL=LR=====R=RR=L=RL==L=LLRL=LL=L==LR=RLLRR=RLRLR=LRLLRR===L===RLL=RR==RR=R====RRLR=L=RLRLRLLRLLL=R=R=LLLRRRLR=L==L=R==LLR=L=L==RRLR=LR=R=LR=RR=R=LLRL=L=R=LLLLLR==L=LR=R=L=LL==LRR=L===RL==LL==R==RL", "output": "1 2 2 2 1 2 3 4 1 1 3 3 3 2 1 2 3 4 1 4 3 2 1 2 2 2 2 2 2 3 3 4 5 6 2 1 4 4 4 3 2 2 1 1 2 4 4 3 3 2 2 2 1 2 3 4 4 2 1 1 2 3 3 1 2 3 4 1 3 2 1 2 2 3 3 3 4 1 1 2 3 1 1 1 1 2 3 4 1 1 2 1 2 3 4 5 6 1 3 2 1 2 2 1 3 3 3 2 1 1 2 2 3 4 5 1 4 3 2 1 3 2 2 1 1 2 1 1 2 2 2 1 1 1 2 3 2 1 2 3 4 4 5 6 7 7 7 8 1 1 1 1 1 1 2 2 3 3 3 4 1 2 2 3 3 3 1 1 1 2 1 1 2 3 4 4 6 5 4 4 3 3 2 1 1 3 2 1 2 2 2 2 3 3 4 2 2 2 1 2 2 1 4 3 2 1 3 3 3 2 2 2 1 2 2 4 3 2 1 2 3 4 5 1 1 2 3 4 1 1 3 2 2 1 2 2 2 2 2 2 3 3 4 5 5 1 1 5 4 4 4 3 3 2 1 6..." }, { "input": "10\nRL=R=RLR=", "output": "1 2 1 1 2 2 3 1 2 2" }, { "input": "2\nL", "output": "2 1" }, { "input": "100\nR=R=RRR=R=RR=RRLL=RLRLLLLLR==L=======L=LLR==RL=R=LRLLLR==LLLL=RRRL=LRL=LR=====L=LLLRRL=LLR===RLR=RR", "output": "1 2 2 3 3 4 5 6 6 7 7 8 9 9 10 11 2 1 1 2 1 6 5 4 3 2 1 5 5 5 4 4 4 4 4 4 4 4 3 3 2 1 2 2 2 3 1 1 2 2 1 4 3 2 1 5 5 5 4 3 2 1 1 2 3 4 2 2 1 3 2 2 1 5 5 5 5 5 5 4 4 3 2 1 2 4 3 3 2 1 2 2 2 2 3 1 2 2 3 4" }, { "input": "23\nL=LLLLRL=RR=RLLLL=RR==", "output": "6 5 5 4 3 2 1 2 1 1 2 3 3 5 4 3 2 1 1 2 3 3 3" }, { "input": "432\n=R=RRL=LLR=LLRLLRL=RL==R===L===LR=RR=LL==RLRLRRL=LRL=RLLRRLLL==RLLR=LLLRL=RLRRLLRRL=RLRRL=LL=RR=RL==LL===R==RR=LLL=RRR===R=RLLLR====R==RL=LRL=LLRLRLLRL=LLR==R==LLLL===R=R=LR=L=LRR=LR==LLL=L=LR=R=RLR=L=R==L=RLLLRR=R===R==L==R===L=RLLRLLLLLLL=LRRL=LLLL=RR==R===RR=LLLLRLRL==R====LR==LRL=L=R=R=L====LRLRL=RRR=RRRL====R=LRLRL===LRLLLR==R==LL=R==L==L=LRRRL==LL=R=L=LL=RRRLLRLRL==LLR===RRR=RRLRRR=R=RL===L=RRRR=R=RL===R==L===LLR=LLRLLLRL", "output": "1 1 2 2 3 4 3 3 2 1 3 3 2 1 3 2 1 2 1 1 2 1 1 1 3 3 3 3 2 2 2 2 1 2 2 3 4 4 2 1 1 1 2 1 2 1 2 3 2 2 1 2 1 1 3 2 1 2 4 3 2 1 1 1 3 2 1 4 4 3 2 1 2 1 1 2 1 2 3 2 1 2 3 1 1 2 1 2 4 3 3 2 1 1 2 3 3 4 3 3 3 2 1 1 1 1 2 2 2 3 4 4 3 2 1 1 2 3 4 4 4 4 5 5 6 3 2 1 2 2 2 2 2 3 3 3 4 2 2 1 4 3 3 2 1 2 1 3 2 1 4 3 3 2 1 2 2 2 5 5 5 4 3 2 1 1 1 1 2 2 3 3 1 3 3 2 2 1 2 3 3 1 6 6 6 5 4 3 3 2 2 1 2 2 3 3 4 1 2 2 1 1 2 2 2 1 1 4 3 2 1 2 3 3 4 4 4 4 5 5 5 1 1 1 2 2 2 2 1 1 3 2 1 9 8 7 6 5 4 3 2 2 1 2 6 5 5 4 3 2 1 1 2 3 3 3..." }, { "input": "4\nRRL", "output": "1 2 3 1" }, { "input": "17\n=RRR=L==LLLLRRRL", "output": "1 1 2 3 6 6 5 5 5 4 3 2 1 2 3 4 1" }, { "input": "20\nRRLLLLLRRRRRRRRLRLR", "output": "1 2 6 5 4 3 2 1 2 3 4 5 6 7 8 9 1 2 1 2" }, { "input": "9\nR===RRLL", "output": "1 2 2 2 2 3 4 2 1" }, { "input": "15\n=RRR=LLLLLRRRL", "output": "1 1 2 3 6 6 5 4 3 2 1 2 3 4 1" } ]
1,586,521,199
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
280
0
n = int(input()) s = input() a = [1]*n for i in range(n-1): if(s[i] == 'R'): a[i+1] = a[i] + 1 for i in range(n-2,-1,-1): if(s[i] == 'L'): a[i] = a[i+1] + 1 for i in range(n-1): if(s[i] == '='): if(a[i]>=a[i+1]): a[i+1] = a[i] else: a[i] = a[i+1] print(*a)
Title: Partial Teacher Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one. It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum. Input Specification: The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks. Output Specification: Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. Demo Input: ['5\nLRLR\n', '5\n=RRR\n'] Demo Output: ['2 1 2 1 2\n', '1 1 2 3 4\n'] Note: none
```python n = int(input()) s = input() a = [1]*n for i in range(n-1): if(s[i] == 'R'): a[i+1] = a[i] + 1 for i in range(n-2,-1,-1): if(s[i] == 'L'): a[i] = a[i+1] + 1 for i in range(n-1): if(s[i] == '='): if(a[i]>=a[i+1]): a[i+1] = a[i] else: a[i] = a[i+1] print(*a) ```
0
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" } ]
1,696,813,861
2,147,483,647
PyPy 3-64
OK
TESTS
46
717
13,312,000
def solve(): x = int(input()) l = [] for i in range(x): a, b = map(int, input().split()) l.append((a, b)) l.sort(key=lambda p: p[0]) for i in range(1, x): if l[i][1]-l[i-1][1] < 0: print('Happy Alex') return print('Poor Alex') # t = int(input()) t = 1 while t: solve() t -= 1
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python def solve(): x = int(input()) l = [] for i in range(x): a, b = map(int, input().split()) l.append((a, b)) l.sort(key=lambda p: p[0]) for i in range(1, x): if l[i][1]-l[i-1][1] < 0: print('Happy Alex') return print('Poor Alex') # t = int(input()) t = 1 while t: solve() t -= 1 ```
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,600,653,548
2,147,483,647
Python 3
OK
TESTS
30
216
0
""""" def uccf( str ): x = 0 while x < len(str): if ('a' <= str[x]) and ('z' >= str[x]): str.replace(str[x], chr(65 + ord(str[x]) - ord('a'))) #print(str[x]) x = x+1 def lccF(str): str.lower() x = 0 while x < len(str): if ('A' <= str[x]) and ('Z' >= str[x]): str.replace(str[x],chr(ord('a') + ord(str[x]) - 65)) #print(str[x]) x = x + 1""" string = input() """"x=ord('a') print((x))""""" lcc = 0 ucc = 0 for x in string: #print(x) if ('a' <= x) and ('z' >= x): lcc = lcc+1 else: ucc = ucc+1 #print(lcc) #print(ucc) if lcc<ucc: print(string.upper()) else: print(string.lower()) #print(string) exit()
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 """"" def uccf( str ): x = 0 while x < len(str): if ('a' <= str[x]) and ('z' >= str[x]): str.replace(str[x], chr(65 + ord(str[x]) - ord('a'))) #print(str[x]) x = x+1 def lccF(str): str.lower() x = 0 while x < len(str): if ('A' <= str[x]) and ('Z' >= str[x]): str.replace(str[x],chr(ord('a') + ord(str[x]) - 65)) #print(str[x]) x = x + 1""" string = input() """"x=ord('a') print((x))""""" lcc = 0 ucc = 0 for x in string: #print(x) if ('a' <= x) and ('z' >= x): lcc = lcc+1 else: ucc = ucc+1 #print(lcc) #print(ucc) if lcc<ucc: print(string.upper()) else: print(string.lower()) #print(string) exit() ```
3.946
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,674,890,862
2,147,483,647
Python 3
OK
TESTS
59
46
0
d = input().split(' ') A = int(d[0]) B = int(d[1]) def factorial(x): if x == 0: return 1 return x * factorial(x-1) if A>=B: print(factorial(B)) else: print(factorial(A))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python d = input().split(' ') A = int(d[0]) B = int(d[1]) def factorial(x): if x == 0: return 1 return x * factorial(x-1) if A>=B: print(factorial(B)) else: print(factorial(A)) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481 554 1000 821", "output": "15" }, { "input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396", "output": "144" }, { "input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366", "output": "145" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n2", "output": "2" }, { "input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19", "output": "63" }, { "input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386", "output": "31" }, { "input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518", "output": "75" }, { "input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397", "output": "41" }, { "input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118", "output": "116" } ]
1,690,388,070
2,147,483,647
PyPy 3-64
OK
TESTS
29
62
0
friends_num, fence_height = map(int, input().split()) friends_heights = [int(height) for height in input().split()] road_width = sum( 1 if height <= fence_height else 2 for height in friends_heights ) print(road_width)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? Input Specification: The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. Output Specification: Print a single integer — the minimum possible valid width of the road. Demo Input: ['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n'] Demo Output: ['4\n', '6\n', '11\n'] Note: In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
```python friends_num, fence_height = map(int, input().split()) friends_heights = [int(height) for height in input().split()] road_width = sum( 1 if height <= fence_height else 2 for height in friends_heights ) print(road_width) ```
3
507
A
Amr and Music
PROGRAMMING
1,000
[ "greedy", "implementation", "sortings" ]
null
null
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
[ "4 10\n4 3 1 2\n", "5 6\n4 3 1 1 2\n", "1 3\n4\n" ]
[ "4\n1 2 3 4", "3\n1 3 4", "0\n" ]
In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
500
[ { "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4" }, { "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5" }, { "input": "1 3\n4", "output": "0" }, { "input": "2 100\n100 100", "output": "1\n1" }, { "input": "3 150\n50 50 50", "output": "3\n1 2 3" }, { "input": "4 0\n100 100 100 100", "output": "0" }, { "input": "100 7567\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": "75\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" }, { "input": "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50", "output": "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68" }, { "input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "100\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" }, { "input": "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93", "output": "25\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" }, { "input": "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76", "output": "98\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" }, { "input": "5 249\n96 13 7 2 81", "output": "5\n1 2 3 4 5" }, { "input": "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44", "output": "61\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" }, { "input": "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80", "output": "99\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" }, { "input": "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97", "output": "89\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" }, { "input": "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8", "output": "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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" }, { "input": "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12", "output": "27\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" }, { "input": "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93", "output": "55\n1 2 3 4 5 6 7 8 9 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" }, { "input": "6 41\n6 8 9 8 9 8", "output": "5\n1 2 3 4 6" }, { "input": "9 95\n9 11 12 11 12 11 8 11 10", "output": "9\n1 2 3 4 5 6 7 8 9" }, { "input": "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52", "output": "89\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" }, { "input": "5 29\n6 3 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "5 49\n16 13 7 2 1", "output": "5\n1 2 3 4 5" }, { "input": "6 84\n16 21 25 6 17 16", "output": "5\n1 2 4 5 6" }, { "input": "4 9\n7 4 2 1", "output": "3\n2 3 4" }, { "input": "50 2500\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "50\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" }, { "input": "100 10000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6", "output": "96\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" }, { "input": "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3", "output": "47\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" }, { "input": "100 200\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100" }, { "input": "2 10000\n1 1", "output": "2\n1 2" }, { "input": "1 2\n1", "output": "1\n1" }, { "input": "1 3\n2", "output": "1\n1" }, { "input": "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71", "output": "34\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34" }, { "input": "2 2\n1 10", "output": "1\n1" }, { "input": "2 5\n1 1", "output": "2\n1 2" }, { "input": "1 4\n3", "output": "1\n1" }, { "input": "4 384\n1 2 3 4", "output": "4\n1 2 3 4" } ]
1,581,871,165
2,147,483,647
Python 3
OK
TESTS
39
108
0
n, k = map(int, input().split()) req_days = [int(c) for c in input().split()] req_days_sorted = sorted((e, i) for i, e in enumerate(req_days, 1)) acc = 0 #print(req_days_sorted) ans = [] for e, i in req_days_sorted: #print(acc, i, e, k) if acc + e <= k: acc += e ans.append(i) print(len(ans)) if len(ans) > 0: print(*ans)
Title: Amr and Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. Input Specification: The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. Output Specification: In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying. Demo Input: ['4 10\n4 3 1 2\n', '5 6\n4 3 1 1 2\n', '1 3\n4\n'] Demo Output: ['4\n1 2 3 4', '3\n1 3 4', '0\n'] Note: In the first test Amr can learn all 4 instruments. In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}. In the third test Amr doesn't have enough time to learn the only presented instrument.
```python n, k = map(int, input().split()) req_days = [int(c) for c in input().split()] req_days_sorted = sorted((e, i) for i, e in enumerate(req_days, 1)) acc = 0 #print(req_days_sorted) ans = [] for e, i in req_days_sorted: #print(acc, i, e, k) if acc + e <= k: acc += e ans.append(i) print(len(ans)) if len(ans) > 0: print(*ans) ```
3
601
A
The Two Routes
PROGRAMMING
1,600
[ "graphs", "shortest paths" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns.
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
500
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "-1" }, { "input": "2 1\n1 2", "output": "-1" }, { "input": "2 0", "output": "-1" }, { "input": "20 0", "output": "-1" }, { "input": "381 0", "output": "-1" }, { "input": "3 3\n1 2\n2 3\n3 1", "output": "-1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 3", "output": "2" }, { "input": "3 2\n2 3\n3 1", "output": "-1" }, { "input": "4 1\n1 4", "output": "2" }, { "input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3", "output": "2" }, { "input": "20 1\n20 1", "output": "2" }, { "input": "21 1\n21 1", "output": "2" }, { "input": "100 1\n100 1", "output": "2" }, { "input": "400 1\n1 400", "output": "2" }, { "input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2", "output": "2" } ]
1,587,881,038
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
n, m = map(int, input().split()) b = [[j for j in range(1,n+1) if j != i+1] for i in range(n)] b.insert(0,[]) t = [[] for i in range(n+1)] for _ in range(m): u, v = map(int, input().split()) b[u].remove(v) b[v].remove(u) t[u].append(v) t[v].append(u) def find_shorteset_path(n, start, des, adj): queue = [(start,0)] visited = [False for i in range(n+1)] visited[start] = True while queue != []: v = queue[0] if v[0] == des: return v[1] for neig in adj[v[0]]: if not visited[neig]: visited[neig]=True queue.append((neig, v[1]+1)) del queue[0] print(queue) print(visited) return False print(b) bus_sol = find_shorteset_path(n, 1, n, b) print(t) train_sol = find_shorteset_path(n, 1, n, t) if train_sol and bus_sol: print(max(train_sol, bus_sol)) else: print(-1)
Title: The Two Routes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. Input Specification: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns. Output Specification: Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. Demo Input: ['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n'] Demo Output: ['2\n', '-1\n', '3\n'] Note: In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time. In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
```python n, m = map(int, input().split()) b = [[j for j in range(1,n+1) if j != i+1] for i in range(n)] b.insert(0,[]) t = [[] for i in range(n+1)] for _ in range(m): u, v = map(int, input().split()) b[u].remove(v) b[v].remove(u) t[u].append(v) t[v].append(u) def find_shorteset_path(n, start, des, adj): queue = [(start,0)] visited = [False for i in range(n+1)] visited[start] = True while queue != []: v = queue[0] if v[0] == des: return v[1] for neig in adj[v[0]]: if not visited[neig]: visited[neig]=True queue.append((neig, v[1]+1)) del queue[0] print(queue) print(visited) return False print(b) bus_sol = find_shorteset_path(n, 1, n, b) print(t) train_sol = find_shorteset_path(n, 1, n, t) if train_sol and bus_sol: print(max(train_sol, bus_sol)) else: print(-1) ```
0
52
A
123-sequence
PROGRAMMING
900
[ "implementation" ]
A. 123-sequence
2
256
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
[ "9\n1 3 2 2 2 1 1 2 3\n" ]
[ "5\n" ]
In the example all the numbers equal to 1 and 3 should be replaced by 2.
500
[ { "input": "9\n1 3 2 2 2 1 1 2 3", "output": "5" }, { "input": "6\n3 3 2 2 1 3", "output": "3" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10" }, { "input": "2\n2 1", "output": "1" }, { "input": "2\n3 2", "output": "1" }, { "input": "2\n3 1", "output": "1" }, { "input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2", "output": "10" }, { "input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1", "output": "19" }, { "input": "1\n1", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "1\n3", "output": "0" } ]
1,639,054,388
2,147,483,647
Python 3
OK
TESTS
23
374
11,059,200
n = int(input()) s = input().split() max_ = 0 for el in range(1,4): if s.count(str(el)) > max_: max_ = s.count(str(el)) print(len(s) - max_)
Title: 123-sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). Output Specification: Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Demo Input: ['9\n1 3 2 2 2 1 1 2 3\n'] Demo Output: ['5\n'] Note: In the example all the numbers equal to 1 and 3 should be replaced by 2.
```python n = int(input()) s = input().split() max_ = 0 for el in range(1,4): if s.count(str(el)) > max_: max_ = s.count(str(el)) print(len(s) - max_) ```
3.885901
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,658,755,069
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n = int(input()) m = int(input()) a = int(input()) area = n * m tileArea = a * a vTiles = round(n / a) hTiles = round(m / a) numberOfTiles = vTiles + hTiles print(numberOfTiles)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n = int(input()) m = int(input()) a = int(input()) area = n * m tileArea = a * a vTiles = round(n / a) hTiles = round(m / a) numberOfTiles = vTiles + hTiles print(numberOfTiles) ```
-1
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,654,023,926
2,147,483,647
PyPy 3-64
OK
TESTS
20
46
0
from math import ceil n,m,a=map(int, input().split()) print(ceil(n/a)*ceil(m/a))
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python from math import ceil n,m,a=map(int, input().split()) print(ceil(n/a)*ceil(m/a)) ```
3.977
849
B
Tell Your World
PROGRAMMING
1,600
[ "brute force", "geometry" ]
null
null
Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
[ "5\n7 5 8 6 9\n", "5\n-1 -2 0 0 -5\n", "5\n5 4 3 2 1\n", "5\n1000000000 0 0 0 0\n" ]
[ "Yes\n", "No\n", "No\n", "Yes\n" ]
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
1,000
[ { "input": "5\n7 5 8 6 9", "output": "Yes" }, { "input": "5\n-1 -2 0 0 -5", "output": "No" }, { "input": "5\n5 4 3 2 1", "output": "No" }, { "input": "5\n1000000000 0 0 0 0", "output": "Yes" }, { "input": "5\n1000000000 1 0 -999999999 -1000000000", "output": "Yes" }, { "input": "3\n998 244 353", "output": "Yes" }, { "input": "3\n-1000000000 0 1000000000", "output": "No" }, { "input": "5\n-1 -1 -1 -1 1", "output": "Yes" }, { "input": "4\n-9763 530 3595 6660", "output": "Yes" }, { "input": "4\n-253090305 36298498 374072642 711846786", "output": "Yes" }, { "input": "5\n-186772848 -235864239 -191561068 -193955178 -243046569", "output": "Yes" }, { "input": "5\n-954618456 -522919664 -248330428 -130850748 300848044", "output": "Yes" }, { "input": "10\n4846 6705 2530 5757 5283 -944 -2102 -3260 -4418 2913", "output": "No" }, { "input": "10\n-6568 -5920 -5272 -4624 -2435 -635 -2680 -2032 -1384 6565", "output": "No" }, { "input": "20\n319410377 286827025 254243673 221660321 189076969 156493617 123910265 91326913 58743561 26160209 -6423143 -39006495 -71589847 -104173199 -136756551 -169339903 -201923255 -234506607 -267089959 -299673311", "output": "No" }, { "input": "20\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 758268836 -975467175 758268835 -975467176 758268834 -975467177 758268833 -975467178 758268832 -975467179 758268831", "output": "Yes" }, { "input": "4\n1 0 3 0", "output": "No" }, { "input": "4\n100 2 3 4", "output": "Yes" }, { "input": "5\n7 5 8 6 3", "output": "No" }, { "input": "3\n1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "4\n1 0 1 4", "output": "Yes" }, { "input": "7\n1 2 -1 0 1 6 7", "output": "Yes" }, { "input": "4\n0 0 4 0", "output": "Yes" }, { "input": "7\n0 0 2 3 4 5 5", "output": "Yes" }, { "input": "5\n7 5 8 6 8", "output": "No" }, { "input": "5\n1 2 9 4 5", "output": "Yes" }, { "input": "8\n1 12 3 14 5 16 7 8", "output": "Yes" }, { "input": "5\n1 6 7 4 9", "output": "Yes" }, { "input": "5\n2 1 0 1 2", "output": "No" }, { "input": "4\n0 0 1 3", "output": "Yes" }, { "input": "4\n100 50 50 10000000", "output": "No" }, { "input": "5\n1 2 3 3 3", "output": "No" }, { "input": "5\n1 2 6 10 17", "output": "Yes" }, { "input": "4\n1 3 4 4", "output": "Yes" }, { "input": "4\n100 50 50 1000000", "output": "No" }, { "input": "6\n1 2 4 5 7 9", "output": "No" }, { "input": "6\n0 0 1 2 3 4", "output": "Yes" }, { "input": "5\n7 5 9 10 8", "output": "Yes" }, { "input": "7\n1 2 2 1 2 2 1", "output": "Yes" }, { "input": "4\n2 2 4 5", "output": "Yes" }, { "input": "6\n1 2 1 3 4 5", "output": "No" }, { "input": "4\n1 3 3 6", "output": "No" }, { "input": "5\n1 2 -3 4 -1", "output": "Yes" } ]
1,504,275,763
2,863
PyPy 3
WRONG_ANSWER
PRETESTS
6
93
0
import sys def main(): n = int(input()) s = list(map(int, sys.stdin.readline().split())) p1 = (0, 0) for z in range(2): for i in range(1, n): k = (s[i] - s[0]) / i oka = True okp = False for j in range(1, n): if i == j: continue c = (s[j] - s[0]) / j if c != k: if not okp: p1 = (j, s[j]) okp = True else: k2 = (s[j] - p1[1]) / (j - p1[0]) if k!=k2: oka = False break if oka and okp: print("Yes") return s[1],s[0] = s[0],s[1] print("No") main()
Title: Tell Your World Time Limit: None seconds Memory Limit: None megabytes Problem Description: Connect the countless points with lines, till we reach the faraway yonder. There are *n* points on a coordinate plane, the *i*-th of which being (*i*,<=*y**i*). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. Input Specification: The first line of input contains a positive integer *n* (3<=≤<=*n*<=≤<=1<=000) — the number of points. The second line contains *n* space-separated integers *y*1,<=*y*2,<=...,<=*y**n* (<=-<=109<=≤<=*y**i*<=≤<=109) — the vertical coordinates of each point. Output Specification: Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['5\n7 5 8 6 9\n', '5\n-1 -2 0 0 -5\n', '5\n5 4 3 2 1\n', '5\n1000000000 0 0 0 0\n'] Demo Output: ['Yes\n', 'No\n', 'No\n', 'Yes\n'] Note: In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
```python import sys def main(): n = int(input()) s = list(map(int, sys.stdin.readline().split())) p1 = (0, 0) for z in range(2): for i in range(1, n): k = (s[i] - s[0]) / i oka = True okp = False for j in range(1, n): if i == j: continue c = (s[j] - s[0]) / j if c != k: if not okp: p1 = (j, s[j]) okp = True else: k2 = (s[j] - p1[1]) / (j - p1[0]) if k!=k2: oka = False break if oka and okp: print("Yes") return s[1],s[0] = s[0],s[1] print("No") main() ```
0
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer — the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "22" }, { "input": "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1", "output": "70" }, { "input": "100\n0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 1 1", "output": "60" }, { "input": "18\n0 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0", "output": "11" }, { "input": "25\n0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1", "output": "18" }, { "input": "55\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1", "output": "36" }, { "input": "75\n1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0", "output": "44" }, { "input": "100\n0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1 0 1", "output": "61" }, { "input": "100\n0 0 0 1 0 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 1 1 0", "output": "61" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "99" }, { "input": "100\n0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 0", "output": "61" }, { "input": "100\n0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1", "output": "59" }, { "input": "99\n1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1", "output": "61" }, { "input": "2\n1 1", "output": "1" } ]
1,685,207,370
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
def main(): n=int(input()) a=list(map(int,input().split())) q,w=0,0 for i in range(n): if a[i]==1: q=i+1 break for i in range(n): if a[i]==1: w=i+1 print(w-(q-1)) main()
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≤<=*k*<=≤<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. Output Specification: Print an integer — the maximal number of 1s that can be obtained after exactly one move. Demo Input: ['5\n1 0 0 1 0\n', '4\n1 0 0 1\n'] Demo Output: ['4\n', '4\n'] Note: In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all numbers into 1.
```python def main(): n=int(input()) a=list(map(int,input().split())) q,w=0,0 for i in range(n): if a[i]==1: q=i+1 break for i in range(n): if a[i]==1: w=i+1 print(w-(q-1)) main() ```
0
985
C
Liebig's Barrels
PROGRAMMING
1,500
[ "greedy" ]
null
null
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel. Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it. You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109). The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
[ "4 2 1\n2 2 1 2 3 2 2 3\n", "2 1 0\n10 10\n", "1 2 1\n5 2\n", "3 2 1\n1 2 3 4 5 6\n" ]
[ "7\n", "20\n", "2\n", "0\n" ]
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3]. In the second example you can form the following barrels: [10], [10]. In the third example you can form the following barrels: [2, 5]. In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
0
[ { "input": "4 2 1\n2 2 1 2 3 2 2 3", "output": "7" }, { "input": "2 1 0\n10 10", "output": "20" }, { "input": "1 2 1\n5 2", "output": "2" }, { "input": "3 2 1\n1 2 3 4 5 6", "output": "0" }, { "input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71", "output": "0" }, { "input": "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494", "output": "2979" }, { "input": "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104", "output": "5045" }, { "input": "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9", "output": "28" }, { "input": "2 1 2\n1 2", "output": "3" } ]
1,527,171,997
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
171
7,884,800
n,k,l = map(int, input().split()) a = sorted(map(int, input().split())) al = a[0] + l from bisect import bisect ni = bisect(a, al) if n > ni: print(0) exit(0) ni = min(ni, (n-1)*k) s = [min(k*i, ni) for i in range(n)] for i in range(n-1, 0, -1): if s[i] <= s[n-1]: s[n-1] = s[i]-1 else: break print(sum(a[s1] for s1 in s))
Title: Liebig's Barrels Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel. Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it. You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above. Input Specification: The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109). The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves. Output Specification: Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*. Demo Input: ['4 2 1\n2 2 1 2 3 2 2 3\n', '2 1 0\n10 10\n', '1 2 1\n5 2\n', '3 2 1\n1 2 3 4 5 6\n'] Demo Output: ['7\n', '20\n', '2\n', '0\n'] Note: In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3]. In the second example you can form the following barrels: [10], [10]. In the third example you can form the following barrels: [2, 5]. In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
```python n,k,l = map(int, input().split()) a = sorted(map(int, input().split())) al = a[0] + l from bisect import bisect ni = bisect(a, al) if n > ni: print(0) exit(0) ni = min(ni, (n-1)*k) s = [min(k*i, ni) for i in range(n)] for i in range(n-1, 0, -1): if s[i] <= s[n-1]: s[n-1] = s[i]-1 else: break print(sum(a[s1] for s1 in s)) ```
0