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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 th... | 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,574,875,636 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s = input()
mal = 0
bol = 0
for element in s:
if 'a'<=element<='z':
mal += 1
elif 'A'<=element<='Z':
bol += 1
if mal > bol:
print(s.lower())
elif mal < bol:
print(s.upper())
elif mal == bol:
print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
mal = 0
bol = 0
for element in s:
if 'a'<=element<='z':
mal += 1
elif 'A'<=element<='Z':
bol += 1
if mal > bol:
print(s.lower())
elif mal < bol:
print(s.upper())
elif mal == bol:
print(s.lower())
``` | 3.9455 |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,622,874,942 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 3,174,400 | s1=input()
cnt=0
cntb=0
ind=s1.index('a')
s=s1[ind:]
i=len(s)-1
while(i>=0):
if cntb==0 and s[i]=='a':
i-=1
continue
elif s[i]=='b':
cntb+=1
elif s[i]=='a':
cnt+=cntb
cntb*=2
i-=1
print(cnt%1000000007)
| Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
s1=input()
cnt=0
cntb=0
ind=s1.index('a')
s=s1[ind:]
i=len(s)-1
while(i>=0):
if cntb==0 and s[i]=='a':
i-=1
continue
elif s[i]=='b':
cntb+=1
elif s[i]=='a':
cnt+=cntb
cntb*=2
i-=1
print(cnt%1000000007)
``` | 0 | |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,569,701,641 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 233 | 307,200 |
number = list(map(int,input().split()))
all_IP = []
for i in range(number[0]):
s = list(map(str , input().split()))
s[1] = s[1]+';'
all_IP.append(s)
for i in range(number[1]):
x = input()
z = list(map(str , x.split()))
ip = z[1]
for j in range(number[0]):
if all_IP... | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
number = list(map(int,input().split()))
all_IP = []
for i in range(number[0]):
s = list(map(str , input().split()))
s[1] = s[1]+';'
all_IP.append(s)
for i in range(number[1]):
x = input()
z = list(map(str , x.split()))
ip = z[1]
for j in range(number[0]):
... | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,660,305,942 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 187 | 14,131,200 |
n = int(input()); arr = list(map(int, input().split()))
turn = n; fell = [False]*n
for i in range(n):
fell[arr[i]-1] = True
if arr[i] == turn:
while fell[turn - 1] and turn >= 1:
print(turn, end=' ')
turn -= 1
print()
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input()); arr = list(map(int, input().split()))
turn = n; fell = [False]*n
for i in range(n):
fell[arr[i]-1] = True
if arr[i] == turn:
while fell[turn - 1] and turn >= 1:
print(turn, end=' ')
turn -= 1
print()
``` | 3 | |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,560,860,938 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 |
n = int( input() )
a = list( map( int, input().strip().split( ' ' ) ) )
m = max( set( a ), key=a.count )
if (n == 1):
print( "YES" )
elif (m > n / 2):
print( "NO" )
else:
print( "YES" ) | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
n = int( input() )
a = list( map( int, input().strip().split( ' ' ) ) )
m = max( set( a ), key=a.count )
if (n == 1):
print( "YES" )
elif (m > n / 2):
print( "NO" )
else:
print( "YES" )
``` | 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.... | 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,524,709,048 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 78 | 7,065,600 | k, n, s, p = [int(x) for x in input().split()]
ans = ((n + s - 1) // s * k + p - 1) // p
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 p... | ```python
k, n, s, p = [int(x) for x in input().split()]
ans = ((n + s - 1) // s * k + p - 1) // p
print(ans)
``` | 3 | |
124 | B | Permutations | PROGRAMMING | 1,400 | [
"brute force",
"combinatorics",
"implementation"
] | null | null | You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. | The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits. | Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule. | [
"6 4\n5237\n2753\n7523\n5723\n5327\n2537\n",
"3 3\n010\n909\n012\n",
"7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n"
] | [
"2700\n",
"3\n",
"20522\n"
] | In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102. | 1,000 | [
{
"input": "6 4\n5237\n2753\n7523\n5723\n5327\n2537",
"output": "2700"
},
{
"input": "3 3\n010\n909\n012",
"output": "3"
},
{
"input": "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156",
"output": "20522"
},
{
"input": "5 5\n61374\n74304\n41924\n46010\n09118",
"output... | 1,690,461,455 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 122 | 2,867,200 | def permute(vis,ds):
if len(ds)==k:
result.append(ds[:])
else:
for i in nums:
if (not vis[i]):
ds.append(i)
vis[i]=True
permute(vis,ds)
vis[i]=False
ds.pop()
n,k = list(map(int,input().... | Title: Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all int... | ```python
def permute(vis,ds):
if len(ds)==k:
result.append(ds[:])
else:
for i in nums:
if (not vis[i]):
ds.append(i)
vis[i]=True
permute(vis,ds)
vis[i]=False
ds.pop()
n,k = list(map(in... | -1 | |
704 | B | Ant Man | PROGRAMMING | 2,500 | [
"dp",
"graphs",
"greedy"
] | null | null | Scott Lang is at war with Darren Cross. There are *n* chairs in a hall where they are, numbered with 1,<=2,<=...,<=*n* from left to right. The *i*-th chair is located at coordinate *x**i*. Scott is on chair number *s* and Cross is on chair number *e*. Scott can jump to all other chairs (not only neighboring chairs). He... | The first line of the input contains three integers *n*,<=*s* and *e* (2<=≤<=*n*<=≤<=5000,<=1<=≤<=*s*,<=*e*<=≤<=*n*,<=*s*<=≠<=*e*) — the total number of chairs, starting and ending positions of Scott.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=... | Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once. | [
"7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8\n"
] | [
"139\n"
] | In the sample testcase, an optimal solution would be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5bbd3e094ffa5a72e263dfaec7aeaff795bc22a3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139. | 1,250 | [
{
"input": "7 4 3\n8 11 12 16 17 18 20\n17 16 20 2 20 5 13\n17 8 8 16 12 15 13\n12 4 16 4 15 7 6\n8 14 2 11 17 12 8",
"output": "139"
},
{
"input": "2 1 2\n75475634 804928248\n476927808 284875072\n503158867 627937890\n322595515 786026685\n645468307 669240390",
"output": "1659795993"
},
{
... | 1,688,098,875 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 512,000 | import sys,math
from bisect import bisect_left , bisect_right
def rd(): return sys.stdin.readline().strip()
def rdl(typ,sep=" "): return list(map(typ, rd().split(sep)))
def wt(x,sep="\n") : sys.stdout.write(str(x) + sep) # string / num
def wtBoolUp(x): wt("YES" if x==True else "NO") # True = YES/ False =N... | Title: Ant Man
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scott Lang is at war with Darren Cross. There are *n* chairs in a hall where they are, numbered with 1,<=2,<=...,<=*n* from left to right. The *i*-th chair is located at coordinate *x**i*. Scott is on chair number *s* and Cross... | ```python
import sys,math
from bisect import bisect_left , bisect_right
def rd(): return sys.stdin.readline().strip()
def rdl(typ,sep=" "): return list(map(typ, rd().split(sep)))
def wt(x,sep="\n") : sys.stdout.write(str(x) + sep) # string / num
def wtBoolUp(x): wt("YES" if x==True else "NO") # True = YES... | 0 | |
523 | A | Rotate, Flip and Zoom | PROGRAMMING | 1,200 | [
"*special",
"implementation"
] | null | null | Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ... | The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as ... | Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. | [
"3 2\n.*.\n.*.\n",
"9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n"
] | [
"....\n....\n****\n****\n....\n....\n",
"********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......*****... | none | 500 | [
{
"input": "3 2\n.*.\n.*.",
"output": "....\n....\n****\n****\n....\n...."
},
{
"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**....... | 1,426,371,189 | 25,989 | Python 3 | OK | TESTS | 24 | 62 | 102,400 | w, h = map(int, input().split())
a = []
for i in range(h):
a.append(list(input()))
b = [[0 for j in range(h)] for i in range(w)]
for i in range(h):
for j in range(w):
b[j][i] = a[i][j]
for i in range(w):
x = ''
for j in range(h):
x = x + b[i][j] + b[i][j]
print(x)
... | Title: Rotate, Flip and Zoom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally... | ```python
w, h = map(int, input().split())
a = []
for i in range(h):
a.append(list(input()))
b = [[0 for j in range(h)] for i in range(w)]
for i in range(h):
for j in range(w):
b[j][i] = a[i][j]
for i in range(w):
x = ''
for j in range(h):
x = x + b[i][j] + b[i][j]
pr... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 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,691,604,657 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 2,867,200 | # list = input().split("\n")
list = []
while True:
line = input()
if line:
list.append(line)
else:
break
input = '\n'.join(list)
new_list = []
for i in list:
index = list.index(i)
new_word = ""
if index == 0:
continue
elif len(i) > 10:
new_word += i[0]
... | 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 character... | ```python
# list = input().split("\n")
list = []
while True:
line = input()
if line:
list.append(line)
else:
break
input = '\n'.join(list)
new_list = []
for i in list:
index = list.index(i)
new_word = ""
if index == 0:
continue
elif len(i) > 10:
new_word += ... | -1 |
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v... | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ... | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i... | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"inpu... | 1,696,490,334 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 467 | 25,600,000 | ############ ---- Input Functions and Setup ---- ############
import sys
import math
from collections import Counter, defaultdict, deque
from functools import cmp_to_key
def inp(): # int input
return(int(input()))
def inlt(): # int list input
return(list(map(int,input().split())))
def insr(): # strin... | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house... | ```python
############ ---- Input Functions and Setup ---- ############
import sys
import math
from collections import Counter, defaultdict, deque
from functools import cmp_to_key
def inp(): # int input
return(int(input()))
def inlt(): # int list input
return(list(map(int,input().split())))
def insr(... | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,643,454,029 | 4,529 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | initial=[[1 for i in range(3)] for j in range(3)]
matrix=[]
for i in range(3):
t=list(map(int,input().split()))
matrix.append(t)
for i in range(3):
for j in range(3):
if matrix[i][j]%2==1:
initial[i][i]=1-initial[i][j]
if i<2:
initial[i+1][j]=1-initi... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
initial=[[1 for i in range(3)] for j in range(3)]
matrix=[]
for i in range(3):
t=list(map(int,input().split()))
matrix.append(t)
for i in range(3):
for j in range(3):
if matrix[i][j]%2==1:
initial[i][i]=1-initial[i][j]
if i<2:
initial[i+1][... | 0 | |
980 | B | Marlin | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the ... | The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is odd, the width of the city, and the number of hotels to be placed, respectively. | Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "#" if that cell has a hotel on it, or "." if not. | [
"7 2\n",
"5 3\n"
] | [
"YES\n.......\n.#.....\n.#.....\n.......\n",
"YES\n.....\n.###.\n.....\n.....\n"
] | none | 1,000 | [
{
"input": "7 2",
"output": "YES\n.......\n.#.....\n.#.....\n......."
},
{
"input": "5 3",
"output": "YES\n.....\n.###.\n.....\n....."
},
{
"input": "3 2",
"output": "YES\n...\n.#.\n.#.\n..."
},
{
"input": "3 0",
"output": "YES\n...\n...\n...\n..."
},
{
"input": "... | 1,525,792,964 | 1,063 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 61 | 6,963,200 | n, k = list(map(int, input().split()))
if 2 * (n - 2) < k or k % 2 == 1:
print('NO')
else:
print('YES')
total = 0
arr = []
for j in range(4):
arr.append(['.' for i in range(n)])
for i in range(1, n - 1):
for j in range(1, 3):
if total < k:
... | Title: Marlin
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bo... | ```python
n, k = list(map(int, input().split()))
if 2 * (n - 2) < k or k % 2 == 1:
print('NO')
else:
print('YES')
total = 0
arr = []
for j in range(4):
arr.append(['.' for i in range(n)])
for i in range(1, n - 1):
for j in range(1, 3):
if total < k:
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 0 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,581,094,276 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 155 | 0 | def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
def lcm(a,b):
return a*b//gcd(a,b)
n,k=map(int,input().split())
print(lcm(n,10**k))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000... | ```python
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
def lcm(a,b):
return a*b//gcd(a,b)
n,k=map(int,input().split())
print(lcm(n,10**k))
``` | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,646,839,492 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 | a, b = list(map(int, input().split()))
h = a
while a >= b:
a-=b
a+=1
h+=1
print(h) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
a, b = list(map(int, input().split()))
h = a
while a >= b:
a-=b
a+=1
h+=1
print(h)
``` | 3 | |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,696,826,400 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | n=int(input());b=input().upper()
for i in range(65,91):
if chr(i) in b:
continue
else:
print("NO")
break
else:
print("YES") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
n=int(input());b=input().upper()
for i in range(65,91):
if chr(i) in b:
continue
else:
print("NO")
break
else:
print("YES")
``` | 3 | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,592,511,771 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 140 | 0 | q = 1;
a = []
temp = ""
n = int(input())
while n > 0:
n-=1
a.append(int(input()))
#print(a)
temp = list(set(a))
#print(temp)
if len(temp)==2 and a.count(temp[0])==a.count(temp[1]):
print("YES")
print(*temp)
else:
print("NO") | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
q = 1;
a = []
temp = ""
n = int(input())
while n > 0:
n-=1
a.append(int(input()))
#print(a)
temp = list(set(a))
#print(temp)
if len(temp)==2 and a.count(temp[0])==a.count(temp[1]):
print("YES")
print(*temp)
else:
print("NO")
``` | 3 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,457,413,639 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 1,809 | 24,473,600 | from operator import itemgetter
n=int(input().strip())
ans=0
l=[]
for i in range(n):
l.append([int(x) for x in input().strip().split()])
l.sort(key=itemgetter(1))
x=l[0][1]
y=1
for i in range(1,len(l)):
if l[i][1]!=x:
ans=ans+(y*(y-1))//2
x=l[i][1]
y=1
else:
y=y+1
ans=ans+(y*(y-1))//2
... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
from operator import itemgetter
n=int(input().strip())
ans=0
l=[]
for i in range(n):
l.append([int(x) for x in input().strip().split()])
l.sort(key=itemgetter(1))
x=l[0][1]
y=1
for i in range(1,len(l)):
if l[i][1]!=x:
ans=ans+(y*(y-1))//2
x=l[i][1]
y=1
else:
y=y+1
ans=ans+(y*(y-1... | 3 | |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,567,337,464 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 342 | 7,372,800 | n=int(input())
a=list(map(int,input().split()))
c=0
f=0
li=[0]*n
for i in range(n):
li[a[i]]=i
for i in range(n):
if a[i]==i:
c+=1
else:
if a[i]==li[i] and f==0:
f=1
c+=2
if f==0:
print(c+1)
else:
print(c) | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
n=int(input())
a=list(map(int,input().split()))
c=0
f=0
li=[0]*n
for i in range(n):
li[a[i]]=i
for i in range(n):
if a[i]==i:
c+=1
else:
if a[i]==li[i] and f==0:
f=1
c+=2
if f==0:
print(c+1)
else:
print(c)
``` | 0 | |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,022,564 | 17,664 | Python 3 | OK | TESTS | 52 | 62 | 5,632,000 | n, k = map(int, input().split())
cor = [int(x) for x in input().split()]
N = 1
kon = n
tek = 0
while tek!=kon-1:
for i in range(tek+1,kon):
if cor[i]-cor[tek]>k:
break
if cor[kon-1] - cor[tek] <= k:
break
if i==tek+1:
N=-1
break
tek=i-1
N+=1
print (N)
| Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
n, k = map(int, input().split())
cor = [int(x) for x in input().split()]
N = 1
kon = n
tek = 0
while tek!=kon-1:
for i in range(tek+1,kon):
if cor[i]-cor[tek]>k:
break
if cor[kon-1] - cor[tek] <= k:
break
if i==tek+1:
N=-1
break
tek=i-1
N+=1
pri... | 3 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,633,731,471 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 |
v = ['h', 'e','i','d','i']
for c in s:
if c == v[0]:
v.pop(0)
if (v == []):
print("YES")
else:
print("NO")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
v = ['h', 'e','i','d','i']
for c in s:
if c == v[0]:
v.pop(0)
if (v == []):
print("YES")
else:
print("NO")
``` | -1 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,691,506,196 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import math
def GCD(A,B):
while B:
A,B = B,A % B
return A
def factorial(A,B):
return factorial_gcd(min(A,B)
def factorial_gcd(N):
if(N == 0):
return 1
return N * factorial_gcd(N -1)
A,B = map(int,input().split())
result = factorial(A,B)
print(result) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
def GCD(A,B):
while B:
A,B = B,A % B
return A
def factorial(A,B):
return factorial_gcd(min(A,B)
def factorial_gcd(N):
if(N == 0):
return 1
return N * factorial_gcd(N -1)
A,B = map(int,input().split())
result = factorial(A,B)
print(result)
... | -1 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,692,777,990 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 307,200 | from collections import Counter
n = int(input())
li =[]
for i in range(n):
t=input()
li.append(t)
c = Counter(li)
t = max(c, key=c.get)
print(t)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
from collections import Counter
n = int(input())
li =[]
for i in range(n):
t=input()
li.append(t)
c = Counter(li)
t = max(c, key=c.get)
print(t)
``` | 3.968428 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,628,157,350 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 92 | 6,963,200 | n = int(input())
g = {}
if n == 1:
print(input())
quit()
for i in range(n):
t = input()
if t not in g:
g[t] = 0
g[t] += 1
teams = list(g.keys())
goals = list(g.values())
print(teams[0] if goals[0] > goals[1] else teams[1]) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
g = {}
if n == 1:
print(input())
quit()
for i in range(n):
t = input()
if t not in g:
g[t] = 0
g[t] += 1
teams = list(g.keys())
goals = list(g.values())
print(teams[0] if goals[0] > goals[1] else teams[1])
``` | -1 |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,670,685,020 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | import math
ab = input().split()
a = max(int(ab[0]),int(ab[1]))
b = min(int(ab[0]),int(ab[1]))
A,B =1,1
for i in range(1,b+1):
B*=i
for i in range(1,a+1):
A*=i
if A%B==0 :
break
print(math.gcd(A,B))
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
ab = input().split()
a = max(int(ab[0]),int(ab[1]))
b = min(int(ab[0]),int(ab[1]))
A,B =1,1
for i in range(1,b+1):
B*=i
for i in range(1,a+1):
A*=i
if A%B==0 :
break
print(math.gcd(A,B))
``` | 3 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,572,981,801 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 170 | 5,324,800 | x,y=map(int,input().split())
a=list(map(int,input().split()))
i=1
j=0
lol=[]
while y>=i:
if j<len(a):
if a[j]==i:
j+=1
i+=1
else:
lol.append(i)
y-=i
i+=1
else:
lol.append(i)
y-=i
i+=1
pr... | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
x,y=map(int,input().split())
a=list(map(int,input().split()))
i=1
j=0
lol=[]
while y>=i:
if j<len(a):
if a[j]==i:
j+=1
i+=1
else:
lol.append(i)
y-=i
i+=1
else:
lol.append(i)
y-=i
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil a... | First line of the input contains six integers *a**x*, *a**y*, *b**x*, *b**y*, *t**x* and *t**y* (0<=≤<=*a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*t**x*,<=*t**y*<=≤<=109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of bo... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The ... | [
"3 1 1 2 0 0\n3\n1 1\n2 1\n2 3\n",
"5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3\n"
] | [
"11.084259940083\n",
"33.121375178000\n"
] | Consider the first sample.
Adil will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/37eea809c04afe04f2670475cc5b21df4a90afd1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Bera will use the following path: <img align="middle" class="tex-formula" src="https:... | 0 | [
{
"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3",
"output": "11.084259940083"
},
{
"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3",
"output": "33.121375178000"
},
{
"input": "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32",
... | 1,689,638,830 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689638830.3904395")# 1689638830.390459 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bott... | ```python
print("_RANDOM_GUESS_1689638830.3904395")# 1689638830.390459
``` | 0 | |
895 | D | String Mark | PROGRAMMING | 2,100 | [
"combinatorics",
"math",
"strings"
] | null | null | At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*.
Recently at the BSU was an important test work on which Vasya recived the mark *a*. It is very hard for the teacher to remember the exact mark of every stud... | First line contains string *a*, second line contains string *b*. Strings *a*,<=*b* consist of lowercase English letters. Their lengths are equal and don't exceed 106.
It is guaranteed that *a* is lexicographically smaller than *b*. | Print one integer — the number of different strings satisfying the condition of the problem modulo 109<=+<=7. | [
"abc\nddd\n",
"abcdef\nabcdeg\n",
"abacaba\nubuduba\n"
] | [
"5\n",
"0\n",
"64\n"
] | In first sample from string *abc* can be obtained strings *acb*, *bac*, *bca*, *cab*, *cba*, all of them are larger than *abc*, but smaller than *ddd*. So the answer is 5.
In second sample any string obtained from *abcdef* is larger than *abcdeg*. So the answer is 0. | 2,000 | [
{
"input": "abc\nddd",
"output": "5"
},
{
"input": "abcdef\nabcdeg",
"output": "0"
},
{
"input": "abacaba\nubuduba",
"output": "64"
},
{
"input": "aac\nbbb",
"output": "1"
},
{
"input": "aaaccc\nbbbbbb",
"output": "9"
},
{
"input": "aaaaaa\nzzzzzz",
... | 1,511,719,030 | 6,730 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 9 | 4,000 | 43,315,200 | import itertools
A = str(input())
b = str(input())
arr = []
def toString(List):
return ''.join(List)
def permute(a, l, r):
if l == r:
if b > toString(a) > A:
arr.append(toString(a))
else:
for i in range(l, r + 1):
a[l], a[i] = a[i], a[l]
per... | Title: String Mark
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the Byteland State University marks are strings of the same length. Mark *x* is considered better than *y* if string *y* is lexicographically smaller than *x*.
Recently at the BSU was an important test work on which Vas... | ```python
import itertools
A = str(input())
b = str(input())
arr = []
def toString(List):
return ''.join(List)
def permute(a, l, r):
if l == r:
if b > toString(a) > A:
arr.append(toString(a))
else:
for i in range(l, r + 1):
a[l], a[i] = a[i], a[l]
... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | 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,689,844,986 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n, m, v = map(int, input().split())
if m % a == 0:
x = m // v
else:
x = m // v + 1
if n % a == 0:
y = n // v
else:
y = n // v + 1
print(x * y)
| 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 ... | ```python
n, m, v = map(int, input().split())
if m % a == 0:
x = m // v
else:
x = m // v + 1
if n % a == 0:
y = n // v
else:
y = n // v + 1
print(x * y)
``` | -1 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and on... | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 4... | 1,514,997,903 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 5,529,600 | n = int(input())
if n == 2:
print(1, "1 1", sep='\n')
elif n == 3:
print(0, "1 3", sep='\n')
elif n & 1:
print(1, n >> 1, sep='\n')
for i in range(2, n+1, 2):
print(i, end=' ')
else:
print(0, n >> 1)
for i in range(1, n+1, 2):
print(i, end=' ')
| Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help P... | ```python
n = int(input())
if n == 2:
print(1, "1 1", sep='\n')
elif n == 3:
print(0, "1 3", sep='\n')
elif n & 1:
print(1, n >> 1, sep='\n')
for i in range(2, n+1, 2):
print(i, end=' ')
else:
print(0, n >> 1)
for i in range(1, n+1, 2):
print(i, end=' ')
``` | 0 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,872,367 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 61 | 0 | x = int(input())
n = x%5
if (n<0): print(1)
elif (n>0): print(int(((x-n)/5)+1))
else: print(int(((x-n)/5))) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x = int(input())
n = x%5
if (n<0): print(1)
elif (n>0): print(int(((x-n)/5)+1))
else: print(int(((x-n)/5)))
``` | 3 | |
453 | A | Little Pony and Expected Maximum | PROGRAMMING | 1,600 | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots... | A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in t... | 500 | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "... | 1,578,081,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | m, n = (int(x) for x in input().split(' '))
print(sum(i * (i/m)**n - ((i-1)/m)**n for i in range(1, m+1))) | Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were ... | ```python
m, n = (int(x) for x in input().split(' '))
print(sum(i * (i/m)**n - ((i-1)/m)**n for i in range(1, m+1)))
``` | 0 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,665,593,010 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | def minfact(j,k):
n=min(j,k)
fact=1
for i in range(1,n+1):
fact*=i
print(fact)
j,k=[int(item) for item in input().split(' ')]
minfact(j,k) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
def minfact(j,k):
n=min(j,k)
fact=1
for i in range(1,n+1):
fact*=i
print(fact)
j,k=[int(item) for item in input().split(' ')]
minfact(j,k)
``` | 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 i... | 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,560,759,649 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n = int(input())
ar = list(map(int, input().split()))
fl = (ar[1] % 2 + ar[0] % 2 + ar[2] % 2) // 2
i = 0
while True:
if ar[i] % 2 != fl:
print(i + 1)
break
i += 1 | 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 — t... | ```python
n = int(input())
ar = list(map(int, input().split()))
fl = (ar[1] % 2 + ar[0] % 2 + ar[2] % 2) // 2
i = 0
while True:
if ar[i] % 2 != fl:
print(i + 1)
break
i += 1
``` | 3.9455 |
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 ... | 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,658,515,147 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n, m = map(int, input().split())
import math
print(math.floor(n*m*0.5)) | 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 p... | ```python
n, m = map(int, input().split())
import math
print(math.floor(n*m*0.5))
``` | 3.977 |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,572,652,650 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 124 | 204,800 | def inp():
return map(int, input().split())
def arr_inp():
return [int(x) for x in input().split()]
def print_arr(arr):
print(*arr, sep=' ')
n = int(input())
count, max = 0, 4127
for i in range(n):
a, b = inp()
if (a == b):
if(a<=max):
count += 1
... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
def inp():
return map(int, input().split())
def arr_inp():
return [int(x) for x in input().split()]
def print_arr(arr):
print(*arr, sep=' ')
n = int(input())
count, max = 0, 4127
for i in range(n):
a, b = inp()
if (a == b):
if(a<=max):
count += 1... | 3 | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,637,858,947 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | a=input()
b=input()
c=input()
if b[0]==b[1]:
if a==c or a==c[::-1]:
print("YES")
else:
print("NO")
else:
print("NO") | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
a=input()
b=input()
c=input()
if b[0]==b[1]:
if a==c or a==c[::-1]:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,691,010,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | melon = int(input("Weight: "))
if(melon % 2 == 0 and melon != 2):
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
melon = int(input("Weight: "))
if(melon % 2 == 0 and melon != 2):
print("YES")
else:
print("NO")
``` | 0 |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee ... | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe ... | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperatur... | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
... | 1,632,673,797 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 29,696,000 | '''3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
'''
n,k,q=map(int,input().split())
hasha=[0 for i in range(200002)]
mini=1000000000000000000
maxi=-1
for i in range(n):
l,r=map(int,input().split())
mini=min(mini,l)
maxi=max(maxi,r)
hasha[l]+=1
hasha[r+1]-=1
#print(hasha[0:100])... | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve... | ```python
'''3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
'''
n,k,q=map(int,input().split())
hasha=[0 for i in range(200002)]
mini=1000000000000000000
maxi=-1
for i in range(n):
l,r=map(int,input().split())
mini=min(mini,l)
maxi=max(maxi,r)
hasha[l]+=1
hasha[r+1]-=1
#print(has... | 0 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,699,167,346 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | nums = input().split('+')
nums.sort()
nums = '+'.join(nums)
print(nums) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
nums = input().split('+')
nums.sort()
nums = '+'.join(nums)
print(nums)
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,682,045,956 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | arr = input().split(" ")
n = int(arr[0])
x = int(arr[1])
r = 0
for _ in range(n):
p = input().split(" ")
c = p[0]
d = int(p[1])
if c == "+" :
x+=d
if c == "-" :
if x >= d :
x-=d
else :
r+=1
print(x,r) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
arr = input().split(" ")
n = int(arr[0])
x = int(arr[1])
r = 0
for _ in range(n):
p = input().split(" ")
c = p[0]
d = int(p[1])
if c == "+" :
x+=d
if c == "-" :
if x >= d :
x-=d
else :
r+=1
print(x,r)
``` | 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 ple... | 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 steward... | 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,684,216,840 | 2,147,483,647 | PyPy 3 | OK | TESTS | 88 | 171 | 10,956,800 | n = int(input())
arr = list(map(int, input().split()))
def count(nums):
if len(nums) <= 2:
print(0)
return
less = nums[0]
large = nums[0]
res = 0
for index in range(len(nums)):
cur = nums[index]
less = min(less, cur)
large = max(large, cur)
fo... | 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... | ```python
n = int(input())
arr = list(map(int, input().split()))
def count(nums):
if len(nums) <= 2:
print(0)
return
less = nums[0]
large = nums[0]
res = 0
for index in range(len(nums)):
cur = nums[index]
less = min(less, cur)
large = max(large, cu... | 3 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,675,523,974 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 342 | 12,595,200 | # LUOGU_RID: 101472716
(n,),*a=[tuple(map(int,s.split()))for s in open(0)]
t=(min(x[0]for x in a),max(x[1]for x in a))
print(t in a and a.index(t)+1 or -1) | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
# LUOGU_RID: 101472716
(n,),*a=[tuple(map(int,s.split()))for s in open(0)]
t=(min(x[0]for x in a),max(x[1]for x in a))
print(t in a and a.index(t)+1 or -1)
``` | 3 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,596,725,693 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 20,172,800 | n=int(input())
r=n/2
if 2*r==n:
print(r-1,r+1)
else :
print(r,n-r) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
n=int(input())
r=n/2
if 2*r==n:
print(r-1,r+1)
else :
print(r,n-r)
``` | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,688,357,935 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n,m = input().split()
n,m = int(n),int(m)
ans=0
cnt = n
day = 1
while cnt>0:
if day==m:
cnt+=1
day=1
else:
day+=1
ans+=1
cnt-=1
print(ans)
# 10 + | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
n,m = input().split()
n,m = int(n),int(m)
ans=0
cnt = n
day = 1
while cnt>0:
if day==m:
cnt+=1
day=1
else:
day+=1
ans+=1
cnt-=1
print(ans)
# 10 +
``` | 3 | |
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and brin... | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to th... | 1,547,856,658 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 156 | 0 | import sys
s = sys.stdin.read()
lines = s.split('\n')
length = 0
left = 1
for inp in lines:
if len(inp) > length:
length = len(s)
print('*' * (length + 2))
for line in lines:
if (length - len(line)) % 2 == 0:
print('*' + ' ' * ((length - len(line)) // 2) + line + ' ' * ((length - len(... | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You ... | ```python
import sys
s = sys.stdin.read()
lines = s.split('\n')
length = 0
left = 1
for inp in lines:
if len(inp) > length:
length = len(s)
print('*' * (length + 2))
for line in lines:
if (length - len(line)) % 2 == 0:
print('*' + ' ' * ((length - len(line)) // 2) + line + ' ' * ((len... | 0 |
207 | D1 | The Beaver's Problem - 3 | PROGRAMMING | 1,800 | [] | null | null | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | The first line contains integer *id* (0<=≤<=*id*<=≤<=106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are ... | Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to. | [] | [] | none | 10 | [
{
"input": "2000\nJAPAN FEBRUARY MONEY SUPPLY RISES 8.8 PCT\nTOKYO, March 17 - Japan's broadly defined money supply\naverage of M-2 plus certificate of deposits (CDs) rose a\npreliminary 8.8 pct in February from a year earlier, compared\nwith an 8.6 pct rise in January, the Bank of Japan said.\nThe seasonally a... | 1,673,005,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS1 | 2 | 31 | 0 | # LUOGU_RID: 98853065
print("1") | Title: The Beaver's Problem - 3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subje... | ```python
# LUOGU_RID: 98853065
print("1")
``` | 0 | |
195 | B | After Training | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly... | The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. | Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. | [
"4 3\n",
"3 1\n"
] | [
"2\n1\n3\n2\n",
"1\n1\n1\n"
] | none | 1,000 | [
{
"input": "4 3",
"output": "2\n1\n3\n2"
},
{
"input": "3 1",
"output": "1\n1\n1"
},
{
"input": "10 3",
"output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2"
},
{
"input": "6 5",
"output": "3\n2\n4\n1\n5\n3"
},
{
"input": "2 6",
"output": "3\n4"
},
{
"input": "5 2"... | 1,646,994,988 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 374 | 11,059,200 | import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
n,b = M()
j = b//2
i = j
if b%2==0:
j+=1
else:
i+=1
j+=1
while n>0:
if b%2==0:
if i==0 and j==b+1:
i ... | Title: After Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are posi... | ```python
import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353
n,b = M()
j = b//2
i = j
if b%2==0:
j+=1
else:
i+=1
j+=1
while n>0:
if b%2==0:
if i==0 and j==b+1:
... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | 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,691,488,933 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a=input()
s=0
d=0
for i in range(len(a)):
if a[i].isupper():
s+=1
else:
d+=1
if s>d:
print(a.upper())
else:
print(a.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a=input()
s=0
d=0
for i in range(len(a)):
if a[i].isupper():
s+=1
else:
d+=1
if s>d:
print(a.upper())
else:
print(a.lower())
``` | 3.977 |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,597,786,658 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 921,600 | # -*- coding: utf-8 -*-
"""
Created on Wed Aug 19 03:13:15 2020
@author: Dark Soul
"""
n=int(input(''))
s=''
cnt=0
if n==1:
print('a')
elif n==2:
print('ab')
else:
freq=n//2
rem=n&1
x='aa'
for i in range(freq):
s+=x
if x=='aa':
x='bb'
e... | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 19 03:13:15 2020
@author: Dark Soul
"""
n=int(input(''))
s=''
cnt=0
if n==1:
print('a')
elif n==2:
print('ab')
else:
freq=n//2
rem=n&1
x='aa'
for i in range(freq):
s+=x
if x=='aa':
x='bb'
... | 3 | |
959 | B | Mahmoud and Ehab and the message | PROGRAMMING | 1,200 | [
"dsu",
"greedy",
"implementation"
] | null | null | Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word ... | The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of l... | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | [
"5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n"
] | [
"107",
"116"
] | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | 1,000 | [
{
"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "107"
},
{
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "116"
},
{
"input": "1 1 1\na\n1000000000\n1 1\na",
"output": ... | 1,605,357,728 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 0 | def find(dd,a):
if dd[a]==a:
return dd[a]
dd[a]=find(dd,dd[a])
return dd[a]
def union(dd,l,d,a,b,i,j):
x=find(dd,a)
y=find(dd,b)
if x!=y:
if l[i]<l[j]:
dd[y]=x
else:
dd[x]=y
n,k,m=map(int,input().split())
s=input().split()
d={}
dd={}
e={}
for i in range(n):
d[i+1]=s[i]
dd[s[i]]=s[i]
l=list(ma... | Title: Mahmoud and Ehab and the message
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words... | ```python
def find(dd,a):
if dd[a]==a:
return dd[a]
dd[a]=find(dd,dd[a])
return dd[a]
def union(dd,l,d,a,b,i,j):
x=find(dd,a)
y=find(dd,b)
if x!=y:
if l[i]<l[j]:
dd[y]=x
else:
dd[x]=y
n,k,m=map(int,input().split())
s=input().split()
d={}
dd={}
e={}
for i in range(n):
d[i+1]=s[i]
dd[s[i]]=s[i]
... | 0 | |
55 | B | Smallest number | PROGRAMMING | 1,600 | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | 1,000 | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 1,674,046,295 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 92 | 0 | def solve(index):
if index==3:
for x in arr:
if x>=0:
ans[0]=min(ans[0],x)
return
for i in range(4):
if arr[i] !=-1:
for j in range(4):
if i==j or arr[j]==-1:
continue
a,b=arr[i],arr[j... | Title: Smallest number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the n... | ```python
def solve(index):
if index==3:
for x in arr:
if x>=0:
ans[0]=min(ans[0],x)
return
for i in range(4):
if arr[i] !=-1:
for j in range(4):
if i==j or arr[j]==-1:
continue
a,b=ar... | 3.977 |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,567,242,075 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | def swap(seq,i,j):
temp=seq[i]
seq[i]=seq[j]
seq[j]=temp
def argsort(n,seq):
i=1
indices=[]
while i<=n:
indices.append(i)
i+=1
i=0
while i<n-1:
j=i+1
while j<n:
if(seq[j]<seq[i]):
swap(seq,i,j)
swap(indices,i,j)
j+=1
i+=1
return indices
def Cards(n, seq):
arg... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
def swap(seq,i,j):
temp=seq[i]
seq[i]=seq[j]
seq[j]=temp
def argsort(n,seq):
i=1
indices=[]
while i<=n:
indices.append(i)
i+=1
i=0
while i<n-1:
j=i+1
while j<n:
if(seq[j]<seq[i]):
swap(seq,i,j)
swap(indices,i,j)
j+=1
i+=1
return indices
def Cards(n, s... | 3 | |
415 | B | Mashmokh and Tokens | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation",
"math"
] | null | null | Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest o... | The first line of input contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109). | Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day. | [
"5 1 4\n12 6 11 9 1\n",
"3 1 2\n1 2 3\n",
"1 1 1\n1\n"
] | [
"0 2 3 1 1 ",
"1 0 1 ",
"0 "
] | none | 1,000 | [
{
"input": "5 1 4\n12 6 11 9 1",
"output": "0 2 3 1 1 "
},
{
"input": "3 1 2\n1 2 3",
"output": "1 0 1 "
},
{
"input": "1 1 1\n1",
"output": "0 "
},
{
"input": "1 1 1000000000\n1000000000",
"output": "0 "
},
{
"input": "1 1 1000000000\n999999999",
"output": "9... | 1,396,799,291 | 491 | Python 3 | OK | TESTS | 47 | 186 | 9,830,400 | """
Codeforces Round 240 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
... | Title: Mashmokh and Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each... | ```python
"""
Codeforces Round 240 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
... | 3 | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,517,484,605 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 62 | 5,632,000 | n, s = map(int, input().split())
MAXN = 1010
T = [-1]*MAXN
for i in range(n):
f, t = map(int, input().split())
T[f] = max(T[f], t)
now = 0
nowf = s
while nowf > 0:
now = max(now, T[nowf])
nowf-=1
now+=1
print(now)
| Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n, s = map(int, input().split())
MAXN = 1010
T = [-1]*MAXN
for i in range(n):
f, t = map(int, input().split())
T[f] = max(T[f], t)
now = 0
nowf = s
while nowf > 0:
now = max(now, T[nowf])
nowf-=1
now+=1
print(now)
``` | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,545,561,515 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 500 | 0 | x=input().split()
a=int(x[0])
b=int(x[1])
if a%b==0:
c=a+b
else:
while a%b!=0:
a+=1
c=a
print(c)
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
x=input().split()
a=int(x[0])
b=int(x[1])
if a%b==0:
c=a+b
else:
while a%b!=0:
a+=1
c=a
print(c)
``` | 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 th... | 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,589,893,493 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | string = input()
print (string.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string = input()
print (string.lower())
``` | 0 |
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 mini... | 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 ... | 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,666,891,977 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x = int(input())
c = 0
while x != 0:
c += x % 2
x = x // 2
print(c
| 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... | ```python
x = int(input())
c = 0
while x != 0:
c += x % 2
x = x // 2
print(c
``` | -1 | |
1,008 | A | Romaji | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. | Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"sumimasen\n",
"ninja\n",
"codeforces\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese. | 500 | [
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"in... | 1,694,004,957 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 77 | 0 | x = input()
vow=['a','e','i','o','u']
n=len(x)
for i in range(n):
if x[i] in vow or x[i]=='n':
continue
else:
if i==n-1:
print('NO')
exit(0)
else:
if x[i+1] not in vow:
print('NO')
exit(0)
print('YES'... | Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after eve... | ```python
x = input()
vow=['a','e','i','o','u']
n=len(x)
for i in range(n):
if x[i] in vow or x[i]=='n':
continue
else:
if i==n-1:
print('NO')
exit(0)
else:
if x[i+1] not in vow:
print('NO')
exit(0)
p... | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,687,496,221 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | letters_set = input()[1:-1]
letters_list = letters_set.split(", ")
distinct_letters = set(letters_list)
count = len(distinct_letters)
print(count)
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
letters_set = input()[1:-1]
letters_list = letters_set.split(", ")
distinct_letters = set(letters_list)
count = len(distinct_letters)
print(count)
``` | 0 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,655,464,611 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 77 | 0 | n= int(input())
s= [int(x) for x in input().split()]
a=[]
b=[]
for i in range(0,len(s)-2):
a.append(s[i+2]-s[i])
m = a.index((min(a)))
s.pop(m+1)
for i in range(len(s)-1):
b.append(s[i+1]-s[i])
print(max(b)) | Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
n= int(input())
s= [int(x) for x in input().split()]
a=[]
b=[]
for i in range(0,len(s)-2):
a.append(s[i+2]-s[i])
m = a.index((min(a)))
s.pop(m+1)
for i in range(len(s)-1):
b.append(s[i+1]-s[i])
print(max(b))
``` | 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 ... | 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,607,539,180 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | M, N = input().split()
M = int(M)
N = int(N)
liczba_pol = M * N
if liczba_pol % 2 == 0:
print(liczba_pol / 2)
else:
print((liczba_pol - 1) / 2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
M, N = input().split()
M = int(M)
N = int(N)
liczba_pol = M * N
if liczba_pol % 2 == 0:
print(liczba_pol / 2)
else:
print((liczba_pol - 1) / 2)
``` | 0 |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,617,212,625 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 35 | 124 | 0 | def find_best_snow_drifts(snow_drifts, point):
snow_drifts.remove(point)
if len(snow_drifts) > 0:
same_line_snow_drifts = get_points_same_line(snow_drifts, point)
for p in same_line_snow_drifts:
find_best_snow_drifts(snow_drifts, p)
def is_same_line(point1, point2):
return point1[0] == point2[0] or... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
def find_best_snow_drifts(snow_drifts, point):
snow_drifts.remove(point)
if len(snow_drifts) > 0:
same_line_snow_drifts = get_points_same_line(snow_drifts, point)
for p in same_line_snow_drifts:
find_best_snow_drifts(snow_drifts, p)
def is_same_line(point1, point2):
return point1[0] == po... | -1 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,693,577,649 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 155 | 26,521,600 | from sys import stdin
def input(): return stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
l=a+b
ans=l[0]
for i in range(1,2*n-1):
ans^=l[i]
print(ans)
l=b+c
ans=l[0]
for i in range(1,2*n-3):
ans^=l[i]
print(ans) | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
from sys import stdin
def input(): return stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
l=a+b
ans=l[0]
for i in range(1,2*n-1):
ans^=l[i]
print(ans)
l=b+c
ans=l[0]
for i in range(1,2*n-3):
ans^=l[i]
prin... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,690,186,776 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | p=list(map(int,input().split()))
for i in p:
if n%2==0 and n!=2:
print("yes")
else:
print("no")
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
p=list(map(int,input().split()))
for i in p:
if n%2==0 and n!=2:
print("yes")
else:
print("no")
``` | -1 |
899 | B | Months and Years | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.
... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=24) — the number of integers.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (28<=≤<=*a**i*<=≤<=31) — the numbers you are to check. | If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large). | [
"4\n31 31 30 31\n",
"2\n30 30\n",
"5\n29 31 30 31 30\n",
"3\n31 28 30\n",
"3\n31 31 28\n"
] | [
"Yes\n\n",
"No\n\n",
"Yes\n\n",
"No\n\n",
"Yes\n\n"
] | In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of... | 1,000 | [
{
"input": "4\n31 31 30 31",
"output": "Yes"
},
{
"input": "2\n30 30",
"output": "No"
},
{
"input": "5\n29 31 30 31 30",
"output": "Yes"
},
{
"input": "3\n31 28 30",
"output": "No"
},
{
"input": "3\n31 31 28",
"output": "Yes"
},
{
"input": "24\n29 28 3... | 1,630,648,203 | 1,683 | PyPy 3 | WRONG_ANSWER | TESTS | 54 | 108 | 20,172,800 | n = int(input())
l = list(map(int,input().split()))
o = []
for i in range(12):
if i%2 == 0 and i < 7:
o.append(31)
if i%2 == 1 and i < 7:
o.append(30)
if i%2 == 0 and i >= 7:
o.append(30)
if i%2 == 1 and i >= 7:
o.append(31)
o[1] = 28
# print(o)
z = ... | Title: Months and Years
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, ... | ```python
n = int(input())
l = list(map(int,input().split()))
o = []
for i in range(12):
if i%2 == 0 and i < 7:
o.append(31)
if i%2 == 1 and i < 7:
o.append(30)
if i%2 == 0 and i >= 7:
o.append(30)
if i%2 == 1 and i >= 7:
o.append(31)
o[1] = 28
# prin... | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,638,555,909 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | y,k,n=map(int,input().split())
if n<=y:
print(-1)
exit()
potatoes=[]
i=1
while y+i<=n:
if (i+y)%k==0:
potatoes.append(i)
i+=1
print(*potatoes) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y,k,n=map(int,input().split())
if n<=y:
print(-1)
exit()
potatoes=[]
i=1
while y+i<=n:
if (i+y)%k==0:
potatoes.append(i)
i+=1
print(*potatoes)
``` | 0 | |
535 | A | Tavas and Nafas | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without... | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | 500 | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
... | 1,587,797,560 | 2,147,483,647 | Python 3 | OK | TESTS | 100 | 124 | 307,200 | first = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen',
'fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
second = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
n = int(input())
if(n < 20):
print(first... | Title: Tavas and Nafas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit... | ```python
first = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen',
'fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
second = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
n = int(input())
if(n < 20):
p... | 3 | |
464 | E | The Classic Problem | PROGRAMMING | 3,000 | [
"data structures",
"graphs",
"shortest paths"
] | null | null | You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist. | The first line of the input contains two space-separated integers — *n* and *m* (1<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105).
Next *m* lines contain the description of the graph edges. The *i*-th line contains three space-separated integers — *u**i*, *v**i*, *x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 0<=≤<=*x**i*<=≤<=105). That... | In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109<=+<=7) if the path exists, and -1 if the path doesn't exist.
If the path exists print in the second line integer *k* — the number of vertices in the shortest path from vertex *s* to vertex *t*; in the third line pri... | [
"4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n",
"4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n",
"4 2\n1 2 0\n3 4 1\n1 4\n"
] | [
"3\n4\n1 2 3 4 \n",
"112\n4\n1 2 3 4 \n",
"-1\n"
] | A path from vertex *s* to vertex *t* is a sequence *v*<sub class="lower-index">0</sub>, ..., *v*<sub class="lower-index">*k*</sub>, such that *v*<sub class="lower-index">0</sub> = *s*, *v*<sub class="lower-index">*k*</sub> = *t*, and for any *i* from 0 to *k* - 1 vertices *v*<sub class="lower-index">*i*</sub> and *v*<s... | 2,500 | [] | 1,621,673,941 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 5,000 | 3,584,000 | import sys
def solve():
n,m = [int(x) for x in input().split()]
n = n+1
neighbours = [[] for i in range(n)]
for i in range(m):
a,b, dist = [int(x) for x in input().split()]
#dist is the exponent of 2. actual cost would be 2**dist
neighbours[a].append([b,dist])
... | Title: The Classic Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist.
Input Specification:
The first line of the i... | ```python
import sys
def solve():
n,m = [int(x) for x in input().split()]
n = n+1
neighbours = [[] for i in range(n)]
for i in range(m):
a,b, dist = [int(x) for x in input().split()]
#dist is the exponent of 2. actual cost would be 2**dist
neighbours[a].append([b,dist])... | 0 | |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX"... | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
... | 1,487,086,572 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 4,608,000 | print("contest" if int(input())%2 else "home") | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei... | ```python
print("contest" if int(input())%2 else "home")
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,567,432,284 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 0 | books = int(input())
digits = 0
for i in range(1, books + 1):
digits += len(str(i))
print(digits)
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
books = int(input())
digits = 0
for i in range(1, books + 1):
digits += len(str(i))
print(digits)
``` | 0 | |
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "854193955406789... | 1,644,186,366 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
m = int(input())
print(9*(10**(n-1)+m) | Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=... | ```python
n = int(input())
m = int(input())
print(9*(10**(n-1)+m)
``` | -1 | |
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... | 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 t... | 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,611,924,070 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,048,000 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
#print(a)
#print(b)
list1=[]
m=1000
for i in range(n):
#print("1st")
if(a[i] in b):
m=a[i]
list1.append(a[i])
break
for i in range(m):
#print("2nd")
i... | 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 sm... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
#print(a)
#print(b)
list1=[]
m=1000
for i in range(n):
#print("1st")
if(a[i] in b):
m=a[i]
list1.append(a[i])
break
for i in range(m):
#print("2n... | -1 | |
686 | B | Little Robber Girl's Zoo | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"sortings"
] | null | null | Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — number of animals in the robber girl's zoo.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the height of the animal occupying the *i*-th place. | Print the sequence of operations that will rearrange the animals by non-decreasing height.
The output should contain several lines, *i*-th of the lines should contain two space-separated integers *l**i* and *r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*) — descriptions of segments the robber girl should name. The segments... | [
"4\n2 1 4 3\n",
"7\n36 28 57 39 66 69 68\n",
"5\n1 2 1 2 1\n"
] | [
"1 4\n",
"1 4\n6 7\n",
"2 5\n3 4\n1 4\n1 4\n"
] | Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed. | 1,000 | [
{
"input": "4\n2 1 4 3",
"output": "1 2\n3 4"
},
{
"input": "7\n36 28 57 39 66 69 68",
"output": "1 2\n3 4\n6 7"
},
{
"input": "5\n1 2 1 2 1",
"output": "2 3\n4 5\n3 4"
},
{
"input": "78\n7 3 8 8 9 8 10 9 12 11 16 14 17 17 18 18 20 20 25 22 27 26 29 27 35 35 36 36 37 37 38 38... | 1,623,561,914 | 1,514 | PyPy 3 | OK | TESTS | 37 | 140 | 4,300,800 | n= int(input())
a = list(map(int,input().split()))
QQQ = 0
while True:
B = list(a)
for i in range(n-1):
if a[i] > a[i+1]:
print(i+1,i+2)
a[i],a[i+1] = a[i+1],a[i]
#print(a)
if a == B:
break | Title: Little Robber Girl's Zoo
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in th... | ```python
n= int(input())
a = list(map(int,input().split()))
QQQ = 0
while True:
B = list(a)
for i in range(n-1):
if a[i] > a[i+1]:
print(i+1,i+2)
a[i],a[i+1] = a[i+1],a[i]
#print(a)
if a == B:
break
``` | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,633,362,798 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 20,172,800 | r, c = map(int, input().split())
ar = list()
line = 0
row = 0
for i in range(r):
s = input()
if 'S' in s:
line += 1
for j in range(len(s)):
if j not in ar:
row +=1
ar.append(j)
print(r * c - line * row) | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r, c = map(int, input().split())
ar = list()
line = 0
row = 0
for i in range(r):
s = input()
if 'S' in s:
line += 1
for j in range(len(s)):
if j not in ar:
row +=1
ar.append(j)
print(r * c - line * row)
``` | 0 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,696,017,211 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | L=input().split('+')
LL=sorted([int(i)for i in L])
s=''
for i in LL:
s=s+str(i)
print(s-'+')
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
L=input().split('+')
LL=sorted([int(i)for i in L])
s=''
for i in LL:
s=s+str(i)
print(s-'+')
``` | -1 | |
522 | B | Photo to Remember | PROGRAMMING | 1,100 | [
"*special",
"data structures",
"dp",
"implementation"
] | null | null | One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangl... | The first line contains integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of friends.
Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≤<=*w**i*<=≤<=10,<=1<=≤<=*h**i*<=≤<=1000) — the width and height in pixels of the correspo... | Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* — the total number of pixels on the minimum photo containing all friends expect for the *i*-th one. | [
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n"
] | [
"75 110 60 ",
"6 4 6 "
] | none | 1,000 | [
{
"input": "3\n1 10\n5 5\n10 1",
"output": "75 110 60 "
},
{
"input": "3\n2 1\n1 2\n2 1",
"output": "6 4 6 "
},
{
"input": "2\n1 5\n2 3",
"output": "6 5 "
},
{
"input": "2\n2 3\n1 1",
"output": "1 6 "
},
{
"input": "3\n1 10\n2 10\n3 10",
"output": "50 40 30 "
... | 1,425,832,108 | 1,888 | Python 3 | OK | TESTS | 44 | 1,404 | 6,656,000 | st=int(input())
summa=0
q=[]
w=[]
ish=[]
for i in range(st):
z,x=map(int,input().split())
q.append(z)
w.append(x)
ish.append(x)
summa=sum(q)
w.sort()
for i in range(st):
qw=w[st-1]
if ish[i]==qw:
qw=w[st-2]
print((summa-q[i])*qw,end=' ') | Title: Photo to Remember
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the p... | ```python
st=int(input())
summa=0
q=[]
w=[]
ish=[]
for i in range(st):
z,x=map(int,input().split())
q.append(z)
w.append(x)
ish.append(x)
summa=sum(q)
w.sort()
for i in range(st):
qw=w[st-1]
if ish[i]==qw:
qw=w[st-2]
print((summa-q[i])*qw,end=' ')
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 0 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,658,725 | 2,025 | Python 3 | OK | TESTS | 46 | 93 | 4,608,000 | """task a."""
import math
str = input()
number_strings = str.split(" ")
[n, m, k] = [int(n) for n in number_strings]
s = "L" if k % 2 == 1 else "R"
d = math.ceil((k / 2)) % m
d = m if d == 0 else d
r = math.ceil(k / (m * 2))
print(" ", r, d, s)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desk... | ```python
"""task a."""
import math
str = input()
number_strings = str.split(" ")
[n, m, k] = [int(n) for n in number_strings]
s = "L" if k % 2 == 1 else "R"
d = math.ceil((k / 2)) % m
d = m if d == 0 else d
r = math.ceil(k / (m * 2))
print(" ", r, d, s)
``` | 3 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,450,078,366 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 218 | 819,200 | import string
s = input()
x = input()
y = input()
a = False
b = False
if x in s:
if y in s[s.find(x) + len(x):]:
a = True
s = s[::-1]
if x in s:
if y in s[s.find(x) + len(x):]:
b = True
if a and b:
print("both")
elif a:
print("forward")
elif b:
print("backward")
el... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
import string
s = input()
x = input()
y = input()
a = False
b = False
if x in s:
if y in s[s.find(x) + len(x):]:
a = True
s = s[::-1]
if x in s:
if y in s[s.find(x) + len(x):]:
b = True
if a and b:
print("both")
elif a:
print("forward")
elif b:
print("back... | 3.884896 |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,660,304,936 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 |
n=int(input())
s=[int(x) for x in input().split()]
a=s.count(1)
b=s.count(2)
c=s.count(3)
ans=min(a,b,c)
print(min(a,b,c))
p1=[]
p2=[]
p3=[]
for i in range(0,n):
if s[i]==1:
p1.append(i+1)
elif s[i]==2:
p2.append(i+1)
else:
p3.append(i+1)
for k in range(0,ans):
... | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n=int(input())
s=[int(x) for x in input().split()]
a=s.count(1)
b=s.count(2)
c=s.count(3)
ans=min(a,b,c)
print(min(a,b,c))
p1=[]
p2=[]
p3=[]
for i in range(0,n):
if s[i]==1:
p1.append(i+1)
elif s[i]==2:
p2.append(i+1)
else:
p3.append(i+1)
for k in range(0... | 3 | |
576 | A | Vasya and Petya's Game | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can a... | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Th... | 500 | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "2... | 1,564,472,574 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | n = int(input())
h = []
for i in range(2, n):
g = 0
for j in range(2, int(i ** 0.5) + 1):
if i % j == 0:
g += 1
if g == 0:
h.append(i)
g = 0
while g < len(h):
x = h[g]
if x ** 2 <= n:
h.append(x ** 2)
g += 1
print(*h)
| Title: Vasya and Petya's Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The... | ```python
n = int(input())
h = []
for i in range(2, n):
g = 0
for j in range(2, int(i ** 0.5) + 1):
if i % j == 0:
g += 1
if g == 0:
h.append(i)
g = 0
while g < len(h):
x = h[g]
if x ** 2 <= n:
h.append(x ** 2)
g += 1
print(*h)
``` | 0 | |
761 | B | Dasha and friends | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if... | The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length.
The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the ra... | Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). | [
"3 8\n2 4 6\n1 5 7\n",
"4 9\n2 3 5 8\n0 1 3 6\n",
"2 4\n1 3\n1 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | The first test is analyzed in the statement. | 1,000 | [
{
"input": "3 8\n2 4 6\n1 5 7",
"output": "YES"
},
{
"input": "4 9\n2 3 5 8\n0 1 3 6",
"output": "YES"
},
{
"input": "2 4\n1 3\n1 2",
"output": "NO"
},
{
"input": "5 9\n0 2 5 6 7\n1 3 6 7 8",
"output": "YES"
},
{
"input": "5 60\n7 26 27 40 59\n14 22 41 42 55",
... | 1,485,976,205 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,608,000 | n,l=map(int,input().split())
lis1=list(map(int,input().split()))
lis2=list(map(int,input().split()))
ans="YES"
dif=lis1[0]-lis2[0]
for i in range(1,n):
if(lis1[i]-lis2[i]==dif):
ans="NO"
break
print (ans) | Title: Dasha and friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinc... | ```python
n,l=map(int,input().split())
lis1=list(map(int,input().split()))
lis2=list(map(int,input().split()))
ans="YES"
dif=lis1[0]-lis2[0]
for i in range(1,n):
if(lis1[i]-lis2[i]==dif):
ans="NO"
break
print (ans)
``` | 0 | |
253 | C | Text Editor | PROGRAMMING | 1,600 | [
"data structures",
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, b... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the file. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105), separated by single spaces. The third line contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*r*2<=≤<=*n*,<=1<=... | Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2). | [
"4\n2 1 6 4\n3 4 4 2\n",
"4\n10 5 6 4\n1 11 4 2\n",
"3\n10 1 10\n1 10 1 1\n"
] | [
"3\n",
"6\n",
"3\n"
] | In the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter *s* represents the cursor's initial position, letter *t* represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.
123
12... | 1,500 | [
{
"input": "4\n2 1 6 4\n3 4 4 2",
"output": "3"
},
{
"input": "4\n10 5 6 4\n1 11 4 2",
"output": "6"
},
{
"input": "3\n10 1 10\n1 10 1 1",
"output": "3"
},
{
"input": "4\n2 1 6 4\n4 2 3 5",
"output": "4"
},
{
"input": "3\n20 3 20\n1 20 1 1",
"output": "5"
},... | 1,641,469,190 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 186 | 409,600 | from collections import *
import sys
#sys.setrecursionlimit((10**5))
import heapq
import sys
def inpu(): return int(input())
def sep(): return map(int,input().split())
def lis(): return list(sep())
"""
def main():
f = open('input.txt','r')
o = open('output.txt','w')
b,g = map(int,f.readline().sp... | Title: Text Editor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In f... | ```python
from collections import *
import sys
#sys.setrecursionlimit((10**5))
import heapq
import sys
def inpu(): return int(input())
def sep(): return map(int,input().split())
def lis(): return list(sep())
"""
def main():
f = open('input.txt','r')
o = open('output.txt','w')
b,g = map(int,f.rea... | 0 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | 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,637,241,600 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n =int(input())
main_arr =[]
arr = [1]*n
arr2 =[1]
for i in range(n-1):
for j in range(n-1):
value = arr[j+1]+arr2[j]
arr2.append(value)
arr = arr2
arr2 = [1]
print(max(arr))
| 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 t... | ```python
n =int(input())
main_arr =[]
arr = [1]*n
arr2 =[1]
for i in range(n-1):
for j in range(n-1):
value = arr[j+1]+arr2[j]
arr2.append(value)
arr = arr2
arr2 = [1]
print(max(arr))
``` | 3 | |
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\... | 1,613,065,781 | 2,147,483,647 | PyPy 3 | OK | TESTS | 93 | 109 | 0 | n=(int)(input())
d={}
a=list(map(int,input().split()))
for i in a:
if i in d:
d[i]+=1
else:
d[i]=1
res=0
for i in d:
res+=(int)(d[i]/2)
print((int)(res/2)) | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin w... | ```python
n=(int)(input())
d={}
a=list(map(int,input().split()))
for i in a:
if i in d:
d[i]+=1
else:
d[i]=1
res=0
for i in d:
res+=(int)(d[i]/2)
print((int)(res/2))
``` | 3 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,614,200,349 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,k1,k2;
scanf("%d %d %d",&n,&k1,&k2);
int k=k1+k2;
vector <int> a(n),b(n), c;
for (int i=0;i<n;i++) {
scanf("%d", &a[i]);
}
for (int i=0;i<n;i++) {
scanf("%d", &b... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,k1,k2;
scanf("%d %d %d",&n,&k1,&k2);
int k=k1+k2;
vector <int> a(n),b(n), c;
for (int i=0;i<n;i++) {
scanf("%d", &a[i]);
}
for (int i=0;i<n;i++) {
scan... | -1 | |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the chi... | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space... | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
... | 1,620,675,945 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 6,656,000 | with open("input.txt","r") as file:
with open("output.txt","w") as file2:
N = file.readline()
N = int(N)
n = int(N/2)
S = file.readline()
S = str(S)
for i in range(0,n):
if S[i] == "R" and S[i+n] =="L":
file2.write(i+n+1,i+1)
... | Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t... | ```python
with open("input.txt","r") as file:
with open("output.txt","w") as file2:
N = file.readline()
N = int(N)
n = int(N/2)
S = file.readline()
S = str(S)
for i in range(0,n):
if S[i] == "R" and S[i+n] =="L":
file2.write(i+n+1,i... | -1 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,569,907,982 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | x = input()
y = input()
left, right = x.split('|')
for i in y:
if(len(left) < len(right)):
left+=i
else:
right+=i
if(len(left)==len(right)):
print("{}|{}".format(left, right))
else:
print("Immpossible")
| Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
x = input()
y = input()
left, right = x.split('|')
for i in y:
if(len(left) < len(right)):
left+=i
else:
right+=i
if(len(left)==len(right)):
print("{}|{}".format(left, right))
else:
print("Immpossible")
``` | 0 | |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,696,234,342 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 8 | 62 | 2,867,200 | import sys
def solve(ch, subsequences):
if len(subsequences[ch]) == 0:
return 0
start_i, end_i = subsequences[ch][0][0], subsequences[ch][0][1]
max_len = end_i - start_i + k
current_len = end_i - start_i
used_k = 0
k_list = []
ends = [end_i]
for i in range(1, len(subsequences[ch])):
next_start_i, next_en... | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
import sys
def solve(ch, subsequences):
if len(subsequences[ch]) == 0:
return 0
start_i, end_i = subsequences[ch][0][0], subsequences[ch][0][1]
max_len = end_i - start_i + k
current_len = end_i - start_i
used_k = 0
k_list = []
ends = [end_i]
for i in range(1, len(subsequences[ch])):
next_start_... | -1 | |
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 shoul... | 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,660,538,005 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | x = int(input())
n = input()
factorial = {
2:[2],
3:[3],
4:[3,2,2],
5:[5],
6:[3,5],
7:[7],
8:[7,2,2,2],
9:[7,3,3,2]
}
res = []
for i in n:
num = int(i)
if num != 1 and num != 0:
res += factorial[num]
res = sorted(res,reverse = True)
s = ""
for i in res:
s+=str(i)
... | 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 cont... | ```python
x = int(input())
n = input()
factorial = {
2:[2],
3:[3],
4:[3,2,2],
5:[5],
6:[3,5],
7:[7],
8:[7,2,2,2],
9:[7,3,3,2]
}
res = []
for i in n:
num = int(i)
if num != 1 and num != 0:
res += factorial[num]
res = sorted(res,reverse = True)
s = ""
for i in res:
s... | 3 | |
557 | C | Arthur and Table | PROGRAMMING | 1,900 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input ... | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | 1,500 | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\... | 1,629,640,310 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 20,172,800 | # https://codeforces.com/problemset/problem/713/A
t = int(input())
inp_arr = []
for _ in range(t):
inp_arr.append(input().split(' '))
multiset = {}
pattern_set = {}
odd = set(['1','3','5','7','9'])
even = set(['2','4','6','8','0'])
def add_value_to_multiset(val):
num = str(val)
curr = ''
f... | Title: Arthur and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arth... | ```python
# https://codeforces.com/problemset/problem/713/A
t = int(input())
inp_arr = []
for _ in range(t):
inp_arr.append(input().split(' '))
multiset = {}
pattern_set = {}
odd = set(['1','3','5','7','9'])
even = set(['2','4','6','8','0'])
def add_value_to_multiset(val):
num = str(val)
curr =... | 0 | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,699,069,476 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 13 | 92 | 0 | # LUOGU_RID: 133246561
a=[0 for i in range(1000)]
top=-1
sum=0
s=input()
for i in s:
if i=="(":
top+=1
a[top]="("
else:
if top!=-1:
top-=1
sum+=2
print(sum) | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
# LUOGU_RID: 133246561
a=[0 for i in range(1000)]
top=-1
sum=0
s=input()
for i in s:
if i=="(":
top+=1
a[top]="("
else:
if top!=-1:
top-=1
sum+=2
print(sum)
``` | -1 |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,693,408,707 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n = str(input())
x = n.replace("WUB", " ")
x = x.lstrip()
print(x) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
n = str(input())
x = n.replace("WUB", " ")
x = x.lstrip()
print(x)
``` | 3 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,670,399,278 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 265 | 12,390,400 | # -*- coding: utf-8 -*-
"""
Created on Wed Dec 7 14:01:59 2022
@author: 86138
"""
n,m=map(int,input().split())
li=list(map(int,input().split()))
s=set();dp=[0]*n;p=0
for i in range(n-1,-1,-1):
if li[i] not in s:
p+=1
s.add(li[i]);dp[i]=p
li_1=[]
for j in range(m):
a=int(input());l... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 7 14:01:59 2022
@author: 86138
"""
n,m=map(int,input().split())
li=list(map(int,input().split()))
s=set();dp=[0]*n;p=0
for i in range(n-1,-1,-1):
if li[i] not in s:
p+=1
s.add(li[i]);dp[i]=p
li_1=[]
for j in range(m):
a=int(... | 3 | |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,082,007 | 77,107 | Python 3 | OK | TESTS | 52 | 77 | 5,632,000 | import bisect
n,k = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
bord = 0
bikes = 0
while bord < n - 1:
path = x[bord] + k
cur = bisect.bisect_right(x, path)
if cur - 1 != bord:
bord = cur - 1
bikes += 1
else:
bikes = -1
break
print(bikes)
| Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
import bisect
n,k = map(int, input().split(' '))
x = list(map(int, input().split(' ')))
bord = 0
bikes = 0
while bord < n - 1:
path = x[bord] + k
cur = bisect.bisect_right(x, path)
if cur - 1 != bord:
bord = cur - 1
bikes += 1
else:
bikes = -1
break
print(bikes... | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,659,071,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n = int(input())
t =[*map(int,input().split())]
m = 0; cnt = 1
for i in range(0,n):
if((t[i]-m)<=15):m = t[i]
else: m += 15;cnt = 0; break
if(cnt): m = 90
print(m) | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
n = int(input())
t =[*map(int,input().split())]
m = 0; cnt = 1
for i in range(0,n):
if((t[i]-m)<=15):m = t[i]
else: m += 15;cnt = 0; break
if(cnt): m = 90
print(m)
``` | 0 | |
652 | A | Gabriel and Caterpillar | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when ... | The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=<<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeter... | Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer <=-<=1. | [
"10 30\n2 1\n",
"10 13\n1 1\n",
"10 19\n1 2\n",
"1 50\n5 4\n"
] | [
"1\n",
"0\n",
"-1\n",
"1\n"
] | In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the n... | 0 | [
{
"input": "10 30\n2 1",
"output": "1"
},
{
"input": "10 13\n1 1",
"output": "0"
},
{
"input": "10 19\n1 2",
"output": "-1"
},
{
"input": "1 50\n5 4",
"output": "1"
},
{
"input": "1 1000\n2 1",
"output": "82"
},
{
"input": "999 1000\n1 1",
"output"... | 1,646,755,794 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 76 | 62 | 0 | def solve(h1, h2, a, b):
d = max(h2 - a * 8 - h1, 0)
if d and a <= b:
return -1
x = max(1, (a - b) * 12)
return (d + x - 1) // x
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
print(solve(h1, h2, a, b))
| Title: Gabriel and Caterpillar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*... | ```python
def solve(h1, h2, a, b):
d = max(h2 - a * 8 - h1, 0)
if d and a <= b:
return -1
x = max(1, (a - b) * 12)
return (d + x - 1) // x
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
print(solve(h1, h2, a, b))
``` | 3 | |
980 | C | Posterized | PROGRAMMING | 1,700 | [
"games",
"greedy"
] | null | null | Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, theref... | The first line of input contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 256$), the number of pixels in the image, and the maximum size of a group, respectively.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i \leq 255$), where $p_i$ is the color of the $i$-th pixel. | Print $n$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter. | [
"4 3\n2 14 3 4\n",
"5 2\n0 2 1 255 254\n"
] | [
"0 12 3 3\n",
"0 1 1 254 254\n"
] | One possible way to group colors and assign keys for the first sample:
Color $2$ belongs to the group $[0,2]$, with group key $0$.
Color $14$ belongs to the group $[12,14]$, with group key $12$.
Colors $3$ and $4$ belong to group $[3, 5]$, with group key $3$.
Other groups won't affect the result so they are not lis... | 1,500 | [
{
"input": "4 3\n2 14 3 4",
"output": "0 12 3 3"
},
{
"input": "5 2\n0 2 1 255 254",
"output": "0 1 1 254 254"
},
{
"input": "10 3\n112 184 161 156 118 231 191 128 91 229",
"output": "110 182 159 154 116 229 189 126 89 229"
},
{
"input": "9 3\n174 149 118 124 166 146 219 233 ... | 1,525,798,610 | 6,710 | PyPy 3 | WRONG_ANSWER | PRETESTS | 8 | 93 | 21,401,600 | import sys
n, k = map(int, next(sys.stdin).rstrip().split())
xs = list(map(int, next(sys.stdin).rstrip().split()))
mapka = {}
lengths = {}
result = []
for x in xs:
if x in mapka:
result.append(mapka[x])
else:
left = max(0, x - k + 1)
range_potential = x - left
for i in range... | Title: Posterized
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.
Their algorithm will be tested on an array of integers, where the $i$-th intege... | ```python
import sys
n, k = map(int, next(sys.stdin).rstrip().split())
xs = list(map(int, next(sys.stdin).rstrip().split()))
mapka = {}
lengths = {}
result = []
for x in xs:
if x in mapka:
result.append(mapka[x])
else:
left = max(0, x - k + 1)
range_potential = x - left
for ... | 0 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,619,459,020 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 93 | 1,740,800 | length = int(input())
number = input()
def add(n):
num = str(n)
s = ""
for i in num:
ad = int(i) + 1
if(ad>9):
ad = 0
s = s + str(ad)
return s
def reverse(num):
return num[-1] + num[:-1]
dict_map ={}
def recursion(num,height... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
length = int(input())
number = input()
def add(n):
num = str(n)
s = ""
for i in num:
ad = int(i) + 1
if(ad>9):
ad = 0
s = s + str(ad)
return s
def reverse(num):
return num[-1] + num[:-1]
dict_map ={}
def recursion(... | 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 Vasy... | 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,684,496,973 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | num = int(input().split())
yomama = [0,0,0]
for a in range(num):
x = input().split()
for b in range(3):
yomama[b] += x[b] | 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. S... | ```python
num = int(input().split())
yomama = [0,0,0]
for a in range(num):
x = input().split()
for b in range(3):
yomama[b] += x[b]
``` | -1 |
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.