contestId int64 0 1.01k | index stringclasses 57 values | name stringlengths 2 58 | type stringclasses 2 values | rating int64 0 3.5k | tags listlengths 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 listlengths 0 7 | demo-output listlengths 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,666,759,258 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 716,800 | from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
from random import randint
from fractions import Fraction as frac
import math
hpop = heappop
hpush = heappush
MOD = 10**9 + 7
def solution():
pattern = input()
pattern_lsp = [0]*len(pattern)
length = 0
for i in range(1, len(pattern)):
while length and pattern[length] != pattern[i]:
length = pattern_lsp[length - 1]
if pattern[length] == pattern[i]:
length += 1
pattern_lsp[i] = length
length = pattern_lsp[-1]
suffix = pattern[-length:]
if suffix in pattern[1:-1]:
return print(suffix)
return print("Just a legend")
def main():
#test()
t = 1
#t = int(input())
for _ in range(t):
solution()
#import sys
#import threading
#sys.setrecursionlimit(10**6)
#threading.stack_size(1 << 27)
#thread = threading.Thread(target=main)
#thread.start(); thread.join()
main()
| Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none | ```python
from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
from random import randint
from fractions import Fraction as frac
import math
hpop = heappop
hpush = heappush
MOD = 10**9 + 7
def solution():
pattern = input()
pattern_lsp = [0]*len(pattern)
length = 0
for i in range(1, len(pattern)):
while length and pattern[length] != pattern[i]:
length = pattern_lsp[length - 1]
if pattern[length] == pattern[i]:
length += 1
pattern_lsp[i] = length
length = pattern_lsp[-1]
suffix = pattern[-length:]
if suffix in pattern[1:-1]:
return print(suffix)
return print("Just a legend")
def main():
#test()
t = 1
#t = int(input())
for _ in range(t):
solution()
#import sys
#import threading
#sys.setrecursionlimit(10**6)
#threading.stack_size(1 << 27)
#thread = threading.Thread(target=main)
#thread.start(); thread.join()
main()
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,633,146,825 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 216 | 20,172,800 | s=input()
b=[]
count1=0
count2=0
for i in s:
if(i.isupper()):
count1=count1+1
if(i.islower()):
count2=count2+1
if(count1>count2):
for i in s:
b.append(i.upper())
else:
for i in s:
b.append(i.lower())
for i in b:
print(i,end="") | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s=input()
b=[]
count1=0
count2=0
for i in s:
if(i.isupper()):
count1=count1+1
if(i.islower()):
count2=count2+1
if(count1>count2):
for i in s:
b.append(i.upper())
else:
for i in s:
b.append(i.lower())
for i in b:
print(i,end="")
``` | 3.908425 |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,674,735,095 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 62 | 0 | s = input()
ss = input()
res = 0
for i in range(len(ss)):
if s[res] == ss[i]:
res+=1
print(res+1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none | ```python
s = input()
ss = input()
res = 0
for i in range(len(ss)):
if s[res] == ss[i]:
res+=1
print(res+1)
``` | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits. | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,672,133,076 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 62 | 0 | def start():
n = list(map(int, input()))
s1, s2 = n[:3], n[3:]
mx = max(sum(s1), sum(s2))
mn= min(sum(s1),sum(s2))
raz=mx-mn
mn = s1
if sum(s2) < sum(s1):
mn = s2
mn.sort()
if sum(s1) == sum(s2):
print(0)
else:
if abs(raz-mn[0])<raz:
print(2)
else:
print(1)
start() | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
Input Specification:
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
Output Specification:
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
Demo Input:
['000000\n', '123456\n', '111000\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required. | ```python
def start():
n = list(map(int, input()))
s1, s2 = n[:3], n[3:]
mx = max(sum(s1), sum(s2))
mn= min(sum(s1),sum(s2))
raz=mx-mn
mn = s1
if sum(s2) < sum(s1):
mn = s2
mn.sort()
if sum(s1) == sum(s2):
print(0)
else:
if abs(raz-mn[0])<raz:
print(2)
else:
print(1)
start()
``` | 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... | 1,644,413,099 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 16,896,000 | from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int(inp())
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
M,M1=1000000007,998244353
from functools import lru_cache
def main():
how_much_noob_I_am = 1
#how_much_noob_I_am = inpu()
for __ in range(how_much_noob_I_am):
n,k = sep()
l=[lis() for i in range(n)]
@lru_cache()
def fun(i,cnt,taken):
if taken>n or i>=n:
return False
if taken>0:
p = list(cnt)
#print(i,p,taken)
for j in range(len(p)):
if p[j]>(taken)//2:
break
else:
#print(i,cnt,taken)
return True
cnt2 = list(cnt).copy()
taken2 = taken
if i<n:
for j in range(k):
if l[i][j]==1:
cnt2[j]+=1
return (fun(i,tuple(cnt2),taken2+1) or fun(i+1,cnt,taken))
cnt=[0]*(k)
if (fun(0,tuple(cnt),0)):
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
| 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
from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int(inp())
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
M,M1=1000000007,998244353
from functools import lru_cache
def main():
how_much_noob_I_am = 1
#how_much_noob_I_am = inpu()
for __ in range(how_much_noob_I_am):
n,k = sep()
l=[lis() for i in range(n)]
@lru_cache()
def fun(i,cnt,taken):
if taken>n or i>=n:
return False
if taken>0:
p = list(cnt)
#print(i,p,taken)
for j in range(len(p)):
if p[j]>(taken)//2:
break
else:
#print(i,cnt,taken)
return True
cnt2 = list(cnt).copy()
taken2 = taken
if i<n:
for j in range(k):
if l[i][j]==1:
cnt2[j]+=1
return (fun(i,tuple(cnt2),taken2+1) or fun(i+1,cnt,taken))
cnt=[0]*(k)
if (fun(0,tuple(cnt),0)):
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
``` | 0 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order. | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,659,718,385 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 44 | 280 | 10,342,400 | # -*- coding: utf-8 -*-
"""
Created on Fri Aug 5 17:40:43 2022
@author: Conor
CFSheet B Problem 48 - CF262-DIV2B
"""
n, k = map(int,input().split())
ar = list(map(int,input().split()))
ptr = 0
while ptr < len(ar):
if ar[ptr] >= 0:
break
ptr += 1
if ptr >= k:
for i in range(k):
ar[i] = -ar[i]
print(sum(ar))
elif ptr == 0:
ar[0] = pow(-1,k)*ar[0]
print(int(sum(ar)))
else:
for i in range(ptr):
ar[i] = -ar[i]
ar[ptr-1] = pow(-1,ptr-k)*ar[ptr-1]
print(int(sum(ar)))
| Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
Output Specification:
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
Demo Input:
['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 5 17:40:43 2022
@author: Conor
CFSheet B Problem 48 - CF262-DIV2B
"""
n, k = map(int,input().split())
ar = list(map(int,input().split()))
ptr = 0
while ptr < len(ar):
if ar[ptr] >= 0:
break
ptr += 1
if ptr >= k:
for i in range(k):
ar[i] = -ar[i]
print(sum(ar))
elif ptr == 0:
ar[0] = pow(-1,k)*ar[0]
print(int(sum(ar)))
else:
for i in range(ptr):
ar[i] = -ar[i]
ar[ptr-1] = pow(-1,ptr-k)*ar[ptr-1]
print(int(sum(ar)))
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,583,337,149 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | import sys
s = input()
a = 0
b = 0
for i in range(len(s)):
if(s[i].isupper()):
a += 1
else:
b += 1
if( a > b):
s = s.upper()
else:
s =s.lower()
print(s)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
import sys
s = input()
a = 0
b = 0
for i in range(len(s)):
if(s[i].isupper()):
a += 1
else:
b += 1
if( a > b):
s = s.upper()
else:
s =s.lower()
print(s)
``` | 3.938 |
628 | A | Tennis Tournament | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes.
Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). | The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* — the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | 0 | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
... | 1,639,430,628 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | n,m,k=map(int,input().split())
z=n-1
print (z*(2*m+1),n*k) | Title: Tennis Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes.
Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input Specification:
The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement.
Output Specification:
Print two integers *x* and *y* — the number of bottles and towels need for the tournament.
Demo Input:
['5 2 3\n', '8 2 4\n']
Demo Output:
['20 15\n', '35 32\n']
Note:
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | ```python
n,m,k=map(int,input().split())
z=n-1
print (z*(2*m+1),n*k)
``` | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,655,800,643 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | import sys
input = sys.stdin.readline
def in_single_int():
return(int(input()))
def in_list():
return(list(map(int,input().split())))
def in_string_to_list():
s = input()
return(list(s[:len(s) - 1]))
def in_map():
return(map(int,input().split()))
n = in_single_int()
arr = in_list()
m = {}
l = []
for i in range(len(arr)):
if arr[i] in m:
idx, incre = m[arr[i]]
if incre < 0:
break
if idx <= 0:
m[arr[i]] = (i, i - abs(idx))
elif incre != i - idx:
m[arr[i]] = -1
l.remove(arr[i])
else:
m[arr[i]] = (idx, idx - i)
elif arr[i] not in m:
l.append(arr[i])
m[arr[i]] = (-i, 0)
l.sort()
print(len(l))
for i in l:
idx, incre = m[i]
print(i, incre if incre > 0 else 0) | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | ```python
import sys
input = sys.stdin.readline
def in_single_int():
return(int(input()))
def in_list():
return(list(map(int,input().split())))
def in_string_to_list():
s = input()
return(list(s[:len(s) - 1]))
def in_map():
return(map(int,input().split()))
n = in_single_int()
arr = in_list()
m = {}
l = []
for i in range(len(arr)):
if arr[i] in m:
idx, incre = m[arr[i]]
if incre < 0:
break
if idx <= 0:
m[arr[i]] = (i, i - abs(idx))
elif incre != i - idx:
m[arr[i]] = -1
l.remove(arr[i])
else:
m[arr[i]] = (idx, idx - i)
elif arr[i] not in m:
l.append(arr[i])
m[arr[i]] = (-i, 0)
l.sort()
print(len(l))
for i in l:
idx, incre = m[i]
print(i, incre if incre > 0 else 0)
``` | 0 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,673,852,746 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 |
x = list(map(int,input().split(' ')))
dic = [chr(x) for x in range(ord('a'),ord('a')+x[1])]
password = ''
for i in range(x[0]):
password += dic[i % x[1]]
print(password) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | ```python
x = list(map(int,input().split(' ')))
dic = [chr(x) for x in range(ord('a'),ord('a')+x[1])]
password = ''
for i in range(x[0]):
password += dic[i % x[1]]
print(password)
``` | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,695,993,279 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k, r = map(int, input().split())
ans = 1
while ans*k%10 != 0 and (ans*k-r)%10 != 0:
ans += 1
print(ans) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | ```python
k, r = map(int, input().split())
ans = 1
while ans*k%10 != 0 and (ans*k-r)%10 != 0:
ans += 1
print(ans)
``` | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,566,489,984 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | import math
r, x1, y1, x2, y2 = [int(var) for var in input().split()]
d = math.sqrt(pow((x2-x1),2)+pow((y2-y1),2))
s = d/r/2
math.ceil(s)
print(s)
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
r, x1, y1, x2, y2 = [int(var) for var in input().split()]
d = math.sqrt(pow((x2-x1),2)+pow((y2-y1),2))
s = d/r/2
math.ceil(s)
print(s)
``` | 0 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,695,523,026 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | m=[list(map( int , input().split() ) ) for _ in range (5)]
for i in range (5):
for j in range (5):
if m[i][j] == 1 :
r=i+1
c=j+1
mov=abs(r-3)+abs(c-3)
print(mov) | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
m=[list(map( int , input().split() ) ) for _ in range (5)]
for i in range (5):
for j in range (5):
if m[i][j] == 1 :
r=i+1
c=j+1
mov=abs(r-3)+abs(c-3)
print(mov)
``` | 3 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4]. | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,647,103,010 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 16,179,200 | n=int(input())
l=list(map(int,input().split()))
i1=(n-1)//2
while(i1>=0):
l1=l[i1:n-i1]
l=l[:i1]+l1[::-1]+l[n-i1:]
i1-=1
for i in l:
print(i,end=" ")
print() | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Output Specification:
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique.
Demo Input:
['7\n4 3 7 6 9 1 2\n', '8\n6 1 4 2 5 6 9 2\n']
Demo Output:
['2 3 9 6 7 1 4', '2 1 6 2 5 4 9 6']
Note:
Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4]. | ```python
n=int(input())
l=list(map(int,input().split()))
i1=(n-1)//2
while(i1>=0):
l1=l[i1:n-i1]
l=l[:i1]+l1[::-1]+l[n-i1:]
i1-=1
for i in l:
print(i,end=" ")
print()
``` | 0 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,625,866,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | n = int(input())
s = input()
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
count = 0
for i in d:
if d[i]>=2:
count += d[i]-1
if n>100 and count>=50:
print(-1)
else:
print(count) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters.
Output Specification:
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
Demo Input:
['2\naa\n', '4\nkoko\n', '5\nmurat\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | ```python
n = int(input())
s = input()
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
count = 0
for i in d:
if d[i]>=2:
count += d[i]-1
if n>100 and count>=50:
print(-1)
else:
print(count)
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,690,546,812 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | n=int(input())
aa=bb=cc=0
for i in range(n):
arr=map(int,input().split())
aa+=arr[0]
bb+=arr[1]
cc+=arr[2]
if(aa==bb==cc==0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n=int(input())
aa=bb=cc=0
for i in range(n):
arr=map(int,input().split())
aa+=arr[0]
bb+=arr[1]
cc+=arr[2]
if(aa==bb==cc==0):
print("YES")
else:
print("NO")
``` | -1 |
708 | A | Letters Cyclic Shift | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? | The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | 500 | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "... | 1,674,950,408 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | def shift(a):
s=[]
n=0
for i in a:
if i!='a':
n+=ord(i)-1
s.append(chr(n))
n=0
else:
s.append(chr(122))
n=0
e=''
for i in s:
e+=i
print(e)
a=input()
shift(a) | Title: Letters Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once?
Input Specification:
The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters.
Output Specification:
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
Demo Input:
['codeforces\n', 'abacaba\n']
Demo Output:
['bncdenqbdr\n', 'aaacaba\n']
Note:
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | ```python
def shift(a):
s=[]
n=0
for i in a:
if i!='a':
n+=ord(i)-1
s.append(chr(n))
n=0
else:
s.append(chr(122))
n=0
e=''
for i in s:
e+=i
print(e)
a=input()
shift(a)
``` | 0 | |
171 | G | Mysterious numbers - 2 | PROGRAMMING | 1,600 | [
"*special"
] | null | null | The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces.
Output a single integer. | The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces. | Output a single integer. | [
"2 3 2\n",
"13 14 1\n",
"14 5 9\n",
"17 18 3\n"
] | [
"5\n",
"14\n",
"464\n",
"53\n"
] | none | 0 | [
{
"input": "2 3 2",
"output": "5"
},
{
"input": "13 14 1",
"output": "14"
},
{
"input": "14 5 9",
"output": "464"
},
{
"input": "17 18 3",
"output": "53"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "4 6 7",
"output": "110"
},
{
"inpu... | 1,665,388,594 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 92 | 0 | a,b,c=eval(input().replace(' ',','))
def func(x):
if x==0:
return a
if x==1:
return b
return func(x-1)+func(x-2)
print(func(c)) | Title: Mysterious numbers - 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces.
Output a single integer.
Input Specification:
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=20), separated by spaces.
Output Specification:
Output a single integer.
Demo Input:
['2 3 2\n', '13 14 1\n', '14 5 9\n', '17 18 3\n']
Demo Output:
['5\n', '14\n', '464\n', '53\n']
Note:
none | ```python
a,b,c=eval(input().replace(' ',','))
def func(x):
if x==0:
return a
if x==1:
return b
return func(x-1)+func(x-2)
print(func(c))
``` | 3 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,551,305,655 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 0 | ans = input().split()
n = int(input())
while(n is not 0):
print(ans[0],ans[1])
a,b=input().split()
ans[ans.index(a)]=b
print(ans[0],ans[1]) | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
Input Specification:
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output Specification:
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
Demo Input:
['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n']
Demo Output:
['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n']
Note:
In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | ```python
ans = input().split()
n = int(input())
while(n is not 0):
print(ans[0],ans[1])
a,b=input().split()
ans[ans.index(a)]=b
print(ans[0],ans[1])
``` | -1 | |
932 | C | Permutation Cycle | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms"
] | null | null | For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows:
Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists.
For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=*N*, *g*(*i*) equals either *A* or *B*. | The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*). | If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*. | [
"9 2 5\n",
"3 2 1\n"
] | [
"6 5 8 3 4 1 9 2 7",
"1 2 3 "
] | In the first example, *g*(1) = *g*(6) = *g*(7) = *g*(9) = 2 and *g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5
In the second example, *g*(1) = *g*(2) = *g*(3) = 1 | 1,500 | [
{
"input": "9 2 5",
"output": "2 1 4 3 6 7 8 9 5 "
},
{
"input": "3 2 1",
"output": "1 2 3 "
},
{
"input": "7 4 4",
"output": "-1"
},
{
"input": "1000000 999998 3",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "993012 997 1001",
... | 1,680,724,165 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
N,A,B = map(int, input().split())
dp = [-1]*(N+1)
dp[0] = 0
for a in (A,B):
for i in range(a,N+1):
if dp[i-a]!=-1:
dp[i] = a
if dp[-1]==-1:
exit(print(-1))
dat = []
i = N
while i>0 and dp[i]>0:
dat.append(dp[i])
i-=dp[i]
ans = []
cur = 1
for a in dat:
tmp = [i for i in range(cur+1,cur+a)]+[cur]
cur+=a
ans+=tmp
print(ans)
| Title: Permutation Cycle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows:
Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists.
For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=*N*, *g*(*i*) equals either *A* or *B*.
Input Specification:
The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*).
Output Specification:
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*.
Demo Input:
['9 2 5\n', '3 2 1\n']
Demo Output:
['6 5 8 3 4 1 9 2 7', '1 2 3 ']
Note:
In the first example, *g*(1) = *g*(6) = *g*(7) = *g*(9) = 2 and *g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5
In the second example, *g*(1) = *g*(2) = *g*(3) = 1 | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N,A,B = map(int, input().split())
dp = [-1]*(N+1)
dp[0] = 0
for a in (A,B):
for i in range(a,N+1):
if dp[i-a]!=-1:
dp[i] = a
if dp[-1]==-1:
exit(print(-1))
dat = []
i = N
while i>0 and dp[i]>0:
dat.append(dp[i])
i-=dp[i]
ans = []
cur = 1
for a in dat:
tmp = [i for i in range(cur+1,cur+a)]+[cur]
cur+=a
ans+=tmp
print(ans)
``` | 0 | |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,675,517,756 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 28,774,400 | n = str(input())
a = []
a1 = list(map(int , input().split()))
for el in a1 :
if(el in a):
continue
else:
if(a1.count(el) == 1):
continue
else:
a.append(el)
count = 0
for i in a :
count += (a1.count(i)-1)
print(count) | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Output Specification:
Print the only number — the minimum number of changes needed to get the permutation.
Demo Input:
['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n']
Demo Output:
['0\n', '1\n', '2\n']
Note:
The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | ```python
n = str(input())
a = []
a1 = list(map(int , input().split()))
for el in a1 :
if(el in a):
continue
else:
if(a1.count(el) == 1):
continue
else:
a.append(el)
count = 0
for i in a :
count += (a1.count(i)-1)
print(count)
``` | 0 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,545,288,615 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 0 | k=int(input())
n=int(input())
s=int(input())
p=int(input())
if n%s==0:
t=int(n/s)
else:
t=int(n/s)+1
jk=k*t
if jk%p==0:
ans=int(jk/p)
else:
ans=int(jk/p)+1
print(ans)
| Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
Input Specification:
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output Specification:
Print a single integer — the minimum number of packs they should buy.
Demo Input:
['5 3 2 3\n', '5 3 100 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | ```python
k=int(input())
n=int(input())
s=int(input())
p=int(input())
if n%s==0:
t=int(n/s)
else:
t=int(n/s)+1
jk=k*t
if jk%p==0:
ans=int(jk/p)
else:
ans=int(jk/p)+1
print(ans)
``` | -1 | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,474,890,946 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 108 | 9,011,200 | input()
a = [int(i) for i in input().split()]
a.sort()
b = [i for i in a if i != a[0] and i != a[-1]]
if a[0] == a[-1] or (a.count(a[0]) + a.count(a[-1])) == len(a):
print("YES")
elif b[0] == b[-1] and (a[0] + a[-1]) // 2 == b[0]:
print("YES")
else:
print("NO")
| Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
Demo Input:
['5\n1 3 3 2 1\n', '5\n1 2 3 4 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | ```python
input()
a = [int(i) for i in input().split()]
a.sort()
b = [i for i in a if i != a[0] and i != a[-1]]
if a[0] == a[-1] or (a.count(a[0]) + a.count(a[-1])) == len(a):
print("YES")
elif b[0] == b[-1] and (a[0] + a[-1]) // 2 == b[0]:
print("YES")
else:
print("NO")
``` | 0 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,684,736,917 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 27 | 46 | 0 | """
A. Brain's Photos: implementation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Small, but very brave, mouse Brain was not accepted to summer school of young villains.
He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form.
But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color.
There are only 6 colors:
'C' (cyan)
'M' (magenta)
'Y' (yellow)
'W' (white)
'G' (grey)
'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it.
If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row.
Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
"""
def brain_photos():
n, m = map(int, input().split(' '))
for i in range(n):
c = list(input().split(' '))
if 'C' in c or 'M' in c or 'Y' in c:
print('#Color')
else:
print('#Black&White')
if __name__ == '__main__':
brain_photos() | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none | ```python
"""
A. Brain's Photos: implementation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Small, but very brave, mouse Brain was not accepted to summer school of young villains.
He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form.
But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color.
There are only 6 colors:
'C' (cyan)
'M' (magenta)
'Y' (yellow)
'W' (white)
'G' (grey)
'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it.
If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row.
Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
"""
def brain_photos():
n, m = map(int, input().split(' '))
for i in range(n):
c = list(input().split(' '))
if 'C' in c or 'M' in c or 'Y' in c:
print('#Color')
else:
print('#Black&White')
if __name__ == '__main__':
brain_photos()
``` | 0 | |
846 | B | Math Show | PROGRAMMING | 1,800 | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1.
Polycarp has *M* minutes of time. What is the maximum number of points he can earn? | The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | 0 | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"outpu... | 1,504,629,294 | 5,394 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n,k,M = map(int, input().split())
a = list(map(int,input().split()))
res = 0
ball = 0
if sum(a)<M:
for i in range(n*k):
if res<M:
a.append(i)
res+=a[i]
ball+=1
else:
for i in a:
if res<M:
for j in range(1,n):
if res<=M and i!=1:
res+=j*i
ball+=1
if i == 1:
res+=n
ball+=n
break
else:
break
else:
break
print(ball)
| Title: Math Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all *k* of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is *k*<=+<=1.
Polycarp has *M* minutes of time. What is the maximum number of points he can earn?
Input Specification:
The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task.
Output Specification:
Print the maximum amount of points Polycarp can earn in *M* minutes.
Demo Input:
['3 4 11\n1 2 3 4\n', '5 5 10\n1 2 4 8 16\n']
Demo Output:
['6\n', '7\n']
Note:
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | ```python
n,k,M = map(int, input().split())
a = list(map(int,input().split()))
res = 0
ball = 0
if sum(a)<M:
for i in range(n*k):
if res<M:
a.append(i)
res+=a[i]
ball+=1
else:
for i in a:
if res<M:
for j in range(1,n):
if res<=M and i!=1:
res+=j*i
ball+=1
if i == 1:
res+=n
ball+=n
break
else:
break
else:
break
print(ball)
``` | 0 | |
702 | B | Powers of Two | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"implementation",
"math"
] | null | null | You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=<<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*). | The first line contains the single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the number of pairs of indexes *i*,<=*j* (*i*<=<<=*j*) that *a**i*<=+<=*a**j* is a power of 2. | [
"4\n7 3 2 1\n",
"3\n1 1 1\n"
] | [
"2\n",
"3\n"
] | In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).
In the second example all pairs of indexes (*i*, *j*) (where *i* < *j*) include in answer. | 0 | [
{
"input": "4\n7 3 2 1",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "10\n2827343 1373647 96204862 723505 796619138 71550121 799843967 5561265 402690754 446173607",
"output": "2"
},
{
"input": "1... | 1,661,663,476 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 155 | 20,275,200 | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
w = Counter(map(int, input().split()))
d = []
c = 0
for i in range(31):
d.append(2**i)
for i in w:
for j in d:
if j > i:
x = j-i
if x == i:
c += w[i]*(w[i]-1)
elif x in w:
c += w[x]*w[i]
print(c//2)
| Title: Powers of Two
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Find the number of pairs of indexes *i*,<=*j* (*i*<=<<=*j*) that *a**i*<=+<=*a**j* is a power of 2 (i. e. some integer *x* exists so that *a**i*<=+<=*a**j*<==<=2*x*).
Input Specification:
The first line contains the single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the number of pairs of indexes *i*,<=*j* (*i*<=<<=*j*) that *a**i*<=+<=*a**j* is a power of 2.
Demo Input:
['4\n7 3 2 1\n', '3\n1 1 1\n']
Demo Output:
['2\n', '3\n']
Note:
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).
In the second example all pairs of indexes (*i*, *j*) (where *i* < *j*) include in answer. | ```python
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
w = Counter(map(int, input().split()))
d = []
c = 0
for i in range(31):
d.append(2**i)
for i in w:
for j in d:
if j > i:
x = j-i
if x == i:
c += w[i]*(w[i]-1)
elif x in w:
c += w[x]*w[i]
print(c//2)
``` | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,694,593,327 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 10 | 62 | 0 | import sys
input = sys.stdin.readline
def main() -> None :
N:int = int(input())
maximumValue:int = 0
tableValues:list[list[int]] = [[1]*N for _ in range(N)]
for rowIndex in range(1, N) :
for colIndex in range(1, N) :
tableValues[rowIndex][colIndex] = tableValues[rowIndex-1][colIndex]+tableValues[rowIndex][colIndex-1]
maximumValue = tableValues[-1][-1]
print(maximumValue)
main() | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
import sys
input = sys.stdin.readline
def main() -> None :
N:int = int(input())
maximumValue:int = 0
tableValues:list[list[int]] = [[1]*N for _ in range(N)]
for rowIndex in range(1, N) :
for colIndex in range(1, N) :
tableValues[rowIndex][colIndex] = tableValues[rowIndex-1][colIndex]+tableValues[rowIndex][colIndex-1]
maximumValue = tableValues[-1][-1]
print(maximumValue)
main()
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,665,477,020 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | nn=[int(i) for i in input().split()]
yy=[int(i) for i in input().split()]
yy.sort()
k=yy[:nn[1]]
m1=-sum(k)
m2=0
for y in k:
if y<0:
m2-=y
if m1>m2:
print(m1)
else:
print(m2) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
nn=[int(i) for i in input().split()]
yy=[int(i) for i in input().split()]
yy.sort()
k=yy[:nn[1]]
m1=-sum(k)
m2=0
for y in k:
if y<0:
m2-=y
if m1>m2:
print(m1)
else:
print(m2)
``` | 3.977 |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*). | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,553,798,518 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 216 | 0 | n, x, y = map(int, input().strip().split())
answer = max(0, - ((-y * n)//100) - x)
print(answer) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | ```python
n, x, y = map(int, input().strip().split())
answer = max(0, - ((-y * n)//100) - x)
print(answer)
``` | 3 | |
887 | B | Cubes for Masha | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. | In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. | Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. | [
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n"
] | [
"87",
"98"
] | In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | 1,000 | [
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7",
"output": "87"
},
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9",
"output": "98"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8",
... | 1,514,464,141 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import numpy as np
n=int(input())
a=np.zeros((n, 6), dtype=np.int)
for i in range(n):
a[i]=input().strip().split()
def maxout(a):
for k in range(1,10):
if k not in a:
out=k-1
break
elif k==9 and 0 in a:
for i in range(n):
if 1 in a[i,:]:
for j in range(n) and j!=i:
if 0 in a[j:]:
for p in range(1,10):
if list(a.reshape(n*6,)).count(p)<2:
out=p*10+p-1
break
else:
out=9
break
elif k==9 and o not in a:
out=9
break
maxout(a) | Title: Cubes for Masha
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
Input Specification:
In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube.
Output Specification:
Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1.
Demo Input:
['3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n', '3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n']
Demo Output:
['87', '98']
Note:
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | ```python
import numpy as np
n=int(input())
a=np.zeros((n, 6), dtype=np.int)
for i in range(n):
a[i]=input().strip().split()
def maxout(a):
for k in range(1,10):
if k not in a:
out=k-1
break
elif k==9 and 0 in a:
for i in range(n):
if 1 in a[i,:]:
for j in range(n) and j!=i:
if 0 in a[j:]:
for p in range(1,10):
if list(a.reshape(n*6,)).count(p)<2:
out=p*10+p-1
break
else:
out=9
break
elif k==9 and o not in a:
out=9
break
maxout(a)
``` | -1 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,498,814,019 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 5,529,600 | x, y = input(), input()
n = len(x)
z = y
for i in range(n):
if x[i] < y[i]:
print(-1)
break
else:
print(''.join(z)) | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
Input Specification:
The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
Output Specification:
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
Demo Input:
['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n']
Demo Output:
['ba\n', 'xiyez\n', '-1\n']
Note:
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | ```python
x, y = input(), input()
n = len(x)
z = y
for i in range(n):
if x[i] < y[i]:
print(-1)
break
else:
print(''.join(z))
``` | 3 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,658,947,764 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 93 | 8,806,400 | n = int(input())
lst = list(map(int, input().split()))
counter = 0
maxs = max(lst)
mins = min(lst)
for i in range(n):
if lst[i] != maxs and lst[i] != mins:
counter += 1
print(counter) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
n = int(input())
lst = list(map(int, input().split()))
counter = 0
maxs = max(lst)
mins = min(lst)
for i in range(n):
if lst[i] != maxs and lst[i] != mins:
counter += 1
print(counter)
``` | 3 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0.
As usual, Alyona has some troubles and asks you to help. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case. | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,609,327,485 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 717 | 307,200 | n,m = map(int,input().split())
one,two,three,four,five, = 0,0,0,0,0
for i in range(4,max(n,m)+1,5):
one+=1
for i in range(3,max(n,m)+1,5):
two+=1
for i in range(2,max(n,m)+1,5):
three+=1
for i in range(1,max(n,m)+1,5):
four+=1
for i in range(5,max(n,m)+1,5):
five+=1
count=0
for i in range(1,min(n,m)+1):
if i%5==1: count+=one
elif i%5==2: count+=two
elif i%5==3: count+=three
elif i%5==4: count+=four
else: count+=five
print(count) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and equals 0.
As usual, Alyona has some troubles and asks you to help.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Output Specification:
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
Demo Input:
['6 12\n', '11 14\n', '1 5\n', '3 8\n', '5 7\n', '21 21\n']
Demo Output:
['14\n', '31\n', '1\n', '5\n', '7\n', '88\n']
Note:
Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case. | ```python
n,m = map(int,input().split())
one,two,three,four,five, = 0,0,0,0,0
for i in range(4,max(n,m)+1,5):
one+=1
for i in range(3,max(n,m)+1,5):
two+=1
for i in range(2,max(n,m)+1,5):
three+=1
for i in range(1,max(n,m)+1,5):
four+=1
for i in range(5,max(n,m)+1,5):
five+=1
count=0
for i in range(1,min(n,m)+1):
if i%5==1: count+=one
elif i%5==2: count+=two
elif i%5==3: count+=three
elif i%5==4: count+=four
else: count+=five
print(count)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,569,764,082 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 124 | 0 | first = [int(i) for i in input()]
last =[int(i) for i in input()]
for i in range(0, len(first)):
if first[i] !=last[i]:
print("1", end="")
else:
print("0", end="")
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
first = [int(i) for i in input()]
last =[int(i) for i in input()]
for i in range(0, len(first)):
if first[i] !=last[i]:
print("1", end="")
else:
print("0", end="")
``` | 3.969 |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,530,193,270 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 93 | 0 | piso = input()
pasos = 1
piso = str(int(piso) + 1)
while "8" not in piso :
piso = str(int(piso) + 1)
pasos +=1
print(pasos)
| Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number.
Input Specification:
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Output Specification:
Print the minimum *b* in a line.
Demo Input:
['179\n', '-1\n', '18\n']
Demo Output:
['1\n', '9\n', '10\n']
Note:
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | ```python
piso = input()
pasos = 1
piso = str(int(piso) + 1)
while "8" not in piso :
piso = str(int(piso) + 1)
pasos +=1
print(pasos)
``` | 3 | |
414 | B | Mashmokh and ACM | PROGRAMMING | 1,400 | [
"combinatorics",
"dp",
"number theory"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.
A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1).
Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). | The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). | Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). | [
"3 2\n",
"6 4\n",
"2 1\n"
] | [
"5\n",
"39\n",
"2\n"
] | In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | 1,000 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "6 4",
"output": "39"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "1478 194",
"output": "312087753"
},
{
"input": "1415 562",
"output": "953558593"
},
{
"input": "1266 844",
"output": "735042656"
... | 1,564,047,286 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 2,560,000 | import numpy as np
def solve():
N = 2005
div = list()
for i in range(N):
temp_list = set()
div.append(temp_list)
sqrt = int(N**(0.5))+1
i = 1
while i <= sqrt:
j = i
while i*j < (N-1):
if(i*j>=N):
break
div[i*j].add(i)
div[i*j].add(j)
j += 1
i += 1
i = 0
return div
n, k = map(int,input().split())
dp = list()
for i in range(n+1):
temp = list()
dp.append(temp)
for j in range(k+1):
dp[i].append(0)
for i in range(n+1):
dp[i][1] = 1
div = solve()
i = 2
while i<=k:
j = 1
while j<=n:
for num in div[j]:
dp[j][i] += dp[num][i-1]
j += 1
i += 1
i = 1
ans = 0
MOD = 1000000007
while i<=n:
ans += dp[i][k]
i += 1
print(ans%MOD) | Title: Mashmokh and ACM
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.
A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1).
Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output Specification:
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
Demo Input:
['3 2\n', '6 4\n', '2 1\n']
Demo Output:
['5\n', '39\n', '2\n']
Note:
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3]. | ```python
import numpy as np
def solve():
N = 2005
div = list()
for i in range(N):
temp_list = set()
div.append(temp_list)
sqrt = int(N**(0.5))+1
i = 1
while i <= sqrt:
j = i
while i*j < (N-1):
if(i*j>=N):
break
div[i*j].add(i)
div[i*j].add(j)
j += 1
i += 1
i = 0
return div
n, k = map(int,input().split())
dp = list()
for i in range(n+1):
temp = list()
dp.append(temp)
for j in range(k+1):
dp[i].append(0)
for i in range(n+1):
dp[i][1] = 1
div = solve()
i = 2
while i<=k:
j = 1
while j<=n:
for num in div[j]:
dp[j][i] += dp[num][i-1]
j += 1
i += 1
i = 1
ans = 0
MOD = 1000000007
while i<=n:
ans += dp[i][k]
i += 1
print(ans%MOD)
``` | -1 | |
416 | C | Booking System | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"greedy",
"implementation"
] | null | null | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.
We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.
Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.
Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.
The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table. | In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.
If there are multiple optimal answers, print any of them. | [
"3\n10 50\n2 100\n5 30\n3\n4 6 9\n"
] | [
"2 130\n2 1\n3 2\n"
] | none | 1,500 | [
{
"input": "3\n10 50\n2 100\n5 30\n3\n4 6 9",
"output": "2 130\n2 1\n3 2"
},
{
"input": "1\n1 1\n1\n1",
"output": "1 1\n1 1"
},
{
"input": "1\n2 1\n1\n1",
"output": "0 0"
},
{
"input": "2\n10 10\n5 5\n1\n5",
"output": "1 5\n2 1"
},
{
"input": "2\n10 10\n5 5\n1\n10... | 1,640,101,984 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 124 | 3,481,600 | import sys
def readline():
return sys.stdin.readline().strip()
def read(t=int):
s = sys.stdin.readline()
return list(map(t, s.strip().split(' ')))
def readint():
return read()[0]
def go():
n = readint()
cplist = []
for i in range(n):
c, p = read()
cplist += [(c, p)]
k = readint()
rlist = sorted([(r, i) for i, r in enumerate(read(), 1)])
cplist = sorted([(i, v) for i, v in enumerate(cplist, 1)],
key=lambda x: -x[1][1])
res = 0
cnt = 0
www = []
for ii, v in cplist:
c, p = v
for i, (r, index) in enumerate(rlist):
if r >= c and r > 0:
res += p
cnt += 1
rlist[i] = (-1, index)
www += [[ii, index]]
break
print(cnt, res)
for i in www:
ind, v = i
print(ind, v)
go()
| Title: Booking System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i* and *p**i* — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.
We know that for each request, all *c**i* people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.
Unfortunately, there only are *k* tables in the restaurant. For each table, we know *r**i* — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.
Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.
The next line contains integer *k* (1<=≤<=*k*<=≤<=1000) — the number of tables in the restaurant. The last line contains *k* space-separated integers: *r*1,<=*r*2,<=...,<=*r**k* (1<=≤<=*r**i*<=≤<=1000) — the maximum number of people that can sit at each table.
Output Specification:
In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.
If there are multiple optimal answers, print any of them.
Demo Input:
['3\n10 50\n2 100\n5 30\n3\n4 6 9\n']
Demo Output:
['2 130\n2 1\n3 2\n']
Note:
none | ```python
import sys
def readline():
return sys.stdin.readline().strip()
def read(t=int):
s = sys.stdin.readline()
return list(map(t, s.strip().split(' ')))
def readint():
return read()[0]
def go():
n = readint()
cplist = []
for i in range(n):
c, p = read()
cplist += [(c, p)]
k = readint()
rlist = sorted([(r, i) for i, r in enumerate(read(), 1)])
cplist = sorted([(i, v) for i, v in enumerate(cplist, 1)],
key=lambda x: -x[1][1])
res = 0
cnt = 0
www = []
for ii, v in cplist:
c, p = v
for i, (r, index) in enumerate(rlist):
if r >= c and r > 0:
res += p
cnt += 1
rlist[i] = (-1, index)
www += [[ii, index]]
break
print(cnt, res)
for i in www:
ind, v = i
print(ind, v)
go()
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practice.
Applying the simplest variant of median smoothing to the sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* will result a new sequence *b*1,<=*b*2,<=...,<=*b**n* obtained by the following algorithm:
- *b*1<==<=*a*1, *b**n*<==<=*a**n*, that is, the first and the last number of the new sequence match the corresponding numbers of the original sequence. - For *i*<==<=2,<=...,<=*n*<=-<=1 value *b**i* is equal to the median of three values *a**i*<=-<=1, *a**i* and *a**i*<=+<=1.
The median of a set of three numbers is the number that goes on the second place, when these three numbers are written in the non-decreasing order. For example, the median of the set 5, 1, 2 is number 2, and the median of set 1, 0, 1 is equal to 1.
In order to make the task easier, Vasya decided to apply the method to sequences consisting of zeros and ones only.
Having made the procedure once, Vasya looked at the resulting sequence and thought: what if I apply the algorithm to it once again, and then apply it to the next result, and so on? Vasya tried a couple of examples and found out that after some number of median smoothing algorithm applications the sequence can stop changing. We say that the sequence is stable, if it does not change when the median smoothing is applied to it.
Now Vasya wonders, whether the sequence always eventually becomes stable. He asks you to write a program that, given a sequence of zeros and ones, will determine whether it ever becomes stable. Moreover, if it ever becomes stable, then you should determine what will it look like and how many times one needs to apply the median smoothing algorithm to initial sequence in order to obtain a stable one. | The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself. | If the sequence will never become stable, print a single number <=-<=1.
Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space — the resulting sequence itself. | [
"4\n0 0 1 1\n",
"5\n0 1 0 1 0\n"
] | [
"0\n0 0 1 1\n",
"2\n0 0 0 0 0\n"
] | In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable. | 0 | [
{
"input": "4\n0 0 1 1",
"output": "0\n0 0 1 1"
},
{
"input": "5\n0 1 0 1 0",
"output": "2\n0 0 0 0 0"
},
{
"input": "3\n1 0 0",
"output": "0\n1 0 0"
},
{
"input": "4\n1 0 0 1",
"output": "0\n1 0 0 1"
},
{
"input": "7\n1 0 1 1 1 0 1",
"output": "1\n1 1 1 1 1 1... | 1,453,983,206 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
n = int(input())
a = [i for i in input().split()]
big = True
zeros = True
if a[0] == "1":
zeros = False
final = ["0" for i in range(n)]
final[0] = a[0]
final[n-1] = a[n-1]
f = 0
for i in range(1, n-1):
if big and zeros and a[i] == "1":
big = False
if big and not zeros and a[i] == "0":
big = False
if a[i] == a[i-1]:
big = True
if a[i] == "0":
zeros = True
else:
zeros = False
if big:
final[i] = a[i]
else:
if zeros and a[i] == "1":
f += 1
if not zeros and a[i] == "0":
f += 1
if zeros:
final[i] = "0"
else:
final[i] = "1"
print(f)
print(" ".join(final))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practice.
Applying the simplest variant of median smoothing to the sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* will result a new sequence *b*1,<=*b*2,<=...,<=*b**n* obtained by the following algorithm:
- *b*1<==<=*a*1, *b**n*<==<=*a**n*, that is, the first and the last number of the new sequence match the corresponding numbers of the original sequence. - For *i*<==<=2,<=...,<=*n*<=-<=1 value *b**i* is equal to the median of three values *a**i*<=-<=1, *a**i* and *a**i*<=+<=1.
The median of a set of three numbers is the number that goes on the second place, when these three numbers are written in the non-decreasing order. For example, the median of the set 5, 1, 2 is number 2, and the median of set 1, 0, 1 is equal to 1.
In order to make the task easier, Vasya decided to apply the method to sequences consisting of zeros and ones only.
Having made the procedure once, Vasya looked at the resulting sequence and thought: what if I apply the algorithm to it once again, and then apply it to the next result, and so on? Vasya tried a couple of examples and found out that after some number of median smoothing algorithm applications the sequence can stop changing. We say that the sequence is stable, if it does not change when the median smoothing is applied to it.
Now Vasya wonders, whether the sequence always eventually becomes stable. He asks you to write a program that, given a sequence of zeros and ones, will determine whether it ever becomes stable. Moreover, if it ever becomes stable, then you should determine what will it look like and how many times one needs to apply the median smoothing algorithm to initial sequence in order to obtain a stable one.
Input Specification:
The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself.
Output Specification:
If the sequence will never become stable, print a single number <=-<=1.
Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space — the resulting sequence itself.
Demo Input:
['4\n0 0 1 1\n', '5\n0 1 0 1 0\n']
Demo Output:
['0\n0 0 1 1\n', '2\n0 0 0 0 0\n']
Note:
In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable. | ```python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
n = int(input())
a = [i for i in input().split()]
big = True
zeros = True
if a[0] == "1":
zeros = False
final = ["0" for i in range(n)]
final[0] = a[0]
final[n-1] = a[n-1]
f = 0
for i in range(1, n-1):
if big and zeros and a[i] == "1":
big = False
if big and not zeros and a[i] == "0":
big = False
if a[i] == a[i-1]:
big = True
if a[i] == "0":
zeros = True
else:
zeros = False
if big:
final[i] = a[i]
else:
if zeros and a[i] == "1":
f += 1
if not zeros and a[i] == "0":
f += 1
if zeros:
final[i] = "0"
else:
final[i] = "1"
print(f)
print(" ".join(final))
``` | 0 | |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different. | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,592,110,304 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 108 | 409,600 | def getLetterFreq(text):
letterFreq = {}
for i in range(len(text)):
if text[i] in letterFreq:
letterFreq[text[i]] += 1
else:
letterFreq[text[i]] = 1
return letterFreq
def countMinWordFreq(letterFreq):
s = {'l': 1, 'B': 1, 'b': 2, 'a': 2, 'u': 2, 's': 1, 'r': 1}
minWordFreq = int()
if 'B' in letterFreq.keys():
minWordFreq = letterFreq['B']
else:
return 0
for letter in s.keys():
if letter in letterFreq.keys():
minWordFreq = min(letterFreq[letter] // s[letter], minWordFreq)
else:
return 0
return minWordFreq
print(countMinWordFreq(getLetterFreq(input()))) | Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
Input Specification:
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
Output Specification:
Output a single integer, the answer to the problem.
Demo Input:
['Bulbbasaur\n', 'F\n', 'aBddulbasaurrgndgbualdBdsagaurrgndbb\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | ```python
def getLetterFreq(text):
letterFreq = {}
for i in range(len(text)):
if text[i] in letterFreq:
letterFreq[text[i]] += 1
else:
letterFreq[text[i]] = 1
return letterFreq
def countMinWordFreq(letterFreq):
s = {'l': 1, 'B': 1, 'b': 2, 'a': 2, 'u': 2, 's': 1, 'r': 1}
minWordFreq = int()
if 'B' in letterFreq.keys():
minWordFreq = letterFreq['B']
else:
return 0
for letter in s.keys():
if letter in letterFreq.keys():
minWordFreq = min(letterFreq[letter] // s[letter], minWordFreq)
else:
return 0
return minWordFreq
print(countMinWordFreq(getLetterFreq(input())))
``` | 0 | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem. | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day. | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,643,030,994 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 873 | 12,288,000 | x,y=input().split()
n=int(x)
f=int(y)
l=[]
k=[]
k1=[]
l1=[]
d=[]
s=0
m=0
for i in range (n):
x,y=input().split()
k.append(int(x))
l.append(int(y))
for i in range(n):
if(k[i]>=l[i]):
s+=l[i]
else:
l1.append(l[i])
k1.append(k[i])
d.append(min(k[i]*2,l[i]))
r=d
ma=sorted(r)[len(d)-f:]
for i in range(len(d)):
if d[i] in ma:
s+=d[i]
ma.remove(d[i])
else:
s+=k1[i]
print(s)
| Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manager knows exactly, that in *i*-th day *k**i* products will be put up for sale and exactly *l**i* clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any *f* days from *n* next for sell-outs. On each of *f* chosen days the number of products were put up for sale would be doubled. Thus, if on *i*-th day shop planned to put up for sale *k**i* products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·*k**i* products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose *f* days to maximize total number of sold products. She asks you to help her with such a difficult problem.
Input Specification:
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denoting the number of products on the shelves of the shop on the *i*-th day and the number of clients that will come to the shop on *i*-th day.
Output Specification:
Print a single integer denoting the maximal number of products that shop can sell.
Demo Input:
['4 2\n2 1\n3 5\n2 3\n1 5\n', '4 1\n0 2\n0 3\n3 5\n0 6\n']
Demo Output:
['10', '5']
Note:
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | ```python
x,y=input().split()
n=int(x)
f=int(y)
l=[]
k=[]
k1=[]
l1=[]
d=[]
s=0
m=0
for i in range (n):
x,y=input().split()
k.append(int(x))
l.append(int(y))
for i in range(n):
if(k[i]>=l[i]):
s+=l[i]
else:
l1.append(l[i])
k1.append(k[i])
d.append(min(k[i]*2,l[i]))
r=d
ma=sorted(r)[len(d)-f:]
for i in range(len(d)):
if d[i] in ma:
s+=d[i]
ma.remove(d[i])
else:
s+=k1[i]
print(s)
``` | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,650,650,928 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | n = int(input())
res = 0
lis1 = input()
lis2 = input()
for i in range(n):
a = abs(max( int(lis1[i]),int(lis2[i]) ) - 10 ) + min( int(lis1[i]) , int(lis2[i]))
b = abs(int(lis1[i]) - int(lis2[i]))
res += min(a, b)
print(res) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Output Specification:
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Demo Input:
['5\n82195\n64723\n']
Demo Output:
['13\n']
Note:
In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = int(input())
res = 0
lis1 = input()
lis2 = input()
for i in range(n):
a = abs(max( int(lis1[i]),int(lis2[i]) ) - 10 ) + min( int(lis1[i]) , int(lis2[i]))
b = abs(int(lis1[i]) - int(lis2[i]))
res += min(a, b)
print(res)
``` | 3 | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,622,707,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 109 | 0 | temp = [int(x) for x in input().split()]
n = temp[0]
k = temp[1]
s = input().strip()
s = sorted(s)
counter = 1
bool = True
for i in range(1, n):
if s[i] == s[i-1]:
counter += 1
else:
if counter > k:
print('NO')
bool = False
break
else:
counter = 1
if bool:
print('YES')
| Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
temp = [int(x) for x in input().split()]
n = temp[0]
k = temp[1]
s = input().strip()
s = sorted(s)
counter = 1
bool = True
for i in range(1, n):
if s[i] == s[i-1]:
counter += 1
else:
if counter > k:
print('NO')
bool = False
break
else:
counter = 1
if bool:
print('YES')
``` | 0 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,689,078,710 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | import bisect
# Read the number of shops
n = int(input())
# Read the prices of the bottles
prices = list(map(int, input().split()))
# Calculate the prefix sum array
prefix_sums = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sums[i] = prefix_sums[i - 1] + prices[i - 1]
# Read the number of days
q = int(input())
# Process each query
for _ in range(q):
# Read the number of coins Vasiliy can spend
coins = int(input())
# Find the index where the prefix sum exceeds the coins
index = bisect.bisect_right(prefix_sums, coins)
# Print the number of shops Vasiliy can buy from
print(index)
| Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Output Specification:
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
Demo Input:
['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n']
Demo Output:
['0\n4\n1\n5\n']
Note:
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | ```python
import bisect
# Read the number of shops
n = int(input())
# Read the prices of the bottles
prices = list(map(int, input().split()))
# Calculate the prefix sum array
prefix_sums = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sums[i] = prefix_sums[i - 1] + prices[i - 1]
# Read the number of days
q = int(input())
# Process each query
for _ in range(q):
# Read the number of coins Vasiliy can spend
coins = int(input())
# Find the index where the prefix sum exceeds the coins
index = bisect.bisect_right(prefix_sums, coins)
# Print the number of shops Vasiliy can buy from
print(index)
``` | 0 | |
870 | A | Search for Pretty Integers | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | 500 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,573,815,637 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 0 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
w=min(a)
w1=min(b)
q=set(a).intersection(set(b))
if len(q)!=0:
print(min(q))
else:
print("{}{}".format(min(w,w1),max(w,w1))) | Title: Search for Pretty Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Output Specification:
Print the smallest pretty integer.
Demo Input:
['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n']
Demo Output:
['25\n', '1\n']
Note:
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer. | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
w=min(a)
w1=min(b)
q=set(a).intersection(set(b))
if len(q)!=0:
print(min(q))
else:
print("{}{}".format(min(w,w1),max(w,w1)))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1.
Your task is to find out if it is possible to rearrange characters in string *s* so that for any prime number *p*<=≤<=|*s*| and for any integer *i* ranging from 1 to |*s*|<=/<=*p* (inclusive) the following condition was fulfilled *s**p*<==<=*s**p*<=×<=*i*. If the answer is positive, find one way to rearrange the characters. | The only line contains the initial string *s*, consisting of small Latin letters (1<=≤<=|*s*|<=≤<=1000). | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | [
"abc\n",
"abcd\n",
"xxxyxxx\n"
] | [
"YES\nabc\n",
"NO\n",
"YES\nxxxxxxy\n"
] | In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".
In the second sample no letter permutation will satisfy the condition at *p* = 2 (*s*<sub class="lower-index">2</sub> = *s*<sub class="lower-index">4</sub>).
In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | 0 | [
{
"input": "abc",
"output": "YES\nabc"
},
{
"input": "abcd",
"output": "NO"
},
{
"input": "xxxyxxx",
"output": "YES\nxxxxxxy"
},
{
"input": "xxxjddyxduquybxdxx",
"output": "NO"
},
{
"input": "jjjjjjjjjjzjjjjjjjjjjjjjjjj",
"output": "YES\njjjjjjjjjjjjjjjjjjjjjj... | 1,676,115,393 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 100 | 154 | 2,252,800 | from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZ = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "n" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZ))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZ))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def solve():
s = input()
n = len(s)
if n < 4:
print("YES")
print(s)
return
# Getting the primes till N
ps = [_ & 1 if _ != 1 else 0 for _ in range(n+1)]
ps[2] = 1
primes = []
for i in range(2, n+1):
if i == 1:
continue
cnt = i
while i * cnt < n:
ps[i * cnt] = 0
cnt += 2
if ps[i]:
primes.append(i)
count = Counter(s)
com = count.most_common()[0][0]
# every symbol except first until n // 2 should have to be the same.
# imagine we have prime P, then next prime for that number will be 2 * P.
# if 2 * P <= N, then this should be the same number as 2
ans = ["" for _ in range(n)]
for prime in primes:
if prime > n:
break
if prime <= n >> 1:
for i in range(prime - 1, n, prime):
if not ans[i]:
ans[i] = com
count[com] -= 1
if count[com] < 0:
print("NO")
return
# Deal with leftovers
for i in range(n):
if not ans[i]:
while not count[next(iter(count))[0]]:
del count[next(iter(count))[0]]
k = next(iter(count))[0]
ans[i] = k
count[k] -= 1
print("YES", "".join(ans), sep="\n")
solve()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s*, consisting of small Latin letters. Let's denote the length of the string as |*s*|. The characters in the string are numbered starting from 1.
Your task is to find out if it is possible to rearrange characters in string *s* so that for any prime number *p*<=≤<=|*s*| and for any integer *i* ranging from 1 to |*s*|<=/<=*p* (inclusive) the following condition was fulfilled *s**p*<==<=*s**p*<=×<=*i*. If the answer is positive, find one way to rearrange the characters.
Input Specification:
The only line contains the initial string *s*, consisting of small Latin letters (1<=≤<=|*s*|<=≤<=1000).
Output Specification:
If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO".
Demo Input:
['abc\n', 'abcd\n', 'xxxyxxx\n']
Demo Output:
['YES\nabc\n', 'NO\n', 'YES\nxxxxxxy\n']
Note:
In the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".
In the second sample no letter permutation will satisfy the condition at *p* = 2 (*s*<sub class="lower-index">2</sub> = *s*<sub class="lower-index">4</sub>).
In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | ```python
from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZ = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "n" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZ))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZ))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def solve():
s = input()
n = len(s)
if n < 4:
print("YES")
print(s)
return
# Getting the primes till N
ps = [_ & 1 if _ != 1 else 0 for _ in range(n+1)]
ps[2] = 1
primes = []
for i in range(2, n+1):
if i == 1:
continue
cnt = i
while i * cnt < n:
ps[i * cnt] = 0
cnt += 2
if ps[i]:
primes.append(i)
count = Counter(s)
com = count.most_common()[0][0]
# every symbol except first until n // 2 should have to be the same.
# imagine we have prime P, then next prime for that number will be 2 * P.
# if 2 * P <= N, then this should be the same number as 2
ans = ["" for _ in range(n)]
for prime in primes:
if prime > n:
break
if prime <= n >> 1:
for i in range(prime - 1, n, prime):
if not ans[i]:
ans[i] = com
count[com] -= 1
if count[com] < 0:
print("NO")
return
# Deal with leftovers
for i in range(n):
if not ans[i]:
while not count[next(iter(count))[0]]:
del count[next(iter(count))[0]]
k = next(iter(count))[0]
ans[i] = k
count[k] -= 1
print("YES", "".join(ans), sep="\n")
solve()
``` | 3 | |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes. | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,653,142,087 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 46 | 0 | import sys
input = sys.stdin.readline
n = int(input())
g = sorted([list(map(int, input().split())) for _ in range(n)])
if n == 1:
print(-1)
elif n == 2:
if g[0][0] == g[1][0] or g[0][1] == g[1][1]:
print(-1)
else:
print(abs(g[0][0] - g[1][0]) * abs(g[0][1] - g[1][1]))
else:
for i in g[1:]:
if i[0] != g[0][0] and i[1] != g[0][1]:
print(abs(g[0][0] - i[0]) * abs(g[0][1] - i[1]))
break | Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output Specification:
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1.
Demo Input:
['2\n0 0\n1 1\n', '1\n1 1\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | ```python
import sys
input = sys.stdin.readline
n = int(input())
g = sorted([list(map(int, input().split())) for _ in range(n)])
if n == 1:
print(-1)
elif n == 2:
if g[0][0] == g[1][0] or g[0][1] == g[1][1]:
print(-1)
else:
print(abs(g[0][0] - g[1][0]) * abs(g[0][1] - g[1][1]))
else:
for i in g[1:]:
if i[0] != g[0][0] and i[1] != g[0][1]:
print(abs(g[0][0] - i[0]) * abs(g[0][1] - i[1]))
break
``` | 0 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,583,830,251 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 109 | 307,200 | s = input()
l = []
l1 = [" " for i in range(len(s))]
for i in range(len(s)):
l1[i] = s[i]
d1 = ["a","b","c"]
set1 = set({})
for i in range(1,len(l1)-1):
if l1[i] == l1[i-1]:
if abs(ord(l1[i]) - ord(l1[i+1])) > 1:
l1[i] = chr((ord(l1[i])+ord(l1[i+1])//2))
else:
if l1[i] == "y" or l1[i] == "z":
l1[i] = "a"
else:
l1[i] = chr(ord(l1[i])+2)
if l1[-1] == l1[-2]:
if l1[-2] != "b":
l1[-1] = "b"
else:
l1[-1] = "m"
print("".join(l1))
| Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
Input Specification:
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Output Specification:
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters.
Demo Input:
['aab\n', 'caaab\n', 'zscoder\n']
Demo Output:
['bab\n', 'cabab\n', 'zscoder\n']
Note:
none | ```python
s = input()
l = []
l1 = [" " for i in range(len(s))]
for i in range(len(s)):
l1[i] = s[i]
d1 = ["a","b","c"]
set1 = set({})
for i in range(1,len(l1)-1):
if l1[i] == l1[i-1]:
if abs(ord(l1[i]) - ord(l1[i+1])) > 1:
l1[i] = chr((ord(l1[i])+ord(l1[i+1])//2))
else:
if l1[i] == "y" or l1[i] == "z":
l1[i] = "a"
else:
l1[i] = chr(ord(l1[i])+2)
if l1[-1] == l1[-2]:
if l1[-2] != "b":
l1[-1] = "b"
else:
l1[-1] = "m"
print("".join(l1))
``` | -1 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,665,579,158 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
A = 0
B = 0
C = 0
for i in range(n):
a,b,c = [int(d) for d in input().split()]
A = A+a
B = B+b
C = C+c
if A == 0 and B == 0 and C == 0:
print('YES')
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
A = 0
B = 0
C = 0
for i in range(n):
a,b,c = [int(d) for d in input().split()]
A = A+a
B = B+b
C = C+c
if A == 0 and B == 0 and C == 0:
print('YES')
else:
print("NO")
``` | 3.977 |
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
... | 1,670,338,742 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
if n < 4:
if n == 1:
print(0)
elif n == 2:
print(3)
else:
print(6)
a, b = 6, 3
for i in range(n - 3):
b, a = a, (3 * b + 2 * a) % 1000000007
print(a)
| Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
if n < 4:
if n == 1:
print(0)
elif n == 2:
print(3)
else:
print(6)
a, b = 6, 3
for i in range(n - 3):
b, a = a, (3 * b + 2 * a) % 1000000007
print(a)
``` | 0 | |
515 | C | Drazil and Factorial | PROGRAMMING | 1,400 | [
"greedy",
"math",
"sortings"
] | null | null | Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. | Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. | [
"4\n1234\n",
"3\n555\n"
] | [
"33222\n",
"555\n"
] | In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "4\n1234",
"output": "33222"
},
{
"input": "3\n555",
"output": "555"
},
{
"input": "15\n012345781234578",
"output": "7777553333222222222222"
},
{
"input": "1\n8",
"output": "7222"
},
{
"input": "10\n1413472614",
"output": "75333332222222"
},
{
... | 1,620,366,314 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 93 | 20,172,800 | import math
def primeNum(num):
for i in range(2, int(math.pow(num, 0.5)) + 1):
if num % i == 0:
return False
return True
n = int(input())
a = list(map(int, input()))
ans = []
for i in range(len(a)):
if a[i] == 0 or a[i] == 1:
pass
elif primeNum(a[i]):
ans.append(a[i])
else:
while not primeNum(a[i]):
A = a[i]
div = 2
while A != 1:
if A % div == 0:
ans.append(div)
A //= div
else:
div += 1
a[i] -= 1
ans.append(a[i])
ans.sort(reverse=True)
print("".join(map(str, ans)))
| Title: Drazil and Factorial
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil is playing a math game with Varda.
Let's define for positive integer *x* as a product of factorials of its digits. For example, .
First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions:
1. *x* doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*.
The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output Specification:
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Demo Input:
['4\n1234\n', '3\n555\n']
Demo Output:
['33222\n', '555\n']
Note:
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
def primeNum(num):
for i in range(2, int(math.pow(num, 0.5)) + 1):
if num % i == 0:
return False
return True
n = int(input())
a = list(map(int, input()))
ans = []
for i in range(len(a)):
if a[i] == 0 or a[i] == 1:
pass
elif primeNum(a[i]):
ans.append(a[i])
else:
while not primeNum(a[i]):
A = a[i]
div = 2
while A != 1:
if A % div == 0:
ans.append(div)
A //= div
else:
div += 1
a[i] -= 1
ans.append(a[i])
ans.sort(reverse=True)
print("".join(map(str, ans)))
``` | 0 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,433,770,027 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n = int(input())
s = ''; ans = 0
while n > 0:
m = int("".join(['1' if d != '0' else '0' for d in str(n)]))
n -= m
if n >= 0:
ans += 1
s += str(m) + ' '
print(ans, s, sep='\n') | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
Output Specification:
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Demo Input:
['9\n', '32\n']
Demo Output:
['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n']
Note:
none | ```python
n = int(input())
s = ''; ans = 0
while n > 0:
m = int("".join(['1' if d != '0' else '0' for d in str(n)]))
n -= m
if n >= 0:
ans += 1
s += str(m) + ' '
print(ans, s, sep='\n')
``` | 3 | |
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 9983201... | 1,661,371,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 31 | 0 | a,b,s = map(int,input().split())
if (not ((a+b-s) % 2)) and (s >= a+b):
print('Yes')
else:
print('No')
| Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
Input Specification:
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
Output Specification:
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes".
Demo Input:
['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n']
Demo Output:
['No\n', 'Yes\n', 'No\n', 'Yes\n']
Note:
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
a,b,s = map(int,input().split())
if (not ((a+b-s) % 2)) and (s >= a+b):
print('Yes')
else:
print('No')
``` | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,590,765,482 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 0 | n,m= map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
count =0
i =0
while(i<m):
if(arr[i]>=0):
break
count+=arr[i]
i+=1
print(abs(count))
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
n,m= map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
count =0
i =0
while(i<m):
if(arr[i]>=0):
break
count+=arr[i]
i+=1
print(abs(count))
``` | 3.9455 |
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"... | 1,677,691,298 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | import math
n, m, a = [ int(x) for x in input().split() ]
c = 1
while m*n > c*a*a:
c += 1
if not m*n == a*a:
while c % 2:
c += 1
print(c) | 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
import math
n, m, a = [ int(x) for x in input().split() ]
c = 1
while m*n > c*a*a:
c += 1
if not m*n == a*a:
while c % 2:
c += 1
print(c)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the *i*-th day this value is equal to *m**i*.
Define *d**i* as the number of marks strictly under the water level on the *i*-th day. You are to find out the minimum possible sum of *d**i* over all days. There are no marks on the channel before the first day. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of days.
The second line contains *n* space-separated integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=<<=*i*) — the number of marks strictly above the water on each day. | Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days. | [
"6\n0 1 0 3 0 2\n",
"5\n0 1 2 1 2\n",
"5\n0 1 1 2 2\n"
] | [
"6\n",
"1\n",
"0\n"
] | In the first example, the following figure shows an optimal case.
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case. | 0 | [
{
"input": "6\n0 1 0 3 0 2",
"output": "6"
},
{
"input": "5\n0 1 2 1 2",
"output": "1"
},
{
"input": "5\n0 1 1 2 2",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "100\n0 1 2 2 3 0 1 5 6 6 0 0 8 7 1 9 9 4 10 11 12 2 12 12 12 12 9 13 14 8 15 15 15... | 1,587,401,917 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | N = int(input())
M = list(map(int, input().split()))
s = 0
for i in range(1, N - 1):
if M[i] < M[i - 1]:
s += max(M[i - 1] - M[i], M[i + 1] - M[i])
s += max(0, M[N - 2] - M[N - 1])
print(s)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady decides to observe a river for *n* consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the *i*-th day this value is equal to *m**i*.
Define *d**i* as the number of marks strictly under the water level on the *i*-th day. You are to find out the minimum possible sum of *d**i* over all days. There are no marks on the channel before the first day.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of days.
The second line contains *n* space-separated integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=<<=*i*) — the number of marks strictly above the water on each day.
Output Specification:
Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days.
Demo Input:
['6\n0 1 0 3 0 2\n', '5\n0 1 2 1 2\n', '5\n0 1 1 2 2\n']
Demo Output:
['6\n', '1\n', '0\n']
Note:
In the first example, the following figure shows an optimal case.
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case. | ```python
N = int(input())
M = list(map(int, input().split()))
s = 0
for i in range(1, N - 1):
if M[i] < M[i - 1]:
s += max(M[i - 1] - M[i], M[i + 1] - M[i])
s += max(0, M[N - 2] - M[N - 1])
print(s)
``` | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,689,265,155 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
th = n // 2
th += 1 if n % 2 == 1 else 0
for i in range(n):
if i % 2 == 0:
print('I hate ', end = '')
else:
print('I love ', end = '')
if th > 0:
print('that ', end = "")
th -= 1
print("it") | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
n = int(input())
th = n // 2
th += 1 if n % 2 == 1 else 0
for i in range(n):
if i % 2 == 0:
print('I hate ', end = '')
else:
print('I love ', end = '')
if th > 0:
print('that ', end = "")
th -= 1
print("it")
``` | 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": "tymbzjyqhymeda... | 1,663,178,072 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | s = input()
h = 'hello'
j = pas = 0
for i in s:
if i == h[j]:
j += 1
pas += 1
if pas == 5:
break
if pas == 5:
print('YES')
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
h = 'hello'
j = pas = 0
for i in s:
if i == h[j]:
j += 1
pas += 1
if pas == 5:
break
if pas == 5:
print('YES')
else:
print('NO')
``` | 3.977 |
909 | B | Segments | PROGRAMMING | 1,300 | [
"constructive algorithms",
"math"
] | null | null | You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*. | The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100). | Output a single integer - the minimal number of layers required to draw the segments for the given *N*. | [
"2\n",
"3\n",
"4\n"
] | [
"2\n",
"4\n",
"6\n"
] | As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | 1,000 | [
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "4"
},
{
"input": "4",
"output": "6"
},
{
"input": "21",
"output": "121"
},
{
"input": "100",
"output": "2550"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "9"
... | 1,590,906,762 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n = int(input())
res = 1
norig = n
n -= 1
seglen = 2
while(n > 0):
if(norig//seglen >=2):
if(n%2 == 1):
res += (n-1)/2 + 1
else:
res += n/2
else:
res += n
n-=1
seglen += 1
print(int(res))
| Title: Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given *N*.
Input Specification:
The only input line contains a single integer *N* (1<=≤<=*N*<=≤<=100).
Output Specification:
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
Demo Input:
['2\n', '3\n', '4\n']
Demo Output:
['2\n', '4\n', '6\n']
Note:
As an example, here are the segments and their optimal arrangement into layers for *N* = 4. | ```python
n = int(input())
res = 1
norig = n
n -= 1
seglen = 2
while(n > 0):
if(norig//seglen >=2):
if(n%2 == 1):
res += (n-1)/2 + 1
else:
res += n/2
else:
res += n
n-=1
seglen += 1
print(int(res))
``` | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,677,359,960 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <list>
using namespace std;
int main()
{
int numOfEvents;
cin >> numOfEvents;
int* events = new int[numOfEvents];
int countCrime = 0;
for (int i = 0; i < numOfEvents; i++)
{
cin >> events[i];
}
int numPolice = 0;
for (int i = 0; i < numOfEvents; i++)
{
if (events[i] > 0)
numPolice += events[i];
else if (events[i] == -1)
{
if (numPolice > 0)
numPolice--;
else
countCrime++;
}
}
cout << countCrime;
return 0;
}
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <list>
using namespace std;
int main()
{
int numOfEvents;
cin >> numOfEvents;
int* events = new int[numOfEvents];
int countCrime = 0;
for (int i = 0; i < numOfEvents; i++)
{
cin >> events[i];
}
int numPolice = 0;
for (int i = 0; i < numOfEvents; i++)
{
if (events[i] > 0)
numPolice += events[i];
else if (events[i] == -1)
{
if (numPolice > 0)
numPolice--;
else
countCrime++;
}
}
cout << countCrime;
return 0;
}
``` | -1 | |
590 | D | Top Secret Task | PROGRAMMING | 2,300 | [
"dp"
] | null | null | A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. According to the charter, each top-secret military base must include a top-secret troop that should... well, we cannot tell you exactly what it should do, it is a top secret troop at the end. The problem is that Zuev's base is missing this top-secret troop for some reasons.
The colonel decided to deal with the problem immediately and ordered to line up in a single line all *n* soldiers of the base entrusted to him. Zuev knows that the loquacity of the *i*-th soldier from the left is equal to *q**i*. Zuev wants to form the top-secret troop using *k* leftmost soldiers in the line, thus he wants their total loquacity to be as small as possible (as the troop should remain top-secret). To achieve this, he is going to choose a pair of consecutive soldiers and swap them. He intends to do so no more than *s* times. Note that any soldier can be a participant of such swaps for any number of times. The problem turned out to be unusual, and colonel Zuev asked you to help.
Determine, what is the minimum total loquacity of the first *k* soldiers in the line, that can be achieved by performing no more than *s* swaps of two consecutive soldiers. | The first line of the input contains three positive integers *n*, *k*, *s* (1<=≤<=*k*<=≤<=*n*<=≤<=150, 1<=≤<=*s*<=≤<=109) — the number of soldiers in the line, the size of the top-secret troop to be formed and the maximum possible number of swap operations of the consecutive pair of soldiers, respectively.
The second line of the input contains *n* integer *q**i* (1<=≤<=*q**i*<=≤<=1<=000<=000) — the values of loquacity of soldiers in order they follow in line from left to right. | Print a single integer — the minimum possible total loquacity of the top-secret troop. | [
"3 2 2\n2 4 1\n",
"5 4 2\n10 1 6 2 5\n",
"5 2 3\n3 1 4 2 5\n"
] | [
"3\n",
"18\n",
"3\n"
] | In the first sample Colonel has to swap second and third soldiers, he doesn't really need the remaining swap. The resulting soldiers order is: (2, 1, 4). Minimum possible summary loquacity of the secret troop is 3. In the second sample Colonel will perform swaps in the following order:
1. (10, 1, 6 — 2, 5) 1. (10, 1, 2, 6 — 5)
The resulting soldiers order is (10, 1, 2, 5, 6).
Minimum possible summary loquacity is equal to 18. | 1,750 | [] | 1,689,595,126 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689595126.081517")# 1689595126.0815375 | Title: Top Secret Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. According to the charter, each top-secret military base must include a top-secret troop that should... well, we cannot tell you exactly what it should do, it is a top secret troop at the end. The problem is that Zuev's base is missing this top-secret troop for some reasons.
The colonel decided to deal with the problem immediately and ordered to line up in a single line all *n* soldiers of the base entrusted to him. Zuev knows that the loquacity of the *i*-th soldier from the left is equal to *q**i*. Zuev wants to form the top-secret troop using *k* leftmost soldiers in the line, thus he wants their total loquacity to be as small as possible (as the troop should remain top-secret). To achieve this, he is going to choose a pair of consecutive soldiers and swap them. He intends to do so no more than *s* times. Note that any soldier can be a participant of such swaps for any number of times. The problem turned out to be unusual, and colonel Zuev asked you to help.
Determine, what is the minimum total loquacity of the first *k* soldiers in the line, that can be achieved by performing no more than *s* swaps of two consecutive soldiers.
Input Specification:
The first line of the input contains three positive integers *n*, *k*, *s* (1<=≤<=*k*<=≤<=*n*<=≤<=150, 1<=≤<=*s*<=≤<=109) — the number of soldiers in the line, the size of the top-secret troop to be formed and the maximum possible number of swap operations of the consecutive pair of soldiers, respectively.
The second line of the input contains *n* integer *q**i* (1<=≤<=*q**i*<=≤<=1<=000<=000) — the values of loquacity of soldiers in order they follow in line from left to right.
Output Specification:
Print a single integer — the minimum possible total loquacity of the top-secret troop.
Demo Input:
['3 2 2\n2 4 1\n', '5 4 2\n10 1 6 2 5\n', '5 2 3\n3 1 4 2 5\n']
Demo Output:
['3\n', '18\n', '3\n']
Note:
In the first sample Colonel has to swap second and third soldiers, he doesn't really need the remaining swap. The resulting soldiers order is: (2, 1, 4). Minimum possible summary loquacity of the secret troop is 3. In the second sample Colonel will perform swaps in the following order:
1. (10, 1, 6 — 2, 5) 1. (10, 1, 2, 6 — 5)
The resulting soldiers order is (10, 1, 2, 5, 6).
Minimum possible summary loquacity is equal to 18. | ```python
print("_RANDOM_GUESS_1689595126.081517")# 1689595126.0815375
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,633,267,749 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def main() -> None:
a = input()
b = input()
s = ''
for i in range(len(a)):
s += '0' if a[i] != b[i] else '1'
print(s)
if __name__ == "__main__":
main()
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
def main() -> None:
a = input()
b = input()
s = ''
for i in range(len(a)):
s += '0' if a[i] != b[i] else '1'
print(s)
if __name__ == "__main__":
main()
``` | 0 |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,687,905,792 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 31 | 0 | import sys
def read_input():
return sys.stdin.readline().rstrip()
str1 = "I hate"
str2 = "I love"
num1 = int(read_input())
output = []
for x in range(num1):
if x % 2 == 0:
output.append(str1)
else:
output.append(str2)
output[-1] += " it"
print(" that ".join(output))
import sys | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none | ```python
import sys
def read_input():
return sys.stdin.readline().rstrip()
str1 = "I hate"
str2 = "I love"
num1 = int(read_input())
output = []
for x in range(num1):
if x % 2 == 0:
output.append(str1)
else:
output.append(str2)
output[-1] += " it"
print(" that ".join(output))
import sys
``` | 3 | |
870 | B | Maximum of Maximums of Minimums | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* > 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is *min*( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. | 1,000 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,602,359,600 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | first_line = input().split(" ")
array_size = first_line[0]
subsegments = first_line[1]
# print(subsegments)
array = input().split(" ")
array.sort(reverse=True)
# print(array)
if (subsegments == 1):
print(array[-1])
else:
print(array[0])
| Title: Maximum of Maximums of Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109).
Output Specification:
Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments.
Demo Input:
['5 2\n1 2 3 4 5\n', '5 1\n-4 -5 -3 -2 -1\n']
Demo Output:
['5\n', '-5\n']
Note:
A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index">1</sub>], [*l*<sub class="lower-index">2</sub>, *r*<sub class="lower-index">2</sub>], ..., [*l*<sub class="lower-index">*k*</sub>, *r*<sub class="lower-index">*k*</sub>] (*l*<sub class="lower-index">1</sub> = 1, *r*<sub class="lower-index">*k*</sub> = *n*, *l*<sub class="lower-index">*i*</sub> = *r*<sub class="lower-index">*i* - 1</sub> + 1 for all *i* > 1) is *k* sequences (*a*<sub class="lower-index">*l*<sub class="lower-index">1</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">1</sub></sub>), ..., (*a*<sub class="lower-index">*l*<sub class="lower-index">*k*</sub></sub>, ..., *a*<sub class="lower-index">*r*<sub class="lower-index">*k*</sub></sub>).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are *min*(1, 2, 3, 4) = 1 and *min*(5) = 5. The resulting maximum is *max*(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is *min*( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. | ```python
first_line = input().split(" ")
array_size = first_line[0]
subsegments = first_line[1]
# print(subsegments)
array = input().split(" ")
array.sort(reverse=True)
# print(array)
if (subsegments == 1):
print(array[-1])
else:
print(array[0])
``` | 0 | |
234 | B | Reading | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all *n* hours of the trip — *n* numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose *k* hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours. | The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour. | In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers *b**i* in an arbitrary order. | [
"5 3\n20 10 30 40 10\n",
"6 5\n90 20 35 40 60 100\n"
] | [
"20\n1 3 4 \n",
"35\n1 3 4 5 6 \n"
] | In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | 0 | [
{
"input": "5 3\n20 10 30 40 10",
"output": "20\n1 3 4 "
},
{
"input": "6 5\n90 20 35 40 60 100",
"output": "35\n1 3 4 5 6 "
},
{
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 2... | 1,620,260,159 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,963,200 | input = open("input.txt","r")
totalhours = input.readline()
wantedHours = input.readline()
wantedHours = int(wantedHours)
lights = input.readline().split()
readingHours = ""
minLight = min(lights)
for i in range(wantedHours):
bestLighting = max(lights)
bestHour = lights.index(bestLighting)
bestLighting = int(bestLighting)
if bestLighting < minLight:
minLight = bestLighting
lights[bestHour] = -1
readingHours+= str(bestHour +1)+" "
output = open("output.txt","w")
mango.write(bestLighting)
mango.write(readingHours)
| Title: Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all *n* hours of the trip — *n* numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose *k* hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours.
Input Specification:
The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour.
Output Specification:
In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers *b**i* in an arbitrary order.
Demo Input:
['5 3\n20 10 30 40 10\n', '6 5\n90 20 35 40 60 100\n']
Demo Output:
['20\n1 3 4 \n', '35\n1 3 4 5 6 \n']
Note:
In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | ```python
input = open("input.txt","r")
totalhours = input.readline()
wantedHours = input.readline()
wantedHours = int(wantedHours)
lights = input.readline().split()
readingHours = ""
minLight = min(lights)
for i in range(wantedHours):
bestLighting = max(lights)
bestHour = lights.index(bestLighting)
bestLighting = int(bestLighting)
if bestLighting < minLight:
minLight = bestLighting
lights[bestHour] = -1
readingHours+= str(bestHour +1)+" "
output = open("output.txt","w")
mango.write(bestLighting)
mango.write(readingHours)
``` | -1 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,691,596,969 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 60 | 0 | n = int(input())
l = list(map(int, input().split()))
l1 = l.copy()
l1.sort()
if l1[0]==l1[1]:
print("Still Rozdil")
else:
mini = l1[0]
index = 0
for i in range(len(l)):
if l[i] == mini:
index = i
break
print(index+1) | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Output Specification:
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
Demo Input:
['2\n7 4\n', '7\n7 4 47 100 4 9 12\n']
Demo Output:
['2\n', 'Still Rozdil\n']
Note:
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | ```python
n = int(input())
l = list(map(int, input().split()))
l1 = l.copy()
l1.sort()
if l1[0]==l1[1]:
print("Still Rozdil")
else:
mini = l1[0]
index = 0
for i in range(len(l)):
if l[i] == mini:
index = i
break
print(index+1)
``` | -1 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,696,845,842 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def output(s1, s2, string):
if (len(s1) + len(s2)) != len(string):
return "NO"
for letter in string:
if letter in s1:
s1.replace(letter, "_")
if letter in s2:
s2.replace(letter, "_")
for letter in s1:
if letter != "_":
return "NO"
for letter in s2:
if letter != "_":
return "NO"
return "YES"
s1, s2 = "", ""
shuffle_str = ""
for i in range(3):
s1 = input()
s2 = input()
shuffle_str = input()
print(output(s1, s2, shuffle_str))
| Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
Input Specification:
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Output Specification:
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
Demo Input:
['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | ```python
def output(s1, s2, string):
if (len(s1) + len(s2)) != len(string):
return "NO"
for letter in string:
if letter in s1:
s1.replace(letter, "_")
if letter in s2:
s2.replace(letter, "_")
for letter in s1:
if letter != "_":
return "NO"
for letter in s2:
if letter != "_":
return "NO"
return "YES"
s1, s2 = "", ""
shuffle_str = ""
for i in range(3):
s1 = input()
s2 = input()
shuffle_str = input()
print(output(s1, s2, shuffle_str))
``` | -1 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,658,580,479 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 156 | 10,547,200 | # -*- coding: utf-8 -*-
"""
Created on Sat Jul 23 13:44:33 2022
@author: Conor
CFSheet A Problem 22 - CF709-DIV2A
"""
numorange, maxSize, oflow = map(int,input().split())
oranges = list(map(int,input().split()))
runSize = 0
ans = 0
for i in range(numorange):
if oranges[i] <= maxSize:
runSize += oranges[i]
if runSize > oflow:
ans += 1
runSize = 0
print(ans) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 23 13:44:33 2022
@author: Conor
CFSheet A Problem 22 - CF709-DIV2A
"""
numorange, maxSize, oflow = map(int,input().split())
oranges = list(map(int,input().split()))
runSize = 0
ans = 0
for i in range(numorange):
if oranges[i] <= maxSize:
runSize += oranges[i]
if runSize > oflow:
ans += 1
runSize = 0
print(ans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out *n* numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no two pluses in such a partition can stand together (between any two adjacent pluses there must be at least one digit), and no plus can stand at the beginning or the end of a line. For example, in the string 100500, ways 100500 (add no pluses), 1+00+500 or 10050+0 are correct, and ways 100++500, +1+0+0+5+0+0 or 100500+ are incorrect.
The lesson was long, and Vasya has written all the correct ways to place exactly *k* pluses in a string of digits. At this point, he got caught having fun by a teacher and he was given the task to calculate the sum of all the resulting arithmetic expressions by the end of the lesson (when calculating the value of an expression the leading zeros should be ignored). As the answer can be large, Vasya is allowed to get only its remainder modulo 109<=+<=7. Help him! | The first line contains two integers, *n* and *k* (0<=≤<=*k*<=<<=*n*<=≤<=105).
The second line contains a string consisting of *n* digits. | Print the answer to the problem modulo 109<=+<=7. | [
"3 1\n108\n",
"3 2\n108\n"
] | [
"27",
"9"
] | In the first sample the result equals (1 + 08) + (10 + 8) = 27.
In the second sample the result equals 1 + 0 + 8 = 9. | 0 | [
{
"input": "3 1\n108",
"output": "27"
},
{
"input": "3 2\n108",
"output": "9"
},
{
"input": "1 0\n5",
"output": "5"
},
{
"input": "5 2\n39923",
"output": "2667"
},
{
"input": "6 3\n967181",
"output": "3506"
},
{
"input": "7 1\n2178766",
"output": "... | 1,535,327,399 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 1,684 | 7,065,600 | n, k = map(int, input().split())
t = list(map(int, input()))
p, d = 1, 10 ** 9 + 7
s, f = 0, [1] * n
for i in range(2, n): f[i] = (i * f[i - 1]) % d
c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b - a], d - 2, d)) % d
if k:
u = [0] * (n + 1)
p = [1] * (n + 1)
for i in range(n):
u[i] = (p[i] * c(k - 1, n - 2 - i) + u[i - 1]) % d
p[i + 1] = (10 * p[i]) % d
for i in range(n):
v = u[n - 2 - i] + p[n - 1 - i] * c(k, i)
s = (s + t[i] * v) % d
else:
for i in t: s = (s * 10 + i) % d
print(s)
# Made By Mostafa_Khaled | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out *n* numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no two pluses in such a partition can stand together (between any two adjacent pluses there must be at least one digit), and no plus can stand at the beginning or the end of a line. For example, in the string 100500, ways 100500 (add no pluses), 1+00+500 or 10050+0 are correct, and ways 100++500, +1+0+0+5+0+0 or 100500+ are incorrect.
The lesson was long, and Vasya has written all the correct ways to place exactly *k* pluses in a string of digits. At this point, he got caught having fun by a teacher and he was given the task to calculate the sum of all the resulting arithmetic expressions by the end of the lesson (when calculating the value of an expression the leading zeros should be ignored). As the answer can be large, Vasya is allowed to get only its remainder modulo 109<=+<=7. Help him!
Input Specification:
The first line contains two integers, *n* and *k* (0<=≤<=*k*<=<<=*n*<=≤<=105).
The second line contains a string consisting of *n* digits.
Output Specification:
Print the answer to the problem modulo 109<=+<=7.
Demo Input:
['3 1\n108\n', '3 2\n108\n']
Demo Output:
['27', '9']
Note:
In the first sample the result equals (1 + 08) + (10 + 8) = 27.
In the second sample the result equals 1 + 0 + 8 = 9. | ```python
n, k = map(int, input().split())
t = list(map(int, input()))
p, d = 1, 10 ** 9 + 7
s, f = 0, [1] * n
for i in range(2, n): f[i] = (i * f[i - 1]) % d
c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b - a], d - 2, d)) % d
if k:
u = [0] * (n + 1)
p = [1] * (n + 1)
for i in range(n):
u[i] = (p[i] * c(k - 1, n - 2 - i) + u[i - 1]) % d
p[i + 1] = (10 * p[i]) % d
for i in range(n):
v = u[n - 2 - i] + p[n - 1 - i] * c(k, i)
s = (s + t[i] * v) % d
else:
for i in t: s = (s * 10 + i) % d
print(s)
# Made By Mostafa_Khaled
``` | 3 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,694,069,929 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 124 | 0 | n = int(input())
coins = list(map(int, input().split()))
coins.sort(reverse=True)
my_coins = 0
total_coins = sum(coins)
for i in range(n):
my_coins += coins[i]
total_coins -= coins[i]
if my_coins > total_coins:
print(i+1)
break
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | ```python
n = int(input())
coins = list(map(int, input().split()))
coins.sort(reverse=True)
my_coins = 0
total_coins = sum(coins)
for i in range(n):
my_coins += coins[i]
total_coins -= coins[i]
if my_coins > total_coins:
print(i+1)
break
``` | 3 | |
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"
... | 1,691,290,616 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | n = int(input())
l = []
ha = False
for i in range(n):
pq = list(map(int, input().split()))
l.append(pq)
l = sorted(l)
for m in range(n):
if l[m] > l[m+1]:
print("Happy Alex")
else:
print("Poor Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
n = int(input())
l = []
ha = False
for i in range(n):
pq = list(map(int, input().split()))
l.append(pq)
l = sorted(l)
for m in range(n):
if l[m] > l[m+1]:
print("Happy Alex")
else:
print("Poor Alex")
``` | -1 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,663,664,997 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | """
Code's Noob Coder
Từ Trường THPT Nguyễn Công Trứ
Từ Trường Đại học Bách Khoa - Đại học Quốc Gia TPHCM
"""
import itertools,sys
from operator import truediv
import math
INT_MAX = 9223372036854775807
INT_MIN = -9223372036854775807
MOD = 1e9 + 7
"""
Algorithm
"""
##################### memset #####################
def memset(a,Value,Size):
a[:] = bytearray(Size)
a[:] = itertools.repeat(Value,len(a))
return a
##################### Kadane Algorithm #####################
def Kadane_Algorithm(a):
max_so_far = INT_MIN
max_ending_here = 0
for i in a:
max_ending_here += i
max_so_far = max(max_ending_here,max_so_far)
max_ending_here = max(max_ending_here,0)
return max_so_far
##################### Sieve of Eratosthenes #####################
List_of_Prime_Number = []
lpf = []
def Sieve_of_Eratosthenes(n):
memset(List_of_Prime_Number,2,1)
memset(lpf,2,n+1)
x = 3
while x <= n:
if lpf[x] == 2:
List_of_Prime_Number.append(x)
lpf[x]=x
i = 0
while i < len(List_of_Prime_Number) and List_of_Prime_Number[i] <= lpf[x] and List_of_Prime_Number[i] * x <= n:
lpf[List_of_Prime_Number[i]*x] = List_of_Prime_Number[i]
i += 1
x += 2
"""
Data Structers
"""
##################### Fenwick Tree #####################
class Fenwick_Tree(object):
bit = []
def init(n):
memset(Fenwick_Tree.bit,0,n+1)
def Update_Point(i,v,n):
idx = i
while idx <= n:
Fenwick_Tree.bit[idx] += v;
idx += idx&(-idx)
def Update_Range(l,r,v,n):
Fenwick_Tree.Update_Point(l,v,n)
Fenwick_Tree.Update_Point(r+1,-v,n)
def Get_ai(r,n):
idx = r
res = 0
while idx > 0:
res += Fenwick_Tree.bit[idx]
idx -= idx&(-idx)
return res
##################### Segment Tree #####################
class Segment_Tree(object):
tree = []
def init(n):
Size = 1
while Size < n:
Size *= 2
memset(Segment_Tree.tree,0,Size*2)
return Size
def build(i,v,x,lx,rx):
if lx + 1 == rx:
Segment_Tree.tree[x] = v
return
mid = (lx + rx)/2
if i < mid:
Segment_Tree.build(i,v,2*x+1,lx,mid)
else:
Segment_Tree.build(i,v,2*x+2,mid,rx)
Segment_Tree.tree[x] = max(Segment_Tree.tree[2*x+1], Segment_Tree.tree[2*x+2])
def Query(l,r,x,lx,rx):
if l >= rx or r <= lx:
return INT_MIN
if l <= lx and rx <= r:
return Segment_Tree.tree[x]
mid = (lx + rx)/2
return max(Segment_Tree.Query(l,r,2*x+1,lx,mid), Segment_Tree.Query(l,r,2*x+2,mid,rx))
##################### Giải bài #####################
x = int(input())
temp = x
while True:
if temp - (temp & (-temp) ) == 0:
break
else:
temp-=temp&(-temp)
print(1 + x - temp) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
"""
Code's Noob Coder
Từ Trường THPT Nguyễn Công Trứ
Từ Trường Đại học Bách Khoa - Đại học Quốc Gia TPHCM
"""
import itertools,sys
from operator import truediv
import math
INT_MAX = 9223372036854775807
INT_MIN = -9223372036854775807
MOD = 1e9 + 7
"""
Algorithm
"""
##################### memset #####################
def memset(a,Value,Size):
a[:] = bytearray(Size)
a[:] = itertools.repeat(Value,len(a))
return a
##################### Kadane Algorithm #####################
def Kadane_Algorithm(a):
max_so_far = INT_MIN
max_ending_here = 0
for i in a:
max_ending_here += i
max_so_far = max(max_ending_here,max_so_far)
max_ending_here = max(max_ending_here,0)
return max_so_far
##################### Sieve of Eratosthenes #####################
List_of_Prime_Number = []
lpf = []
def Sieve_of_Eratosthenes(n):
memset(List_of_Prime_Number,2,1)
memset(lpf,2,n+1)
x = 3
while x <= n:
if lpf[x] == 2:
List_of_Prime_Number.append(x)
lpf[x]=x
i = 0
while i < len(List_of_Prime_Number) and List_of_Prime_Number[i] <= lpf[x] and List_of_Prime_Number[i] * x <= n:
lpf[List_of_Prime_Number[i]*x] = List_of_Prime_Number[i]
i += 1
x += 2
"""
Data Structers
"""
##################### Fenwick Tree #####################
class Fenwick_Tree(object):
bit = []
def init(n):
memset(Fenwick_Tree.bit,0,n+1)
def Update_Point(i,v,n):
idx = i
while idx <= n:
Fenwick_Tree.bit[idx] += v;
idx += idx&(-idx)
def Update_Range(l,r,v,n):
Fenwick_Tree.Update_Point(l,v,n)
Fenwick_Tree.Update_Point(r+1,-v,n)
def Get_ai(r,n):
idx = r
res = 0
while idx > 0:
res += Fenwick_Tree.bit[idx]
idx -= idx&(-idx)
return res
##################### Segment Tree #####################
class Segment_Tree(object):
tree = []
def init(n):
Size = 1
while Size < n:
Size *= 2
memset(Segment_Tree.tree,0,Size*2)
return Size
def build(i,v,x,lx,rx):
if lx + 1 == rx:
Segment_Tree.tree[x] = v
return
mid = (lx + rx)/2
if i < mid:
Segment_Tree.build(i,v,2*x+1,lx,mid)
else:
Segment_Tree.build(i,v,2*x+2,mid,rx)
Segment_Tree.tree[x] = max(Segment_Tree.tree[2*x+1], Segment_Tree.tree[2*x+2])
def Query(l,r,x,lx,rx):
if l >= rx or r <= lx:
return INT_MIN
if l <= lx and rx <= r:
return Segment_Tree.tree[x]
mid = (lx + rx)/2
return max(Segment_Tree.Query(l,r,2*x+1,lx,mid), Segment_Tree.Query(l,r,2*x+2,mid,rx))
##################### Giải bài #####################
x = int(input())
temp = x
while True:
if temp - (temp & (-temp) ) == 0:
break
else:
temp-=temp&(-temp)
print(1 + x - temp)
``` | 0 | |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,564,757,528 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 140 | 0 | N, M = map(int, input().split())
Queue = list(map(int, input().split()))
Entered, Number, i = 0, 0, 0
while i < N:
Entered += Queue[i]
if Entered > M:
Number, Entered, i = Number + 1, 0, i - 1
i += 1
print(Number + 1)
# UB_CodeForces
# Advice: " Do your best in all your time "
# Location: Behind my desk
# Caption: On the right way
# CodeNumber: 553
| Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Output Specification:
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
Demo Input:
['4 3\n2 3 2 1\n', '3 4\n1 2 1\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
N, M = map(int, input().split())
Queue = list(map(int, input().split()))
Entered, Number, i = 0, 0, 0
while i < N:
Entered += Queue[i]
if Entered > M:
Number, Entered, i = Number + 1, 0, i - 1
i += 1
print(Number + 1)
# UB_CodeForces
# Advice: " Do your best in all your time "
# Location: Behind my desk
# Caption: On the right way
# CodeNumber: 553
``` | 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"... | 1,605,734,107 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | n=int(input())
l=list(map(int,input().split()))
for i in range(1,len(l)):
if l[i]-l[i-1] %2!=0:
print(l[i])
break
| 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())
l=list(map(int,input().split()))
for i in range(1,len(l)):
if l[i]-l[i-1] %2!=0:
print(l[i])
break
``` | 0 |
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round. | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 ... | 1,564,048,902 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 0 | input();print(max(max(list(map(int,input().split())))-25,0)) | Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.
Input Specification:
The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Output Specification:
Print the minimum possible number of contestants that declined the invitation to compete onsite.
Demo Input:
['25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n', '5\n16 23 8 15 4\n', '3\n14 15 92\n']
Demo Output:
['3\n', '0\n', '67\n']
Note:
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | ```python
input();print(max(max(list(map(int,input().split())))-25,0))
``` | 3 | |
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",
"... | 1,621,276,898 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 0 | s = input()
pin = 'a'
count = 0
for char in s:
if abs(ord(pin) - ord(char)) > 13:
count+= 26 - abs(ord(char) - ord(pin))
else:
count+= abs(ord(char) - ord(pin))
pin = char
print(count)
| 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
s = input()
pin = 'a'
count = 0
for char in s:
if abs(ord(pin) - ord(char)) > 13:
count+= 26 - abs(ord(char) - ord(pin))
else:
count+= abs(ord(char) - ord(pin))
pin = char
print(count)
``` | 3 | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.
You are given a binary string *s*. Your task is to find the number of its substrings, containing exactly *k* characters "1". | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,649,776,148 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | k = int(input())
d = {0: 1}
s = 0
for c in input():
s += int(c)
d[s] = d.get(s, 0) + 1
res = 0
for i in range(k, s+1):
res += d[i]*d[i-k]
print(res) | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.
You are given a binary string *s*. Your task is to find the number of its substrings, containing exactly *k* characters "1".
Input Specification:
The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters.
Output Specification:
Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['1\n1010\n', '2\n01010\n', '100\n01010\n']
Demo Output:
['6\n', '4\n', '0\n']
Note:
In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | ```python
k = int(input())
d = {0: 1}
s = 0
for c in input():
s += int(c)
d[s] = d.get(s, 0) + 1
res = 0
for i in range(k, s+1):
res += d[i]*d[i-k]
print(res)
``` | 0 | |
57 | C | Array | PROGRAMMING | 1,900 | [
"combinatorics",
"math"
] | C. Array | 2 | 256 | Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of *n*, containing only integers from 1 to *n*. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions:
- each elements, starting from the second one, is no more than the preceding one - each element, starting from the second one, is no less than the preceding one
Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last. | The single line contains an integer *n* which is the size of the array (1<=≤<=*n*<=≤<=105). | You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007. | [
"2\n",
"3\n"
] | [
"4\n",
"17\n"
] | none | 1,500 | [
{
"input": "2",
"output": "4"
},
{
"input": "3",
"output": "17"
},
{
"input": "12",
"output": "2704144"
},
{
"input": "19",
"output": "345263536"
},
{
"input": "20",
"output": "846527841"
},
{
"input": "26",
"output": "529476652"
},
{
"inpu... | 1,541,937,875 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 218 | 0 | def main():
bound=int(input())
arr=[1]*(bound)
for x in range(bound-1):
store=[]
sub=0
for y in range(len(arr)):
sub+=arr[y]
store.append(sub)
arr=store.copy()
print(2*sum(arr)-bound)
main()
| Title: Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of *n*, containing only integers from 1 to *n*. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions:
- each elements, starting from the second one, is no more than the preceding one - each element, starting from the second one, is no less than the preceding one
Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last.
Input Specification:
The single line contains an integer *n* which is the size of the array (1<=≤<=*n*<=≤<=105).
Output Specification:
You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007.
Demo Input:
['2\n', '3\n']
Demo Output:
['4\n', '17\n']
Note:
none | ```python
def main():
bound=int(input())
arr=[1]*(bound)
for x in range(bound-1):
store=[]
sub=0
for y in range(len(arr)):
sub+=arr[y]
store.append(sub)
arr=store.copy()
print(2*sum(arr)-bound)
main()
``` | 0 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,598,386,452 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 278 | 0 | sb=input();
c=0
s=0
s1=""
for ch in sb:
if ch.isupper():
c+=1
else:
s+=1
s1= sb.upper() if c>s else sb.lower()
print(s1) | 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
sb=input();
c=0
s=0
s1=""
for ch in sb:
if ch.isupper():
c+=1
else:
s+=1
s1= sb.upper() if c>s else sb.lower()
print(s1)
``` | 3.9305 |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task. | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them. | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,578,482,208 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 307,200 | length = int(input())
listofNum = input()
listofNum = list(map(int, listofNum.split()))
output = [0]*length
zeroPos = []
count = 0
for i in range(length):
if listofNum[i]==0:
count+=1
zeroPos.append(i)
for i in range(zeroPos[0],-1,-1):
output[i]+=zeroPos[0]-i
for i in range(zeroPos[count-1], length):
output[i] += i-zeroPos[count-1]
if count >= 2:
pos_1 = 0
pos_2 = 1
while(pos_2<count):
midpoint = int((zeroPos[pos_1]+zeroPos[pos_2])/2)
if(zeroPos[pos_2]-zeroPos[pos_1] != 1):
for i in range(zeroPos[pos_1], midpoint):
output[i] += i - zeroPos[pos_1]
for i in range(zeroPos[pos_2], midpoint - 1, -1):
output[i] += zeroPos[pos_2] - i
pos_1+=1
pos_2+=1
outputStr = ''
for x in output:
outputStr += str(x) + ' '
print(outputStr) | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input Specification:
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
Output Specification:
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them.
Demo Input:
['3\n', '4\n']
Demo Output:
['2\n1 1 2 ', '2\n2 1 1 2\n']
Note:
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | ```python
length = int(input())
listofNum = input()
listofNum = list(map(int, listofNum.split()))
output = [0]*length
zeroPos = []
count = 0
for i in range(length):
if listofNum[i]==0:
count+=1
zeroPos.append(i)
for i in range(zeroPos[0],-1,-1):
output[i]+=zeroPos[0]-i
for i in range(zeroPos[count-1], length):
output[i] += i-zeroPos[count-1]
if count >= 2:
pos_1 = 0
pos_2 = 1
while(pos_2<count):
midpoint = int((zeroPos[pos_1]+zeroPos[pos_2])/2)
if(zeroPos[pos_2]-zeroPos[pos_1] != 1):
for i in range(zeroPos[pos_1], midpoint):
output[i] += i - zeroPos[pos_1]
for i in range(zeroPos[pos_2], midpoint - 1, -1):
output[i] += zeroPos[pos_2] - i
pos_1+=1
pos_2+=1
outputStr = ''
for x in output:
outputStr += str(x) + ' '
print(outputStr)
``` | -1 | |
463 | A | Caisa and Sugar | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.
Unfortunately, he has just *s* dollars for sugar. But that's not a reason to be sad, because there are *n* types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).
Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change. | The first line contains two space-separated integers *n*,<=*s* (1<=≤<=*n*,<=*s*<=≤<=100).
The *i*-th of the next *n* lines contains two integers *x**i*, *y**i* (1<=≤<=*x**i*<=≤<=100; 0<=≤<=*y**i*<=<<=100), where *x**i* represents the number of dollars and *y**i* the number of cents needed in order to buy the *i*-th type of sugar. | Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar. | [
"5 10\n3 90\n12 0\n9 70\n5 50\n7 0\n",
"5 5\n10 10\n20 20\n30 30\n40 40\n50 50\n"
] | [
"50\n",
"-1\n"
] | In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change. | 500 | [
{
"input": "5 10\n3 90\n12 0\n9 70\n5 50\n7 0",
"output": "50"
},
{
"input": "5 5\n10 10\n20 20\n30 30\n40 40\n50 50",
"output": "-1"
},
{
"input": "1 2\n1 0",
"output": "0"
},
{
"input": "2 10\n20 99\n30 99",
"output": "-1"
},
{
"input": "15 21\n16 51\n33 44\n32 ... | 1,692,623,062 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 0 | n,m=map(int,input().split())
counter=-1
for i in range(n):
x,y=map(int,input().split())
if(m*100>=(x*100)+y):
counter=max(counter,(100-y)%100)
print(counter) | Title: Caisa and Sugar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.
Unfortunately, he has just *s* dollars for sugar. But that's not a reason to be sad, because there are *n* types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).
Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Input Specification:
The first line contains two space-separated integers *n*,<=*s* (1<=≤<=*n*,<=*s*<=≤<=100).
The *i*-th of the next *n* lines contains two integers *x**i*, *y**i* (1<=≤<=*x**i*<=≤<=100; 0<=≤<=*y**i*<=<<=100), where *x**i* represents the number of dollars and *y**i* the number of cents needed in order to buy the *i*-th type of sugar.
Output Specification:
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
Demo Input:
['5 10\n3 90\n12 0\n9 70\n5 50\n7 0\n', '5 5\n10 10\n20 20\n30 30\n40 40\n50 50\n']
Demo Output:
['50\n', '-1\n']
Note:
In the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change. | ```python
n,m=map(int,input().split())
counter=-1
for i in range(n):
x,y=map(int,input().split())
if(m*100>=(x*100)+y):
counter=max(counter,(100-y)%100)
print(counter)
``` | 3 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,471,586,732 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 701 | 14,438,400 | n, m = map(int, input().split())
a = input().split().count('1')
b = min(a, n - a) * 2
ans = []
for i in range(m):
l, r = map(int, input().split())
length = r - l + 1
ans += ['0'] if length % 2 or length > b else ['1']
print('\n'.join(ans))
| Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
Demo Input:
['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n']
Demo Output:
['0\n1\n0\n', '0\n1\n0\n1\n0\n']
Note:
none | ```python
n, m = map(int, input().split())
a = input().split().count('1')
b = min(a, n - a) * 2
ans = []
for i in range(m):
l, r = map(int, input().split())
length = r - l + 1
ans += ['0'] if length % 2 or length > b else ['1']
print('\n'.join(ans))
``` | 3 | |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year. | The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"ou... | 1,689,181,187 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689181187.149054")# 1689181187.149073 | Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=109) — current year in Berland.
Output Specification:
Output amount of years from the current year to the next lucky one.
Demo Input:
['4\n', '201\n', '4000\n']
Demo Output:
['1\n', '99\n', '1000\n']
Note:
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | ```python
print("_RANDOM_GUESS_1689181187.149054")# 1689181187.149073
``` | 0 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,687,090,263 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def solve(n):
"""
Solves the football uniform problem.
Args:
n: The number of teams.
Returns:
The number of games where the host team is going to play in the guest uniform.
"""
guest_colors = set()
for i in range(n):
hi, ai = map(int, input().split())
guest_colors.add(ai)
count = 0
for i in range(n):
for j in range(i + 1, n):
if hi == ai or aj == ai:
count += 1
return count
if __name__ == "__main__":
n = int(input())
print(solve(n))
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
def solve(n):
"""
Solves the football uniform problem.
Args:
n: The number of teams.
Returns:
The number of games where the host team is going to play in the guest uniform.
"""
guest_colors = set()
for i in range(n):
hi, ai = map(int, input().split())
guest_colors.add(ai)
count = 0
for i in range(n):
for j in range(i + 1, n):
if hi == ai or aj == ai:
count += 1
return count
if __name__ == "__main__":
n = int(input())
print(solve(n))
``` | -1 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.
Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=><=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.
Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test? | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5. | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,635,925 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def decompose_and_count(n, l, r):
sequence = [n]
while True:
if len(sequence) >= r:
break
current = sequence.pop(0)
if current > 1:
sequence.extend([current // 2, current % 2, current // 2])
else:
sequence.append(current)
return sequence[l-1:r].count(1)
n = int(input())
l = int(input())
r = int(input())
count = decompose_and_count(n, l, r)
print(count) # 输出:4
| Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.
Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=><=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.
Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?
Input Specification:
The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list.
Output Specification:
Output the total number of 1s in the range *l* to *r* in the final sequence.
Demo Input:
['7 2 5\n', '10 3 10\n']
Demo Output:
['4\n', '5\n']
Note:
Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5. | ```python
def decompose_and_count(n, l, r):
sequence = [n]
while True:
if len(sequence) >= r:
break
current = sequence.pop(0)
if current > 1:
sequence.extend([current // 2, current % 2, current // 2])
else:
sequence.append(current)
return sequence[l-1:r].count(1)
n = int(input())
l = int(input())
r = int(input())
count = decompose_and_count(n, l, r)
print(count) # 输出:4
``` | -1 | |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half. | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,381,423,578 | 4,578 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 124 | 0 | n = int(input())
count = -1
A = [0] * 3
for i in range(n):
a, b = map(int, input().split())
if a % 2 == 1 and b % 2 == 1:
A[0] += 1
elif a % 2 == 1:
A[1] += 1
elif b % 2 == 1:
A[2] += 1
if A[0] % 2 == 0 and (A[1] + A[2]) % 2 == 0:
print(min(A[1], A[2]))
else:
print(-1)
| Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half.
Output Specification:
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
Demo Input:
['2\n4 2\n6 4\n', '1\n2 3\n', '3\n1 4\n2 3\n4 4\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | ```python
n = int(input())
count = -1
A = [0] * 3
for i in range(n):
a, b = map(int, input().split())
if a % 2 == 1 and b % 2 == 1:
A[0] += 1
elif a % 2 == 1:
A[1] += 1
elif b % 2 == 1:
A[2] += 1
if A[0] % 2 == 0 and (A[1] + A[2]) % 2 == 0:
print(min(A[1], A[2]))
else:
print(-1)
``` | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,667,926,863 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | cnt=0
n,k=map(int,input().split())
l=[i for i in range(k+1)]
for i in range(n):
a=input()
if all(str(j) in a for j in l):
cnt+=1
print(cnt) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
Input Specification:
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the number of *k*-good numbers in *a*.
Demo Input:
['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n']
Demo Output:
['10\n', '1\n']
Note:
none | ```python
cnt=0
n,k=map(int,input().split())
l=[i for i in range(k+1)]
for i in range(n):
a=input()
if all(str(j) in a for j in l):
cnt+=1
print(cnt)
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,665,247,213 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 122 | 0 | import math
m, n = map(int, input().split())
print(math.ceil(m / 2) * math.ceil(n / 1)) | 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
import math
m, n = map(int, input().split())
print(math.ceil(m / 2) * math.ceil(n / 1))
``` | 0 |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,694,920,272 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 2,764,800 | k, l, m, n, d = map(int, input().split())
count = sum(1 for i in range(d) if any(i % x == 0 for x in (k, l, m, n)))
print(count)
| Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input Specification:
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output Specification:
Output the number of damaged dragons.
Demo Input:
['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n']
Demo Output:
['12\n', '17\n']
Note:
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | ```python
k, l, m, n, d = map(int, input().split())
count = sum(1 for i in range(d) if any(i % x == 0 for x in (k, l, m, n)))
print(count)
``` | -1 | |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,606,096,355 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | n=int(input())
ans=list(range(1,n+1))
print(*ans) | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
Input Specification:
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Output Specification:
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any.
Demo Input:
['2\n', '3\n']
Demo Output:
['1 2 ', '1 3 2 ']
Note:
none | ```python
n=int(input())
ans=list(range(1,n+1))
print(*ans)
``` | 0 |
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:
- the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q. | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA_... | 1,670,716,628 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 61 | 0 | def pass_check(passw):
is_large = 0
is_small = 0
if len(passw) < 5 :
print("Too weak")
return
if "0" not in passw and "1" not in passw and "2" not in passw and "3" not in passw and "4" not in passw and "5" not in passw and "6" not in passw and "7" not in passw and "8" not in passw and "9" not in passw:
print("Too weak")
return
for i in passw:
if ord(i) in range(65,91):
is_large = 1
elif ord(i) in range(97,123):
is_small = 1
if is_large == 1 and is_small ==1:
print("Correct")
return
else:
print("Too weak")
return
pass_check(input()) | Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:
- the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q.
Input Specification:
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
Output Specification:
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
Demo Input:
['abacaba\n', 'X12345\n', 'CONTEST_is_STARTED!!11\n']
Demo Output:
['Too weak\n', 'Too weak\n', 'Correct\n']
Note:
none | ```python
def pass_check(passw):
is_large = 0
is_small = 0
if len(passw) < 5 :
print("Too weak")
return
if "0" not in passw and "1" not in passw and "2" not in passw and "3" not in passw and "4" not in passw and "5" not in passw and "6" not in passw and "7" not in passw and "8" not in passw and "9" not in passw:
print("Too weak")
return
for i in passw:
if ord(i) in range(65,91):
is_large = 1
elif ord(i) in range(97,123):
is_small = 1
if is_large == 1 and is_small ==1:
print("Correct")
return
else:
print("Too weak")
return
pass_check(input())
``` | 3 | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program. | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,514,396,123 | 3,623 | Python 3 | RUNTIME_ERROR | PRETESTS | 4 | 701 | 6,963,200 | import sys
sys.setrecursionlimit = 10000
n = int(input())
MOD = 10**9 + 7
statements = []
for _ in range(n):
statements.append(input().strip())
rez = len(statements) - 1
while statements[rez] == 'f':
rez -= 1
statements = statements[:rez+1]
memo = dict()
def calc(ind,ident):
if (ind, ident) in memo:
return memo[ind, ident]
if ind == len(statements):
return 1
ALL = 0
if statements[ind] == 's':
for k in range(1, ident + 1):
ALL += calc(ind + 1, k)
else:
for k in range(1, ident + 1):
i = ind
size = k
while i < len(statements) and statements[i] == 'f':
i += 1
size += 1
i += 1
if i < len(statements):
ALL += calc(i, size)
else:
ALL += 1
memo[ind,ident] = ALL % MOD
return memo[ind, ident]
#print(statements)
print(calc(0,1) % MOD)
| Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
Input Specification:
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output Specification:
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
Demo Input:
['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n']
Demo Output:
['1\n', '2\n']
Note:
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or | ```python
import sys
sys.setrecursionlimit = 10000
n = int(input())
MOD = 10**9 + 7
statements = []
for _ in range(n):
statements.append(input().strip())
rez = len(statements) - 1
while statements[rez] == 'f':
rez -= 1
statements = statements[:rez+1]
memo = dict()
def calc(ind,ident):
if (ind, ident) in memo:
return memo[ind, ident]
if ind == len(statements):
return 1
ALL = 0
if statements[ind] == 's':
for k in range(1, ident + 1):
ALL += calc(ind + 1, k)
else:
for k in range(1, ident + 1):
i = ind
size = k
while i < len(statements) and statements[i] == 'f':
i += 1
size += 1
i += 1
if i < len(statements):
ALL += calc(i, size)
else:
ALL += 1
memo[ind,ident] = ALL % MOD
return memo[ind, ident]
#print(statements)
print(calc(0,1) % MOD)
``` | -1 | |
30 | B | Codeforces World Finals | PROGRAMMING | 1,700 | [
"implementation"
] | B. Codeforces World Finals | 2 | 256 | The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.
The final round of the Codeforces World Finals 20YY is scheduled for *DD*.*MM*.*YY*, where *DD* is the day of the round, *MM* is the month and *YY* are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on *BD*.*BM*.*BY*. This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day *DD*.*MM*.*YY*. He can always tell that in his motherland dates are written differently. Help him.
According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant's 18-th birthday, he is allowed to participate.
As we are considering only the years from 2001 to 2099 for the year of the finals, use the following rule: the year is leap if it's number is divisible by four. | The first line contains the date *DD*.*MM*.*YY*, the second line contains the date *BD*.*BM*.*BY*. It is guaranteed that both dates are correct, and *YY* and *BY* are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date. | If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the *DD*.*MM*.*YY*, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits. | [
"01.01.98\n01.01.80\n",
"20.10.20\n10.02.30\n",
"28.02.74\n28.02.64\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 1,000 | [
{
"input": "01.01.98\n01.01.80",
"output": "YES"
},
{
"input": "20.10.20\n10.02.30",
"output": "NO"
},
{
"input": "28.02.74\n28.02.64",
"output": "NO"
},
{
"input": "05.05.25\n06.02.71",
"output": "NO"
},
{
"input": "19.11.54\n29.11.53",
"output": "NO"
},
... | 1,534,526,543 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 102,400 | from datetime import date
import itertools
from dateutil import relativedelta
def mmxd(d,m,y):
if m>2:
m-=2
if m>5:
m-=5
return 30+m%2
elif m==1:
return 31
else:
if y%4==0:
return 29
else:
return 28
def trytodate(ns,pc):
y=ns[pc[0]]
m=ns[pc[1]]
d=ns[pc[2]]
mxd=mmxd(d,m,y)
if m>12 or d>mxd:
return 0
return 1
s=input().split('.')
d,m,y=int(s[0]),int(s[1]),int(s[2])
s=input().split('.')
ns=[]
for c in s:
ns.append(int(c))
td=date(2000+y,m,d)
b=0
ps=itertools.permutations(range(3))
for pc in ps:
if trytodate(ns,pc)==0:
continue
vd=date(2000+ns[pc[0]],ns[pc[1]],ns[pc[2]])
if relativedelta.relativedelta(td,vd).years>=18:
b=1
break
if(b):
print('YES')
else:
print('NO') | Title: Codeforces World Finals
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.
The final round of the Codeforces World Finals 20YY is scheduled for *DD*.*MM*.*YY*, where *DD* is the day of the round, *MM* is the month and *YY* are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on *BD*.*BM*.*BY*. This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day *DD*.*MM*.*YY*. He can always tell that in his motherland dates are written differently. Help him.
According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant's 18-th birthday, he is allowed to participate.
As we are considering only the years from 2001 to 2099 for the year of the finals, use the following rule: the year is leap if it's number is divisible by four.
Input Specification:
The first line contains the date *DD*.*MM*.*YY*, the second line contains the date *BD*.*BM*.*BY*. It is guaranteed that both dates are correct, and *YY* and *BY* are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date.
Output Specification:
If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the *DD*.*MM*.*YY*, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits.
Demo Input:
['01.01.98\n01.01.80\n', '20.10.20\n10.02.30\n', '28.02.74\n28.02.64\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
from datetime import date
import itertools
from dateutil import relativedelta
def mmxd(d,m,y):
if m>2:
m-=2
if m>5:
m-=5
return 30+m%2
elif m==1:
return 31
else:
if y%4==0:
return 29
else:
return 28
def trytodate(ns,pc):
y=ns[pc[0]]
m=ns[pc[1]]
d=ns[pc[2]]
mxd=mmxd(d,m,y)
if m>12 or d>mxd:
return 0
return 1
s=input().split('.')
d,m,y=int(s[0]),int(s[1]),int(s[2])
s=input().split('.')
ns=[]
for c in s:
ns.append(int(c))
td=date(2000+y,m,d)
b=0
ps=itertools.permutations(range(3))
for pc in ps:
if trytodate(ns,pc)==0:
continue
vd=date(2000+ns[pc[0]],ns[pc[1]],ns[pc[2]])
if relativedelta.relativedelta(td,vd).years>=18:
b=1
break
if(b):
print('YES')
else:
print('NO')
``` | -1 |
18 | A | Triangle | PROGRAMMING | 1,500 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these. | The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. | If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. | [
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] | [
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] | none | 0 | [
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},... | 1,618,061,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 124 | 0 | a1,b1,a3,b3,a4,b4 = map(int,input().split())
if((a1 == a3 or a1 == a4) and (b1 == b3 or b1 == b4)):
print("RIGHT")
elif((a1 == a3 or a1 == a4) or (b1 == b3 or b1 == b4)):
if(abs(b1-b3)==1 or abs(b1-b4)==1 or abs(a1-a3)==1 or abs(a1-a4)==1):
print("ALMOST")
elif((a1 == a3 or a3 == a4) and (b1 == b3 or b3 == b4)):
print("RIGHT")
elif((a1 == a3 or a3 == a4) or (b1 == b3 or b3 == b4)):
if(abs(b1-b3)==1 or abs(b3-b4)==1 or abs(a1-a3)==1 or abs(a3-a4)==1):
print("ALMOST")
elif((a4 == a3 or a1 == a4) and (b4 == b3 or b1 == b4)):
print("RIGHT")
elif((a4 == a3 or a1 == a4) or (b4 == b3 or b1 == b4)):
if(abs(b4-b3)==1 or abs(b1-b4)==1 or abs(a4-a3)==1 or abs(a1-a4)==1):
print("ALMOST")
else:
print("NEITHER")
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.
Input Specification:
The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
Output Specification:
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.
Demo Input:
['0 0 2 0 0 1\n', '2 3 4 5 6 6\n', '-1 0 2 0 0 1\n']
Demo Output:
['RIGHT\n', 'NEITHER\n', 'ALMOST\n']
Note:
none | ```python
a1,b1,a3,b3,a4,b4 = map(int,input().split())
if((a1 == a3 or a1 == a4) and (b1 == b3 or b1 == b4)):
print("RIGHT")
elif((a1 == a3 or a1 == a4) or (b1 == b3 or b1 == b4)):
if(abs(b1-b3)==1 or abs(b1-b4)==1 or abs(a1-a3)==1 or abs(a1-a4)==1):
print("ALMOST")
elif((a1 == a3 or a3 == a4) and (b1 == b3 or b3 == b4)):
print("RIGHT")
elif((a1 == a3 or a3 == a4) or (b1 == b3 or b3 == b4)):
if(abs(b1-b3)==1 or abs(b3-b4)==1 or abs(a1-a3)==1 or abs(a3-a4)==1):
print("ALMOST")
elif((a4 == a3 or a1 == a4) and (b4 == b3 or b1 == b4)):
print("RIGHT")
elif((a4 == a3 or a1 == a4) or (b4 == b3 or b1 == b4)):
if(abs(b4-b3)==1 or abs(b1-b4)==1 or abs(a4-a3)==1 or abs(a1-a4)==1):
print("ALMOST")
else:
print("NEITHER")
``` | 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":... | 1,686,564,232 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a=str(input())
if len(a)>10:
print(a[0],len(a)-2,a[-1],sep="")
else:
print(a)
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis
| 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=str(input())
if len(a)>10:
print(a[0],len(a)-2,a[-1],sep="")
else:
print(a)
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis
``` | 0 |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,641,103,457 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n = int(input())
a = []
for i in range(n):
a.append(input())
for i in range(n):
if 'OO' in a[i]:
a[i] = a[i].replace('OO', '++')
break
for i in range(n):
print(*a[i]) | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
n = int(input())
a = []
for i in range(n):
a.append(input())
for i in range(n):
if 'OO' in a[i]:
a[i] = a[i].replace('OO', '++')
break
for i in range(n):
print(*a[i])
``` | 0 | |
190 | D | Non-Secret Cypher | PROGRAMMING | 1,900 | [
"two pointers"
] | null | null | Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*). | The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 2\n1 2 1 2\n",
"5 3\n1 2 1 1 3\n",
"3 1\n1 1 1\n"
] | [
"3",
"2",
"6"
] | In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | 2,000 | [
{
"input": "4 2\n1 2 1 2",
"output": "3"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "20 2\n6 7 2 4 6 8 4 3 10 5 3 5 7 9 1 2 8 1 9 10",
"output": "131"
},
{
"input": "63 2\n1 2 1 2 4 5 1 1 1 1 1 2 3 1 2 3 3... | 1,637,482,430 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | '''
# left - указатель на первый элемент списка, равный val
# right - указатель на последний элемент списка, не равный val
# элементы nums[right] nums[left] меняются местами, ненужные элементы оказываются в конце
# в конце возвращается указатель на последний элемент равный val
class Solution:
def removeElement(self, nums, val):
n = len(nums)
left = 0
right = n - 1
while left < right:
while right > 0 and nums[right] == val:
right -= 1
while left < n and nums[left] != val:
left += 1
if left < right:
nums[right], nums[left] = nums[left], nums[right]
if (left < n and nums[left] == val) or left == n:
return left
else:
return left + 1
s = Solution()
print(s.removeElement([], 3))
'''
n, k = map(int, input().split())
s = list(map(int, input().split()))
d = {s[0]: 1}
left = 0
right = 1
ans = 0
while left < n:
while right < n and d[s[right - 1]] < k:
if s[right] in d.keys():
d[s[right]] += 1
else:
d[s[right]] = 1
right += 1
# print(right, left)
if d[s[right - 1]] >= k:
ans += n - right + 1
while left < n and right <= n and s[left] != s[right - 1]:
d[s[left]] -= 1
left += 1
if left < n:
d[s[left]] -= 1
left += 1
# print(right, left)
# print('l', left, d)
# print(right, left)
print(ans)
| Title: Non-Secret Cypher
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number *m*, the enemies use an array of integers *a*. The number of its subarrays, in which there are at least *k* equal numbers, equals *m*. The number *k* has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers *a* and number *k*, find the number of subarrays of the array of numbers *a*, which has at least *k* equal numbers.
Subarray *a*[*i*... *j*] (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) of array *a*<==<=(*a*1,<=*a*2,<=...,<=*a**n*) is an array, made from its consecutive elements, starting from the *i*-th one and ending with the *j*-th one: *a*[*i*... *j*]<==<=(*a**i*,<=*a**i*<=+<=1,<=...,<=*a**j*).
Input Specification:
The first line contains two space-separated integers *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — elements of the array.
Output Specification:
Print the single number — the number of such subarrays of array *a*, that they have at least *k* equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['4 2\n1 2 1 2\n', '5 3\n1 2 1 1 3\n', '3 1\n1 1 1\n']
Demo Output:
['3', '2', '6']
Note:
In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1). | ```python
'''
# left - указатель на первый элемент списка, равный val
# right - указатель на последний элемент списка, не равный val
# элементы nums[right] nums[left] меняются местами, ненужные элементы оказываются в конце
# в конце возвращается указатель на последний элемент равный val
class Solution:
def removeElement(self, nums, val):
n = len(nums)
left = 0
right = n - 1
while left < right:
while right > 0 and nums[right] == val:
right -= 1
while left < n and nums[left] != val:
left += 1
if left < right:
nums[right], nums[left] = nums[left], nums[right]
if (left < n and nums[left] == val) or left == n:
return left
else:
return left + 1
s = Solution()
print(s.removeElement([], 3))
'''
n, k = map(int, input().split())
s = list(map(int, input().split()))
d = {s[0]: 1}
left = 0
right = 1
ans = 0
while left < n:
while right < n and d[s[right - 1]] < k:
if s[right] in d.keys():
d[s[right]] += 1
else:
d[s[right]] = 1
right += 1
# print(right, left)
if d[s[right - 1]] >= k:
ans += n - right + 1
while left < n and right <= n and s[left] != s[right - 1]:
d[s[left]] -= 1
left += 1
if left < n:
d[s[left]] -= 1
left += 1
# print(right, left)
# print('l', left, d)
# print(right, left)
print(ans)
``` | 0 | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for *q* rounds. In each round, Mike chooses a bear (*i*,<=*j*) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the information about the rounds. Each of them contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*), the row number and the column number of the bear changing his state. | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,432,932,084 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def step(grid, mikes_dec):
grid[mikes_dec[0]][mikes_dec[1]] = \
abs(grid[mikes_dec[0]][mikes_dec[1]] - 1)
def count_cont(row, item):
count = 0
for some_item in row:
if some_item != item:
break
count = count + 1
return count
def max_closed_eyes_in_grid(grid):
ret_val = count_cont(grid[0], 1)
for row in grid[1:]:
ret_val = max(ret_val, count_cont(row, 1))
return ret_val
# input size, etc
n, m, q = list(map(lambda x: int(x), input().split(' ')))
grid = [[] for x in range(n)]
rounds = [[] for x in range(q)]
# input grid
for i in range(n):
grid[i] = list(map(lambda x: int(x), input().split(' ')))
# input rounds
for i in range(q):
rounds[i] = list(map(lambda x: int(x) - 1, input().split(' ')))
for round_in_game in rounds:
step(grid, round_in_game)
closed_eyes = max_closed_eyes_in_grid(grid)
print(closed_eyes)
| Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.
They play for *q* rounds. In each round, Mike chooses a bear (*i*,<=*j*) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.
Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.
Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.
Input Specification:
The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the information about the rounds. Each of them contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*), the row number and the column number of the bear changing his state.
Output Specification:
After each round, print the current score of the bears.
Demo Input:
['5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n']
Demo Output:
['3\n4\n3\n3\n4\n']
Note:
none | ```python
def step(grid, mikes_dec):
grid[mikes_dec[0]][mikes_dec[1]] = \
abs(grid[mikes_dec[0]][mikes_dec[1]] - 1)
def count_cont(row, item):
count = 0
for some_item in row:
if some_item != item:
break
count = count + 1
return count
def max_closed_eyes_in_grid(grid):
ret_val = count_cont(grid[0], 1)
for row in grid[1:]:
ret_val = max(ret_val, count_cont(row, 1))
return ret_val
# input size, etc
n, m, q = list(map(lambda x: int(x), input().split(' ')))
grid = [[] for x in range(n)]
rounds = [[] for x in range(q)]
# input grid
for i in range(n):
grid[i] = list(map(lambda x: int(x), input().split(' ')))
# input rounds
for i in range(q):
rounds[i] = list(map(lambda x: int(x) - 1, input().split(' ')))
for round_in_game in rounds:
step(grid, round_in_game)
closed_eyes = max_closed_eyes_in_grid(grid)
print(closed_eyes)
``` | 0 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,550,983,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n,m=map(int,input().split())
a=0
v=list(map(int,input().split()))
for x in v:
a+=x
s=m-(((n-1)*10)+a)
t=((n-1)*10)//5
if s==0: print(t)
elif s!=0:
for i in range(1,(m//5)+1):
s-=5
if s==0: print(t+i);quit()
else: print(-1)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input Specification:
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
Output Specification:
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Demo Input:
['3 30\n2 2 1\n', '3 20\n2 1 1\n']
Demo Output:
['5\n', '-1\n']
Note:
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | ```python
n,m=map(int,input().split())
a=0
v=list(map(int,input().split()))
for x in v:
a+=x
s=m-(((n-1)*10)+a)
t=((n-1)*10)//5
if s==0: print(t)
elif s!=0:
for i in range(1,(m//5)+1):
s-=5
if s==0: print(t+i);quit()
else: print(-1)
``` | 0 | |
327 | B | Hungry Sequence | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality *a**i*<=<<=*a**j* holds for any two indices *i*,<=*j* (*i*<=<<=*j*). - For any two indices *i* and *j* (*i*<=<<=*j*), *a**j* must not be divisible by *a**i*.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with *n* elements. | The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | 500 | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ... | 1,690,136,009 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 17,612,800 | def prod(l):
prod = 1
for i in l:
prod *= i
return prod
a = int(input())
if(a == 1):
print(1)
if(a == 2):
print("2 3")
if(a > 2):
l = [2, 3]
for i in range (0, a - 2):
l.append(prod(l) - 1)
s = ""
for i in l:
s += str(i) + " "
s.strip(" ")
print(s) | Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality *a**i*<=<<=*a**j* holds for any two indices *i*,<=*j* (*i*<=<<=*j*). - For any two indices *i* and *j* (*i*<=<<=*j*), *a**j* must not be divisible by *a**i*.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with *n* elements.
Input Specification:
The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Demo Input:
['3\n', '5\n']
Demo Output:
['2 9 15\n', '11 14 20 27 31\n']
Note:
none | ```python
def prod(l):
prod = 1
for i in l:
prod *= i
return prod
a = int(input())
if(a == 1):
print(1)
if(a == 2):
print("2 3")
if(a > 2):
l = [2, 3]
for i in range (0, a - 2):
l.append(prod(l) - 1)
s = ""
for i in l:
s += str(i) + " "
s.strip(" ")
print(s)
``` | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,697,618,674 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 3 | 1,247 | 268,390,400 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 15:42:23 2023
@author: GaoMingze 2300011427
"""
n=int(input())
tree=[]
a=0
for _ in range(n):
x,h=map(int,input().split())
tree.append([x,h])
if x+h+1>a:
a=x+h+1
z=0
check=[z for i in range(a)]
for i in range(n):
y=tree[i][0]
check[y]=1
k=2
for i in range(1,n-1):
b=tree[i][0]-tree[i][1]
c=tree[i][0]+tree[i][1]
if b<0:
b=0
if c>a-1:
c=a-1
if check[b]==0 and tree[i-1][0]<b:
k+=1
for j in range(b,tree[i][0]+1):
check[j]=1
elif check[c]==0 and tree[i+1][0]>c:
k+=1
for j in range(tree[i][0],c+1):
check[j]=1
print(k)
| Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 15:42:23 2023
@author: GaoMingze 2300011427
"""
n=int(input())
tree=[]
a=0
for _ in range(n):
x,h=map(int,input().split())
tree.append([x,h])
if x+h+1>a:
a=x+h+1
z=0
check=[z for i in range(a)]
for i in range(n):
y=tree[i][0]
check[y]=1
k=2
for i in range(1,n-1):
b=tree[i][0]-tree[i][1]
c=tree[i][0]+tree[i][1]
if b<0:
b=0
if c>a-1:
c=a-1
if check[b]==0 and tree[i-1][0]<b:
k+=1
for j in range(b,tree[i][0]+1):
check[j]=1
elif check[c]==0 and tree[i+1][0]>c:
k+=1
for j in range(tree[i][0],c+1):
check[j]=1
print(k)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.