contestId int64 0 1.01k | index stringclasses 55
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 7 | title stringclasses 495
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 5 65.5k | instruction_seed stringlengths 262 8.2k | response stringlengths 19 65.5k | score float64 -1 3.99 | _source stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,573,545,326 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | str=input()
sum=0
if str.count('h')>=1:
a1=str.find('h')
sum+=1
if str.count('e',a1+1)>=1:
a2=str.find('e')
sum+=1
if str.count('l',a2+1)>=1:
a3=str.find('l')
sum+=1
if str.count('l',a3+1)>=1:
... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
str=input()
sum=0
if str.count('h')>=1:
a1=str.find('h')
sum+=1
if str.count('e',a1+1)>=1:
a2=str.find('e')
sum+=1
if str.count('l',a2+1)>=1:
a3=str.find('l')
sum+=1
if str.count('l',a3+1)>=1:
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,620,525,941 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 124 | 6,963,200 | def zeros(a,b):
c=a+b
c1=list(str(c))
b=list(str(b))
a=list(str(a))
c1.remove('0')
a.remove('0')
b.remove('0')
ans=int(''.join(c1))
if(ans==(int(''.join(a)))+int(''.join(b))):
return('YES')
else:
return('NO')
a=int(input())
b=int(input())
result=z... | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
def zeros(a,b):
c=a+b
c1=list(str(c))
b=list(str(b))
a=list(str(a))
c1.remove('0')
a.remove('0')
b.remove('0')
ans=int(''.join(c1))
if(ans==(int(''.join(a)))+int(''.join(b))):
return('YES')
else:
return('NO')
a=int(input())
b=int(input())... | -1 | MatrixStudio/Codeforces-Python-Submissions |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,680,286,943 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a,b=list(map(int,input().split()))
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
print(gcd(a,b-a)) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a,b=list(map(int,input().split()))
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
print(gcd(a,b-a))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,659,975,845 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # include <bits/stdc++.h>
# define printa(arr , n) for(int i = 0 ; i < n ; i++ ){cout << arr[i] << " ";} cout << endl ;
# define foor(n1 , n2) for(int i = n1 ; i < n2 ; i++ )
# define ll long long
using namespace std;
int main() {
string bin;
cin>>bin;
int co... | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
# include <bits/stdc++.h>
# define printa(arr , n) for(int i = 0 ; i < n ; i++ ){cout << arr[i] << " ";} cout << endl ;
# define foor(n1 , n2) for(int i = n1 ; i < n2 ; i++ )
# define ll long long
using namespace std;
int main() {
string bin;
cin>>bin;
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,693,471,265 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 31 | 0 | n=int(input())
array=list(map(int, input().split()))
brray=list(map(int, input().split()))
ora=array[0]
orb=brray[0]
for a in range(1,n-1):
ora=ora|array[a]
for b in range(1,n-1):
orb=orb|brray[b]
if n==2:
print(2*(ora+orb))
else:
print(ora+orb) | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
n=int(input())
array=list(map(int, input().split()))
brray=list(map(int, input().split()))
ora=array[0]
orb=brray[0]
for a in range(1,n-1):
ora=ora|array[a]
for b in range(1,n-1):
orb=orb|brray[b]
if n==2:
print(2*(ora+orb))
else:
print(ora+orb)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,501,429,197 | 3,897 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 5 | 1,000 | 10,854,400 | n,k=(int(i )for i in input().split())
s=input()
a=[0]*n
b=[]
x=k
y=0
alf='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
end=[s.rfind(i) for i in alf]
begin=[s.find(i) for i in alf]
f=False
ans=False
for i in range(n):
if ((i!=end[alf.find(s[i])]) and not(s[i] in b)) or ((begin[alf.find(s[i])]==end[alf.find(s[i])])):
... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
n,k=(int(i )for i in input().split())
s=input()
a=[0]*n
b=[]
x=k
y=0
alf='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
end=[s.rfind(i) for i in alf]
begin=[s.find(i) for i in alf]
f=False
ans=False
for i in range(n):
if ((i!=end[alf.find(s[i])]) and not(s[i] in b)) or ((begin[alf.find(s[i])]==end[alf.find(s[i]... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,498,245,212 | 2,147,483,647 | PyPy 3 | OK | TESTS | 95 | 2,152 | 46,284,800 | '''input
4
alex
ivan
roman
ivan
'''
n = int(input())
u = {}
for x in [input() for _ in range(n)][::-1]:
if x not in u:
u[x] = 1
print(x) | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
'''input
4
alex
ivan
roman
ivan
'''
n = int(input())
u = {}
for x in [input() for _ in range(n)][::-1]:
if x not in u:
u[x] = 1
print(x)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,568,435,442 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 13,926,400 | n=int(input())
arr=list(map(int,input().split()))
arr2=[]
p=0
for j in range(n,-1,-1):
for u in range(j+1,len(arr)):
if arr[j]==arr[u]:
arr2.append(u-j)
arr.pop(u)
if u-j==1:
arr.pop(j)
val=u-1
break
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
n=int(input())
arr=list(map(int,input().split()))
arr2=[]
p=0
for j in range(n,-1,-1):
for u in range(j+1,len(arr)):
if arr[j]==arr[u]:
arr2.append(u-j)
arr.pop(u)
if u-j==1:
arr.pop(j)
val=u-1
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,630,076,733 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 6,963,200 | n,x = map(int,input().split())
brojac = x
didina = 0
for i in range(n):
a,b = map(str, input().split())
if a == "-" and int(b) > brojac:
didina += 1
elif a == "-" and int(b) < brojac:
brojac = brojac - int(b)
else:
brojac = brojac + int(b)
print(brojac, didina)
| 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
n,x = map(int,input().split())
brojac = x
didina = 0
for i in range(n):
a,b = map(str, input().split())
if a == "-" and int(b) > brojac:
didina += 1
elif a == "-" and int(b) < brojac:
brojac = brojac - int(b)
else:
brojac = brojac + int(b)
print(brojac, didin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
181 | B | Number of Triplets | PROGRAMMING | 1,300 | [
"binary search",
"brute force"
] | null | null | You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points are considered unordered, that is, if point *B* is the middle of segment *AC*, then groups (*A*,<=*B*,<=*C... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=3000) — the number of points.
Next *n* lines contain the points. The *i*-th line contains coordinates of the *i*-th point: two space-separated integers *x**i*,<=*y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000).
It is guaranteed that all given points are diff... | Print the single number — the answer to the problem. | [
"3\n1 1\n2 2\n3 3\n",
"3\n0 0\n-1 0\n0 1\n"
] | [
"1\n",
"0\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "1"
},
{
"input": "3\n0 0\n-1 0\n0 1",
"output": "0"
},
{
"input": "4\n0 0\n1 0\n2 0\n3 0",
"output": "2"
},
{
"input": "5\n0 -1\n0 -2\n0 -3\n0 -4\n0 -5",
"output": "4"
},
{
"input": "7\n1 1\n-1 -1\n1 0\n0 1\n-1 0\n0 -1\n0 ... | 1,668,070,199 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 8,294,400 | import sys
n = int(sys.stdin.readline())
s = set()
for i in range(n):
a, b = map(int, input().split())
t = str(a) + " " + str(b)
s.add(t)
res = 0
l = list(s)
for i in range(n-1):
for j in range(i+1, n):
xi, yi = map(int, l[i].split())
xj, yj = map(int, l[j].split())
if (xi+xj)%2 ==0 and (yi + yj)%2==0:
if... | Title: Number of Triplets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a plane. All points are different.
Find the number of different groups of three points (*A*,<=*B*,<=*C*) such that point *B* is the middle of segment *AC*.
The groups of three points ar... | ```python
import sys
n = int(sys.stdin.readline())
s = set()
for i in range(n):
a, b = map(int, input().split())
t = str(a) + " " + str(b)
s.add(t)
res = 0
l = list(s)
for i in range(n-1):
for j in range(i+1, n):
xi, yi = map(int, l[i].split())
xj, yj = map(int, l[j].split())
if (xi+xj)%2 ==0 and (yi + yj)%2... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
154 | B | Colliders | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discov... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of colliders and the number of requests, correspondingly.
Next *m* lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the *i*-th collider, or "- i" (without ... | Print *m* lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes. | [
"10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3\n"
] | [
"Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on\n"
] | Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3". | 1,000 | [
{
"input": "10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3",
"output": "Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on"
},
{
"input": "7 5\n+ 7\n+ 6\n+ 4\n+ 3\n- 7",
"output": "Success\nSuccess\nConflict with 6\nConfli... | 1,681,115,064 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import math
n, m = map(int, input().split())
# precompute primes up to n
is_prime = [True] * (n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(math.sqrt(n))+1):
if is_prime[i]:
for j in range(i*i, n+1, i):
is_prime[j] = False
primes = set(i for i in range(2, n+1) if is_p... | Title: Colliders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simul... | ```python
import math
n, m = map(int, input().split())
# precompute primes up to n
is_prime = [True] * (n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(math.sqrt(n))+1):
if is_prime[i]:
for j in range(i*i, n+1, i):
is_prime[j] = False
primes = set(i for i in range(2, n+... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
724 | E | Goods transportation | PROGRAMMING | 2,900 | [
"dp",
"flows",
"greedy"
] | null | null | There are *n* cities located along the one-way road. Cities are numbered from 1 to *n* in the direction of the road.
The *i*-th city had produced *p**i* units of goods. No more than *s**i* units of goods can be sold in the *i*-th city.
For each pair of cities *i* and *j* such that 1<=≤<=*i*<=<<=*j*<=≤<=*n* you can... | The first line of the input contains two integers *n* and *c* (1<=≤<=*n*<=≤<=10<=000, 0<=≤<=*c*<=≤<=109) — the number of cities and the maximum amount of goods for a single transportation.
The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=109) — the number of units of goods that were produced in each city... | Print the maximum total number of produced goods that can be sold in all cities after a sequence of transportations. | [
"3 0\n1 2 3\n3 2 1\n",
"5 1\n7 4 2 1 0\n1 2 3 4 5\n",
"4 3\n13 10 7 4\n4 7 10 13\n"
] | [
"4\n",
"12\n",
"34\n"
] | none | 2,500 | [
{
"input": "3 0\n1 2 3\n3 2 1",
"output": "4"
},
{
"input": "5 1\n7 4 2 1 0\n1 2 3 4 5",
"output": "12"
},
{
"input": "4 3\n13 10 7 4\n4 7 10 13",
"output": "34"
},
{
"input": "10 1\n0 2 1 1 0 2 5 2 5 5\n4 0 1 4 2 4 4 5 2 3",
"output": "18"
},
{
"input": "10 3\n10... | 1,611,231,448 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 409,600 | n,c=map(int,input().split())
Q=[1<<56]*(1+n)
Q[0]=0
for x,(p,s) in enumerate(zip(map(int,input().split()),map(int,input().split())),1):
for y in range(x,0,-1):
Q[y]=min(p+c*y+Q[y],s+Q[y-1])
Q[0]+=p
print(min(Q)) | Title: Goods transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities located along the one-way road. Cities are numbered from 1 to *n* in the direction of the road.
The *i*-th city had produced *p**i* units of goods. No more than *s**i* units of goods can be so... | ```python
n,c=map(int,input().split())
Q=[1<<56]*(1+n)
Q[0]=0
for x,(p,s) in enumerate(zip(map(int,input().split()),map(int,input().split())),1):
for y in range(x,0,-1):
Q[y]=min(p+c*y+Q[y],s+Q[y-1])
Q[0]+=p
print(min(Q))
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,615,470,299 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 307,200 | word = input().strip()
upper = 0
alphabet = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
for x in word:
if x in alphabet:
upper = upper + 1
if upper > len(word)//2:
print (word.upper())
else:
print(word.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
word = input().strip()
upper = 0
alphabet = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
for x in word:
if x in alphabet:
upper = upper + 1
if upper > len(word)//2:
print (word.upper())
else:
print(word.lower())
``` | 3.968428 | MatrixStudio/Codeforces-Python-Submissions |
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,668,072,218 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 5,000 | 100,044,800 | from collections import defaultdict
from heapq import heappush, heappop
# import sys
# sys.setrecursionlimit(1<<24)
def solve(n,s,t,adj):
visited = [[float("inf"),[]] for _ in range(n)]
visited[s][0] = 0
visited[s][1] = [s]
heap = [(0,s)]
while heap:
dist,u = heappop(heap)
... | 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
from collections import defaultdict
from heapq import heappush, heappop
# import sys
# sys.setrecursionlimit(1<<24)
def solve(n,s,t,adj):
visited = [[float("inf"),[]] for _ in range(n)]
visited[s][0] = 0
visited[s][1] = [s]
heap = [(0,s)]
while heap:
dist,u = heap... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
603 | A | Alternative Thinking | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"math"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is... | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 500 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
... | 1,644,656,163 | 2,147,483,647 | PyPy 3 | OK | TESTS | 116 | 218 | 5,427,200 | from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int(inp())
d... | Title: Alternative Thinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one o... | ```python
from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *
def inp(): return sys.stdin.readline().rstrip("\r\n")
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def inpu(): return int... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,686,753,784 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 122 | 0 | words = input().split("WUB")
while "" in words:
words.remove("")
print(" ".join(words))
| 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
words = input().split("WUB")
while "" in words:
words.remove("")
print(" ".join(words))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,699,453,088 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 77 | 2,355,200 | if __name__ == '__main__':
worm_count = int(input())
wih = input()
no_of_ew = int(input())
ew = input()
worms_in_holes = wih.split() # 2 7 3 4 9
eaten_worms = ew.split() # 1 25 11
output_list = []
len_wih = len(worms_in_holes)
for i in range(len(worms_in_holes)-1):... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
if __name__ == '__main__':
worm_count = int(input())
wih = input()
no_of_ew = int(input())
ew = input()
worms_in_holes = wih.split() # 2 7 3 4 9
eaten_worms = ew.split() # 1 25 11
output_list = []
len_wih = len(worms_in_holes)
for i in range(len(worms_in_... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
305 | B | Continued Fractions | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. | The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction.
The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a... | Print "YES" if these fractions are equal and "NO" otherwise. | [
"9 4\n2\n2 4\n",
"9 4\n3\n2 3 1\n",
"9 4\n3\n1 2 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f3... | 1,000 | [
{
"input": "9 4\n2\n2 4",
"output": "YES"
},
{
"input": "9 4\n3\n2 3 1",
"output": "YES"
},
{
"input": "9 4\n3\n1 2 4",
"output": "NO"
},
{
"input": "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "YES"
},
{
... | 1,517,819,305 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 122 | 5,632,000 | import sys
p, q = [int(x) for x in sys.stdin.readline().strip().split(" ")]
n = sys.stdin.readline().strip()
frac = [float(x) for x in sys.stdin.readline().strip().split(" ")]
frac.reverse()
cur = frac[0]
for i in range(1, len(frac)):
a = frac[i]
cur = a + (1/cur)
if(cur == (p/q)):
print("YES")
e... | Title: Continued Fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
In... | ```python
import sys
p, q = [int(x) for x in sys.stdin.readline().strip().split(" ")]
n = sys.stdin.readline().strip()
frac = [float(x) for x in sys.stdin.readline().strip().split(" ")]
frac.reverse()
cur = frac[0]
for i in range(1, len(frac)):
a = frac[i]
cur = a + (1/cur)
if(cur == (p/q)):
print... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
245 | C | Game with Coins | PROGRAMMING | 1,700 | [
"greedy"
] | null | null | Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins.
Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of chests with coins. The second line contains a sequence of space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the number of coins in the chest number *i* at the beginning of the game. | Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. | [
"1\n1\n",
"3\n1 2 3\n"
] | [
"-1\n",
"3\n"
] | In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.
In the second sample there is only one possible move *x* = 1. This move should be repeated at least 3 times to empty the third chest. | 0 | [
{
"input": "1\n1",
"output": "-1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 5... | 1,592,973,318 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <stdio.h>
int main()
{
int t, i, p, q, dif, count, ar[200];
scanf("%d", &t);
ar[0] = 0;
for(i=1; i<=t; i++){
scanf("%d", &ar[i]);
}
if(t==1 || t%2==0){
printf("-1");
return 0;
}
count = 0;
for(i=1; (2*i)+1<=t; i++){
p = 2*i;
... | Title: Game with Coins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins.
Polycarpus and Vasily move in tu... | ```python
#include <stdio.h>
int main()
{
int t, i, p, q, dif, count, ar[200];
scanf("%d", &t);
ar[0] = 0;
for(i=1; i<=t; i++){
scanf("%d", &ar[i]);
}
if(t==1 || t%2==0){
printf("-1");
return 0;
}
count = 0;
for(i=1; (2*i)+1<=t; i++){
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
670 | E | Correct Bracket Sequence Editor | PROGRAMMING | 1,700 | [
"data structures",
"dsu",
"strings"
] | null | null | Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS).
Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, ... | The first line contains three positive integers *n*, *m* and *p* (2<=≤<=*n*<=≤<=500<=000, 1<=≤<=*m*<=≤<=500<=000, 1<=≤<=*p*<=≤<=*n*) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting ... | Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence. | [
"8 4 5\n(())()()\nRDLD\n",
"12 5 3\n((()())(()))\nRRDLD\n",
"8 8 8\n(())()()\nLLLLLLDD\n"
] | [
"()\n",
"(()(()))\n",
"()()\n"
] | In the first sample the cursor is initially at position 5. Consider actions of the editor:
1. command "R" — the cursor moves to the position 6 on the right; 1. command "D" — the deletion of brackets from the position 5 to the position 6. After that CBS takes the form (())(), the cursor is at the position 5; 1. comm... | 2,000 | [
{
"input": "8 4 5\n(())()()\nRDLD",
"output": "()"
},
{
"input": "12 5 3\n((()())(()))\nRRDLD",
"output": "(()(()))"
},
{
"input": "8 8 8\n(())()()\nLLLLLLDD",
"output": "()()"
},
{
"input": "4 2 2\n()()\nLD",
"output": "()"
},
{
"input": "6 4 1\n()()()\nDRRD",
... | 1,678,272,756 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 31 | 1,740,800 | # LUOGU_RID: 104053261
n,m,p=map(int,input().split())
bracketStr=input()
opStr=input()
left,right,pair=[0]*10001,[0]*10001,[0]*10001
stack=[0]*10001
top=-1
for i in range(n):
left[i]=i-1
right[i]=i+1
if bracketStr[i]=='(':
top+=1
stack[top]=i
else:
pair[stack[top]]=i
pair... | Title: Correct Bracket Sequence Editor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS).
Note that a bracket sequence is correct if it is possible to get a correct mathem... | ```python
# LUOGU_RID: 104053261
n,m,p=map(int,input().split())
bracketStr=input()
opStr=input()
left,right,pair=[0]*10001,[0]*10001,[0]*10001
stack=[0]*10001
top=-1
for i in range(n):
left[i]=i-1
right[i]=i+1
if bracketStr[i]=='(':
top+=1
stack[top]=i
else:
pair[stack[top]]=i
... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,563,154,100 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 140 | 0 | a, b = [int(x) for x in input().split()]
if a == b:
print(1)
else:
start = a + 1
if b - start > 12:
print(0)
else:
cur = 1
for x in range(start, b+1):
cur = (cur * x) % 10
print(cur)
| Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
a, b = [int(x) for x in input().split()]
if a == b:
print(1)
else:
start = a + 1
if b - start > 12:
print(0)
else:
cur = 1
for x in range(start, b+1):
cur = (cur * x) % 10
print(cur)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
156 | B | Suspects | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to *n*. After that, he asked each one: "Which one committed the crime?". Suspect number *i*... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=*n*) — the total number of suspects and the number of suspects who told the truth. Next *n* lines contain the suspects' answers. The *i*-th line contains either "+*a**i*" (without the quotes), if the suspect number *i* says that the cri... | Print *n* lines. Line number *i* should contain "Truth" if suspect number *i* has told the truth for sure. Print "Lie" if the suspect number *i* lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime. | [
"1 1\n+1\n",
"3 2\n-1\n-2\n-3\n",
"4 1\n+2\n-3\n+4\n-1\n"
] | [
"Truth\n",
"Not defined\nNot defined\nNot defined\n",
"Lie\nNot defined\nLie\nNot defined\n"
] | The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.
In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling th... | 1,000 | [
{
"input": "1 1\n+1",
"output": "Truth"
},
{
"input": "3 2\n-1\n-2\n-3",
"output": "Not defined\nNot defined\nNot defined"
},
{
"input": "4 1\n+2\n-3\n+4\n-1",
"output": "Lie\nNot defined\nLie\nNot defined"
},
{
"input": "1 0\n-1",
"output": "Lie"
},
{
"input": "2... | 1,655,210,681 | 2,147,483,647 | Python 3 | OK | TESTS | 97 | 902 | 4,710,400 | [n, m] = input().split()
n = int(n)
m = int(m)
arr = []
ps = []
ns = []
suspects = []
for i in range(0, n):
a = input()
a = int(a)
arr.append(a)
ps.append(0)
ns.append(0)
suspects.append(0)
sum_ps = 0
sum_ns = 0
for i in arr:
if i > 0:
ps[i - 1] += 1
... | Title: Suspects
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Sherlock Holmes was investigating a crime, he identified *n* suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from... | ```python
[n, m] = input().split()
n = int(n)
m = int(m)
arr = []
ps = []
ns = []
suspects = []
for i in range(0, n):
a = input()
a = int(a)
arr.append(a)
ps.append(0)
ns.append(0)
suspects.append(0)
sum_ps = 0
sum_ns = 0
for i in arr:
if i > 0:
ps[i - 1] += ... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,671,674,200 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | c = list(map(lambda q:str(q), input()))
f=len(c)
for i in range(f-1):
if len(c)==0:
break
if c[0]=='.':
c.pop(0)
print(0)
elif c[0]=='-' and c[1]=='.':
c.pop(0)
c.pop(0)
print(1)
elif c[0]=='-' and c[1]=='-':
c.pop(0)
c.pop(0)... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
c = list(map(lambda q:str(q), input()))
f=len(c)
for i in range(f-1):
if len(c)==0:
break
if c[0]=='.':
c.pop(0)
print(0)
elif c[0]=='-' and c[1]=='.':
c.pop(0)
c.pop(0)
print(1)
elif c[0]=='-' and c[1]=='-':
c.pop(0)
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
31 | B | Sysadmin Bob | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitra... | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of the... | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wa... | 1,691,723,807 | 2,147,483,647 | Python 3 | OK | TESTS | 76 | 46 | 0 | s = input(); ans = "No solution"
l = list(); var = ""; beg = 0
if s[-1] == "@":
print(ans); exit()
for i in range(len(s)):
var += s[i]
if var[0] == "@":
print(ans); break
elif s[i-1] == "@" and i > 0:
if s[i] == "@":
print(ans); break
l.append(s[beg:i+1]); ... | Title: Sysadmin Bob
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of t... | ```python
s = input(); ans = "No solution"
l = list(); var = ""; beg = 0
if s[-1] == "@":
print(ans); exit()
for i in range(len(s)):
var += s[i]
if var[0] == "@":
print(ans); break
elif s[i-1] == "@" and i > 0:
if s[i] == "@":
print(ans); break
l.append(s[b... | 3 | MatrixStudio/Codeforces-Python-Submissions |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,689,403,343 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n = int(input())
p = {"Tetrahedron": 4,"Cube": 6,"Octahedron": 8,"Dodecahedron": 12,"Icosahedron": 20}
res = 0
for i in range(n):
p = input()
res += p[p]
print(res) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n = int(input())
p = {"Tetrahedron": 4,"Cube": 6,"Octahedron": 8,"Dodecahedron": 12,"Icosahedron": 20}
res = 0
for i in range(n):
p = input()
res += p[p]
print(res)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
298 | B | Sail | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different.
The second line contains *t* characters, the *i*-th character is the wind blowing direction at the... | If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | [
"5 0 0 1 1\nSESNW\n",
"10 5 3 3 6\nNENSWESNEE\n"
] | [
"4\n",
"-1\n"
] | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | 500 | [
{
"input": "5 0 0 1 1\nSESNW",
"output": "4"
},
{
"input": "10 5 3 3 6\nNENSWESNEE",
"output": "-1"
},
{
"input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS",
"output": "13"
},
{
"input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS... | 1,552,931,588 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | t,sx,sy,ex,ey=map(int,input().split())
s=input()
x,y=ex-sx,ey-sy
cx,cy=abs(x),abs(y)
if y>=0:y='N'
else:y='S'
if x>=0:x='E'
else:x='W'
ax=ay=0
for i in range(t):
if ax==cx and ay==cy:break
if s[i]==x and ax<cx:ax+=1
elif s[i]==y and ay<cy:ay+=1
if ax!=cx or ay!=cy:print(-1)
else:print(i)
| Title: Sail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu... | ```python
t,sx,sy,ex,ey=map(int,input().split())
s=input()
x,y=ex-sx,ey-sy
cx,cy=abs(x),abs(y)
if y>=0:y='N'
else:y='S'
if x>=0:x='E'
else:x='W'
ax=ay=0
for i in range(t):
if ax==cx and ay==cy:break
if s[i]==x and ax<cx:ax+=1
elif s[i]==y and ay<cy:ay+=1
if ax!=cx or ay!=cy:print(-1)
else:prin... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
498 | A | Crazy Town | PROGRAMMING | 1,700 | [
"geometry"
] | null | null | Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We ... | The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≤<=*x*1,<=*y*1<=≤<=106) — the coordinates of your home.
The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≤<=*x*2,<=*y*2<=≤<=106) — the coordinates of the university you are studying at.
The third line contains a... | Output the answer to the problem. | [
"1 1\n-1 -1\n2\n0 1 0\n1 0 0\n",
"1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n"
] | [
"2\n",
"2\n"
] | Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | 500 | [
{
"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0",
"output": "2"
},
{
"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3",
"output": "2"
},
{
"input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 85489... | 1,419,438,754 | 154 | Python 3 | OK | TESTS | 51 | 77 | 0 | """
Codeforces Contest 284 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
x1,y1 = read()
x2,y2 = read()
n, = read()
ct = 0
for i in range(n):
a,b,c = read()
if (a*x1+b*y1+c)*... | Title: Crazy Town
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the pl... | ```python
"""
Codeforces Contest 284 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
x1,y1 = read()
x2,y2 = read()
n, = read()
ct = 0
for i in range(n):
a,b,c = read()
if (a*x... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter sta... | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "1... | 1,508,802,046 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 5,529,600 | z=lambda:map(int,input().split())
d=lambda:max(abs(a-b)+1,2)
q,w=z()
e,r=z()
print((d(q,e)+d(w,r))*2) | Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p... | ```python
z=lambda:map(int,input().split())
d=lambda:max(abs(a-b)+1,2)
q,w=z()
e,r=z()
print((d(q,e)+d(w,r))*2)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
17 | E | Palisection | PROGRAMMING | 2,900 | [
"strings"
] | E. Palisection | 2 | 128 | In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: «eye», «pop», «level», «aba», «deed», ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=2·106) — length of the text. The following line contains *n* lower-case Latin letters (from a to z). | In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987. | [
"4\nbabb\n",
"2\naa\n"
] | [
"6\n",
"2\n"
] | none | 0 | [] | 1,667,514,172 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 0 | n = int(input())
text = input()
t = []
count = 0
def is_pal(k, m):
global text
while k < m:
if text[k] != text[m]:
return False
k += 1
m -= 1
return True
for i in range(len(text)):
t.append((i, i))
for j in range(i + 1, len(text)):
if is_pal... | Title: Palisection
Time Limit: 2 seconds
Memory Limit: 128 megabytes
Problem Description:
In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and ... | ```python
n = int(input())
text = input()
t = []
count = 0
def is_pal(k, m):
global text
while k < m:
if text[k] != text[m]:
return False
k += 1
m -= 1
return True
for i in range(len(text)):
t.append((i, i))
for j in range(i + 1, len(text)):
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,599,716,118 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 184 | 0 | n=int(input())
if n==0:
print("0")
else:
a=0
for i in range(1,1000):
a=a+i
if i==n:
print(i)
break
elif i>n:
print(i+1)
break
| Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
n=int(input())
if n==0:
print("0")
else:
a=0
for i in range(1,1000):
a=a+i
if i==n:
print(i)
break
elif i>n:
print(i+1)
break
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,512,757,922 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 5,529,600 | n = int(input())
vx= []
vy = []
for i in range(n):
x,y = [int(x) for x in input().split()]
vx.append(x)
vy.append(y)
if sum(vx)%2 == sum(vy)%2 == 0:
print(0)
elif sum(vx)%2 != sum(vy)%2:
print(-1)
else:
print(1)
# 1512757921232
| Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
n = int(input())
vx= []
vy = []
for i in range(n):
x,y = [int(x) for x in input().split()]
vx.append(x)
vy.append(y)
if sum(vx)%2 == sum(vy)%2 == 0:
print(0)
elif sum(vx)%2 != sum(vy)%2:
print(-1)
else:
print(1)
# 1512757921232
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,620,489,640 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 6,758,400 | n, m = [int(i) for i in input().split()]
count = 0
for i in range(1, n + 1):
for j in range(1, m + 1):
if (i + j) % 5 == 0:
count += 1
print(count) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n, m = [int(i) for i in input().split()]
count = 0
for i in range(1, n + 1):
for j in range(1, m + 1):
if (i + j) % 5 == 0:
count += 1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,502,694,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 4,608,000 | a,b,c,d,e=map(int,input().split())
i=1
if(a==b):
i=1
else:
for i in range(a):
q=b+d
p=q-e
i+=1
b=q
q=p
print(p,q)
if(q==c):
q=c
if(p>=a):
break
print(i)
| Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
a,b,c,d,e=map(int,input().split())
i=1
if(a==b):
i=1
else:
for i in range(a):
q=b+d
p=q-e
i+=1
b=q
q=p
print(p,q)
if(q==c):
q=c
if(p>=a):
break
print(i)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,556,261,228 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 |
n = int(input())
s = [0] + list(map(int, input().split()))
isBreak = False
for i in range(len(s) - 1):
if s[i+1] - s[i] > 15:
print(s[i] + 15)
isBreak = True
break
if not isBreak:
print(90) | 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())
s = [0] + list(map(int, input().split()))
isBreak = False
for i in range(len(s) - 1):
if s[i+1] - s[i] > 15:
print(s[i] + 15)
isBreak = True
break
if not isBreak:
print(90)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,603,479,458 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 204,800 | n=int(input())
a=input()
b=input()
s=0
for i in range(len(a)):
if abs(int(a[i])-int(b[i]))<=4:
s=s+(abs(int(a[i])-int(b[i])))
else:
s=s+(10-(abs(int(a[i])-int(b[i]))))
print(s)
print(s) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n=int(input())
a=input()
b=input()
s=0
for i in range(len(a)):
if abs(int(a[i])-int(b[i]))<=4:
s=s+(abs(int(a[i])-int(b[i])))
else:
s=s+(10-(abs(int(a[i])-int(b[i]))))
print(s)
print(s)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
416 | C | Booking System | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"greedy",
"implementation"
] | null | null | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they w... | In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this... | [
"3\n10 50\n2 100\n5 30\n3\n4 6 9\n"
] | [
"2 130\n2 1\n3 2\n"
] | none | 1,500 | [
{
"input": "3\n10 50\n2 100\n5 30\n3\n4 6 9",
"output": "2 130\n2 1\n3 2"
},
{
"input": "1\n1 1\n1\n1",
"output": "1 1\n1 1"
},
{
"input": "1\n2 1\n1\n1",
"output": "0 0"
},
{
"input": "2\n10 10\n5 5\n1\n5",
"output": "1 5\n2 1"
},
{
"input": "2\n10 10\n5 5\n1\n10... | 1,553,842,851 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 307,200 | def isEl(n, a):
if a[-1] < n:
return -1
i = 0
while a[i] < n:
i += 1
return i
def sort1(a):
for i in range(1, len(a)):
if a[i - 1][0] == a[i][0] and a[i - 1][1] < a[i][1]:
a[i][1], a[i - 1][1] = a[i - 1][1], a[i][1]
return a
n = int(input())
money = [[int(x) for x in input().split()] for... | Title: Booking System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
... | ```python
def isEl(n, a):
if a[-1] < n:
return -1
i = 0
while a[i] < n:
i += 1
return i
def sort1(a):
for i in range(1, len(a)):
if a[i - 1][0] == a[i][0] and a[i - 1][1] < a[i][1]:
a[i][1], a[i - 1][1] = a[i - 1][1], a[i][1]
return a
n = int(input())
money = [[int(x) for x in input().sp... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the... | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"... | 1,598,561,504 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 218 | 0 | import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
s=input().strip()
n=len(s)
al=[[] for i in range(26)]
for i in range(n):
al[ord(s[i])-97].append(i)
an=""
pos=[i for i in range(n)]
for i in range(n):
cr=ord(s[i])-97
if len(al[cr])<3:
an="Just a legend";break
p=al[cr]
an+=s[i]
n... | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carve... | ```python
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
s=input().strip()
n=len(s)
al=[[] for i in range(26)]
for i in range(n):
al[ord(s[i])-97].append(i)
an=""
pos=[i for i in range(n)]
for i in range(n):
cr=ord(s[i])-97
if len(al[cr])<3:
an="Just a legend";break
p=al[cr]
a... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 ... | 1,600,185,866 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 24 | 2,000 | 7,372,800 | n = int(input())
a = list(map(int, input().split()))[:n]
l = 0
r = 0
ans = 1
minV = a[r]
maxV = a[r]
while r < n - 1:
r += 1
v = a[r]
newMinV = min(v, minV)
newMaxV = max(v, maxV)
if newMaxV - newMinV < 1:
minV = newMinV
maxV = newMaxV
else:
for i in ran... | Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo... | ```python
n = int(input())
a = list(map(int, input().split()))[:n]
l = 0
r = 0
ans = 1
minV = a[r]
maxV = a[r]
while r < n - 1:
r += 1
v = a[r]
newMinV = min(v, minV)
newMaxV = max(v, maxV)
if newMaxV - newMinV < 1:
minV = newMinV
maxV = newMaxV
else:
fo... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
1,000 | A | Codehorses T-shirts | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
... | The first line contains one integer $n$ ($1 \le n \le 100$) — the number of T-shirts.
The $i$-th of the next $n$ lines contains $a_i$ — the size of the $i$-th T-shirt of the list for the previous year.
The $i$-th of the next $n$ lines contains $b_i$ — the size of the $i$-th T-shirt of the list for the current year.
... | Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0. | [
"3\nXS\nXS\nM\nXL\nS\nXS\n",
"2\nXXXL\nXXL\nXXL\nXXXS\n",
"2\nM\nXS\nXS\nM\n"
] | [
"2\n",
"1\n",
"0\n"
] | In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".
In the second example Ksenia should replace "L" in "XXXL" with "S".
In the third example lists are equal. | 0 | [
{
"input": "3\nXS\nXS\nM\nXL\nS\nXS",
"output": "2"
},
{
"input": "2\nXXXL\nXXL\nXXL\nXXXS",
"output": "1"
},
{
"input": "2\nM\nXS\nXS\nM",
"output": "0"
},
{
"input": "1\nXXXL\nXXXL",
"output": "0"
},
{
"input": "1\nM\nM",
"output": "0"
},
{
"input": ... | 1,636,767,122 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 4,300,800 | '''
maybe I should consider use a dictionary
how to critic an element has reserved
test of double element
think about the double num i have done before use '^' or other methods?
'''
ans = int(input())
arr = []
for i in range(ans):arr.append(input())
for i in range(ans):
get = input()
if get ... | Title: Codehorses T-shirts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from $0$ to $3$ "X" follo... | ```python
'''
maybe I should consider use a dictionary
how to critic an element has reserved
test of double element
think about the double num i have done before use '^' or other methods?
'''
ans = int(input())
arr = []
for i in range(ans):arr.append(input())
for i in range(ans):
get = input()
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,661,057,578 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,m=map(int,input().split())
count=0
while(n>0):
count=count+n
n=int(n/m)
print(count) | 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=map(int,input().split())
count=0
while(n>0):
count=count+n
n=int(n/m)
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,678,934,355 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 1,945,600 | n, t = map(int, input().split())
a = list(map(int, input().split()))
vis = []
i = 0
try:
while True:
vis.append(i+1)
i += a[i]
except IndexError:
pass
print("YES" if t in vis else "NO")
#########################################
## ##
## ... | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
vis = []
i = 0
try:
while True:
vis.append(i+1)
i += a[i]
except IndexError:
pass
print("YES" if t in vis else "NO")
#########################################
## #... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,530,725,684 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 218 | 0 | n=int(input())
D=dict()
L=list()
BIG=list()
nomm=list()
maxscore=-1000000000000
for o in range(n):
ch=str(input())
LL=list()
LL=ch.split()
nom=str(LL[0])
score=int(LL[1])
BIG.append((nom,score))
if nom not in D:
D[nom]=score
else:
D[nom]+=score
for nom in... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n=int(input())
D=dict()
L=list()
BIG=list()
nomm=list()
maxscore=-1000000000000
for o in range(n):
ch=str(input())
LL=list()
LL=ch.split()
nom=str(LL[0])
score=int(LL[1])
BIG.append((nom,score))
if nom not in D:
D[nom]=score
else:
D[nom]+=score
... | 3.891 | MatrixStudio/Codeforces-Python-Submissions |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,581,375,993 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 124 | 0 | l, r, k = map(int, input().split())
sol = []
x = 1
while x <= r:
if x >= l: sol.append(x)
x *= k
if len(sol) == 0:
print(-1)
else:
print(' '.join(list(map(str, sol))))
| Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
l, r, k = map(int, input().split())
sol = []
x = 1
while x <= r:
if x >= l: sol.append(x)
x *= k
if len(sol) == 0:
print(-1)
else:
print(' '.join(list(map(str, sol))))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and di... | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*,... | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd... | 1,680,871,072 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | entrada = int(input())
nomes = {}
saida = {}
for i in range(entrada):
anterior, novo = input().split()
nomes[anterior] = novo
for key in nomes.keys():
atual = key
while atual in nomes.keys():
atual = nomes[atual]
if atual in saida.values():
continue
saida[key] = atual
print(le... | Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is a... | ```python
entrada = int(input())
nomes = {}
saida = {}
for i in range(entrada):
anterior, novo = input().split()
nomes[anterior] = novo
for key in nomes.keys():
atual = key
while atual in nomes.keys():
atual = nomes[atual]
if atual in saida.values():
continue
saida[key] = atual... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,644,520,258 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | a,b = [int(x) for x in input().split()]
li = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
try:
if b == li[li.index(a) + 1]:
print("YES")
else:
print("NO")
except IndexError:
print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
a,b = [int(x) for x in input().split()]
li = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
try:
if b == li[li.index(a) + 1]:
print("YES")
else:
print("NO")
except IndexError:
print("NO")
``` | 3.977 | MatrixStudio/Codeforces-Python-Submissions |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,672,397,275 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
k=max(a)
res=0
for x in a:
res+=k-x
print(res)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n=int(input())
a=list(map(int,input().split()))
k=max(a)
res=0
for x in a:
res+=k-x
print(res)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,637,790,878 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | (N, M) = [int(i) for i in input().split()]
row = -1
column = -1
columns = []
for i in range(N):
districts = input()
first = districts.find('*')
if first >= 0:
columns.append(first+1)
second = districts.rfind('*')
if second < 0 or first == second:
row = i+1
else:
columns.append(second+1)
columns.sort(... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
(N, M) = [int(i) for i in input().split()]
row = -1
column = -1
columns = []
for i in range(N):
districts = input()
first = districts.find('*')
if first >= 0:
columns.append(first+1)
second = districts.rfind('*')
if second < 0 or first == second:
row = i+1
else:
columns.append(second+1)
col... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,667,415,951 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | n, saldejumi = map(int, input().split())
#print(saldejumi)
d = 0
for i in range(n):
zime, sk = map(str, input().split())
#print(zime, sk)
ss = int(sk)
if saldejumi > 0:
if zime == '+':
saldejumi += ss
else:
if (saldejumi - ss)<0:
... | 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
n, saldejumi = map(int, input().split())
#print(saldejumi)
d = 0
for i in range(n):
zime, sk = map(str, input().split())
#print(zime, sk)
ss = int(sk)
if saldejumi > 0:
if zime == '+':
saldejumi += ss
else:
if (saldejumi - ss)<0:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,693,495,869 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | n = int(input())
sum = 0
for i in range(1,n+1,2):
sum-=i
for i in range(2,n+1,2):
sum+=i
print(sum) | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
n = int(input())
sum = 0
for i in range(1,n+1,2):
sum-=i
for i in range(2,n+1,2):
sum+=i
print(sum)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,656,846,883 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | s = input()
n = len(s)
r = "YES"
for i in range(n):
if n > 1 and i+1 < n:
if s[i] not in "aeioun" and s[i+1] not in "aieou":
r = "NO"
else:
if s[i] not in "aieoun":
r = "NO" | 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
s = input()
n = len(s)
r = "YES"
for i in range(n):
if n > 1 and i+1 < n:
if s[i] not in "aeioun" and s[i+1] not in "aieou":
r = "NO"
else:
if s[i] not in "aieoun":
r = "NO"
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,689,831,973 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n=int(input())
max=0
sum=0
for _ in range(n):
a,b=map(int,input().split())
sum=sum+b-a
if(sum>max):
max=sum
print(max) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n=int(input())
max=0
sum=0
for _ in range(n):
a,b=map(int,input().split())
sum=sum+b-a
if(sum>max):
max=sum
print(max)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
601 | A | The Two Routes | PROGRAMMING | 1,600 | [
"graphs",
"shortest paths"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=... | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo... | 500 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "... | 1,612,346,909 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 264 | 1,331,200 | from collections import deque
n, m = map(int, input().split())
rail_network=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
rail_network[u][v]=rail_network[v][u]=1
que=deque()
dis=[-1]*(n+1)
dis[1]=0
que.append(1)
while que:
temp=que.popleft()
for i in... | Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet... | ```python
from collections import deque
n, m = map(int, input().split())
rail_network=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
rail_network[u][v]=rail_network[v][u]=1
que=deque()
dis=[-1]*(n+1)
dis[1]=0
que.append(1)
while que:
temp=que.popleft()
... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,695,392,559 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | c1=0
c2=0
for _ in range(int(input())):
a,b=map(int,input().split())
if(a > b):
c1+=1
elif(a < b):
c2+=1
if(c1 > c2):
print("Mishka")
elif(c1 == c2):
print("Friendship is magic!^^")
else:
print("Chris") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
c1=0
c2=0
for _ in range(int(input())):
a,b=map(int,input().split())
if(a > b):
c1+=1
elif(a < b):
c2+=1
if(c1 > c2):
print("Mishka")
elif(c1 == c2):
print("Friendship is magic!^^")
else:
print("Chris")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,672,478,636 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 140 | 1,638,400 | x,y=map(int,input("").split(" "))
l=[]
l2=[]
for i in range(x):
l.append(input("").split(" "))
for q in l:
for n in q:
l2.append(n)
if 'C' in l2 or 'M' in l2 or 'Y' in l2:
print("#Color")
else:
print("#Black&White")
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
x,y=map(int,input("").split(" "))
l=[]
l2=[]
for i in range(x):
l.append(input("").split(" "))
for q in l:
for n in q:
l2.append(n)
if 'C' in l2 or 'M' in l2 or 'Y' in l2:
print("#Color")
else:
print("#Black&White")
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,488,103,056 | 6,756 | Python 3 | OK | TESTS | 111 | 62 | 4,608,000 | data = list(map(int, input().split()))
n = str(data[0])
n_str = str(n)
k = data[1]
z = 10 ** k
counter = 0
def remove_last_digit(number):
numero = list(str(number))
for i in range(len(numero) - 1, -1, -1):
if numero[i] != "0":
numero = numero[0:i] + numero[i + 1: len(nume... | Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
data = list(map(int, input().split()))
n = str(data[0])
n_str = str(n)
k = data[1]
z = 10 ** k
counter = 0
def remove_last_digit(number):
numero = list(str(number))
for i in range(len(numero) - 1, -1, -1):
if numero[i] != "0":
numero = numero[0:i] + numero[i + 1... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,694,162,856 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = input()
s = n.lower()
lst = list(s)
lst1 = ['a', 'e', 'i', 'o', 'u', 'y']
for i in lst:
if i in lst1:
lst.pop(i)
lst(i).replace(".", i)
s1 = ""
print(s1.join(str(i) for i in lst))
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
n = input()
s = n.lower()
lst = list(s)
lst1 = ['a', 'e', 'i', 'o', 'u', 'y']
for i in lst:
if i in lst1:
lst.pop(i)
lst(i).replace(".", i)
s1 = ""
print(s1.join(str(i) for i in lst))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,565,378,871 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | a=int(input())
sum=(a//3)*2
if a%3==1 or a%3==2:
sum+=1
print(sum)
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
a=int(input())
sum=(a//3)*2
if a%3==1 or a%3==2:
sum+=1
print(sum)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially I... | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them cont... | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in t... | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3... | 1,668,558,951 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 10 | 1,216 | 268,390,400 | import heapq as hq
def getValidPath(time_prev):
revpath = []
v = n
while v != -1:
revpath.append(v)
v = time_prev[v][1]
#time_prev[v] = [float('inf'), -1]
return list(reversed(revpath))
def dfs(start):
validPaths = []
#visited = [0 for _ in range(n+1)]
... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlato... | ```python
import heapq as hq
def getValidPath(time_prev):
revpath = []
v = n
while v != -1:
revpath.append(v)
v = time_prev[v][1]
#time_prev[v] = [float('inf'), -1]
return list(reversed(revpath))
def dfs(start):
validPaths = []
#visited = [0 for _ in rang... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
834 | A | The Useless Toy | PROGRAMMING | 900 | [
"implementation"
] | null | null | Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each s... | There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated... | Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise. | [
"^ >\n1\n",
"< ^\n3\n",
"^ v\n6\n"
] | [
"cw\n",
"ccw\n",
"undefined\n"
] | none | 500 | [
{
"input": "^ >\n1",
"output": "cw"
},
{
"input": "< ^\n3",
"output": "ccw"
},
{
"input": "^ v\n6",
"output": "undefined"
},
{
"input": "^ >\n999999999",
"output": "ccw"
},
{
"input": "> v\n1",
"output": "cw"
},
{
"input": "v <\n1",
"output": "cw"
... | 1,595,250,423 | 1,023 | Python 3 | OK | TESTS | 47 | 109 | 6,963,200 | a,b=map(str,input().split())
n=int(input())
l=[118,60,94,62]
for x in range(4):
if l[x]==ord(a):
c1=x
if l[x]==ord(b):
c2=x
if (c2-c1)%4==0 or (c2-c1)%4==2:
p='undefined'
elif ((c2-c1)%4==1 and n%4==1) or ((c2-c1)%4==3 and n%4==3):
p='cw'
else:
p='ccw'
print(p)
| Title: The Useless Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bough... | ```python
a,b=map(str,input().split())
n=int(input())
l=[118,60,94,62]
for x in range(4):
if l[x]==ord(a):
c1=x
if l[x]==ord(b):
c2=x
if (c2-c1)%4==0 or (c2-c1)%4==2:
p='undefined'
elif ((c2-c1)%4==1 and n%4==1) or ((c2-c1)%4==3 and n%4==3):
p='cw'
else:
p='ccw'
print(p)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,664,013,427 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
248 | B | Chilly Willy | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous... | A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. | [
"1\n",
"5\n"
] | [
"-1\n",
"10080"
] | none | 1,000 | [
{
"input": "1",
"output": "-1"
},
{
"input": "5",
"output": "10080"
},
{
"input": "6",
"output": "100170"
},
{
"input": "4",
"output": "1050"
},
{
"input": "15",
"output": "100000000000110"
},
{
"input": "16",
"output": "1000000000000050"
},
{
... | 1,547,743,255 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 216 | 0 | n = int(input())
stl = '1'
for i in range(n-1):
stl += '0'
stl = int(stl)
for i in range(stl,10*stl):
if i%210 == 0:
print(i)
break
else:
print("-1")
break | Title: Chilly Willy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit... | ```python
n = int(input())
stl = '1'
for i in range(n-1):
stl += '0'
stl = int(stl)
for i in range(stl,10*stl):
if i%210 == 0:
print(i)
break
else:
print("-1")
break
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,616,172,520 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 62 | 307,200 | def solve(arr,n):
d = {}
for i in arr:
for j in i:
if j == '.':
continue
if not d.get(j):
d[j] = 1
else:
d[j]+=1
for i in d:
if d[i] > 2*n:
return "NO"
return "YES"
def main() :
n = int(input())
# arr = list(map(int, input().split(' ')))
ar... | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
def solve(arr,n):
d = {}
for i in arr:
for j in i:
if j == '.':
continue
if not d.get(j):
d[j] = 1
else:
d[j]+=1
for i in d:
if d[i] > 2*n:
return "NO"
return "YES"
def main() :
n = int(input())
# arr = list(map(int, input().split('... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,620,023,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n=int(input())
cnt=n//2
if(n%2!=0):
output="b"
else:
output=""
ch="aa"
for i in range(0,cnt,2):
output+=ch
if(ch=="aa"):
ch="bb"
print(output)
| 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
n=int(input())
cnt=n//2
if(n%2!=0):
output="b"
else:
output=""
ch="aa"
for i in range(0,cnt,2):
output+=ch
if(ch=="aa"):
ch="bb"
print(output)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,504,024,789 | 5,689 | Python 3 | OK | TESTS | 34 | 623 | 0 | def isInter(x1, y1, r1, x2, y2, r2):
r = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
if r < r1 + r2 and r > abs(r1 - r2):
return True
return False
def di(x1, y1, x2, y2):
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
r, d = map(int, input().split())
n = int(input())
ans = 0
for ... | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
def isInter(x1, y1, r1, x2, y2, r2):
r = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
if r < r1 + r2 and r > abs(r1 - r2):
return True
return False
def di(x1, y1, x2, y2):
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
r, d = map(int, input().split())
n = int(input())
ans... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,659,014,318 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n1=(input("Enter a word : "))
u=0
l=0
for i in n1:
if 65<=ord(i)<=90:
u+=1
else:
l+=1
if u>l:
print(n1.upper())
else:
print(n1.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
n1=(input("Enter a word : "))
u=0
l=0
for i in n1:
if 65<=ord(i)<=90:
u+=1
else:
l+=1
if u>l:
print(n1.upper())
else:
print(n1.lower())
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
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,675,531,923 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 62 | 4,505,600 | n = int(input())
def pair(a):
if(a%2==0):
return True
return False
tab = []
tab.extend([int(x) for x in input().split()])
for k in range(n):
if(pair(tab[k]) != pair(tab[k-1]) and k>=1):
if(pair(tab[k])==pair(tab[k+1])):
print(k)
break
else:
... | 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())
def pair(a):
if(a%2==0):
return True
return False
tab = []
tab.extend([int(x) for x in input().split()])
for k in range(n):
if(pair(tab[k]) != pair(tab[k-1]) and k>=1):
if(pair(tab[k])==pair(tab[k+1])):
print(k)
break
els... | -1 | MatrixStudio/Codeforces-Python-Submissions |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,574,673,230 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | a=len(input()[2:])
b=len(input()[2:])
c=len(input()[2:])
d=len(input()[2:])
nice,k=0,'C'
if a>=2*b and a>=2*c and a>=2*d:nice+=1;k='A'
if 2*a<=b and 2*a<=c and 2*a<=d:nice+=1;k='A'
if b>=2*a and b>=2*c and b>=2*d:nice+=1;k='B'
if 2*b<=a and 2*b<=c and 2*b<=d:nice+=1;k='B'
if c>=2*b and c>=2*a and c>=2*d:ni... | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
a=len(input()[2:])
b=len(input()[2:])
c=len(input()[2:])
d=len(input()[2:])
nice,k=0,'C'
if a>=2*b and a>=2*c and a>=2*d:nice+=1;k='A'
if 2*a<=b and 2*a<=c and 2*a<=d:nice+=1;k='A'
if b>=2*a and b>=2*c and b>=2*d:nice+=1;k='B'
if 2*b<=a and 2*b<=c and 2*b<=d:nice+=1;k='B'
if c>=2*b and c>=2*a and... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
870 | B | Maximum of Maximums of Minimums | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 1,000 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,601,418,178 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,k;
cin >> n >> k;
long long int arr[n];
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
if(k>2) cout << *max_element(arr,arr+n) <<endl;
else if(k==1) cout << *min_element(arr,arr+n) <<endl;
else
{
... | Title: Maximum of Maximums of Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integ... | ```python
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,k;
cin >> n >> k;
long long int arr[n];
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
if(k>2) cout << *max_element(arr,arr+n) <<endl;
else if(k==1) cout << *min_element(arr,arr+n) <<endl;
e... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
524 | A | Возможно, вы знаете этих людей? | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*.
В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую ве... | В первой строке следуют два целых числа *m* и *k* (1<=≤<=*m*<=≤<=100, 0<=≤<=*k*<=≤<=100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом.
В последующих *m* строках записано по два числа *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109, *a**i*<=≠<=*b**i*), обозна... | Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "*id*:<= *k* *id*1 *id*2 ... *id**k*", где *id* — это id самого человека, *k* — количество его предполагаемых друзей, а *id*1, *id*2, ..., *id**k* — идентификаторы его предполагаемых друзей в воз... | [
"5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n",
"5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n"
] | [
"10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n",
"1: 0\n2: 0\n3: 1 4\n4: 1 3\n"
] | none | 500 | [
{
"input": "5 51\n10 23\n23 42\n39 42\n10 39\n39 58",
"output": "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42"
},
{
"input": "5 100\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "1: 0\n2: 0\n3: 1 4\n4: 1 3"
},
{
"input": "4 1\n1 2\n1 3\n2 3\n4 5",
"output": "1: 0\n2: 0\n3: 0\n4: 0\n5: ... | 1,426,948,682 | 2,282 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | def main():
n = int(input())
W, H = [],[]
sumW = 0
maxH = 0
for i in range(n):
w,h = map(int, input().split())
W.append(w)
H.append(h)
sumW += w
if maxH < h:
maxH = h
for i in range(n):
if sumW*maxH>(sumW-W[i]+H[i])*max(W[i... | Title: Возможно, вы знаете этих людей?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b... | ```python
def main():
n = int(input())
W, H = [],[]
sumW = 0
maxH = 0
for i in range(n):
w,h = map(int, input().split())
W.append(w)
H.append(h)
sumW += w
if maxH < h:
maxH = h
for i in range(n):
if sumW*maxH>(sumW-W[i]+H[i... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,446,576,269 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n, c = map(int, input().split())
x = list(map(int, input().split()))
res = c
for i in range(n - 1):
res = max(res, x[i] - x[i + 1])
print(max(0, res - c)) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
n, c = map(int, input().split())
x = list(map(int, input().split()))
res = c
for i in range(n - 1):
res = max(res, x[i] - x[i + 1])
print(max(0, res - c))
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,670,893,429 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 826 | 153,292,800 | l = list(map(int,input().split()))
print(eval('+'.join(input()).replace("1","l[0]").replace("2","l[1]").replace("3","l[2]").replace("4","l[3]"))) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
l = list(map(int,input().split()))
print(eval('+'.join(input()).replace("1","l[0]").replace("2","l[1]").replace("3","l[2]").replace("4","l[3]")))
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
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,496,596,449 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 1,107 | 28,876,800 | # Description of the problem can be found at http://codeforces.com/problemset/problem/650/A
p = int(input())
d_x = {}
d_y = {}
d_t = {}
t = 0
for _ in range(p):
x, y = map(int, input().split())
if x in d_x:
t += d_x[x]
d_x[x] += 1
else:
d_x[x] = 1
if y in d_y... | 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
# Description of the problem can be found at http://codeforces.com/problemset/problem/650/A
p = int(input())
d_x = {}
d_y = {}
d_t = {}
t = 0
for _ in range(p):
x, y = map(int, input().split())
if x in d_x:
t += d_x[x]
d_x[x] += 1
else:
d_x[x] = 1
i... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
707 | B | Bakery | PROGRAMMING | 1,300 | [
"graphs"
] | null | null | Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different c... | The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.
Then *m* lines follow. Each of them contains three integers *u*, *v* and *l... | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.
If the bakery can not be opened (while satisfying conditions) in any of the *n* cities, print <=-<=1 in the only line. | [
"5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5\n",
"3 1 1\n1 2 3\n3\n"
] | [
"3",
"-1"
] | Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | 1,000 | [
{
"input": "5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5",
"output": "3"
},
{
"input": "3 1 1\n1 2 3\n3",
"output": "-1"
},
{
"input": "2 3 1\n1 2 3\n1 2 18\n1 2 13\n2",
"output": "3"
},
{
"input": "3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8",
"output": "-1"
... | 1,696,439,349 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | n, m, k = input().split(" ")
if k == "0": print(-1); exit()
distances = []; roads = []
for i in range(int(m)):
u, v, l = input().split(" ")
roads.append(int(u)); roads.append(int(v))
distances.append(int(l))
k = list(set([eval(i) for i in input().split(" ")]))
max_intp = 2147483647; nl = len(roads)
... | Title: Bakery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to e... | ```python
n, m, k = input().split(" ")
if k == "0": print(-1); exit()
distances = []; roads = []
for i in range(int(m)):
u, v, l = input().split(" ")
roads.append(int(u)); roads.append(int(v))
distances.append(int(l))
k = list(set([eval(i) for i in input().split(" ")]))
max_intp = 2147483647; nl = l... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,697,897,659 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 102,400 |
#false表示白,true表示黑
def check(matrix,line,row):
'''检验是否存在2x2黑格子'''
new_matrix = [[False] * (row + 2)]+[[False] + lines + [False] for lines in matrix]+ [[False] * (row + 2)]
flag=False
for x in range(line+2):
for y in range(row+2):
if new_matrix[x][y]:
if new_m... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
#false表示白,true表示黑
def check(matrix,line,row):
'''检验是否存在2x2黑格子'''
new_matrix = [[False] * (row + 2)]+[[False] + lines + [False] for lines in matrix]+ [[False] * (row + 2)]
flag=False
for x in range(line+2):
for y in range(row+2):
if new_matrix[x][y]:
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
762 | E | Radio stations | PROGRAMMING | 2,200 | [
"binary search",
"data structures"
] | null | null | In the lattice points of the coordinate line there are *n* radio stations, the *i*-th of which is described by three integers:
- *x**i* — the coordinate of the *i*-th station on the line, - *r**i* — the broadcasting range of the *i*-th station, - *f**i* — the broadcasting frequency of the *i*-th station.
We will s... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=10) — the number of radio stations and the maximum difference in the frequencies for the pair of stations that reach each other to be considered bad.
In the next *n* lines follow the descriptions of radio stations. Each line contains th... | Output the number of bad pairs of radio stations. | [
"3 2\n1 3 10\n3 2 5\n4 10 8\n",
"3 3\n1 3 10\n3 2 5\n4 10 8\n",
"5 1\n1 3 2\n2 2 4\n3 2 1\n4 2 1\n5 3 3\n",
"5 1\n1 5 2\n2 5 4\n3 5 1\n4 5 1\n5 5 3\n"
] | [
"1\n",
"2\n",
"2\n",
"5\n"
] | none | 0 | [
{
"input": "3 2\n1 3 10\n3 2 5\n4 10 8",
"output": "1"
},
{
"input": "3 3\n1 3 10\n3 2 5\n4 10 8",
"output": "2"
},
{
"input": "5 1\n1 3 2\n2 2 4\n3 2 1\n4 2 1\n5 3 3",
"output": "2"
},
{
"input": "5 1\n1 5 2\n2 5 4\n3 5 1\n4 5 1\n5 5 3",
"output": "5"
},
{
"input... | 1,668,343,838 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 140 | 9,011,200 | from sys import stdin
input=lambda :stdin.readline()[:-1]
class segtree():
def __init__(self,init,func,ide):
self.n=len(init)
self.func=func
self.ide=ide
self.size=1<<(self.n-1).bit_length()
self.tree=[self.ide for i in range(2*self.size)]
for i in range(self.n):
self.tree[se... | Title: Radio stations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the lattice points of the coordinate line there are *n* radio stations, the *i*-th of which is described by three integers:
- *x**i* — the coordinate of the *i*-th station on the line, - *r**i* — the broadcasting r... | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
class segtree():
def __init__(self,init,func,ide):
self.n=len(init)
self.func=func
self.ide=ide
self.size=1<<(self.n-1).bit_length()
self.tree=[self.ide for i in range(2*self.size)]
for i in range(self.n):
se... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
265 | B | Roadside Trees (Simplified Edition) | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees.
Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*. | Print a single integer — the minimal time required to eat all nuts in seconds. | [
"2\n1\n2\n",
"5\n2\n1\n2\n1\n1\n"
] | [
"5\n",
"14\n"
] | none | 1,000 | [
{
"input": "2\n1\n2",
"output": "5"
},
{
"input": "5\n2\n1\n2\n1\n1",
"output": "14"
},
{
"input": "1\n1",
"output": "2"
}
] | 1,611,414,013 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | n=int(input())
count=0
h=int(input())
count=h+1
while(n>1):
n-=1
h1=int(input())
if(h>h1):
count+=h-h1
h=h-h1
count+=1
count+=h1-h
count+=1
h=h1
print(count)
| Title: Roadside Trees (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan... | ```python
n=int(input())
count=0
h=int(input())
count=h+1
while(n>1):
n-=1
h1=int(input())
if(h>h1):
count+=h-h1
h=h-h1
count+=1
count+=h1-h
count+=1
h=h1
print(count)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,623,296,813 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 77 | 0 | n, t, k, d = list(map(int, input().split()))
time_One_Oven = n // k * t if n % k == 0 else (n // k + 1) * t
time_Two_Oven = 0
cakes = 0
delta_t = [0, d]
while cakes < n:
if delta_t[0] < delta_t[1]:
delta_t[0] += t
time_Two_Oven = delta_t[0]
cakes += k
if delta_t[1] < delta_t[0]:
... | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
n, t, k, d = list(map(int, input().split()))
time_One_Oven = n // k * t if n % k == 0 else (n // k + 1) * t
time_Two_Oven = 0
cakes = 0
delta_t = [0, d]
while cakes < n:
if delta_t[0] < delta_t[1]:
delta_t[0] += t
time_Two_Oven = delta_t[0]
cakes += k
if delta_t[1] < delta_t[... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,585,332,217 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s1 = str(input())
s2 = str(input())
s3 = s2[::-1]
flag = 0
for i in range(len(s1)):
if(s1[i] != s3[i]):
flag = 1
break
if(flag == 1 or len(s1)!=len(s2)):
print("NO")
else:
print("YES")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s1 = str(input())
s2 = str(input())
s3 = s2[::-1]
flag = 0
for i in range(len(s1)):
if(s1[i] != s3[i]):
flag = 1
break
if(flag == 1 or len(s1)!=len(s2)):
print("NO")
else:
print("YES")
``` | 3.9455 | MatrixStudio/Codeforces-Python-Submissions |
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,688,038,652 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | l=[int(x) for x in input().split()]
m=l[0]
n=l[1]
if (m*n)%2==0:
print(int((m*n)/2))
else:
print(int((m*n-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
l=[int(x) for x in input().split()]
m=l[0]
n=l[1]
if (m*n)%2==0:
print(int((m*n)/2))
else:
print(int((m*n-1)/2))
``` | 3.969 | MatrixStudio/Codeforces-Python-Submissions |
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,618,207,757 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 0 | M,N=map(int,input().split())
S=M*N
a=S//2
count=a
print(count) | 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=map(int,input().split())
S=M*N
a=S//2
count=a
print(count)
``` | 3.9615 | MatrixStudio/Codeforces-Python-Submissions |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,686,078,833 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 122 | 0 | s = input().lower()
vowels = 'aeiouy'
consonants = 'bcdfghjklmnpqrstvwxz'
for i in range(len(s) - 1, -1, -1):
if s[i] in vowels:
print('YES')
break
elif s[i] in consonants:
print('NO')
break | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s = input().lower()
vowels = 'aeiouy'
consonants = 'bcdfghjklmnpqrstvwxz'
for i in range(len(s) - 1, -1, -1):
if s[i] in vowels:
print('YES')
break
elif s[i] in consonants:
print('NO')
break
``` | 3.9695 | MatrixStudio/Codeforces-Python-Submissions |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,662,970,859 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 404 | 13,926,400 | from fractions import Fraction
a, b = map(int, input().split())
c = max(a, b)
d = 6 - c + 1
e = (Fraction(d , 6))
if e == 1:
print("1/1")
elif e == 0:
print("0/1")
else:
print(e) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
a, b = map(int, input().split())
c = max(a, b)
d = 6 - c + 1
e = (Fraction(d , 6))
if e == 1:
print("1/1")
elif e == 0:
print("0/1")
else:
print(e)
``` | 3.69424 | MatrixStudio/Codeforces-Python-Submissions |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,596,172,542 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 372 | 22,425,600 | x=input()
t=0
while x>9:
x=sum(map(int,str(x)))
t=t+1
print(t) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
x=input()
t=0
while x>9:
x=sum(map(int,str(x)))
t=t+1
print(t)
``` | -1 | MatrixStudio/Codeforces-Python-Submissions |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,603,990,384 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 686 | 52,326,400 | '''input
()))()(())
'''
s = input().lstrip(')')
max_len = 0
num_max = 1
count = 0
start_pos = {}
for i, c in enumerate(s):
if c == '(':
count += 1
if count not in start_pos:
start_pos[count] = i
else:
count -= 1
if count < 0:
count = 0
start_p... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
'''input
()))()(())
'''
s = input().lstrip(')')
max_len = 0
num_max = 1
count = 0
start_pos = {}
for i, c in enumerate(s):
if c == '(':
count += 1
if count not in start_pos:
start_pos[count] = i
else:
count -= 1
if count < 0:
count = 0
... | 3.731034 | MatrixStudio/Codeforces-Python-Submissions |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,496,384,272 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | s=input()
num=0
p=0
for i in range(len(s)-1):
if s[i]=='V' and s[i+1]=='K':
num += 1
if s[i]=='V' and s[i+1]=='V':
p = 1
print(num+p)
| Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s=input()
num=0
p=0
for i in range(len(s)-1):
if s[i]=='V' and s[i+1]=='K':
num += 1
if s[i]=='V' and s[i+1]=='V':
p = 1
print(num+p)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,502,119,471 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 4,608,000 | n = int(input())
a = [i for i in input().split()]
ans = 0
cnt = 0
for i in a:
for j in i:
if j >= 'A' and j <= 'Z':
cnt += 1
ans = max(ans, cnt)
cnt = 0
print(ans) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
a = [i for i in input().split()]
ans = 0
cnt = 0
for i in a:
for j in i:
if j >= 'A' and j <= 'Z':
cnt += 1
ans = max(ans, cnt)
cnt = 0
print(ans)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
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,694,179,728 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | a = int(input())
k = 0
if a % 2 == 0 and a != 2:
k = 1
if k == 1:
print("YES")
if k == 0:
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
a = int(input())
k = 0
if a % 2 == 0 and a != 2:
k = 1
if k == 1:
print("YES")
if k == 0:
print("NO")
``` | 3.954 | MatrixStudio/Codeforces-Python-Submissions |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,633,966,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 6,963,200 | s = input().strip()
ob, cb = [], []
if len(set(s)) == 1:
print("Impossible")
else:
for b in s:
if b == "{" or b == "[" or b == "<" or b == "(":
ob.append(b)
elif b == "}" or b == "]" or b == ">" or b == ")":
if (ob[-1] == "[" and b == "]") or (ob[-1] == "<" and b == ">") or (ob[-1] == "(" and b == ")") or ... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
s = input().strip()
ob, cb = [], []
if len(set(s)) == 1:
print("Impossible")
else:
for b in s:
if b == "{" or b == "[" or b == "<" or b == "(":
ob.append(b)
elif b == "}" or b == "]" or b == ">" or b == ")":
if (ob[-1] == "[" and b == "]") or (ob[-1] == "<" and b == ">") or (ob[-1] == "(" and b ==... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
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,619,181,598 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l=[];for _ in ' '*int(input()): l.append(input())
if(len(set(l))==2 and l.count(l[0])==n//2):print("YES\n"+list(set(l))[0],list(set(l))[1])
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
l=[];for _ in ' '*int(input()): l.append(input())
if(len(set(l))==2 and l.count(l[0])==n//2):print("YES\n"+list(set(l))[0],list(set(l))[1])
else:print("NO")
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
771 | B | Bear and Different Names | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy"
] | null | null | In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).
A group of soldiers is effective if and only if their names... | The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively.
The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k... | Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.
... | [
"8 3\nNO NO YES YES YES NO\n",
"9 8\nYES NO\n",
"3 2\nNO NO\n"
] | [
"Adam Bob Bob Cpqepqwer Limak Adam Bob Adam",
"R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc",
"Na Na Na"
] | In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:
- First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</... | 500 | [
{
"input": "8 3\nNO NO YES YES YES NO",
"output": "Ab Ac Ab Ac Af Ag Ah Ag "
},
{
"input": "9 8\nYES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Ac "
},
{
"input": "3 2\nNO NO",
"output": "Ab Ab Ab "
},
{
"input": "2 2\nYES",
"output": "Ab Ac "
},
{
"input": "2 2\nNO"... | 1,587,991,981 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define sll set<ll>
#define str string
#define rev reverse
#define mp make_pair
#define pb push_back
#define acc accumulate
#define vll vector<ll>
#define eb emplace_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define... | Title: Bear and Different Names
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an orde... | ```python
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define sll set<ll>
#define str string
#define rev reverse
#define mp make_pair
#define pb push_back
#define acc accumulate
#define vll vector<ll>
#define eb emplace_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll>... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
784 | C | INTERCALC | PROGRAMMING | 1,800 | [
"*special",
"implementation"
] | null | null | DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I M... | The first line of input data contains a single integer *n* (1<=≤<=*n*<=≤<=10).
The second line of input data contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=11). | Output a single integer. | [
"4\n2 5 3 1\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "4\n2 5 3 1",
"output": "4"
},
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "1\n8",
"output": "0"
},
{
"input": "6\n1 1 1 3 2 9",
"output": "0"
},
{
"input": "5\n8 9 3 1 9",
"output": "0"
},
{
"input": "6\n1 5 2 1 7 11",
"output": "0... | 1,645,874,809 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,maxx=INT_MIN,x;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
maxx=max(maxx,x);
}
cout<<(maxx^x)<<endl;
return 0;
}
| Title: INTERCALC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO ... | ```python
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,maxx=INT_MIN,x;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
maxx=max(maxx,x);
}
cout<<(maxx^x)<<endl;
return 0;
}
``` | -1 | MatrixStudio/Codeforces-Python-Submissions | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,599,657,526 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 0 | s=str(input())
c=s
best=0;a=0;ans=0
for i in range(len(s)):
c=s[:i]+s[i+1:]
a=0
for x in range(len(c)):
a+=(2**(len(c)-x-1) * int(c[x]))
if a>best:
ans=c
best=a
print(ans)
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s=str(input())
c=s
best=0;a=0;ans=0
for i in range(len(s)):
c=s[:i]+s[i+1:]
a=0
for x in range(len(c)):
a+=(2**(len(c)-x-1) * int(c[x]))
if a>best:
ans=c
best=a
print(ans)
``` | 0 | MatrixStudio/Codeforces-Python-Submissions | |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,573,848,794 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 140 | 1,945,600 | n, m = map(int, input().split())
mat = list()
for i in range(n):
mat.append(list())
s = input()
for j in range(m):
mat[i].append(int(s[j]))
ans = set()
for i in range(m):
temp = -1
for j in range(n):
temp = max(temp, mat[j][i])
for j in range(n):
if mat[j][i]... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
n, m = map(int, input().split())
mat = list()
for i in range(n):
mat.append(list())
s = input()
for j in range(m):
mat[i].append(int(s[j]))
ans = set()
for i in range(m):
temp = -1
for j in range(n):
temp = max(temp, mat[j][i])
for j in range(n):
if... | 3 | MatrixStudio/Codeforces-Python-Submissions | |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,617,982,803 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | n = int(input())
t = int(input())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
for i in range(n-1,1,-1):
p,q = a[i][0],a[i][1]
r,s = (7-p),(7-q)
l = [p,q,r,s]
if a[i-1][0] in l:
if a[i-1][1] in l:
print('YES')
exit()
print('NO'... | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
n = int(input())
t = int(input())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
for i in range(n-1,1,-1):
p,q = a[i][0],a[i][1]
r,s = (7-p),(7-q)
l = [p,q,r,s]
if a[i-1][0] in l:
if a[i-1][1] in l:
print('YES')
exit()
... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,648,696,396 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # coding=utf-8
x=input()
a=x.find('h')
b=x.find('e')
c=x.find('l')
d=x.find('o')
if a!=0 and b!=0 and c>=2 and d!=0 and a<b<c<d:
print('Yes')
else:
print('No')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
# coding=utf-8
x=input()
a=x.find('h')
b=x.find('e')
c=x.find('l')
d=x.find('o')
if a!=0 and b!=0 and c>=2 and d!=0 and a<b<c<d:
print('Yes')
else:
print('No')
``` | 0 | MatrixStudio/Codeforces-Python-Submissions |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,609,257,867 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 409,600 | from collections import Counter
n = int(input())
c = Counter(input().split())
one = c['1']
two = c['2']
f = c['4']
th = c['3']
si = c['6']
if '5' not in c and '7' not in c and one>=two and two>=f and one>=th and th<=si and one>=two and two>=si and c['1']>=c['2'] and len(c)>2 and c['1']==n//3 and c['4']<=c['2']... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
from collections import Counter
n = int(input())
c = Counter(input().split())
one = c['1']
two = c['2']
f = c['4']
th = c['3']
si = c['6']
if '5' not in c and '7' not in c and one>=two and two>=f and one>=th and th<=si and one>=two and two>=si and c['1']>=c['2'] and len(c)>2 and c['1']==n//3 and c['4... | 0 | MatrixStudio/Codeforces-Python-Submissions | |
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ... | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n*... | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. I... | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3... | 1,658,743,989 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 6,348,800 | n,k=map(int,input().split())
l=list(map(int,input().split()))
mn=10000000000
idx=0
for i in range(k):
x=0
for j in range(i,n,k):
x+=l[j]
if x<mn:idx=i;mn=x
print(idx+1) | Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything h... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
mn=10000000000
idx=0
for i in range(k):
x=0
for j in range(i,n,k):
x+=l[j]
if x<mn:idx=i;mn=x
print(idx+1)
``` | 3 | MatrixStudio/Codeforces-Python-Submissions | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,482,192,813 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | import numpy as np
n = int(input())
g = input()
if n % 4 == 0:
thr = n/4
gnome = np.array(list(g))
na = sum(gnome == 'A')
nc = sum(gnome == 'C')
ng = sum(gnome == 'G')
nt = sum(gnome == 'T')
if na > thr or nc > thr or ng > thr or nt > thr:
print('===')
else:
... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
import numpy as np
n = int(input())
g = input()
if n % 4 == 0:
thr = n/4
gnome = np.array(list(g))
na = sum(gnome == 'A')
nc = sum(gnome == 'C')
ng = sum(gnome == 'G')
nt = sum(gnome == 'T')
if na > thr or nc > thr or ng > thr or nt > thr:
print('===')
els... | -1 | MatrixStudio/Codeforces-Python-Submissions | |
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8... | 1,594,353,321 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 966 | 6,963,200 | n, m, k, t = map(int, input().split())
waste = []
for i in range(k):
r, c = map(int, input().split())
waste.append((r-1)*m+c-1)
waste.sort()
plant = ['Carrots', 'Kiwis', 'Grapes']
for i in range(t):
count = 0
r, c = map(int, input().split())
num = (r-1)*m + c-1
crop = True
for j in range(k):
if waste[j] > n... | Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
... | ```python
n, m, k, t = map(int, input().split())
waste = []
for i in range(k):
r, c = map(int, input().split())
waste.append((r-1)*m+c-1)
waste.sort()
plant = ['Carrots', 'Kiwis', 'Grapes']
for i in range(t):
count = 0
r, c = map(int, input().split())
num = (r-1)*m + c-1
crop = True
for j in range(k):
if wa... | 3.74553 | MatrixStudio/Codeforces-Python-Submissions |
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,671,991,798 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 122 | 0 | n1=input()
n2=n1[::-1]
t1=input()
t2=input()
if len(t1)+len(t2)<=len(n1):
if t1 in n1 and t2 in n1 and t1 in n2 and t2 in n2 and n1.index(t1)<len(n1)-n2.index(t2) and n2.index(t1)<len(n2)-n1.index(t2):
print("both")
elif t1 in n1 and t2 in n1 and n1.index(t1)<len(n1)-n2.index(t2):
print(... | 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
n1=input()
n2=n1[::-1]
t1=input()
t2=input()
if len(t1)+len(t2)<=len(n1):
if t1 in n1 and t2 in n1 and t1 in n2 and t2 in n2 and n1.index(t1)<len(n1)-n2.index(t2) and n2.index(t1)<len(n2)-n1.index(t2):
print("both")
elif t1 in n1 and t2 in n1 and n1.index(t1)<len(n1)-n2.index(t2):
... | 0 | MatrixStudio/Codeforces-Python-Submissions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.